void MapObject::OnControllerEvent(SControllerEvent Event) { float ax,ay,az,aw; Matrix MVP; int mx=0; int my=0; float fx=0; float fy=0; __INT32 distance=0; TowerObject* tower; if (Event.Type == ECE_POINTER) { switch (Event.PointerData.Event) { case EPE_PRESSED: isPressed = true; dragDistanceX = 0; dragDistanceY = 0; break; case EPE_DRAGGED: distance= dragDistanceX*dragDistanceX + dragDistanceY*dragDistanceY; if (distance>50) isDrag=true; break; case EPE_RELEASED: if (isPressed) { MVP.LoadIdentity(); MVP.Multiply(*(CCamera3D::GetInstance()->GetProjectMatrix())); MVP.Multiply(*(CCamera3D::GetInstance()->GetViewMatrix())); ScreenPos2MapPos(Event.PointerData.X,Event.PointerData.Y,MVP,fx,fy); mx = __INT32(fx/scale); my = __INT32(fy/scale); if ((!isDrag)/* && ((mLogicMap[my*mWidth+mx]==OBJECT_NONE) || (mLogicMap[my*mWidth+mx]==OBJECT_TOWER))*/) { if (mx>=0 && mx<mWidth &&my>=0 && my<mHeight) { if (mLogicMap[my*mWidth+mx]==OBJECT_NONE) //click len vung dat trong' { ScreenPos2TowerPos(Event.PointerData.X,Event.PointerData.Y,MVP,mx,my); Log("Logic map position: %d %d", mx, my); if ((mx<mWidth) && (my<mHeight) && (mx>=0) && (my>=0)) { if (selected == my * mWidth + mx) { selected =-1; drawRange = 0; CList<__INT32> NullList; UpdateTowerBuildBar(&NullList); return; } selected = my * mWidth + mx; if ((mLogicMap[selected]==OBJECT_NONE) && (mLogicMap[selected+1]==OBJECT_NONE) && (mLogicMap[selected+mWidth]==OBJECT_NONE) && (mLogicMap[selected+mWidth+1]==OBJECT_NONE) && CPathManagement::GetInstance()->IsStillExist(selected)) //Vung dat 2x2 trong' { CStateIngame::currentBuildBar->sellButton->SetVisible(false); //kiem tra so button xay tru can hien CStateIngame::currentBuildBar->Tower1->SetVisible(true); Log("Truoc calc boundary"); CalculateBoundary(mx, my, SELECTED_BUILDABLE_CELL_COLOR,0); Log("Sau calc boundary"); CList<__INT32> towerList;//sau nay de thong tin cac tower co the xay tu dat' trong vao day towerList.AddItem(TOWER_GUN); UpdateTowerBuildBar(&towerList); } else //2x2 khong trong' { CStateIngame::currentBuildBar->sellButton->SetVisible(false); CalculateBoundary(mx, my, SELECTED_UNBUILDABLE_CELL_COLOR,0); //an het cac button xay tru CStateIngame::currentBuildBar->Tower1->SetVisible(false); CStateIngame::currentBuildBar->Tower2->SetVisible(false); CStateIngame::currentBuildBar->Tower3->SetVisible(false); CStateIngame::currentBuildBar->Tower4->SetVisible(false); } } } else if(mLogicMap[my*mWidth+mx]==OBJECT_TOWER)//click len TOWER { CStateIngame::currentBuildBar->sellButton->SetVisible(true); tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx,my))); if (!tower) tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx-1,my))); if (!tower) tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx-1,my-1))); if (!tower) tower = (CObjectManagement::GetInstance()->GetTower(MapPosition(mx,my-1))); if (selected == tower->mPosition.mY * mWidth + tower->mPosition.mX) { selected =-1; drawRange = 0; CList<__INT32> NullList; UpdateTowerBuildBar(&NullList); return; } selected = tower->mPosition.mY * mWidth + tower->mPosition.mX; CalculateBoundary( tower->mPosition.mX, tower->mPosition.mY, SELECTED_TOWER_CELL_COLOR, tower->mProperties->mRange); UpdateTowerBuildBar(tower->mProperties->mLstChildren); } else //click len Enemy hoac tree { CStateIngame::currentBuildBar->sellButton->SetVisible(false); ScreenPos2TowerPos(Event.PointerData.X,Event.PointerData.Y,MVP,mx,my); CalculateBoundary(mx, my, SELECTED_UNBUILDABLE_CELL_COLOR,0); //an het cac button xay tru CStateIngame::currentBuildBar->Tower1->SetVisible(false); CStateIngame::currentBuildBar->Tower2->SetVisible(false); CStateIngame::currentBuildBar->Tower3->SetVisible(false); CStateIngame::currentBuildBar->Tower4->SetVisible(false); } } else selected = -1; } isPressed = false; } isDrag = false; break; } } }