Implemented zooming and minimap navigation.
This commit is contained in:
parent
ab6c43f347
commit
e632af5d58
@ -34,7 +34,9 @@ bool VirusAttack::OnUserCreate(){
|
||||
}
|
||||
|
||||
void VirusAttack::HandleDraggingSelection(){
|
||||
auto NotClickingOnMinimap=[&](){return !(GetMouseX()>=ScreenWidth()-64&&GetMouseY()>=ScreenHeight()-64);};
|
||||
if(GetMouse(0).bPressed){
|
||||
if(NotClickingOnMinimap()){
|
||||
for(auto&u:units){
|
||||
u->Deselect();
|
||||
}
|
||||
@ -42,7 +44,8 @@ void VirusAttack::HandleDraggingSelection(){
|
||||
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;
|
||||
|
@ -21,6 +21,7 @@ private:
|
||||
vf2d GetWorldMousePos();
|
||||
void HandlePanAndZoom(float fElapsedTime);
|
||||
void DrawMinimap();
|
||||
void HandleMinimapClick();
|
||||
|
||||
public:
|
||||
VirusAttack();
|
||||
|
Loading…
x
Reference in New Issue
Block a user