diff --git a/source/glest_game/gui/display.cpp b/source/glest_game/gui/display.cpp index 46e8a1e1c..ce73c405a 100644 --- a/source/glest_game/gui/display.cpp +++ b/source/glest_game/gui/display.cpp @@ -112,6 +112,24 @@ int Display::computeDownIndex(int x, int y) const { return index; } +int Display::computeUpIndex(int x, int y) const { + y= y-(Metrics::getInstance().getDisplayH()-upCellSideCount*upImageSize); + + if(y>imageSize*upCellSideCount || y < 0){ + return invalidPos; + } + + int cellX= x/upImageSize; + int cellY= (y/upImageSize) % upCellSideCount; + int index= (upCellSideCount-cellY-1)*upCellSideCount+cellX;; + + if(index<0 || index>=upCellCount || upImages[index]==NULL){ + index= invalidPos; + } + + return index; +} + int Display::computeDownX(int index) const{ return (index % cellSideCount) * imageSize; } diff --git a/source/glest_game/gui/display.h b/source/glest_game/gui/display.h index a910692de..fa8b1764d 100644 --- a/source/glest_game/gui/display.h +++ b/source/glest_game/gui/display.h @@ -105,6 +105,7 @@ class Display{ void clear(); void switchColor(); int computeDownIndex(int x, int y) const; + int computeUpIndex(int x, int y) const; int computeDownX(int index) const; int computeDownY(int index) const; int computeUpX(int index) const; diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 1d0c9d877..fe6749131 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -102,6 +102,7 @@ Gui::Gui(){ activeCommandType= NULL; activeCommandClass= ccStop; selectingBuilding= false; + hoveringUnitPortrait= false; selectedBuildingFacing = CardinalDir(CardinalDir::NORTH); selectingPos= false; selectingMeetingPoint= false; @@ -203,6 +204,7 @@ void Gui::invalidatePosObjWorld(){ void Gui::resetState(){ selectingBuilding= false; + hoveringUnitPortrait= false; selectedBuildingFacing = CardinalDir(CardinalDir::NORTH); selectingPos= false; selectingMeetingPoint= false; @@ -237,7 +239,10 @@ void Gui::mouseDownLeftDisplay(int x, int y) { int posDisplay = computePosDisplay(x, y); if(posDisplay != invalidPos) { - if(selection.isCommandable()) { + if (hoveringUnitPortrait) { + mouseDownPortrait(posDisplay); + } else { + if(selection.isCommandable()) { if(selectingBuilding) { mouseDownDisplayUnitBuild(posDisplay); @@ -249,6 +254,7 @@ void Gui::mouseDownLeftDisplay(int x, int y) { else { resetState(); } + } } computeDisplay(); } @@ -646,6 +652,17 @@ void Gui::clickCommonCommand(CommandClass commandClass) { computeDisplay(); } +void Gui::mouseDownPortrait(int posDisplay) { + Unit *unit = selection.getUnitPtr(posDisplay); + if (isKeyDown(vkControl)) { + selection.selectType(unit); + } else if (!isKeyDown(vkShift)) { + selection.clear(); + selection.select(unit, false); + } else { + selection.unSelect(posDisplay); + } +} void Gui::mouseDownDisplayUnitSkills(int posDisplay) { if(selection.isEmpty() == false) { if(posDisplay != cancelPos) { @@ -778,7 +795,7 @@ void Gui::computeInfoString(int posDisplay){ display.setInfoText(computeDefaultInfoString()); - if(posDisplay!=invalidPos && selection.isCommandable()){ + if(!hoveringUnitPortrait && posDisplay!=invalidPos && selection.isCommandable()){ if(!selectingBuilding){ if(posDisplay==cancelPos){ display.setInfoText(lang.getString("Cancel")); @@ -1113,6 +1130,12 @@ int Gui::computePosDisplay(int x, int y){ } //printf("computePosDisplay returning = %d\n",posDisplay); + if (posDisplay == invalidPos) { + posDisplay = display.computeUpIndex(x, y); + if (posDisplay != invalidPos) { + hoveringUnitPortrait = true; + } + } return posDisplay; } diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index c9c8905c9..033f1923c 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -139,6 +139,7 @@ class Gui { //states bool selectingBuilding; + bool hoveringUnitPortrait; bool selectingPos; bool selectingMeetingPoint; @@ -222,6 +223,7 @@ class Gui { int computePosDisplay(int x, int y); void computeDisplay(); void resetState(); + void mouseDownPortrait(int posDisplay); void mouseDownDisplayUnitSkills(int posDisplay); void mouseDownDisplayUnitBuild(int posDisplay); void computeInfoString(int posDisplay); diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 878099501..2927dd116 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -149,6 +149,16 @@ void Selection::select(const UnitContainer &units, bool addToSelection){ } } +void Selection::selectType(Unit *unit) { + UnitContainer units; + for (int i = 0; i < (int)selectedUnits.size(); i++) { + if (selectedUnits[i]->getType() == unit->getType() && unit->isOperative() == selectedUnits[i]->isOperative() ) { + units.push_back(selectedUnits[i]); + } + } + selectedUnits = units; +} + void Selection::unSelect(const UnitContainer &units) { //add units to gui diff --git a/source/glest_game/gui/selection.h b/source/glest_game/gui/selection.h index b305df8f9..e306d4446 100644 --- a/source/glest_game/gui/selection.h +++ b/source/glest_game/gui/selection.h @@ -69,6 +69,7 @@ class Selection: public UnitObserver { virtual ~Selection(); bool select(Unit *unit, bool addToSelection); + void selectType(Unit *unit); void select(const UnitContainer &units, bool addToSelection); void unSelect(const UnitContainer &units); void unSelect(int unitIndex);