Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control group hotkeys #229

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions source/glest_game/gui/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,17 +362,11 @@ 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);
// if(!clearGroup){
// Unit* unit=selection.getFrontUnit();
// if(unit!=null && unit->getType()->getMultiSelect()==false){
// return;
// }
// }
bool allAssigned=selection.assignGroup(groupIndex,clearGroup);
bool move=isKeyDown(vkAlt);
bool clearGroup= move && isKeyDown(vkControl) || !move && isKeyDown(vkShift);
bool allAssigned=selection.assignGroup(groupIndex,clearGroup, move);
if(!allAssigned){
console->addStdMessage("GroupAssignFailed");
}
Expand Down
7 changes: 6 additions & 1 deletion source/glest_game/gui/selection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion source/glest_game/gui/selection.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down