From 5cf0313c5ad82b74ff54fb76952be3a58d874941 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Thu, 28 Oct 2010 18:31:12 +0000 Subject: [PATCH] - bugfix for cancel icon displaying when unit has only the 'stop' command active --- source/glest_game/gui/gui.cpp | 45 ++++++++++++++------ source/glest_game/gui/selection.cpp | 4 +- source/glest_game/type_instances/command.cpp | 2 +- source/glest_game/type_instances/unit.cpp | 18 +++++++- source/glest_game/type_instances/unit.h | 2 +- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/source/glest_game/gui/gui.cpp b/source/glest_game/gui/gui.cpp index 6aad564f..c1a26fa6 100644 --- a/source/glest_game/gui/gui.cpp +++ b/source/glest_game/gui/gui.cpp @@ -672,7 +672,9 @@ void Gui::computeInfoString(int posDisplay){ } } -void Gui::computeDisplay(){ +void Gui::computeDisplay() { + + //printf("Start ===> computeDisplay()\n"); //init display.clear(); @@ -693,35 +695,49 @@ void Gui::computeDisplay(){ // ================ PART 2 ================ - if(selectingPos || selectingMeetingPoint){ + if(selectingPos || selectingMeetingPoint) { + //printf("selectingPos || selectingMeetingPoint\n"); display.setDownSelectedPos(activePos); } - if(selection.isComandable()){ - if(!selectingBuilding){ + if(selection.isComandable()) { + //printf("selection.isComandable()\n"); + + if(selectingBuilding == false) { //cancel button const Unit *u= selection.getFrontUnit(); const UnitType *ut= u->getType(); - if(selection.isCancelable()){ + if(selection.isCancelable()) { + //printf("selection.isCancelable() commandcount = %d\n",selection.getUnit(0)->getCommandSize()); + if(selection.getUnit(0)->getCommandSize() > 0) { + //printf("Current Command [%s]\n",selection.getUnit(0)->getCurrCommand()->toString().c_str()); + } + display.setDownImage(cancelPos, ut->getCancelImage()); display.setDownLighted(cancelPos, true); } //meeting point - if(selection.isMeetable()){ + if(selection.isMeetable()) { + //printf("selection.isMeetable()\n"); + display.setDownImage(meetingPointPos, ut->getMeetingPointImage()); display.setDownLighted(meetingPointPos, true); } - if(selection.isUniform()){ + if(selection.isUniform()) { + //printf("selection.isUniform()\n"); + //uniform selection - if(u->isBuilt()){ + if(u->isBuilt()) { + //printf("u->isBuilt()\n"); + int morphPos= 8; - for(int i=0; igetCommandTypeCount(); ++i){ + for(int i=0; igetCommandTypeCount(); ++i) { int displayPos= i; const CommandType *ct= ut->getCommandType(i); - if(ct->getClass()==ccMorph){ + if(ct->getClass()==ccMorph) { displayPos= morphPos++; } display.setDownImage(displayPos, ct->getImage()); @@ -730,13 +746,14 @@ void Gui::computeDisplay(){ } } } + else { + //printf("selection.isUniform() == FALSE\n"); - else{ //non uniform selection int lastCommand= 0; - for(int i=0; i(i); - if(isSharedCommandClass(cc) && cc!=ccBuild){ + if(isSharedCommandClass(cc) && cc!=ccBuild) { display.setDownLighted(lastCommand, true); display.setDownImage(lastCommand, ut->getFirstCtOfClass(cc)->getImage()); display.setCommandClass(lastCommand, cc); @@ -745,7 +762,7 @@ void Gui::computeDisplay(){ } } } - else{ + else { //selecting building const Unit *unit= selection.getFrontUnit(); diff --git a/source/glest_game/gui/selection.cpp b/source/glest_game/gui/selection.cpp index 1ccda42b..e476f5fd 100644 --- a/source/glest_game/gui/selection.cpp +++ b/source/glest_game/gui/selection.cpp @@ -141,8 +141,8 @@ bool Selection::isComandable() const{ bool Selection::isCancelable() const{ return - selectedUnits.size()>1 || - (selectedUnits.size()==1 && selectedUnits[0]->anyCommand()); + selectedUnits.size() > 1 || + (selectedUnits.size() == 1 && selectedUnits[0]->anyCommand(true)); } bool Selection::isMeetable() const{ diff --git a/source/glest_game/type_instances/command.cpp b/source/glest_game/type_instances/command.cpp index 51953dd1..8d2c8f70 100644 --- a/source/glest_game/type_instances/command.cpp +++ b/source/glest_game/type_instances/command.cpp @@ -103,7 +103,7 @@ std::string Command::toString() const { //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__, __LINE__); - result = ", stateType = " + intToStr(stateType) + ", stateValue = " + intToStr(stateValue); + result += ", stateType = " + intToStr(stateType) + ", stateValue = " + intToStr(stateValue); return result; } diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index c999b371..45b7e9c0 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -673,8 +673,22 @@ Vec3f Unit::getCurrVectorFlat() const{ // =================== Command list related =================== //any command -bool Unit::anyCommand() const{ - return !commands.empty(); +bool Unit::anyCommand(bool validateCommandtype) const { + bool result = false; + if(validateCommandtype == false) { + result = (commands.empty() == false); + } + else { + for(Commands::const_iterator it= commands.begin(); it != commands.end(); ++it) { + const CommandType *ct = (*it)->getCommandType(); + if(ct != NULL && ct->getClass() != ccStop) { + result = true; + break; + } + } + } + + return result; } //return current command, assert that there is always one command diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index adf25528..bf5d3398 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -392,7 +392,7 @@ public: Vec3f getCurrVectorFlat() const; //command related - bool anyCommand() const; + bool anyCommand(bool validateCommandtype=false) const; Command *getCurrCommand() const; void replaceCurrCommand(Command *cmd); int getCountOfProducedUnits(const UnitType *ut) const;