From 4ab574150a3c778c178737b034ba9a224f080c9b Mon Sep 17 00:00:00 2001 From: titiger Date: Wed, 10 Jun 2015 00:42:03 +0200 Subject: [PATCH] group selections can be recalled with shift down. Group selections can be recalled with shift down and the group is added to the current selection. --- source/glest_game/game/game.cpp | 8 +++----- source/glest_game/gui/gui.cpp | 7 +++---- source/glest_game/gui/selection.cpp | 12 ++++++++---- source/glest_game/gui/selection.h | 4 ++-- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index b8cb1ef9..229f22aa 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -4859,11 +4859,9 @@ void Game::keyDown(SDL_KeyboardEvent key) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf("input.keysym.mod = %d groupHotKey = %d key = %d (%d) [%s] isgroup = %d\n",key.keysym.mod,groupHotKey,key.keysym.sym,key.keysym.unicode,keyName.c_str(),isKeyPressed(groupHotKey,key)); //printf("input.keysym.mod = %d groupHotKey = %d key = %d (%d) [%s] isgroup = %d\n",key.keysym.mod,groupHotKey,key.keysym.sym,key.keysym.unicode,keyName.c_str(),isKeyPressed(groupHotKey,key)); - - //if(key == groupHotKey) { - if(isKeyPressed(groupHotKey,key) == true) { - //printf("GROUP KEY!\n"); - //gui.groupKey(key-'0'); + //printf("IS GROUP KEY %d scancode:%d sym:%d groupHotKey=%d \n",idx,key.keysym.scancode,key.keysym.sym,groupHotKey); + if(key.keysym.sym==groupHotKey){ + //if(isKeyPressed(groupHotKey,key) == true) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); gui.groupKey(idx-1); break; diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index cb15b307..5cfce2f0 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -349,8 +349,7 @@ void Gui::mouseDoubleClickLeftGraphics(int x, int y){ void Gui::groupKey(int groupIndex) { if(isKeyDown(vkControl)){ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); - - selection.assignGroup(groupIndex); + selection.assignGroup(groupIndex,isKeyDown(vkShift)); } else{ if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex); @@ -361,11 +360,11 @@ void Gui::groupKey(int groupIndex) { lastGroupRecallTime.getMillis() > 0 && lastGroupRecallTime.getMillis() <= recallGroupCenterCameraTimeout) { - selection.recallGroup(groupIndex); + selection.recallGroup(groupIndex,!isKeyDown(vkShift)); centerCameraOnSelection(); } else { - selection.recallGroup(groupIndex); + selection.recallGroup(groupIndex,!isKeyDown(vkShift)); } lastGroupRecallTime.start(); diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index c44f3483..69911923 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -211,13 +211,15 @@ bool Selection::hasUnit(const Unit* unit) const { return find(selectedUnits.begin(), selectedUnits.end(), unit) != selectedUnits.end(); } -void Selection::assignGroup(int groupIndex,const UnitContainer *pUnits) { +void Selection::assignGroup(int groupIndex, bool clearGroup,const UnitContainer *pUnits) { if(groupIndex < 0 || groupIndex >= maxGroups) { throw megaglest_runtime_error("Invalid value for groupIndex = " + intToStr(groupIndex)); } //clear group - groups[groupIndex].clear(); + if(true==clearGroup){ + groups[groupIndex].clear(); + } //assign new group const UnitContainer *addUnits = &selectedUnits; @@ -260,12 +262,14 @@ vector Selection::getUnitsForGroup(int groupIndex) { return groups[groupIndex]; } -void Selection::recallGroup(int groupIndex){ +void Selection::recallGroup(int groupIndex,bool clearSelection){ if(groupIndex < 0 || groupIndex >= maxGroups) { throw megaglest_runtime_error("Invalid value for groupIndex = " + intToStr(groupIndex)); } - clear(); + if(clearSelection==true){ + clear(); + } for(int i = 0; i < (int)groups[groupIndex].size(); ++i) { select(groups[groupIndex][i]); } diff --git a/source/glest_game/gui/selection.h b/source/glest_game/gui/selection.h index f1402dc7..0c58cac9 100644 --- a/source/glest_game/gui/selection.h +++ b/source/glest_game/gui/selection.h @@ -89,10 +89,10 @@ public: Vec3f getRefPos() const; bool hasUnit(const Unit* unit) const; - void assignGroup(int groupIndex,const UnitContainer *pUnits=NULL); + void assignGroup(int groupIndex, bool clearGroup=true, const UnitContainer *pUnits=NULL); void addUnitToGroup(int groupIndex,Unit *unit); void removeUnitFromGroup(int groupIndex,int UnitId); - void recallGroup(int groupIndex); + void recallGroup(int groupIndex, bool clearSelection=true); vector getUnitsForGroup(int groupIndex);