Unit commanding via minimap

This commit is contained in:
Titus Tscharntke
2010-12-18 17:18:36 +00:00
parent 24a0eb31d8
commit 7305391b6d
3 changed files with 55 additions and 16 deletions

View File

@@ -926,14 +926,18 @@ void Game::mouseDownLeft(int x, int y){
//minimap panel //minimap panel
if(messageBoxClick == false) { if(messageBoxClick == false) {
if(metrics.isInMinimap(x, y) && !gui.isSelectingPos()){ if(metrics.isInMinimap(x, y)){
int xm= x - metrics.getMinimapX(); int xm= x - metrics.getMinimapX();
int ym= y - metrics.getMinimapY(); int ym= y - metrics.getMinimapY();
int xCell= static_cast<int>(xm * (static_cast<float>(map->getW()) / metrics.getMinimapW())); int xCell= static_cast<int>(xm * (static_cast<float>(map->getW()) / metrics.getMinimapW()));
int yCell= static_cast<int>(map->getH() - ym * (static_cast<float>(map->getH()) / metrics.getMinimapH())); int yCell= static_cast<int>(map->getH() - ym * (static_cast<float>(map->getH()) / metrics.getMinimapH()));
if(map->isInside(xCell, yCell)){ if(map->isInside(xCell, yCell)){
if(!gui.isSelectingPos()){ if(gui.isSelectingPos()){
gui.mouseDownLeftGraphics(xCell, yCell, true);
}
else
{
gameCamera.setPos(Vec2f(static_cast<float>(xCell), static_cast<float>(yCell))); gameCamera.setPos(Vec2f(static_cast<float>(xCell), static_cast<float>(yCell)));
} }
} }
@@ -947,13 +951,13 @@ void Game::mouseDownLeft(int x, int y){
gui.mouseDownLeftDisplay(xd, yd); gui.mouseDownLeftDisplay(xd, yd);
} }
else{ else{
gui.mouseDownLeftGraphics(x, y); gui.mouseDownLeftGraphics(x, y, false);
} }
} }
//graphics panel //graphics panel
else{ 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){ void Game::mouseDownRight(int x, int y){
try { 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<int>(xm * (static_cast<float>(map->getW()) / metrics.getMinimapW()));
int yCell= static_cast<int>(map->getH() - ym * (static_cast<float>(map->getH()) / metrics.getMinimapH()));
if(map->isInside(xCell, yCell)){
gui.mouseDownRightGraphics(xCell, yCell,true);
}
}
else
gui.mouseDownRightGraphics(x, y,false);
} }
catch(const exception &ex) { catch(const exception &ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what()); SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());

View File

@@ -206,7 +206,7 @@ void Gui::mouseMoveDisplay(int x, int y){
computeInfoString(computePosDisplay(x, 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__); //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__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] selectingPos == true\n",__FILE__,__FUNCTION__);
//give standard orders //give standard orders
giveTwoClickOrders(x, y); giveTwoClickOrders(x, y, prepared);
resetState(); resetState();
} }
//set meeting point //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__); //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__); //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
@@ -254,7 +254,12 @@ void Gui::mouseDownRightGraphics(int x, int y){
resetState(); resetState();
} }
else if(selection.isComandable()){ else if(selection.isComandable()){
giveDefaultOrders(x, y); if(prepared){
givePreparedDefaultOrders(x, y);
}
else{
giveDefaultOrders(x, y);
}
} }
computeDisplay(); computeDisplay();
@@ -399,8 +404,16 @@ void Gui::giveDefaultOrders(int x, int y){
console->addStdMessage("InvalidPosition"); console->addStdMessage("InvalidPosition");
return; 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); bool queueKeyDown = isKeyDown(queueCommandKey);
Vec2i targetPos=Vec2i(x, y);
//give order //give order
CommandResult result= commander->tryGiveCommand(&selection, targetPos, targetUnit, queueKeyDown); CommandResult result= commander->tryGiveCommand(&selection, targetPos, targetUnit, queueKeyDown);
@@ -421,16 +434,22 @@ void Gui::giveDefaultOrders(int x, int y){
resetState(); resetState();
} }
void Gui::giveTwoClickOrders(int x, int y){ void Gui::giveTwoClickOrders(int x, int y , bool prepared){
CommandResult result; CommandResult result;
//compute target //compute target
const Unit *targetUnit= NULL; const Unit *targetUnit= NULL;
Vec2i targetPos; Vec2i targetPos;
if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){ if(prepared){
console->addStdMessage("InvalidPosition"); targetPos=Vec2i(x, y);
return; }
else
{
if(!computeTarget(Vec2i(x, y), targetPos, targetUnit)){
console->addStdMessage("InvalidPosition");
return;
}
} }
bool queueKeyDown = isKeyDown(queueCommandKey); bool queueKeyDown = isKeyDown(queueCommandKey);

View File

@@ -167,8 +167,8 @@ public:
bool mouseValid(int x, int y); bool mouseValid(int x, int y);
void mouseDownLeftDisplay(int x, int y); void mouseDownLeftDisplay(int x, int y);
void mouseMoveDisplay(int x, int y); void mouseMoveDisplay(int x, int y);
void mouseDownLeftGraphics(int x, int y); void mouseDownLeftGraphics(int x, int y, bool prepared);
void mouseDownRightGraphics(int x, int y); void mouseDownRightGraphics(int x, int y, bool prepared);
void mouseUpLeftGraphics(int x, int y); void mouseUpLeftGraphics(int x, int y);
void mouseMoveGraphics(int x, int y); void mouseMoveGraphics(int x, int y);
void mouseDoubleClickLeftGraphics(int x, int y); void mouseDoubleClickLeftGraphics(int x, int y);
@@ -183,8 +183,10 @@ private:
//orders //orders
void giveDefaultOrders(int x, int y); void giveDefaultOrders(int x, int y);
void giveDefaultOrders(int x, int y, const Unit *targetUnit);
void givePreparedDefaultOrders(int x, int y);
void giveOneClickOrders(); void giveOneClickOrders();
void giveTwoClickOrders(int x, int y); void giveTwoClickOrders(int x, int y, bool prepared);
//hotkeys //hotkeys
void centerCameraOnSelection(); void centerCameraOnSelection();