From 1ef6861d325229bd0beb244f5bd99711c830d2db Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 2 Aug 2022 12:30:40 +0200 Subject: [PATCH 1/3] Add hotkey to move units to a group Pressing alt+groupKey will move the selected units to the other group --- source/glest_game/gui/gui.cpp | 5 +++-- source/glest_game/gui/selection.cpp | 7 ++++++- source/glest_game/gui/selection.h | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 1d0c9d877..5056071a8 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -362,17 +362,18 @@ void Gui::mouseDoubleClickLeftGraphics(int x, int y){ } void Gui::groupKey(int groupIndex) { - if(isKeyDown(vkControl)){ + if(isKeyDown(vkControl) || isKeyDown(vkAlt)){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); // bool allAssigned=true; bool clearGroup=!isKeyDown(vkShift); + bool move=isKeyDown(vkAlt) && !isKeyDown(vkControl); // if(!clearGroup){ // Unit* unit=selection.getFrontUnit(); // if(unit!=null && unit->getType()->getMultiSelect()==false){ // return; // } // } - bool allAssigned=selection.assignGroup(groupIndex,clearGroup); + bool allAssigned=selection.assignGroup(groupIndex,!move && clearGroup, move); if(!allAssigned){ console->addStdMessage("GroupAssignFailed"); } diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 878099501..2a6925b7d 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -227,7 +227,7 @@ bool Selection::hasUnit(const Unit* unit) const { return find(selectedUnits.begin(), selectedUnits.end(), unit) != selectedUnits.end(); } -bool Selection::assignGroup(int groupIndex, bool clearGroup,const UnitContainer *pUnits) { +bool Selection::assignGroup(int groupIndex, bool clearGroup, bool move, const UnitContainer *pUnits) { if(groupIndex < 0 || groupIndex >= maxGroups) { throw megaglest_runtime_error("Invalid value for groupIndex = " + intToStr(groupIndex)); } @@ -244,6 +244,11 @@ bool Selection::assignGroup(int groupIndex, bool clearGroup,const UnitContainer } for(unsigned int i = 0; i < addUnits->size(); ++i) { + if (move) { + for (unsigned int g = 0; g < maxGroups; g++) { + removeUnitFromGroup(g,(*addUnits)[i]->getId()); + } + } if(false == addUnitToGroup(groupIndex,(*addUnits)[i])){ // don't try to add more, group is maybe full return false; diff --git a/source/glest_game/gui/selection.h b/source/glest_game/gui/selection.h index b305df8f9..5fdfd0d4b 100644 --- a/source/glest_game/gui/selection.h +++ b/source/glest_game/gui/selection.h @@ -89,7 +89,7 @@ class Selection: public UnitObserver { Vec3f getRefPos() const; bool hasUnit(const Unit* unit) const; - bool assignGroup(int groupIndex, bool clearGroup=true, const UnitContainer *pUnits=NULL); + bool assignGroup(int groupIndex, bool clearGroup=true, bool move=false, const UnitContainer *pUnits=NULL); bool addUnitToGroup(int groupIndex,Unit *unit); void removeUnitFromGroup(int groupIndex,int UnitId); void recallGroup(int groupIndex, bool clearSelection=true); From 7d8aeab75d9aa6cb6c4bb9abcbf4103f28c092d1 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 2 Aug 2022 13:10:11 +0200 Subject: [PATCH 2/3] Remove commented code --- source/glest_game/gui/gui.cpp | 7 ------- 1 file changed, 7 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 5056071a8..db27ccdb2 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -364,15 +364,8 @@ void Gui::mouseDoubleClickLeftGraphics(int x, int y){ void Gui::groupKey(int groupIndex) { if(isKeyDown(vkControl) || isKeyDown(vkAlt)){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); -// bool allAssigned=true; bool clearGroup=!isKeyDown(vkShift); bool move=isKeyDown(vkAlt) && !isKeyDown(vkControl); -// if(!clearGroup){ -// Unit* unit=selection.getFrontUnit(); -// if(unit!=null && unit->getType()->getMultiSelect()==false){ -// return; -// } -// } bool allAssigned=selection.assignGroup(groupIndex,!move && clearGroup, move); if(!allAssigned){ console->addStdMessage("GroupAssignFailed"); From a3bf75118e4c7301aebfc2f2021c3350d5ae0dd7 Mon Sep 17 00:00:00 2001 From: Rampoina Date: Tue, 2 Aug 2022 13:39:13 +0200 Subject: [PATCH 3/3] Control+Alt+groupKey now creates a new group from the selection while removing the selection from all of the groups --- source/glest_game/gui/gui.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index db27ccdb2..81cbb8e4d 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -364,9 +364,9 @@ void Gui::mouseDoubleClickLeftGraphics(int x, int y){ void Gui::groupKey(int groupIndex) { if(isKeyDown(vkControl) || isKeyDown(vkAlt)){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); - bool clearGroup=!isKeyDown(vkShift); - bool move=isKeyDown(vkAlt) && !isKeyDown(vkControl); - bool allAssigned=selection.assignGroup(groupIndex,!move && clearGroup, move); + bool move=isKeyDown(vkAlt); + bool clearGroup= move && isKeyDown(vkControl) || !move && isKeyDown(vkShift); + bool allAssigned=selection.assignGroup(groupIndex,clearGroup, move); if(!allAssigned){ console->addStdMessage("GroupAssignFailed"); }