From ff9c9ad864b7b3e8a03f76e8888c0b733819b24a Mon Sep 17 00:00:00 2001 From: Rampoina Date: Fri, 15 Jul 2022 03:54:55 +0200 Subject: [PATCH 01/24] add hotkeybuild1 --- source/glest_game/gui/gui.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index ce6f79f6..f810d2b0 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -447,6 +447,19 @@ void Gui::hotKey(SDL_KeyboardEvent key) { else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) { clickCommonCommand(ccStop); } + + else if(isKeyPressed(configKeys.getSDLKey("HotKeyBuild1"),key) == true) { + const CommandType *ct; + for(int i=0; igetType()->getFirstCtOfClass(ccBuild); + if(ct != NULL) { + break; + } + } + clickCommonCommand(ct->getClass()); + } + } void Gui::switchToNextDisplayColor(){ From e9b771241fc6bec21ae111b19a7cae61d7d1ce3c Mon Sep 17 00:00:00 2001 From: Rampoina Date: Fri, 15 Jul 2022 18:40:16 +0200 Subject: [PATCH 02/24] Add building and unit hotkeys --- source/glest_game/gui/gui.cpp | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index f810d2b0..22a24911 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -408,22 +408,22 @@ void Gui::hotKey(SDL_KeyboardEvent key) { centerCameraOnSelection(); } //else if(key == configKeys.getCharKey("HotKeySelectIdleHarvesterUnit")) { - else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectIdleHarvesterUnit"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectIdleHarvesterUnit"),key) == true) { selectInterestingUnit(iutIdleHarvester); } //else if(key == configKeys.getCharKey("HotKeySelectBuiltBuilding")) { - else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectBuiltBuilding"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectBuiltBuilding"),key) == true) { selectInterestingUnit(iutBuiltBuilding); } //else if(key == configKeys.getCharKey("HotKeyDumpWorldToLog")) { - else if(isKeyPressed(configKeys.getSDLKey("HotKeyDumpWorldToLog"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeyDumpWorldToLog"),key) == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) { std::string worldLog = world->DumpWorldToLog(); SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str()); } } //else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){ - else if(isKeyPressed(configKeys.getSDLKey("HotKeyRotateUnitDuringPlacement"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeyRotateUnitDuringPlacement"),key) == true) { // Here the user triggers a unit rotation while placing a unit if(isPlacingBuilding()) { if(getBuilding()->getRotationAllowed()){ @@ -432,34 +432,32 @@ void Gui::hotKey(SDL_KeyboardEvent key) { } } //else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) { - else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectDamagedUnit"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectDamagedUnit"),key) == true) { selectInterestingUnit(iutDamaged); } //else if(key == configKeys.getCharKey("HotKeySelectStoreUnit")) { - else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) { selectInterestingUnit(iutStore); } //else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) { - else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) { clickCommonCommand(ccAttack); } //else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) { - else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) { clickCommonCommand(ccStop); } - else if(isKeyPressed(configKeys.getSDLKey("HotKeyBuild1"),key) == true) { - const CommandType *ct; - for(int i=0; igetType()->getFirstCtOfClass(ccBuild); - if(ct != NULL) { - break; + for (int i=0; i<10; i++) { + string name = "HotKeyBuild" + intToStr(i+1); + if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) { + if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { + mouseDownDisplayUnitBuild(i); + } else { + mouseDownDisplayUnitSkills(i); } } - clickCommonCommand(ct->getClass()); } - } void Gui::switchToNextDisplayColor(){ @@ -756,7 +754,7 @@ void Gui::mouseDownDisplayUnitBuild(int posDisplay) { activeCommandType->getClass() == ccBuild) { const BuildCommandType *bct = dynamic_cast(activeCommandType); - if(bct != NULL) { + if(bct != NULL && bct->getBuildingCount() > posDisplay) { const UnitType *ut = bct->getBuilding(posDisplay); const Unit *unit = selection.getFrontUnit(); From 5783db3033304bd432957a7e83b809d053bf4216 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Mon, 18 Jul 2022 19:09:07 +0200 Subject: [PATCH 03/24] Check the number of shared commands before trying to click from a hotkey --- source/glest_game/gui/gui.cpp | 6 +++++- source/glest_game/gui/gui.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 22a24911..e972dc32 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -97,6 +97,7 @@ Gui::Gui(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); lastGroupRecall = -1; + commonCommands=0; posObjWorld= Vec2i(54, 14); validPosObjWorld= false; activeCommandType= NULL; @@ -453,8 +454,10 @@ void Gui::hotKey(SDL_KeyboardEvent key) { if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) { if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { mouseDownDisplayUnitBuild(i); + break; } else { - mouseDownDisplayUnitSkills(i); + if (i < commonCommands) mouseDownDisplayUnitSkills(i); + break; } } } @@ -1056,6 +1059,7 @@ void Gui::computeDisplay(){ lastCommand++; } } + commonCommands = lastCommand; } } else if (activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index c9c8905c..bb5e15a8 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -124,6 +124,7 @@ private: CommandClass activeCommandClass; int activePos; int lastPosDisplay; + int commonCommands; //composite Display display; From f322a3ee52d2ceef70c2b93c949c81ad06106354 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Mon, 18 Jul 2022 19:24:11 +0200 Subject: [PATCH 04/24] Add command grid hotkeys to the default hotkeys --- mk/shared/glestkeys.ini | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mk/shared/glestkeys.ini b/mk/shared/glestkeys.ini index a3018425..28a21e9d 100644 --- a/mk/shared/glestkeys.ini +++ b/mk/shared/glestkeys.ini @@ -3,8 +3,8 @@ RenderInGamePerformance=` RenderNetworkStatus=N ShowFullConsole=M -Screenshot=E -FreeCameraMode=F +Screenshot=J +FreeCameraMode=Y ResetCameraMode=space CameraModeLeft=left CameraModeRight=right @@ -26,20 +26,30 @@ GroupUnitsKey7='6' GroupUnitsKey8='7' GroupUnitsKey9='8' GroupUnitsKey10='9' -CameraRotateLeft=A -CameraRotateRight=D +CameraRotateLeft=O +CameraRotateRight=P CameraRotateUp=S CameraRotateDown=W +HotKeyBuild1=Q +HotKeyBuild2=W +HotKeyBuild3=E +HotKeyBuild4=R +HotKeyBuild5=A +HotKeyBuild6=S +HotKeyBuild7=D +HotKeyBuild8=F +HotKeyBuild9=Z +HotKeyBuild10=X HotKeyCenterCameraOnSelection=G HotKeySelectIdleHarvesterUnit=I HotKeySelectBuiltBuilding=B HotKeyShowDebug=? HotKeyDumpWorldToLog=\ HotKeyRotateUnitDuringPlacement=R -HotKeySelectDamagedUnit=D +HotKeySelectDamagedUnit=U HotKeySelectStoreUnit=T -HotKeySelectedUnitsAttack=A -HotKeySelectedUnitsStop=S +HotKeySelectedUnitsAttack=I +HotKeySelectedUnitsStop=; HotKeyToggleOSMouseEnabled=/ ChatTeamMode=H ToggleHealthbars=# From 2cd190d822ef28f4cb8d24c24d0f9a001819f435 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Mon, 18 Jul 2022 20:48:07 +0200 Subject: [PATCH 05/24] Retabulate (use only tabs) --- source/glest_game/gui/gui.cpp | 200 +++++++++++++++++----------------- source/glest_game/gui/gui.h | 4 +- 2 files changed, 102 insertions(+), 102 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index e972dc32..b7a50a03 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -38,7 +38,7 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ // ===================================================== -// class Mouse3d +// class Mouse3d // ===================================================== const float Mouse3d::fadeSpeed= 1.f/50.f; @@ -65,7 +65,7 @@ void Mouse3d::update(){ } // =============================== -// class SelectionQuad +// class SelectionQuad // =============================== SelectionQuad::SelectionQuad(){ @@ -89,7 +89,7 @@ void SelectionQuad::disable(){ } // ===================================================== -// class Gui +// class Gui // ===================================================== //constructor @@ -97,11 +97,11 @@ Gui::Gui(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); lastGroupRecall = -1; - commonCommands=0; - posObjWorld= Vec2i(54, 14); + commonCommands=0; + posObjWorld= Vec2i(54, 14); validPosObjWorld= false; - activeCommandType= NULL; - activeCommandClass= ccStop; + activeCommandType= NULL; + activeCommandClass= ccStop; selectingBuilding= false; selectedBuildingFacing = CardinalDir(CardinalDir::NORTH); selectingPos= false; @@ -150,8 +150,8 @@ void Gui::end(){ // ==================== get ==================== const UnitType *Gui::getBuilding() const{ - assert(selectingBuilding); - return choosenBuildingType; + assert(selectingBuilding); + return choosenBuildingType; } const Object *Gui::getSelectedResourceObject() const{ if(selectedResourceObjectPos.x==-1){ @@ -197,17 +197,17 @@ bool Gui::isPlacingBuilding() const{ // ==================== set ==================== void Gui::invalidatePosObjWorld(){ - validPosObjWorld= false; + validPosObjWorld= false; } // ==================== reset state ==================== void Gui::resetState(){ - selectingBuilding= false; + selectingBuilding= false; selectedBuildingFacing = CardinalDir(CardinalDir::NORTH); selectingPos= false; selectingMeetingPoint= false; - activePos= invalidPos; + activePos= invalidPos; activeCommandClass= ccStop; activeCommandType= NULL; } @@ -216,9 +216,9 @@ void Gui::resetState(){ void Gui::update(){ - if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize){ - computeSelected(false,false); - } + if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize){ + computeSelected(false,false); + } mouse3d.update(); } @@ -425,12 +425,12 @@ void Gui::hotKey(SDL_KeyboardEvent key) { } //else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){ if(isKeyPressed(configKeys.getSDLKey("HotKeyRotateUnitDuringPlacement"),key) == true) { - // Here the user triggers a unit rotation while placing a unit - if(isPlacingBuilding()) { - if(getBuilding()->getRotationAllowed()){ + // Here the user triggers a unit rotation while placing a unit + if(isPlacingBuilding()) { + if(getBuilding()->getRotationAllowed()){ ++selectedBuildingFacing; - } - } + } + } } //else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectDamagedUnit"),key) == true) { @@ -449,18 +449,18 @@ void Gui::hotKey(SDL_KeyboardEvent key) { clickCommonCommand(ccStop); } - for (int i=0; i<10; i++) { - string name = "HotKeyBuild" + intToStr(i+1); - if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) { - if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { - mouseDownDisplayUnitBuild(i); - break; - } else { - if (i < commonCommands) mouseDownDisplayUnitSkills(i); - break; - } - } - } + for (int i=0; i<10; i++) { + string name = "HotKeyBuild" + intToStr(i+1); + if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) { + if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { + mouseDownDisplayUnitBuild(i); + break; + } else { + if (i < commonCommands) mouseDownDisplayUnitSkills(i); + break; + } + } + } } void Gui::switchToNextDisplayColor(){ @@ -486,8 +486,8 @@ void Gui::giveOneClickOrders(){ result= commander->tryGiveCommand(&selection, activeCommandClass, Vec2i(0), (Unit*)NULL, queueKeyDown); } addOrdersResultToConsole(activeCommandClass, result); - activeCommandType= NULL; - activeCommandClass= ccStop; + activeCommandType= NULL; + activeCommandClass= ccStop; } void Gui::giveDefaultOrders(int x, int y) { @@ -557,7 +557,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) { } bool queueKeyDown = isKeyDown(queueCommandKey); - //give orders to the units of this faction + //give orders to the units of this faction if(selectingBuilding == false) { if(selection.isUniform()) { result= commander->tryGiveCommand(&selection, activeCommandType, @@ -566,14 +566,14 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) { else { result= commander->tryGiveCommand(&selection, activeCommandClass, targetPos, targetUnit,queueKeyDown); - } + } } else { //selecting building result= commander->tryGiveCommand(&selection, activeCommandType, posObjWorld, choosenBuildingType, selectedBuildingFacing,queueKeyDown); - } + } //graphical result addOrdersResultToConsole(activeCommandClass, result); @@ -599,7 +599,7 @@ void Gui::centerCameraOnSelection() { } void Gui::selectInterestingUnit(InterestingUnitType iut) { - const Faction *thisFaction = world->getThisFaction(); + const Faction *thisFaction = world->getThisFaction(); const Unit* previousUnit = NULL; bool previousFound = true; @@ -668,10 +668,10 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { //uniform selection if(selection.isUniform()) { - const CommandType *ct = display.getCommandType(posDisplay); + const CommandType *ct = display.getCommandType(posDisplay); - // try to switch to next attack type - if(activeCommandClass == ccAttack && activeCommandType!=NULL) { + // try to switch to next attack type + if(activeCommandClass == ccAttack && activeCommandType!=NULL) { int maxI = unit->getType()->getCommandTypeCount(); int cmdTypeId = activeCommandType->getId(); @@ -758,7 +758,7 @@ void Gui::mouseDownDisplayUnitBuild(int posDisplay) { const BuildCommandType *bct = dynamic_cast(activeCommandType); if(bct != NULL && bct->getBuildingCount() > posDisplay) { - const UnitType *ut = bct->getBuilding(posDisplay); + const UnitType *ut = bct->getBuilding(posDisplay); const Unit *unit = selection.getFrontUnit(); if(unit != NULL && unit->getFaction() != NULL) { @@ -768,7 +768,7 @@ void Gui::mouseDownDisplayUnitBuild(int posDisplay) { choosenBuildingType = ut; selectingPos = true; - selectedBuildingFacing = CardinalDir(CardinalDir::NORTH); + selectedBuildingFacing = CardinalDir(CardinalDir::NORTH); activePos = posDisplay; } } @@ -878,14 +878,14 @@ void Gui::computeInfoString(int posDisplay){ bool translatedValue= game->showTranslatedTechTree(); const UnitType *building=bct->getBuilding(posDisplay); string str= lang.getString("BuildSpeed",(translatedValue == true ? "" : "english"))+": "+ intToStr(bct->getBuildSkillType()->getSpeed())+"\n"; - str+=""+Lang::getInstance().getString("TimeSteps",(translatedValue == true ? "" : "english"))+": "+intToStr(building->getProductionTime())+"\n"; - int64 speed=bct->getBuildSkillType()->getSpeed()+bct->getBuildSkillType()->getTotalSpeed(unit->getTotalUpgrade()); - int64 time=building->getProductionTime(); - int64 seconds=time*100/speed; - str+=""+Lang::getInstance().getString("Time",(translatedValue == true ? "" : "english"))+": "+intToStr(seconds); - str+="\n\n"; - str+=building->getReqDesc(translatedValue); - display.setInfoText(str); + str+=""+Lang::getInstance().getString("TimeSteps",(translatedValue == true ? "" : "english"))+": "+intToStr(building->getProductionTime())+"\n"; + int64 speed=bct->getBuildSkillType()->getSpeed()+bct->getBuildSkillType()->getTotalSpeed(unit->getTotalUpgrade()); + int64 time=building->getProductionTime(); + int64 seconds=time*100/speed; + str+=""+Lang::getInstance().getString("Time",(translatedValue == true ? "" : "english"))+": "+intToStr(seconds); + str+="\n\n"; + str+=building->getReqDesc(translatedValue); + display.setInfoText(str); } } } @@ -1059,7 +1059,7 @@ void Gui::computeDisplay(){ lastCommand++; } } - commonCommands = lastCommand; + commonCommands = lastCommand; } } else if (activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { @@ -1145,9 +1145,9 @@ int Gui::computePosDisplay(int x, int y){ } } else { - posDisplay= invalidPos; - //printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); - } + posDisplay= invalidPos; + //printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__); + } //printf("computePosDisplay returning = %d\n",posDisplay); @@ -1156,64 +1156,64 @@ int Gui::computePosDisplay(int x, int y){ void Gui::addOrdersResultToConsole(CommandClass cc, std::pair result) { - switch(result.first) { + switch(result.first) { case crSuccess: break; case crFailReqs: - switch(cc){ - case ccBuild: - console->addStdMessage("BuildingNoReqs",result.second); - break; - case ccProduce: - console->addStdMessage("UnitNoReqs",result.second); - break; - case ccMorph: - console->addStdMessage("MorphNoReqs",result.second); - break; - case ccUpgrade: - console->addStdMessage("UpgradeNoReqs",result.second); - break; - default: - break; - } - break; - case crFailRes: - switch(cc){ - case ccBuild: - console->addStdMessage("BuildingNoRes",result.second); - break; - case ccProduce: - console->addStdMessage("UnitNoRes",result.second); - break; - case ccMorph: - console->addStdMessage("MorphNoRes",result.second); - break; - case ccUpgrade: - console->addStdMessage("UpgradeNoRes",result.second); - break; + switch(cc){ + case ccBuild: + console->addStdMessage("BuildingNoReqs",result.second); + break; + case ccProduce: + console->addStdMessage("UnitNoReqs",result.second); + break; + case ccMorph: + console->addStdMessage("MorphNoReqs",result.second); + break; + case ccUpgrade: + console->addStdMessage("UpgradeNoReqs",result.second); + break; default: break; - } + } + break; + case crFailRes: + switch(cc){ + case ccBuild: + console->addStdMessage("BuildingNoRes",result.second); + break; + case ccProduce: + console->addStdMessage("UnitNoRes",result.second); + break; + case ccMorph: + console->addStdMessage("MorphNoRes",result.second); + break; + case ccUpgrade: + console->addStdMessage("UpgradeNoRes",result.second); + break; + default: + break; + } break; - case crFailUndefined: - console->addStdMessage("InvalidOrder",result.second); - break; + case crFailUndefined: + console->addStdMessage("InvalidOrder",result.second); + break; - case crSomeFailed: - console->addStdMessage("SomeOrdersFailed",result.second); - break; - } + case crSomeFailed: + console->addStdMessage("SomeOrdersFailed",result.second); + break; + } } bool Gui::isSharedCommandClass(CommandClass commandClass){ - for(int i=0; igetType()->getFirstCtOfClass(commandClass); + const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass); if(ct==NULL || !unit->getFaction()->reqsOk(ct)) - return false; - } - return true; + return false; + } + return true; } diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index bb5e15a8..6a293c7f 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -88,7 +88,7 @@ public: }; // ===================================================== -// class Gui +// class Gui // /// In game GUI // ===================================================== @@ -124,7 +124,7 @@ private: CommandClass activeCommandClass; int activePos; int lastPosDisplay; - int commonCommands; + int commonCommands; //composite Display display; From c3e8a25e9ed020199f10c2caaf5854613f9b20aa Mon Sep 17 00:00:00 2001 From: Rampoina Date: Thu, 21 Jul 2022 07:31:16 +0200 Subject: [PATCH 06/24] Update commonCommands for a uniform selection --- source/glest_game/gui/gui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index b7a50a03..ba82f33f 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -1030,6 +1030,7 @@ void Gui::computeDisplay(){ } } } + commonCommands = i; } } } From 192252200945fe044cd6f6ab90876d61a5fe294b Mon Sep 17 00:00:00 2001 From: Rampoina Date: Thu, 21 Jul 2022 07:32:37 +0200 Subject: [PATCH 07/24] Rename commonCommands to numberCommands --- source/glest_game/gui/gui.cpp | 8 ++++---- source/glest_game/gui/gui.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index ba82f33f..65a1e3c8 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -97,7 +97,7 @@ Gui::Gui(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); lastGroupRecall = -1; - commonCommands=0; + numberCommands=0; posObjWorld= Vec2i(54, 14); validPosObjWorld= false; activeCommandType= NULL; @@ -456,7 +456,7 @@ void Gui::hotKey(SDL_KeyboardEvent key) { mouseDownDisplayUnitBuild(i); break; } else { - if (i < commonCommands) mouseDownDisplayUnitSkills(i); + if (i < numberCommands) mouseDownDisplayUnitSkills(i); break; } } @@ -1030,7 +1030,7 @@ void Gui::computeDisplay(){ } } } - commonCommands = i; + numberCommands = i; } } } @@ -1060,7 +1060,7 @@ void Gui::computeDisplay(){ lastCommand++; } } - commonCommands = lastCommand; + numberCommands = lastCommand; } } else if (activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 6a293c7f..8711b3d6 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -124,7 +124,7 @@ private: CommandClass activeCommandClass; int activePos; int lastPosDisplay; - int commonCommands; + int numberCommands; //composite Display display; From 3313f187bb3e4c17c62d514d69f08e79f6b9f53f Mon Sep 17 00:00:00 2001 From: Rampoina Date: Thu, 21 Jul 2022 07:35:34 +0200 Subject: [PATCH 08/24] Rename HotKeyBuildN to CommandKeyN --- mk/shared/glestkeys.ini | 20 ++++++++++---------- source/glest_game/gui/gui.cpp | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mk/shared/glestkeys.ini b/mk/shared/glestkeys.ini index 28a21e9d..3c5954be 100644 --- a/mk/shared/glestkeys.ini +++ b/mk/shared/glestkeys.ini @@ -30,16 +30,16 @@ CameraRotateLeft=O CameraRotateRight=P CameraRotateUp=S CameraRotateDown=W -HotKeyBuild1=Q -HotKeyBuild2=W -HotKeyBuild3=E -HotKeyBuild4=R -HotKeyBuild5=A -HotKeyBuild6=S -HotKeyBuild7=D -HotKeyBuild8=F -HotKeyBuild9=Z -HotKeyBuild10=X +CommandKey1=Q +CommandKey2=W +CommandKey3=E +CommandKey4=R +CommandKey5=A +CommandKey6=S +CommandKey7=D +CommandKey8=F +CommandKey9=Z +CommandKey10=X HotKeyCenterCameraOnSelection=G HotKeySelectIdleHarvesterUnit=I HotKeySelectBuiltBuilding=B diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 65a1e3c8..eb48650b 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -450,7 +450,7 @@ void Gui::hotKey(SDL_KeyboardEvent key) { } for (int i=0; i<10; i++) { - string name = "HotKeyBuild" + intToStr(i+1); + string name = "CommandKey" + intToStr(i+1); if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) { if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { mouseDownDisplayUnitBuild(i); From 9276faeeb5f5eeb7f57fc0f25409511042ee1f63 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Thu, 21 Jul 2022 08:12:29 +0200 Subject: [PATCH 09/24] Update the GUI immediately after calling the command from a hotkey Otherwise the gui takes a bit to update --- source/glest_game/gui/gui.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index eb48650b..43756ec3 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -454,9 +454,13 @@ void Gui::hotKey(SDL_KeyboardEvent key) { if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) { if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { mouseDownDisplayUnitBuild(i); + computeDisplay(); break; } else { - if (i < numberCommands) mouseDownDisplayUnitSkills(i); + if (i < numberCommands) { + mouseDownDisplayUnitSkills(i); + computeDisplay(); + } break; } } From c549a6b66c0e0ca43e329eeb2b972503341cc7c6 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Thu, 21 Jul 2022 09:25:33 +0200 Subject: [PATCH 10/24] Correctly update numberCommands --- source/glest_game/gui/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 43756ec3..65cf6d5a 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -1034,8 +1034,8 @@ void Gui::computeDisplay(){ } } } - numberCommands = i; } + numberCommands = ut->getCommandTypeCount(); } } else{ From c4caa6b912cd28eea18bd9ac4e604488cc2d4fc1 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Thu, 21 Jul 2022 09:49:43 +0200 Subject: [PATCH 11/24] Display hotkey on hover --- source/glest_game/gui/gui.cpp | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 65cf6d5a..c9ae037a 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -802,8 +802,14 @@ void Gui::computeInfoString(int posDisplay){ lastPosDisplay = posDisplay; display.setInfoText(computeDefaultInfoString()); + Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); + string commandKeyName = "CommandKey" + intToStr(posDisplay+1); if(posDisplay!=invalidPos && selection.isCommandable()){ + string hotkey = ""; + if (posDisplay < 10) { // there's 10 configurable command hotkeys + hotkey=lang.getString("HotKey")+": "+SDL_GetKeyName(configKeys.getSDLKey(commandKeyName.c_str())) +"\n\n"; + } if(!selectingBuilding){ if(posDisplay==cancelPos){ display.setInfoText(lang.getString("Cancel")); @@ -819,10 +825,10 @@ void Gui::computeInfoString(int posDisplay){ if(ct!=NULL){ if(unit->getFaction()->reqsOk(ct)){ - display.setInfoText(ct->getDesc(unit->getTotalUpgrade(),game->showTranslatedTechTree())); + display.setInfoText(hotkey+ct->getDesc(unit->getTotalUpgrade(),game->showTranslatedTechTree())); } else{ - display.setInfoText(ct->getReqDesc(game->showTranslatedTechTree())); + display.setInfoText(hotkey+ct->getReqDesc(game->showTranslatedTechTree())); if(ct->getClass()==ccUpgrade){ string text=""; const UpgradeCommandType *uct= static_cast(ct); @@ -832,20 +838,20 @@ void Gui::computeInfoString(int posDisplay){ else if(unit->getFaction()->getUpgradeManager()->isUpgraded(uct->getProducedUpgrade())){ text=lang.getString("AlreadyUpgraded")+"\n\n"; } - display.setInfoText(text+ct->getReqDesc(game->showTranslatedTechTree())); + display.setInfoText(hotkey+text+ct->getReqDesc(game->showTranslatedTechTree())); } //locked by scenario else if(ct->getClass()==ccProduce){ string text=""; const ProduceCommandType *pct= static_cast(ct); if(unit->getFaction()->isUnitLocked(pct->getProducedUnit())){ - display.setInfoText(lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree())); + display.setInfoText(hotkey+lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree())); } } else if(ct->getClass()==ccMorph){ const MorphCommandType *mct= static_cast(ct); if(unit->getFaction()->isUnitLocked(mct->getMorphUnit())){ - display.setInfoText(lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree())); + display.setInfoText(hotkey+lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree())); } } } @@ -877,7 +883,7 @@ void Gui::computeInfoString(int posDisplay){ const BuildCommandType *bct= static_cast(activeCommandType); const Unit *unit= selection.getFrontUnit(); if(unit->getFaction()->isUnitLocked(bct->getBuilding(posDisplay))){ - display.setInfoText(lang.getString("LockedByScenario")+"\n\n"+bct->getBuilding(posDisplay)->getReqDesc(game->showTranslatedTechTree())); + display.setInfoText(hotkey+lang.getString("LockedByScenario")+"\n\n"+bct->getBuilding(posDisplay)->getReqDesc(game->showTranslatedTechTree())); } else { bool translatedValue= game->showTranslatedTechTree(); const UnitType *building=bct->getBuilding(posDisplay); @@ -889,7 +895,7 @@ void Gui::computeInfoString(int posDisplay){ str+=""+Lang::getInstance().getString("Time",(translatedValue == true ? "" : "english"))+": "+intToStr(seconds); str+="\n\n"; str+=building->getReqDesc(translatedValue); - display.setInfoText(str); + display.setInfoText(hotkey+str); } } } From 7945fa8c80880ca8eac7fe55a2b1f2917d3f7aa7 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Sat, 23 Jul 2022 14:54:30 +0200 Subject: [PATCH 12/24] Remove key conflics Move back the camera hotkeys to a and d, this means that the equivalent command hotkeys won't be usable in free camera mode --- mk/shared/glestkeys.ini | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mk/shared/glestkeys.ini b/mk/shared/glestkeys.ini index 3c5954be..4cf311b1 100644 --- a/mk/shared/glestkeys.ini +++ b/mk/shared/glestkeys.ini @@ -26,8 +26,8 @@ GroupUnitsKey7='6' GroupUnitsKey8='7' GroupUnitsKey9='8' GroupUnitsKey10='9' -CameraRotateLeft=O -CameraRotateRight=P +CameraRotateLeft=A +CameraRotateRight=D CameraRotateUp=S CameraRotateDown=W CommandKey1=Q @@ -48,7 +48,7 @@ HotKeyDumpWorldToLog=\ HotKeyRotateUnitDuringPlacement=R HotKeySelectDamagedUnit=U HotKeySelectStoreUnit=T -HotKeySelectedUnitsAttack=I +HotKeySelectedUnitsAttack=V HotKeySelectedUnitsStop=; HotKeyToggleOSMouseEnabled=/ ChatTeamMode=H From e209dcbd3553bc2fb98358ee329c131bdcff9eb2 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 2 Aug 2022 09:18:07 +0200 Subject: [PATCH 13/24] Fix numberCommands It wasn't updated correctly for units with morphing abilities --- source/glest_game/gui/gui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index c9ae037a..ec4b7661 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -1040,8 +1040,9 @@ void Gui::computeDisplay(){ } } } + numberCommands = displayPos; } - numberCommands = ut->getCommandTypeCount(); + numberCommands++; } } else{ From 46d5904578f5836283325c6534b78af4cad06a8c Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 2 Aug 2022 09:44:46 +0200 Subject: [PATCH 14/24] Bump Command Keys to 12 Otherwise some units in the game don't have enough hotkeys like the ballista. Moves the hotkey for attacking units to , Moves the hotkey for font cOlor to O --- mk/shared/glestkeys.ini | 6 ++++-- source/glest_game/gui/gui.cpp | 4 ++-- source/glest_game/gui/gui.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mk/shared/glestkeys.ini b/mk/shared/glestkeys.ini index 4cf311b1..1a5fd285 100644 --- a/mk/shared/glestkeys.ini +++ b/mk/shared/glestkeys.ini @@ -11,7 +11,7 @@ CameraModeRight=right CameraModeUp=up CameraModeDown=down PauseGame=P -ChangeFontColor=C +ChangeFontColor=O GameSpeedIncrease='+' GameSpeedDecrease='-' ExitKey=escape @@ -40,6 +40,8 @@ CommandKey7=D CommandKey8=F CommandKey9=Z CommandKey10=X +CommandKey11=C +CommandKey12=V HotKeyCenterCameraOnSelection=G HotKeySelectIdleHarvesterUnit=I HotKeySelectBuiltBuilding=B @@ -48,7 +50,7 @@ HotKeyDumpWorldToLog=\ HotKeyRotateUnitDuringPlacement=R HotKeySelectDamagedUnit=U HotKeySelectStoreUnit=T -HotKeySelectedUnitsAttack=V +HotKeySelectedUnitsAttack=, HotKeySelectedUnitsStop=; HotKeyToggleOSMouseEnabled=/ ChatTeamMode=H diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index ec4b7661..1147c2ad 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -449,7 +449,7 @@ void Gui::hotKey(SDL_KeyboardEvent key) { clickCommonCommand(ccStop); } - for (int i=0; i<10; i++) { + for (int i=0; igetClass() == ccBuild) { @@ -807,7 +807,7 @@ void Gui::computeInfoString(int posDisplay){ if(posDisplay!=invalidPos && selection.isCommandable()){ string hotkey = ""; - if (posDisplay < 10) { // there's 10 configurable command hotkeys + if (posDisplay < commandKeys) { hotkey=lang.getString("HotKey")+": "+SDL_GetKeyName(configKeys.getSDLKey(commandKeyName.c_str())) +"\n\n"; } if(!selectingBuilding){ diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 8711b3d6..a731d26e 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -95,6 +95,7 @@ public: class Gui { public: + static const int commandKeys= 12; static const int maxSelBuff= 128*5; static const int upgradeDisplayIndex= 8; From f1e4a1bf836ef9e44714d8445b331f5b027711aa Mon Sep 17 00:00:00 2001 From: pavanvo Date: Thu, 11 Aug 2022 13:00:09 +0400 Subject: [PATCH 15/24] feat: standart for cammand grid --- source/glest_game/gui/gui.cpp | 42 ++++++------ source/glest_game/gui/gui.h | 1 - source/glest_game/types/command_type.cpp | 14 ++++ source/glest_game/types/command_type.h | 12 ++++ source/glest_game/types/unit_type.cpp | 82 ++++++++++++++++++++++++ source/glest_game/types/unit_type.h | 5 ++ 6 files changed, 132 insertions(+), 24 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 1147c2ad..39c1161d 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -97,7 +97,6 @@ Gui::Gui(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__); lastGroupRecall = -1; - numberCommands=0; posObjWorld= Vec2i(54, 14); validPosObjWorld= false; activeCommandType= NULL; @@ -454,15 +453,11 @@ void Gui::hotKey(SDL_KeyboardEvent key) { if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) { if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { mouseDownDisplayUnitBuild(i); - computeDisplay(); - break; } else { - if (i < numberCommands) { - mouseDownDisplayUnitSkills(i); - computeDisplay(); - } - break; + mouseDownDisplayUnitSkills(i); } + computeDisplay(); + break; } } } @@ -720,7 +715,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { } //give orders depending on command type - if(!selection.isEmpty()){ + if(activeCommandClass != ccNull){ const CommandType *ct= selection.getUnit(0)->getType()->getFirstCtOfClass(activeCommandClass); if (activeCommandClass == ccAttack) { ct = selection.getUnitFromCC(ccAttack)->getType()->getFirstCtOfClass(activeCommandClass); @@ -737,7 +732,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { selectingPos= true; activePos= posDisplay; } - } + } else { posDisplay= invalidPos;} } else{ activePos= posDisplay; @@ -994,10 +989,11 @@ void Gui::computeDisplay(){ if(u->isBuilt()){ //printf("u->isBuilt()\n"); - int morphPos= 8; - for(int i= 0; i < ut->getCommandTypeCount(); ++i){ + int morphPos= CommandHelper::getMorphPos(); + for(int i= 0; i < ut->getCommandTypeSortedCount(); ++i){ int displayPos= i; - const CommandType *ct= ut->getCommandType(i); + const CommandType *ct= ut->getCommandTypeSorted(i); + if(ct == NULL) continue; if(ct->getClass() == ccMorph) { displayPos= morphPos++; } @@ -1040,38 +1036,38 @@ void Gui::computeDisplay(){ } } } - numberCommands = displayPos; } - numberCommands++; } } else{ //printf("selection.isUniform() == FALSE\n"); //non uniform selection - int lastCommand= 0; - for(int i= 0; i < ccCount; ++i){ - CommandClass cc= static_cast (i); + int basicPos= CommandHelper::getBasicPos(); + // only basics can be shared + for(auto &&cc : CommandHelper::getBasicsCC()){ - //printf("computeDisplay i = %d cc = %d isshared = %d lastCommand = %d\n",i,cc,isSharedCommandClass(cc),lastCommand); + //printf("computeDisplay i = %d cc = %d isshared = %d basicPos = %d\n",i,cc,isSharedCommandClass(cc),basicPos); const Unit* attackingUnit = NULL; if (cc == ccAttack) { attackingUnit = selection.getUnitFromCC(ccAttack); } + auto ccPos = CommandHelper::getBasicPos(cc); + if((cc == ccAttack && attackingUnit != NULL) || (isSharedCommandClass(cc) && cc != ccBuild)){ - display.setDownLighted(lastCommand, true); + display.setDownLighted(basicPos + ccPos, true); if (cc == ccAttack && attackingUnit != NULL) { - display.setDownImage(lastCommand, attackingUnit->getType()->getFirstCtOfClass(cc)->getImage()); + display.setDownImage(basicPos + ccPos, attackingUnit->getType()->getFirstCtOfClass(cc)->getImage()); } else { - display.setDownImage(lastCommand, ut->getFirstCtOfClass(cc)->getImage()); + display.setDownImage(basicPos + ccPos, ut->getFirstCtOfClass(cc)->getImage()); } + display.setCommandClass(basicPos + ccPos, cc); display.setCommandClass(lastCommand, cc); lastCommand++; } } - numberCommands = lastCommand; } } else if (activeCommandType != NULL && activeCommandType->getClass() == ccBuild) { diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index a731d26e..d44831b1 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -125,7 +125,6 @@ private: CommandClass activeCommandClass; int activePos; int lastPosDisplay; - int numberCommands; //composite Display display; diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index b254a368..4bda6c0c 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -31,6 +31,20 @@ using namespace Shared::Util; namespace Glest{ namespace Game{ +// ===================================================== +// class CommandHelper +// ===================================================== + +int CommandHelper::getBasicPos(CommandClass cc){ + switch(cc) { + case ccAttack: return 0; break; + case ccStop: return 1; break; + case ccMove: return 2; break; + case ccAttackStopped: return 3; break; + default: + return ccNull; + } +} // ===================================================== // class CommandType diff --git a/source/glest_game/types/command_type.h b/source/glest_game/types/command_type.h index 913272c5..5fec4979 100644 --- a/source/glest_game/types/command_type.h +++ b/source/glest_game/types/command_type.h @@ -66,6 +66,18 @@ enum Queueability { qAlways }; +class CommandHelper {// TODO put magic numbers to settings +public: + inline static int getCorePos() { return 0; } + inline static int getBasicPos() { return 4; } + inline static int getMorphPos() { return 8; } + static int getBasicPos(CommandClass cc); + inline static vector getBasicsCC() { return { ccAttack, ccStop, ccMove, ccAttackStopped }; } + +private: + CommandHelper(){ } +}; + // ===================================================== // class CommandType // diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index ca682ed7..9bce2081 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -880,6 +880,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree, } } } + sortCommandTypes(commandTypes); computeFirstStOfClass(); computeFirstCtOfClass(); @@ -1236,6 +1237,78 @@ void UnitType::computeFirstCtOfClass() { } } +void UnitType::sortCommandTypes(CommandTypes cts){ + CommandTypes ctBuf(cts); + + CommandTypes ctCores; + CommandTypes ctBasics = {NULL,NULL,NULL,NULL}; + CommandTypes ctMorphs; + + CommandTypes ctAttack; + CommandTypes ctBuild; + + //Morphs + for(int i = (int)ctBuf.size(); i --> 0; ) { + if(ctBuf[i]->getClass() == ccMorph) { + ctMorphs.insert(ctMorphs.begin(), ctBuf[i]); + ctBuf.erase(ctBuf.begin() + i); + } + } + + //Attacks + CommandTypeFilter(ctBuf, ctAttack, ccAttack); + if(ctAttack.size() > 0) { + ctBasics[0] = ctAttack[0];// first attack to basics + ctAttack.erase(ctAttack.begin());// another to cores + ctCores.insert(ctCores.end(), ctAttack.begin(), ctAttack.end()); + } + auto basicsCC = CommandHelper::getBasicsCC(); + // removing attack cuz we catch all attacks above + basicsCC.erase( basicsCC.begin() + CommandHelper::getBasicPos(ccAttack)); + + //Basics + for(int i = (int)ctBuf.size(); i --> 0; ) { + for(auto &&cc : basicsCC ){ + if(ctBuf[i]->getClass() == cc) { + auto ccPos = CommandHelper::getBasicPos(cc); + ctBasics[ccPos] = ctBuf[i]; + ctBuf.erase(ctBuf.begin() + i); + } + } + } + +// //Cores + CommandTypeFilter(ctBuf, ctCores, ccProduce); + CommandTypeFilter(ctBuf, ctCores, ccUpgrade); + CommandTypeFilter(ctBuf, ctCores, ccSwitchTeam); + CommandTypeFilter(ctBuf, ctCores, ccHarvest); + CommandTypeFilter(ctBuf, ctCores, ccRepair); + + //Build + CommandTypeFilter(ctBuf, ctBuild, ccBuild);// Build position always 4 in cores + if(ctCores.size() == 4) {/*do nothing*/ } + else if(ctCores.size() < 4) { + int nullCount = 4 - ctCores.size(); + for(int i=0; i 0){ + ctCores[3] = ctBuild[0]; + } + } + commandTypesSorted.insert(commandTypesSorted.end(), ctCores.begin(), ctCores.end()); + commandTypesSorted.insert(commandTypesSorted.end(), ctBasics.begin(), ctBasics.end()); + commandTypesSorted.insert(commandTypesSorted.end(), ctMorphs.begin(), ctMorphs.end()); +} + +void UnitType::CommandTypeFilter(CommandTypes &input, CommandTypes &output, CommandClass cc){ + std::copy_if(input.begin(), input.end(), std::back_inserter(output), [cc](CommandType* i) { + if(i->getClass() == cc) + return true; + else return false; + }); +} + const CommandType* UnitType::findCommandTypeById(int id) const{ const HarvestEmergencyReturnCommandType *result = dynamic_cast(ctHarvestEmergencyReturnCommandType.get()); if(result != NULL && id == result->getId()) { @@ -1260,6 +1333,15 @@ const CommandType *UnitType::getCommandType(int i) const { return commandTypes[i]; } +const CommandType *UnitType::getCommandTypeSorted(int i) const { + if(i >= (int)commandTypesSorted.size()) { + char szBuf[8096]=""; + snprintf(szBuf,8096,"In [%s::%s Line: %d] i >= commandTypesSorted.size(), i = %d, commandTypesSorted.size() = " MG_SIZE_T_SPECIFIER "",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,commandTypesSorted.size()); + throw megaglest_runtime_error(szBuf); + } + return commandTypesSorted[i]; +} + string UnitType::getCommandTypeListDesc() const { string desc = "Commands: "; for(int i=0; i Date: Fri, 12 Aug 2022 04:09:03 +0400 Subject: [PATCH 16/24] fix: if two build buttons, move second to basics --- source/glest_game/types/unit_type.cpp | 31 +++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 9bce2081..23ccffed 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -1238,10 +1238,12 @@ void UnitType::computeFirstCtOfClass() { } void UnitType::sortCommandTypes(CommandTypes cts){ + try{ CommandTypes ctBuf(cts); CommandTypes ctCores; CommandTypes ctBasics = {NULL,NULL,NULL,NULL}; + vector basicNulls = {0,1,2,3}; CommandTypes ctMorphs; CommandTypes ctAttack; @@ -1259,6 +1261,7 @@ void UnitType::sortCommandTypes(CommandTypes cts){ CommandTypeFilter(ctBuf, ctAttack, ccAttack); if(ctAttack.size() > 0) { ctBasics[0] = ctAttack[0];// first attack to basics + basicNulls.erase(basicNulls.begin()); ctAttack.erase(ctAttack.begin());// another to cores ctCores.insert(ctCores.end(), ctAttack.begin(), ctAttack.end()); } @@ -1273,11 +1276,12 @@ void UnitType::sortCommandTypes(CommandTypes cts){ auto ccPos = CommandHelper::getBasicPos(cc); ctBasics[ccPos] = ctBuf[i]; ctBuf.erase(ctBuf.begin() + i); + basicNulls.erase(std::remove(basicNulls.begin(), basicNulls.end(), ccPos), basicNulls.end()); } } } -// //Cores + //Cores CommandTypeFilter(ctBuf, ctCores, ccProduce); CommandTypeFilter(ctBuf, ctCores, ccUpgrade); CommandTypeFilter(ctBuf, ctCores, ccSwitchTeam); @@ -1286,19 +1290,28 @@ void UnitType::sortCommandTypes(CommandTypes cts){ //Build CommandTypeFilter(ctBuf, ctBuild, ccBuild);// Build position always 4 in cores - if(ctCores.size() == 4) {/*do nothing*/ } - else if(ctCores.size() < 4) { - int nullCount = 4 - ctCores.size(); - for(int i=0; i 0){ - ctCores[3] = ctBuild[0]; + int nullCount = 4 - ctCores.size() - ctBuild.size(); + for(int i=0; i 0) { + if(nullCount < 0) {//magic + int buildToBasics = -nullCount;// if we cant push all builds to cores + int until = (int)ctBuild.size() - buildToBasics; + for(int i = (int)ctBuild.size(); i --> until; ) {// we push it to basics + ctBasics[basicNulls[i - until]] = ctBuild[i]; + ctBuild.erase(ctBuild.begin() + i); + basicNulls.erase(basicNulls.begin() + i - until); + } } + ctCores.insert(ctCores.end(), ctBuild.begin(), ctBuild.end()); } commandTypesSorted.insert(commandTypesSorted.end(), ctCores.begin(), ctCores.end()); commandTypesSorted.insert(commandTypesSorted.end(), ctBasics.begin(), ctBasics.end()); commandTypesSorted.insert(commandTypesSorted.end(), ctMorphs.begin(), ctMorphs.end()); + } catch(exception &ex){ + + } } void UnitType::CommandTypeFilter(CommandTypes &input, CommandTypes &output, CommandClass cc){ From 5523bba192525ebf403b68ea7c73fa1bff0a9538 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Fri, 12 Aug 2022 22:07:53 +0400 Subject: [PATCH 17/24] refactor: command sorting code --- source/glest_game/gui/gui.cpp | 4 +- source/glest_game/types/command_type.cpp | 13 ++--- source/glest_game/types/command_type.h | 11 +++- source/glest_game/types/unit_type.cpp | 70 +++++++++--------------- 4 files changed, 42 insertions(+), 56 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 39c1161d..2b9eb2a6 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -989,7 +989,7 @@ void Gui::computeDisplay(){ if(u->isBuilt()){ //printf("u->isBuilt()\n"); - int morphPos= CommandHelper::getMorphPos(); + int morphPos= CommandHelper::getRowPos(crMorphs); for(int i= 0; i < ut->getCommandTypeSortedCount(); ++i){ int displayPos= i; const CommandType *ct= ut->getCommandTypeSorted(i); @@ -1042,7 +1042,7 @@ void Gui::computeDisplay(){ else{ //printf("selection.isUniform() == FALSE\n"); //non uniform selection - int basicPos= CommandHelper::getBasicPos(); + int basicPos= CommandHelper::getRowPos(crBasics); // only basics can be shared for(auto &&cc : CommandHelper::getBasicsCC()){ diff --git a/source/glest_game/types/command_type.cpp b/source/glest_game/types/command_type.cpp index 4bda6c0c..9b591949 100644 --- a/source/glest_game/types/command_type.cpp +++ b/source/glest_game/types/command_type.cpp @@ -36,14 +36,11 @@ namespace Glest{ namespace Game{ // ===================================================== int CommandHelper::getBasicPos(CommandClass cc){ - switch(cc) { - case ccAttack: return 0; break; - case ccStop: return 1; break; - case ccMove: return 2; break; - case ccAttackStopped: return 3; break; - default: - return ccNull; - } + auto basics = getBasicsCC(); + auto it = find(basics.begin(), basics.end(), cc); + if (it != basics.end()) + return it - basics.begin(); + else throw megaglest_runtime_error("Basics command have not class: " + intToStr(cc)); } // ===================================================== diff --git a/source/glest_game/types/command_type.h b/source/glest_game/types/command_type.h index 5fec4979..e367c1d9 100644 --- a/source/glest_game/types/command_type.h +++ b/source/glest_game/types/command_type.h @@ -54,6 +54,12 @@ enum CommandClass { ccNull }; +enum CommandRow { + crCores, + crBasics, + crMorphs, +}; + enum Clicks { cOne, cTwo @@ -68,11 +74,10 @@ enum Queueability { class CommandHelper {// TODO put magic numbers to settings public: - inline static int getCorePos() { return 0; } - inline static int getBasicPos() { return 4; } - inline static int getMorphPos() { return 8; } + inline static int getRowPos(CommandRow cr) { return cr * 4; } static int getBasicPos(CommandClass cc); inline static vector getBasicsCC() { return { ccAttack, ccStop, ccMove, ccAttackStopped }; } + inline static vector getCoresCC() { return { ccAttack, ccProduce, ccUpgrade, ccSwitchTeam, ccHarvest, ccRepair, ccBuild }; } private: CommandHelper(){ } diff --git a/source/glest_game/types/unit_type.cpp b/source/glest_game/types/unit_type.cpp index 23ccffed..ee7b3e03 100644 --- a/source/glest_game/types/unit_type.cpp +++ b/source/glest_game/types/unit_type.cpp @@ -1239,73 +1239,57 @@ void UnitType::computeFirstCtOfClass() { void UnitType::sortCommandTypes(CommandTypes cts){ try{ - CommandTypes ctBuf(cts); - - CommandTypes ctCores; - CommandTypes ctBasics = {NULL,NULL,NULL,NULL}; + CommandTypes ctCores, ctBasics = {NULL,NULL,NULL,NULL}, ctMorphs, ctAttack; vector basicNulls = {0,1,2,3}; - CommandTypes ctMorphs; - - CommandTypes ctAttack; - CommandTypes ctBuild; //Morphs - for(int i = (int)ctBuf.size(); i --> 0; ) { - if(ctBuf[i]->getClass() == ccMorph) { - ctMorphs.insert(ctMorphs.begin(), ctBuf[i]); - ctBuf.erase(ctBuf.begin() + i); + for(int i = (int)cts.size(); i --> 0; ) { + if(cts[i]->getClass() == ccMorph) { + ctMorphs.insert(ctMorphs.begin(), cts[i]); + cts.erase(cts.begin() + i); } } //Attacks - CommandTypeFilter(ctBuf, ctAttack, ccAttack); + CommandTypeFilter(cts, ctAttack, ccAttack); if(ctAttack.size() > 0) { - ctBasics[0] = ctAttack[0];// first attack to basics + ctBasics[CommandHelper::getBasicPos(ccAttack)] = ctAttack[0];// first attack to basics basicNulls.erase(basicNulls.begin()); - ctAttack.erase(ctAttack.begin());// another to cores - ctCores.insert(ctCores.end(), ctAttack.begin(), ctAttack.end()); + ctAttack.erase(ctAttack.begin());// another to cores, see below } - auto basicsCC = CommandHelper::getBasicsCC(); - // removing attack cuz we catch all attacks above - basicsCC.erase( basicsCC.begin() + CommandHelper::getBasicPos(ccAttack)); //Basics - for(int i = (int)ctBuf.size(); i --> 0; ) { - for(auto &&cc : basicsCC ){ - if(ctBuf[i]->getClass() == cc) { + for(int i = (int)cts.size(); i --> 0; ) { + for(auto &&cc : CommandHelper::getBasicsCC()){ + if(cc == ccAttack) continue;// we catch all attacks above + if(cts[i]->getClass() == cc) { auto ccPos = CommandHelper::getBasicPos(cc); - ctBasics[ccPos] = ctBuf[i]; - ctBuf.erase(ctBuf.begin() + i); + ctBasics[ccPos] = cts[i]; + cts.erase(cts.begin() + i); basicNulls.erase(std::remove(basicNulls.begin(), basicNulls.end(), ccPos), basicNulls.end()); } } } //Cores - CommandTypeFilter(ctBuf, ctCores, ccProduce); - CommandTypeFilter(ctBuf, ctCores, ccUpgrade); - CommandTypeFilter(ctBuf, ctCores, ccSwitchTeam); - CommandTypeFilter(ctBuf, ctCores, ccHarvest); - CommandTypeFilter(ctBuf, ctCores, ccRepair); - - //Build - CommandTypeFilter(ctBuf, ctBuild, ccBuild);// Build position always 4 in cores - int nullCount = 4 - ctCores.size() - ctBuild.size(); + for(auto &&cc : CommandHelper::getCoresCC()){ + if(cc == ccAttack) ctCores.insert(ctCores.end(), ctAttack.begin(), ctAttack.end()); + else CommandTypeFilter(cts, ctCores, cc); + } + int nullCount = 4 - ctCores.size(); for(int i=0; i 0) { - if(nullCount < 0) {//magic - int buildToBasics = -nullCount;// if we cant push all builds to cores - int until = (int)ctBuild.size() - buildToBasics; - for(int i = (int)ctBuild.size(); i --> until; ) {// we push it to basics - ctBasics[basicNulls[i - until]] = ctBuild[i]; - ctBuild.erase(ctBuild.begin() + i); - basicNulls.erase(basicNulls.begin() + i - until); - } + + if(nullCount < 0) {//magic: if we cant push all commands to cores + CommandTypes ctToBasics(ctCores.end() + nullCount, ctCores.end()); + ctCores.resize(4); + for(int i = (int)ctToBasics.size(); i --> 0; ) {// we push it to basics + ctBasics[basicNulls[i]] = ctToBasics[i]; + basicNulls.erase(basicNulls.begin() + i); } - ctCores.insert(ctCores.end(), ctBuild.begin(), ctBuild.end()); } + commandTypesSorted.insert(commandTypesSorted.end(), ctCores.begin(), ctCores.end()); commandTypesSorted.insert(commandTypesSorted.end(), ctBasics.begin(), ctBasics.end()); commandTypesSorted.insert(commandTypesSorted.end(), ctMorphs.begin(), ctMorphs.end()); From e277c47583f14ff1b8b571b8515de8b8814ffa4e Mon Sep 17 00:00:00 2001 From: Jammyjamjamman Date: Wed, 10 Aug 2022 00:27:06 +0100 Subject: [PATCH 18/24] Add key mappings to docs --- docs/README.txt | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/README.txt b/docs/README.txt index b5c9851b..19ca94fb 100644 --- a/docs/README.txt +++ b/docs/README.txt @@ -149,7 +149,7 @@ the default keyboard values). * Camera keyboard controls * -f => toggle free camera mode +y => toggle free camera mode w => move camera up (free camera mode only) s => move camera down (free camera mode only) a => rotate camera left (free camera mode only) @@ -185,21 +185,34 @@ n => show network status * Hotkeys (game camera mode only) * -a => activate attack command for selection -s => issue stop command to selection +, => activate attack command for selection +; => issue stop command to selection i => select next idle harvester b => select next building -d => select next damaged unit +u => select next damaged unit t => select next storage unit r => rotate building before placement +Unit commands can be activated using the keyboard by pressing corresponding +keys in the grid layout: + ++---+---+---+---+ +| q | w | e | r | ++---+---+---+---+ +| a | s | d | f | ++---+---+---+---+ +| z | x | c | v | ++---+---+---+---+ + +The position of the command for the selected unit (or group) in the UI +button grid corresponds to the key in the same position in the grid above. * Other Keys * - + => adjust game speed (disabled in multiplayer) p => pause game (disabled in multiplayer) -e => save screen shot to file -c => toggle ingame font color (and font shadow) +j => save screen shot to file +o => toggle ingame font color (and font shadow) m => show faded mesages again ? => when DebugMode=true, display debug info / => toggle mouse pointer rendering mode (OS/MG) From a5438f6a9374048958c640433171f0f33dd2e3b8 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Thu, 11 Aug 2022 17:26:59 +0200 Subject: [PATCH 19/24] Use the cancel icon for the unused grid locations --- source/glest_game/gui/gui.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 2b9eb2a6..96190200 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -993,7 +993,12 @@ void Gui::computeDisplay(){ for(int i= 0; i < ut->getCommandTypeSortedCount(); ++i){ int displayPos= i; const CommandType *ct= ut->getCommandTypeSorted(i); - if(ct == NULL) continue; + if(ct == NULL) { + display.setDownImage(displayPos, ut->getCancelImage()); + display.setCommandType(displayPos, ct); + display.setDownLighted(displayPos,false); + continue; + } if(ct->getClass() == ccMorph) { displayPos= morphPos++; } @@ -1042,7 +1047,15 @@ void Gui::computeDisplay(){ else{ //printf("selection.isUniform() == FALSE\n"); //non uniform selection - int basicPos= CommandHelper::getRowPos(crBasics); + int basicPos = CommandHelper::getRowPos(crBasics); + + // First row is always empty + for (int i = 0; i < 5; i++) { + display.setDownImage(i, ut->getCancelImage()); + display.setCommandType(i, NULL); + display.setDownLighted(i,false); + } + // only basics can be shared for(auto &&cc : CommandHelper::getBasicsCC()){ @@ -1064,8 +1077,10 @@ void Gui::computeDisplay(){ display.setDownImage(basicPos + ccPos, ut->getFirstCtOfClass(cc)->getImage()); } display.setCommandClass(basicPos + ccPos, cc); - display.setCommandClass(lastCommand, cc); - lastCommand++; + } else { + display.setDownImage(basicPos+ccPos, ut->getCancelImage()); + display.setCommandType(basicPos+ccPos, NULL); + display.setDownLighted(basicPos+ccPos,false); } } } From afc26199f7980757857c2bfb949fd225ec4a260f Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 16 Aug 2022 21:56:36 +0400 Subject: [PATCH 20/24] refactor: remove some useless code, since we removed this hotkeys, we don't need this code any more --- source/glest_game/gui/gui.cpp | 22 ---------------------- source/glest_game/gui/gui.h | 1 - 2 files changed, 23 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 96190200..8ace6f90 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -439,14 +439,6 @@ void Gui::hotKey(SDL_KeyboardEvent key) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) { selectInterestingUnit(iutStore); } - //else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) { - if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) { - clickCommonCommand(ccAttack); - } - //else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) { - if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) { - clickCommonCommand(ccStop); - } for (int i=0; igetClass() == commandClass) || - display.getCommandClass(index) == commandClass) { - - mouseDownDisplayUnitSkills(index); - break; - } - } - computeDisplay(); -} - void Gui::mouseDownDisplayUnitSkills(int posDisplay) { if(selection.isEmpty() == false) { if(posDisplay != cancelPos) { diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index d44831b1..396770a2 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -217,7 +217,6 @@ private: //hotkeys void centerCameraOnSelection(); void selectInterestingUnit(InterestingUnitType iut); - void clickCommonCommand(CommandClass commandClass); //misc int computePosDisplay(int x, int y); From ea3ede3c081665ab70d76b26d57124791496bcb7 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 16 Aug 2022 21:58:18 +0400 Subject: [PATCH 21/24] refactor: remove incompatible code, code blocking switching from attack to anothe command --- source/glest_game/gui/gui.cpp | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 8ace6f90..cc501604 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -647,29 +647,6 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { if(selection.isUniform()) { const CommandType *ct = display.getCommandType(posDisplay); - // try to switch to next attack type - if(activeCommandClass == ccAttack && activeCommandType!=NULL) { - - int maxI = unit->getType()->getCommandTypeCount(); - int cmdTypeId = activeCommandType->getId(); - int cmdTypeIdNext = cmdTypeId+1; - - while(cmdTypeIdNext != cmdTypeId) { - if(cmdTypeIdNext >= maxI) { - cmdTypeIdNext = 0; - } - const CommandType *ctype = display.getCommandType(cmdTypeIdNext); - if(ctype != NULL && ctype->getClass() == ccAttack) { - if(ctype != NULL && unit->getFaction()->reqsOk(ctype)) { - posDisplay=cmdTypeIdNext; - ct = display.getCommandType(posDisplay); - break; - } - } - cmdTypeIdNext++; - } - } - if(ct != NULL && unit->getFaction()->reqsOk(ct)) { activeCommandType= ct; activeCommandClass= activeCommandType->getClass(); @@ -681,9 +658,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { return; } } - - //non uniform selection - else { + else {//non uniform selection activeCommandType= NULL; activeCommandClass= display.getCommandClass(posDisplay); if (activeCommandClass == ccAttack) { From aec7bf5c80f68307209a9f7208f6ea078bb376b1 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 16 Aug 2022 21:59:41 +0400 Subject: [PATCH 22/24] fix: reset command position for build commands --- source/glest_game/gui/gui.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index cc501604..2d80ac1d 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -673,9 +673,12 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) { if (activeCommandClass == ccAttack) { ct = selection.getUnitFromCC(ccAttack)->getType()->getFirstCtOfClass(activeCommandClass); } + if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){ assert(selection.isUniform()); selectingBuilding= true; + selectingPos= false; + activePos= invalidPos; } else if(ct->getClicks()==cOne){ invalidatePosObjWorld(); From 8caa800ee1b101d8624810a16234a1e93c545a4d Mon Sep 17 00:00:00 2001 From: pavanvo Date: Tue, 16 Aug 2022 22:00:31 +0400 Subject: [PATCH 23/24] fix: reset command position for non-target commands --- source/glest_game/gui/gui.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 2d80ac1d..05bc4b63 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -479,6 +479,8 @@ void Gui::giveOneClickOrders(){ addOrdersResultToConsole(activeCommandClass, result); activeCommandType= NULL; activeCommandClass= ccStop; + selectingPos= false; + activePos= invalidPos; } void Gui::giveDefaultOrders(int x, int y) { From d5f15d2c7200603b783cbe264e2b1bb995d998c6 Mon Sep 17 00:00:00 2001 From: pavanvo Date: Thu, 18 Aug 2022 05:57:20 +0400 Subject: [PATCH 24/24] Revert "refactor: remove some useless code," This reverts commit afc26199f7980757857c2bfb949fd225ec4a260f. --- source/glest_game/gui/gui.cpp | 22 ++++++++++++++++++++++ source/glest_game/gui/gui.h | 1 + 2 files changed, 23 insertions(+) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 05bc4b63..7e86b46a 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -439,6 +439,14 @@ void Gui::hotKey(SDL_KeyboardEvent key) { if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) { selectInterestingUnit(iutStore); } + //else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) { + clickCommonCommand(ccAttack); + } + //else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) { + if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) { + clickCommonCommand(ccStop); + } for (int i=0; igetClass() == commandClass) || + display.getCommandClass(index) == commandClass) { + + mouseDownDisplayUnitSkills(index); + break; + } + } + computeDisplay(); +} + void Gui::mouseDownDisplayUnitSkills(int posDisplay) { if(selection.isEmpty() == false) { if(posDisplay != cancelPos) { diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 396770a2..d44831b1 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -217,6 +217,7 @@ private: //hotkeys void centerCameraOnSelection(); void selectInterestingUnit(InterestingUnitType iut); + void clickCommonCommand(CommandClass commandClass); //misc int computePosDisplay(int x, int y);