|
|
|
@ -34,15 +34,18 @@ bool VirusAttack::OnUserCreate(){ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void VirusAttack::HandleDraggingSelection(){ |
|
|
|
|
auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);}; |
|
|
|
|
if(GetMouse(0).bPressed){ |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
u->Deselect(); |
|
|
|
|
} |
|
|
|
|
if(startingDragPos==CONSTANT::UNSELECTED){ |
|
|
|
|
startingDragPos=GetWorldMousePos(); |
|
|
|
|
if(NotClickingOnMinimap()){ |
|
|
|
|
for(auto&u:units){ |
|
|
|
|
u->Deselect(); |
|
|
|
|
} |
|
|
|
|
if(startingDragPos==CONSTANT::UNSELECTED){ |
|
|
|
|
startingDragPos=GetWorldMousePos(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(GetMouse(0).bReleased){ |
|
|
|
|
if(GetMouse(0).bReleased&&startingDragPos!=CONSTANT::UNSELECTED){ |
|
|
|
|
vf2d endDragPos=GetWorldMousePos(); |
|
|
|
|
if(endDragPos.x<startingDragPos.x){std::swap(startingDragPos.x,endDragPos.x);} |
|
|
|
|
if(endDragPos.y<startingDragPos.y){std::swap(startingDragPos.y,endDragPos.y);} |
|
|
|
@ -160,10 +163,18 @@ void VirusAttack::HandlePanAndZoom(float fElapsedTime){ |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void VirusAttack::HandleMinimapClick(){ |
|
|
|
|
if(startingDragPos==CONSTANT::UNSELECTED&&GetMouse(0).bHeld&&GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64){ |
|
|
|
|
vf2d minimapTL=GetScreenSize()-vf2d{64,64}; |
|
|
|
|
game.SetWorldOffset(vf2d(GetMousePos()-minimapTL)/64*CONSTANT::WORLD_SIZE*CONSTANT::TILE_SIZE-vf2d(GetScreenSize())/game.GetWorldScale()/2.f); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool VirusAttack::OnUserUpdate(float fElapsedTime){ |
|
|
|
|
HandleDraggingSelection(); |
|
|
|
|
HandleRightClickMove(); |
|
|
|
|
HandlePanAndZoom(fElapsedTime); |
|
|
|
|
HandleMinimapClick(); |
|
|
|
|
|
|
|
|
|
for(auto&u:units){ |
|
|
|
|
Unit*closestUnit=nullptr; |
|
|
|
|