// 做画矩形的鼠标按下操作
	void CEventAreaEditAction::DoDrawLBnDown(const Point& pt)
	{
		

		Ogre::Vector3 TerrainPosition;
		if(GetTerrainPos(pt, TerrainPosition))
		{

			if(m_pCurOperatorRect)
			{
				m_pCurOperatorRect->m_pRectRenderShape->setMaterial("Core/StatsBlockCenter");//fujia EventAreaEdit/UnSelectRect
			}

			m_iEditRectId++;
			m_PrePoint = TerrainPosition;
			m_CurPoint = TerrainPosition;
			m_CurPoint.x += 100;
			m_CurPoint.z += 100;
			NormalRect();
			
			CEventAreaInfo* pRectInfo = new CEventAreaInfo;
			pRectInfo->m_iEventAreaId = m_iCurEditEventAreaId;
			pRectInfo->m_iScriptId    = m_iCurEditScriptid;
			pRectInfo->m_iId          = m_iEditRectId;
			m_pCurOperatorRect        = pRectInfo;

			if(m_pCurOperatorRect)
			{
				m_pCurOperatorRect->m_rect = m_AreaRect;
				//m_pCurOperatorRect->m_rect.m_LeftTop.x = m_AreaRect.m_LeftTop.x;
				//m_pCurOperatorRect->m_rect.m_LeftTop.y = m_AreaRect.m_LeftTop.y;
				//m_pCurOperatorRect->m_rect.m_RightBottom.x = m_AreaRect.m_RightBottom.x;
				//m_pCurOperatorRect->m_rect.m_RightBottom.y = m_AreaRect.m_RightBottom.y;//
			}

			m_RectShowMap[m_iEditRectId] = pRectInfo;

			// 创建显示的数据
			pRectInfo->SetParentSceneNode(m_pSceneNode);
			pRectInfo->SetSceneManipulator(getSceneManipulator());
			pRectInfo->CreateSceneNode();

			// 要创建渲染缓冲区不然在, release下回出现问题.
			
			pRectInfo->CreateRenderShape();
			BuildEventAreaRect();
			pRectInfo->m_pRectRenderShape->SetShapeType(Ogre::RenderOperation::OT_TRIANGLE_LIST);

			getSceneManipulator()->_fireAddNewRect(0, m_iEditRectId);

		}
	}
Ejemplo n.º 2
0
	void CEventAreaEditAction::_readAreaFromSingleFile(const std::string& fileName, bool bLocal)
	{
		char bufInfo[1024];
		memset(bufInfo, 0, sizeof(bufInfo));

		// 读取区域的个数
		int iRectCount = 0;
		iRectCount = ::GetPrivateProfileInt("area_info", "area_count",  0, fileName.c_str());
		

		///////////////////////////////////////////////////////////////////////////////////////////////
		// 保存把场景坐标转换成游戏逻辑坐标.
		float fScale = 0;
		float fTerrainDataPosX = getTerrainData()->mPosition.x;
		float fTerrainDataPosZ = getTerrainData()->mPosition.z;
		if(getSceneManipulator())
		{
			fScale = getSceneManipulator()->getBaseScale();
			if(abs((float)fScale) < 0.00001)
			{
				fScale = 1.0;
			}
		}


		char bufPosInfo[1024];
		int iEventRectIndex = 0;
		CEventAreaInfo* pEventAreaInfo = NULL;

		float fx = 0;
		m_iMaxEventAreaId = 0;
		for(int i = 0; i < iRectCount; i++)
		{
			pEventAreaInfo = new CEventAreaInfo;
			if(pEventAreaInfo)
			{
				pEventAreaInfo->m_iId = i;
				memset(bufInfo, 0, sizeof(bufInfo));
				sprintf(bufInfo, "area%d", i);
			
				// 事件区域id
				pEventAreaInfo->m_iEventAreaId = GetPrivateProfileInt(bufInfo, "guid", 0, fileName.c_str());
			
				// 脚本id
				pEventAreaInfo->m_iScriptId = GetPrivateProfileInt(bufInfo, "script_id", 0, fileName.c_str());
			

				// 记录矩形区域位置
				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "left",  "none", bufPosInfo, sizeof(bufPosInfo), fileName.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosX;
				pEventAreaInfo->m_rect.m_LeftTop.x = fx;

				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "top",  "none", bufPosInfo, sizeof(bufPosInfo), fileName.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosZ;
				pEventAreaInfo->m_rect.m_LeftTop.y = fx;
			

				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "right",  "none", bufPosInfo, sizeof(bufPosInfo), fileName.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosX;
				pEventAreaInfo->m_rect.m_RightBottom.x = fx;
			

				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "bottom",  "none", bufPosInfo, sizeof(bufPosInfo), fileName.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosZ;
				pEventAreaInfo->m_rect.m_RightBottom.y = fx;

				// Params
				int count = 0;
				for (int index = 0; index<10; ++index)
				{					
					memset(bufPosInfo, 0, sizeof(bufPosInfo));
					char temp[24];
					memset(temp, 0, sizeof(temp));
					sprintf(temp, "param_%d", index);
					::GetPrivateProfileString(bufInfo, temp,  "none", bufPosInfo, sizeof(bufPosInfo), fileName.c_str());

					char* params = bufPosInfo;
					Ogre::String paramVec(params);
					Ogre::StringVector vec = Ogre::StringUtil::split(paramVec);
					if ((int)vec.size()>1)
					{
						pEventAreaInfo->m_paramsName[count] = vec[0];
						pEventAreaInfo->m_paramsValue[count] = vec[1];
						count++;
					}
				}

				// 保存信息
			
				bLocal?(m_LocalRectShowMap[i] = pEventAreaInfo):(m_RectShowMap[i] = pEventAreaInfo);						

				// 读取id
				//m_iCurEditEventAreaId = pEventAreaInfo->m_iEventAreaId;
				//m_iCurEditScriptid    = pEventAreaInfo->m_iScriptId;

			

				// 设置当前的最大eventid
				if (bLocal)
				{
					m_iLocalEditRectId = i;

					if(m_iMaxLocalEventAreaId < m_iCurEditEventAreaId)
					{
						m_iMaxLocalEventAreaId = m_iCurEditEventAreaId;
					}
				}
				else
				{
					// 设置当前编辑的矩形id
					m_iEditRectId = i;

					if(m_iMaxEventAreaId < m_iCurEditEventAreaId)
					{
						m_iMaxEventAreaId = m_iCurEditEventAreaId;
					}
				}
				
				// 创建显示的数据
				pEventAreaInfo->SetParentSceneNode(bLocal?m_pLocalSceneNode:m_pSceneNode);
				pEventAreaInfo->SetSceneManipulator(getSceneManipulator());
				pEventAreaInfo->CreateSceneNode();
				pEventAreaInfo->CreateRenderShape();
				pEventAreaInfo->m_pRectRenderShape->SetShapeType(Ogre::RenderOperation::OT_TRIANGLE_LIST);
				
				m_pCurOperatorRect = pEventAreaInfo;

				m_PrePoint.x  = pEventAreaInfo->m_rect.m_LeftTop.x;
				m_PrePoint.z = pEventAreaInfo->m_rect.m_LeftTop.y;

				m_CurPoint.x =  pEventAreaInfo->m_rect.m_RightBottom.x;
				m_CurPoint.z =  pEventAreaInfo->m_rect.m_RightBottom.y;
				NormalRect();
				BuildEventAreaRect();
				m_pCurOperatorRect->m_pRectRenderShape->setMaterial("Core/StatsBlockCenter");//fujia EventAreaEdit/UnSelectRect
										
			}
		}
	}
Ejemplo n.º 3
0
	// 添加一个矩形.
	int CEventAreaEditAction::AddRect(Ogre::Vector3 vectorUnDoPos, Ogre::Vector3 vectorReDoPos, Ogre::StringVector nameVector, Ogre::StringVector valueVector, int iId, bool bLocal)
	{
		int iReturnId= 0;
		if(-1 == iId)
		{
			int rect = bLocal?(++m_iLocalEditRectId):(++m_iEditRectId);
			m_PrePoint = vectorUnDoPos;
			m_CurPoint = vectorReDoPos;
			NormalRect();
			
			CEventAreaInfo* pRectInfo = new CEventAreaInfo;
			pRectInfo->m_iEventAreaId = m_iCurEditEventAreaId;
			pRectInfo->m_iScriptId    = m_iCurEditScriptid;
			pRectInfo->m_iId          = rect;

			for (int index = 0; index<(int)nameVector.size(); ++index)
			{
				pRectInfo->m_paramsName[index] = nameVector[index];
				pRectInfo->m_paramsValue[index] = valueVector[index];
			}

			// 保存信息
			bLocal?(m_LocalRectShowMap[rect] = pRectInfo):(m_RectShowMap[rect]   = pRectInfo);
			
			m_pCurOperatorRect = pRectInfo;
		
			pRectInfo->m_rect = m_AreaRect;
			// 创建显示的数据
			pRectInfo->SetParentSceneNode(bLocal?m_pLocalSceneNode:m_pSceneNode);
			pRectInfo->SetSceneManipulator(getSceneManipulator());
			pRectInfo->CreateSceneNode();
			pRectInfo->CreateRenderShape();
			pRectInfo->m_pRectRenderShape->SetShapeType(Ogre::RenderOperation::OT_TRIANGLE_LIST);
			BuildEventAreaRect();
			m_pCurOperatorRect->m_pRectRenderShape->setMaterial("Core/StatsBlockCenter");//fujia EventAreaEdit/UnSelectRect
					
			iReturnId = rect;
			if (bLocal == m_bLocalArea)
			{
				getSceneManipulator()->_fireAddNewRect(0, iReturnId);
			}
			/*else
			{
				pRectInfo->m_pSceneNode->setVisible(false);
			}*/
		}
		else
		{
			m_PrePoint = vectorUnDoPos;
			m_CurPoint = vectorReDoPos;
			NormalRect();
			
			CEventAreaInfo* pRectInfo = new CEventAreaInfo;
			pRectInfo->m_iEventAreaId = m_iCurEditEventAreaId;
			pRectInfo->m_iScriptId    = m_iCurEditScriptid;
			pRectInfo->m_iId          = iId;

			for (int index = 0; index<(int)nameVector.size(); ++index)
			{
				pRectInfo->m_paramsName[index] = nameVector[index];
				pRectInfo->m_paramsValue[index] = valueVector[index];
			}

			// 保存信息		
			bLocal?(m_LocalRectShowMap[iId] = pRectInfo):(m_RectShowMap[iId] = pRectInfo);

			m_pCurOperatorRect = pRectInfo;
		
			pRectInfo->m_rect = m_AreaRect;
			// 创建显示的数据
			pRectInfo->SetParentSceneNode(bLocal?m_pLocalSceneNode:m_pSceneNode);
			pRectInfo->SetSceneManipulator(getSceneManipulator());
			pRectInfo->CreateSceneNode();
			pRectInfo->CreateRenderShape();
			pRectInfo->m_pRectRenderShape->SetShapeType(Ogre::RenderOperation::OT_TRIANGLE_LIST);
			BuildEventAreaRect();
			m_pCurOperatorRect->m_pRectRenderShape->setMaterial("Core/StatsBlockCenter");//fujia EventAreaEdit/UnSelectRect

			iReturnId = iId;
			if (bLocal == m_bLocalArea)
			{					
				getSceneManipulator()->_fireAddNewRect(0, iReturnId);
			}	
			/*else
			{
				pRectInfo->m_pSceneNode->setVisible(false);
			}*/
		}
			
		return iReturnId;

	}
	// 从区域读取文件
	unsigned long CEventAreaEditAction::ReadEventAreaFromFile(std::string strFileName)
	{

		// 清空矩形信息.
		ReleaseRectInfoMap();

		std::string strEventAreaFileIni = "";
		std::string strEventAreaFile    = "";

		strEventAreaFile    = strFileName;
		int iPos = strEventAreaFile.rfind(".");

		strEventAreaFileIni = strEventAreaFile.substr(0, iPos);
		strEventAreaFileIni += "_area.ini";

		char bufInfo[1024];
		memset(bufInfo, 0, sizeof(bufInfo));

		// 读取区域的个数
		int iRectCount = 0;
		iRectCount = ::GetPrivateProfileInt("area_info", "area_count",  0, strEventAreaFileIni.c_str());
		

		///////////////////////////////////////////////////////////////////////////////////////////////
		// 保存把场景坐标转换成游戏逻辑坐标.
		float fScale = 0;
		float fTerrainDataPosX = getTerrainData()->mPosition.x;
		float fTerrainDataPosZ = getTerrainData()->mPosition.z;
		if(getSceneManipulator())
		{
			fScale = getSceneManipulator()->getBaseScale();
			if(abs((float)fScale) < 0.00001)
			{
				fScale = 1.0;
			}
		}


		char bufPosInfo[1024];
		int iEventRectIndex = 0;
		CEventAreaInfo* pEventAreaInfo = NULL;

		float fx = 0;
		m_iMaxEventAreaId = 0;
		for(int i = 0; i < iRectCount; i++)
		{
			pEventAreaInfo = new CEventAreaInfo;
			if(pEventAreaInfo)
			{
				pEventAreaInfo->m_iId = i;
				memset(bufInfo, 0, sizeof(bufInfo));
				sprintf(bufInfo, "area%d", i);
			
				// 事件区域id
				pEventAreaInfo->m_iEventAreaId = GetPrivateProfileInt(bufInfo, "guid", 0, strEventAreaFileIni.c_str());
			
				// 脚本id
				pEventAreaInfo->m_iScriptId = GetPrivateProfileInt(bufInfo, "script_id", 0, strEventAreaFileIni.c_str());
			

				// 记录矩形区域位置
				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "left",  "none", bufPosInfo, sizeof(bufPosInfo), strEventAreaFileIni.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosX;
				pEventAreaInfo->m_rect.m_LeftTop.x = fx;

				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "top",  "none", bufPosInfo, sizeof(bufPosInfo), strEventAreaFileIni.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosZ;
				pEventAreaInfo->m_rect.m_LeftTop.y = fx;
			

				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "right",  "none", bufPosInfo, sizeof(bufPosInfo), strEventAreaFileIni.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosX;
				pEventAreaInfo->m_rect.m_RightBottom.x = fx;
			

				memset(bufPosInfo, 0, sizeof(bufPosInfo));
				::GetPrivateProfileString(bufInfo, "bottom",  "none", bufPosInfo, sizeof(bufPosInfo), strEventAreaFileIni.c_str());
				fx = atof(bufPosInfo);
				fx = fx * fScale + fTerrainDataPosZ;
				pEventAreaInfo->m_rect.m_RightBottom.y = fx;

				// 保存信息
				m_RectShowMap[i] = pEventAreaInfo;

				// 读取id
				//m_iCurEditEventAreaId = pEventAreaInfo->m_iEventAreaId;
				//m_iCurEditScriptid    = pEventAreaInfo->m_iScriptId;

				// 设置当前编辑的矩形id
				m_iEditRectId = i;

				// 设置当前的最大eventid
				if(m_iMaxEventAreaId < m_iCurEditEventAreaId)
				{
					m_iMaxEventAreaId = m_iCurEditEventAreaId;
				}

				
				// 创建显示的数据
				pEventAreaInfo->SetParentSceneNode(m_pSceneNode);
				pEventAreaInfo->SetSceneManipulator(getSceneManipulator());
				pEventAreaInfo->CreateSceneNode();
				pEventAreaInfo->CreateRenderShape();
				pEventAreaInfo->m_pRectRenderShape->SetShapeType(Ogre::RenderOperation::OT_TRIANGLE_LIST);
				
				m_pCurOperatorRect = pEventAreaInfo;

				m_PrePoint.x  = pEventAreaInfo->m_rect.m_LeftTop.x;
				m_PrePoint.z = pEventAreaInfo->m_rect.m_LeftTop.y;

				m_CurPoint.x =  pEventAreaInfo->m_rect.m_RightBottom.x;
				m_CurPoint.z =  pEventAreaInfo->m_rect.m_RightBottom.y;
				NormalRect();
				BuildEventAreaRect();
				m_pCurOperatorRect->m_pRectRenderShape->setMaterial("Core/StatsBlockCenter");//fujia EventAreaEdit/UnSelectRect
										
			}
		}

		HideScene(m_bIsShow);
		return 0;
	}
	// 添加一个矩形.
	int CEventAreaEditAction::AddRect(Ogre::Vector3 vectorUnDoPos, Ogre::Vector3 vectorReDoPos, int iId)
	{
		int iReturnId= 0;
		if(-1 == iId)
		{
			m_iEditRectId++;
			m_PrePoint = vectorUnDoPos;
			m_CurPoint = vectorReDoPos;
			NormalRect();
			
			CEventAreaInfo* pRectInfo = new CEventAreaInfo;
			pRectInfo->m_iEventAreaId = m_iCurEditEventAreaId;
			pRectInfo->m_iScriptId    = m_iCurEditScriptid;
			pRectInfo->m_iId          = m_iEditRectId;

			// 保存信息
			m_RectShowMap[m_iEditRectId]   = pRectInfo;
			m_pCurOperatorRect = pRectInfo;
		
			pRectInfo->m_rect = m_AreaRect;
			// 创建显示的数据
			pRectInfo->SetParentSceneNode(m_pSceneNode);
			pRectInfo->SetSceneManipulator(getSceneManipulator());
			pRectInfo->CreateSceneNode();
			pRectInfo->CreateRenderShape();
			pRectInfo->m_pRectRenderShape->SetShapeType(Ogre::RenderOperation::OT_TRIANGLE_LIST);
			BuildEventAreaRect();
			m_pCurOperatorRect->m_pRectRenderShape->setMaterial("Core/StatsBlockCenter");//fujia EventAreaEdit/UnSelectRect

			iReturnId = m_iEditRectId;
			getSceneManipulator()->_fireAddNewRect(0, iReturnId);
		}
		else
		{
			m_PrePoint = vectorUnDoPos;
			m_CurPoint = vectorReDoPos;
			NormalRect();
			
			CEventAreaInfo* pRectInfo = new CEventAreaInfo;
			pRectInfo->m_iEventAreaId = m_iCurEditEventAreaId;
			pRectInfo->m_iScriptId    = m_iCurEditScriptid;
			pRectInfo->m_iId          = iId;

			// 保存信息
			m_RectShowMap[m_iEditRectId]   = pRectInfo;
			m_pCurOperatorRect = pRectInfo;
		
			pRectInfo->m_rect = m_AreaRect;
			// 创建显示的数据
			pRectInfo->SetParentSceneNode(m_pSceneNode);
			pRectInfo->SetSceneManipulator(getSceneManipulator());
			pRectInfo->CreateSceneNode();
			pRectInfo->CreateRenderShape();
			pRectInfo->m_pRectRenderShape->SetShapeType(Ogre::RenderOperation::OT_TRIANGLE_LIST);
			BuildEventAreaRect();
			m_pCurOperatorRect->m_pRectRenderShape->setMaterial("Core/StatsBlockCenter");//fujia EventAreaEdit/UnSelectRect

			iReturnId = iId;
			getSceneManipulator()->_fireAddNewRect(0, iReturnId);
		}
			
		return iReturnId;

	}