fixed additional group assign
Still missing is handling of units which are not multiselectable.
This commit is contained in:
parent
dbee447a9a
commit
8686d93b94
|
@ -349,7 +349,18 @@ 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,!isKeyDown(vkShift));
|
||||
bool allAssigned=true;
|
||||
bool clearGroup=!isKeyDown(vkShift);
|
||||
// if(!clearGroup){
|
||||
// Unit* unit=selection.getFrontUnit();
|
||||
// if(unit!=null && unit->getType()->getMultiSelect()==false){
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
allAssigned=selection.assignGroup(groupIndex,clearGroup);
|
||||
if(!allAssigned){
|
||||
console->addStdMessage("GroupAssignFailed");
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] groupIndex = %d\n",__FILE__,__FUNCTION__,__LINE__,groupIndex);
|
||||
|
|
|
@ -211,7 +211,7 @@ bool Selection::hasUnit(const Unit* unit) const {
|
|||
return find(selectedUnits.begin(), selectedUnits.end(), unit) != selectedUnits.end();
|
||||
}
|
||||
|
||||
void Selection::assignGroup(int groupIndex, bool clearGroup,const UnitContainer *pUnits) {
|
||||
bool Selection::assignGroup(int groupIndex, bool clearGroup,const UnitContainer *pUnits) {
|
||||
if(groupIndex < 0 || groupIndex >= maxGroups) {
|
||||
throw megaglest_runtime_error("Invalid value for groupIndex = " + intToStr(groupIndex));
|
||||
}
|
||||
|
@ -227,17 +227,40 @@ void Selection::assignGroup(int groupIndex, bool clearGroup,const UnitContainer
|
|||
addUnits = pUnits;
|
||||
}
|
||||
for(unsigned int i = 0; i < addUnits->size(); ++i) {
|
||||
groups[groupIndex].push_back((*addUnits)[i]);
|
||||
if(false == addUnitToGroup(groupIndex,(*addUnits)[i])){
|
||||
// don't try to add more, group is full
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Selection::addUnitToGroup(int groupIndex,Unit *unit) {
|
||||
/**
|
||||
* returns false if group is already full
|
||||
*/
|
||||
bool Selection::addUnitToGroup(int groupIndex,Unit *unit) {
|
||||
if(groupIndex < 0 || groupIndex >= maxGroups) {
|
||||
throw megaglest_runtime_error("Invalid value for groupIndex = " + intToStr(groupIndex));
|
||||
}
|
||||
bool alreadyExists=false;
|
||||
bool groupIsFull=(int)groups[groupIndex].size() >= Config::getInstance().getInt("MaxUnitSelectCount",intToStr(maxUnits).c_str());
|
||||
|
||||
if(unit != NULL) {
|
||||
for(int i = 0; i < (int)groups[groupIndex].size(); ++i) {
|
||||
if(groups[groupIndex][i] == unit) {
|
||||
alreadyExists=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(alreadyExists){
|
||||
return true;
|
||||
}
|
||||
else if(unit != NULL && !groupIsFull) {
|
||||
groups[groupIndex].push_back(unit);
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,8 +89,8 @@ public:
|
|||
Vec3f getRefPos() const;
|
||||
bool hasUnit(const Unit* unit) const;
|
||||
|
||||
void assignGroup(int groupIndex, bool clearGroup=true, const UnitContainer *pUnits=NULL);
|
||||
void addUnitToGroup(int groupIndex,Unit *unit);
|
||||
bool assignGroup(int groupIndex, bool clearGroup=true, const UnitContainer *pUnits=NULL);
|
||||
bool addUnitToGroup(int groupIndex,Unit *unit);
|
||||
void removeUnitFromGroup(int groupIndex,int UnitId);
|
||||
void recallGroup(int groupIndex, bool clearSelection=true);
|
||||
|
||||
|
|
Loading…
Reference in New Issue