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;
//select all units of the same type if double click
if(doubleClick && units.size()==1){
const Unit *refUnit= units.front();
if(doubleClick && units.size()>0){
const Unit *refUnit= getRelevantObjectFromSelection(&units);
int factionIndex= refUnit->getFactionIndex();
for(int i=0; i<world->getFaction(factionIndex)->getUnitCount(); ++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;
if(uc.empty() == false) {
for(int i=0; i<uc.size(); ++i){
targetUnit= uc.at(i);
targetPos= targetUnit->getPos();
if(targetUnit->getType()->hasSkillClass(scMove))
{// moving units are more relevant than non moving ones
break;
}
}
targetUnit=getRelevantObjectFromSelection(&uc);
targetPos= targetUnit->getPos();
return true;
}
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){
if(getSelectedResourceObject()==o){
selectedResourceObject=NULL;

View File

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