double click selection for units standing near or in buildings

This commit is contained in:
Titus Tscharntke 2011-03-08 20:19:19 +00:00
parent 5b2a6bb45f
commit 5db11ec538
2 changed files with 16 additions and 11 deletions

View File

@ -928,8 +928,8 @@ void Gui::computeSelected(bool doubleClick, bool force){
activeCommandType= NULL; activeCommandType= NULL;
//select all units of the same type if double click //select all units of the same type if double click
if(doubleClick && units.size()==1){ if(doubleClick && units.size()>0){
const Unit *refUnit= units.front(); const Unit *refUnit= getRelevantObjectFromSelection(&units);
int factionIndex= refUnit->getFactionIndex(); int factionIndex= refUnit->getFactionIndex();
for(int i=0; i<world->getFaction(factionIndex)->getUnitCount(); ++i){ for(int i=0; i<world->getFaction(factionIndex)->getUnitCount(); ++i){
Unit *unit= world->getFaction(factionIndex)->getUnit(i); Unit *unit= world->getFaction(factionIndex)->getUnit(i);
@ -971,15 +971,8 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
validPosObjWorld= false; validPosObjWorld= false;
if(uc.empty() == false) { if(uc.empty() == false) {
targetUnit=getRelevantObjectFromSelection(&uc);
for(int i=0; i<uc.size(); ++i){ targetPos= targetUnit->getPos();
targetUnit= uc.at(i);
targetPos= targetUnit->getPos();
if(targetUnit->getType()->hasSkillClass(scMove))
{// moving units are more relevant than non moving ones
break;
}
}
return true; return true;
} }
else if(obj!=NULL) { else if(obj!=NULL) {
@ -1000,6 +993,17 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
} }
} }
Unit* Gui::getRelevantObjectFromSelection(Selection::UnitContainer *uc){
Unit *resultUnit=NULL;
for(int i= 0; i < uc->size(); ++i){
resultUnit= uc->at(i);
if(resultUnit->getType()->hasSkillClass(scMove)){// moving units are more relevant than non moving ones
break;
}
}
return resultUnit;
}
void Gui::removingObjectEvent(Object* o){ void Gui::removingObjectEvent(Object* o){
if(getSelectedResourceObject()==o){ if(getSelectedResourceObject()==o){
selectedResourceObject=NULL; selectedResourceObject=NULL;

View File

@ -211,6 +211,7 @@ private:
bool isSharedCommandClass(CommandClass commandClass); bool isSharedCommandClass(CommandClass commandClass);
void computeSelected(bool doubleCkick,bool force); void computeSelected(bool doubleCkick,bool force);
bool computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit); bool computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&targetUnit);
Unit* getRelevantObjectFromSelection(Selection::UnitContainer *uc);
}; };
}} //end namespace }} //end namespace