Unit commanding via minimap
This commit is contained in:
parent
24a0eb31d8
commit
7305391b6d
|
@ -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<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)){
|
||||
if(!gui.isSelectingPos()){
|
||||
if(gui.isSelectingPos()){
|
||||
gui.mouseDownLeftGraphics(xCell, yCell, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
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);
|
||||
}
|
||||
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<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) {
|
||||
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,ex.what());
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue