From 7305391b6d3f963c0b003b410c214ec7013d441c Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Sat, 18 Dec 2010 17:18:36 +0000 Subject: [PATCH] Unit commanding via minimap --- source/glest_game/game/game.cpp | 28 +++++++++++++++++++++----- source/glest_game/gui/gui.cpp | 35 +++++++++++++++++++++++++-------- source/glest_game/gui/gui.h | 8 +++++--- 3 files changed, 55 insertions(+), 16 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 0cad9460..45105bac 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -926,14 +926,18 @@ void Game::mouseDownLeft(int x, int y){ //minimap panel if(messageBoxClick == false) { - if(metrics.isInMinimap(x, y) && !gui.isSelectingPos()){ + if(metrics.isInMinimap(x, y)){ int xm= x - metrics.getMinimapX(); int ym= y - metrics.getMinimapY(); int xCell= static_cast(xm * (static_cast(map->getW()) / metrics.getMinimapW())); int yCell= static_cast(map->getH() - ym * (static_cast(map->getH()) / metrics.getMinimapH())); if(map->isInside(xCell, yCell)){ - if(!gui.isSelectingPos()){ + if(gui.isSelectingPos()){ + gui.mouseDownLeftGraphics(xCell, yCell, true); + } + else + { gameCamera.setPos(Vec2f(static_cast(xCell), static_cast(yCell))); } } @@ -947,13 +951,13 @@ void Game::mouseDownLeft(int x, int y){ gui.mouseDownLeftDisplay(xd, yd); } else{ - gui.mouseDownLeftGraphics(x, y); + gui.mouseDownLeftGraphics(x, y, false); } } //graphics panel else{ - gui.mouseDownLeftGraphics(x, y); + gui.mouseDownLeftGraphics(x, y, false); } } @@ -998,7 +1002,21 @@ void Game::mouseDownLeft(int x, int y){ void Game::mouseDownRight(int x, int y){ try { - gui.mouseDownRightGraphics(x, y); + Map *map= world.getMap(); + const Metrics &metrics= Metrics::getInstance(); + + if(metrics.isInMinimap(x, y) ){ + int xm= x - metrics.getMinimapX(); + int ym= y - metrics.getMinimapY(); + int xCell= static_cast(xm * (static_cast(map->getW()) / metrics.getMinimapW())); + int yCell= static_cast(map->getH() - ym * (static_cast(map->getH()) / metrics.getMinimapH())); + + if(map->isInside(xCell, yCell)){ + gui.mouseDownRightGraphics(xCell, yCell,true); + } + } + else + gui.mouseDownRightGraphics(x, y,false); } catch(const exception &ex) { SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index c1a26fa6..c12235c9 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -206,7 +206,7 @@ void Gui::mouseMoveDisplay(int x, int y){ computeInfoString(computePosDisplay(x, y)); } -void Gui::mouseDownLeftGraphics(int x, int y){ +void Gui::mouseDownLeftGraphics(int x, int y, bool prepared){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); @@ -214,7 +214,7 @@ void Gui::mouseDownLeftGraphics(int x, int y){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectingPos == true\n",__FILE__,__FUNCTION__); //give standard orders - giveTwoClickOrders(x, y); + giveTwoClickOrders(x, y, prepared); resetState(); } //set meeting point @@ -246,7 +246,7 @@ void Gui::mouseDownLeftGraphics(int x, int y){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] END\n",__FILE__,__FUNCTION__); } -void Gui::mouseDownRightGraphics(int x, int y){ +void Gui::mouseDownRightGraphics(int x, int y , bool prepared){ //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); @@ -254,7 +254,12 @@ void Gui::mouseDownRightGraphics(int x, int y){ resetState(); } else if(selection.isComandable()){ - giveDefaultOrders(x, y); + if(prepared){ + givePreparedDefaultOrders(x, y); + } + else{ + giveDefaultOrders(x, y); + } } computeDisplay(); @@ -399,8 +404,16 @@ void Gui::giveDefaultOrders(int x, int y){ console->addStdMessage("InvalidPosition"); return; } + giveDefaultOrders(targetPos.x,targetPos.y,targetUnit); +} +void Gui::givePreparedDefaultOrders(int x, int y){ + giveDefaultOrders(x, y, NULL); +} + +void Gui::giveDefaultOrders(int x, int y,const Unit *targetUnit){ bool queueKeyDown = isKeyDown(queueCommandKey); + Vec2i targetPos=Vec2i(x, y); //give order CommandResult result= commander->tryGiveCommand(&selection, targetPos, targetUnit, queueKeyDown); @@ -421,16 +434,22 @@ void Gui::giveDefaultOrders(int x, int y){ resetState(); } -void Gui::giveTwoClickOrders(int x, int y){ +void Gui::giveTwoClickOrders(int x, int y , bool prepared){ CommandResult result; //compute target const Unit *targetUnit= NULL; Vec2i targetPos; - if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){ - console->addStdMessage("InvalidPosition"); - return; + if(prepared){ + targetPos=Vec2i(x, y); + } + else + { + if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){ + console->addStdMessage("InvalidPosition"); + return; + } } bool queueKeyDown = isKeyDown(queueCommandKey); diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 311383c4..91eb9ba2 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -167,8 +167,8 @@ public: bool mouseValid(int x, int y); void mouseDownLeftDisplay(int x, int y); void mouseMoveDisplay(int x, int y); - void mouseDownLeftGraphics(int x, int y); - void mouseDownRightGraphics(int x, int y); + void mouseDownLeftGraphics(int x, int y, bool prepared); + void mouseDownRightGraphics(int x, int y, bool prepared); void mouseUpLeftGraphics(int x, int y); void mouseMoveGraphics(int x, int y); void mouseDoubleClickLeftGraphics(int x, int y); @@ -183,8 +183,10 @@ private: //orders void giveDefaultOrders(int x, int y); + void giveDefaultOrders(int x, int y, const Unit *targetUnit); + void givePreparedDefaultOrders(int x, int y); void giveOneClickOrders(); - void giveTwoClickOrders(int x, int y); + void giveTwoClickOrders(int x, int y, bool prepared); //hotkeys void centerCameraOnSelection();