From 5db11ec5380bd973d3f5511d32a88f1b95cc5665 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Tue, 8 Mar 2011 20:19:19 +0000 Subject: [PATCH] double click selection for units standing near or in buildings --- source/glest_game/gui/gui.cpp | 26 +++++++++++++++----------- source/glest_game/gui/gui.h | 1 + 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index ff0d13fd..904c2ff3 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -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; igetFaction(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; igetPos(); - 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; diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index 26a3265f..766247ac 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -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