From cd13807115b03c3191d0a8a7143cbb3d3579b7ac Mon Sep 17 00:00:00 2001 From: Sandy Carter Date: Mon, 24 Aug 2015 17:40:12 -0400 Subject: [PATCH] Garrison: Clarify upg by turning into a class enum --- client/widgets/CGarrisonInt.cpp | 35 ++++++++++++++++----------------- client/widgets/CGarrisonInt.h | 12 ++++++++--- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/client/widgets/CGarrisonInt.cpp b/client/widgets/CGarrisonInt.cpp index ca355eda9..47a94f11f 100644 --- a/client/widgets/CGarrisonInt.cpp +++ b/client/widgets/CGarrisonInt.cpp @@ -71,7 +71,7 @@ void CGarrisonSlot::hover (bool on) } else { - if(upg) + if(upg == EGarrisonType::UP) { temp = CGI->generaltexth->tcommands[32]; //Select %s (visiting) } @@ -119,13 +119,13 @@ void CGarrisonSlot::hover (bool on) const CArmedInstance * CGarrisonSlot::getObj() const { - return (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]); + return owner->armedObjs[upg]; } /// @return Whether the unit in the slot belongs to the current player. bool CGarrisonSlot::our() const { - return upg?(owner->owned[1]):(owner->owned[0]); + return owner->owned[upg]; } /// @return Whether the unit in the slot belongs to an ally but not to the current player. @@ -255,8 +255,8 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState) else if (!( ( selection->our()//our creature is selected || selection->creature == creature )//or we are rebalancing army && ( owner->removableUnits - || (upg == 0 && ( selection->upg == 1 && !creature ) ) - || (upg == 1 && selection->upg == 1 ) ) )) + || (upg == EGarrisonType::UP && ( selection->upg == EGarrisonType::down && !creature ) ) + || (upg == EGarrisonType::down && selection->upg == EGarrisonType::down ) ) )) { // Highlight if(creature) @@ -270,17 +270,16 @@ void CGarrisonSlot::clickLeft(tribool down, bool previousState) refr = split(); // swap else if(creature != selection->creature) - LOCPLINT->cb->swapCreatures( - (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), - (!selection->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), - ID,selection->ID); + LOCPLINT->cb->swapCreatures(owner->armedObjs[upg], owner->armedObjs[selection->upg], ID, selection->ID); // merge else - LOCPLINT->cb->mergeStacks( - (!selection->upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), - (!upg)?(owner->armedObjs[0]):(owner->armedObjs[1]), - selection->ID,ID); - if(refr) {hover(false); hover(true); } //to refresh statusbar + LOCPLINT->cb->mergeStacks(owner->armedObjs[selection->upg], owner->armedObjs[upg], selection->ID, ID); + if(refr) + { + // Refresh Statusbar + hover(false); + hover(true); + } } } @@ -314,7 +313,7 @@ void CGarrisonSlot::update() } } -CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, int Upg, const CStackInstance * Creature): +CGarrisonSlot::CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, CGarrisonSlot::EGarrisonType Upg, const CStackInstance * Creature): ID(IID), owner(Owner), myStack(Creature), @@ -362,7 +361,7 @@ void CGarrisonInt::addSplitBtn(CButton * button) button->block(getSelection() == nullptr); } -void CGarrisonInt::createSet(std::vector &ret, const CCreatureSet * set, int posX, int posY, int distance, int Upg ) +void CGarrisonInt::createSet(std::vector &ret, const CCreatureSet * set, int posX, int posY, int distance, CGarrisonSlot::EGarrisonType Upg ) { ret.resize(7); @@ -392,8 +391,8 @@ void CGarrisonInt::createSlots() int width = smallIcons? 32 : 58; - createSet(slotsUp, armedObjs[0], 0, 0, width+interx, 0); - createSet(slotsDown, armedObjs[1], garOffset.x, garOffset.y, width+interx, 1); + createSet(slotsUp, armedObjs[0], 0, 0, width+interx, CGarrisonSlot::EGarrisonType::UP); + createSet(slotsDown, armedObjs[1], garOffset.x, garOffset.y, width+interx, CGarrisonSlot::EGarrisonType::DOWN); } void CGarrisonInt::recreateSlots() diff --git a/client/widgets/CGarrisonInt.h b/client/widgets/CGarrisonInt.h index 94181c4dc..743076fb5 100644 --- a/client/widgets/CGarrisonInt.h +++ b/client/widgets/CGarrisonInt.h @@ -28,7 +28,13 @@ class CGarrisonSlot : public CIntObject CGarrisonInt *owner; const CStackInstance *myStack; //nullptr if slot is empty const CCreature *creature; - int upg; //0 - up garrison, 1 - down garrison + + /// Type of Garrison for slot (up or down) + enum EGarrisonType + { + UP=0, ///< 0 - up garrison (Garrisoned) + DOWN, ///< 1 - down garrison (Visiting) + } upg; ///< Flag indicating if it is the up or down garrison CAnimImage * creatureImage; CAnimImage * selectionImage; // image for selection, not always visible @@ -47,7 +53,7 @@ public: void clickRight(tribool down, bool previousState); void clickLeft(tribool down, bool previousState); void update(); - CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, int Upg=0, const CStackInstance * Creature=nullptr); + CGarrisonSlot(CGarrisonInt *Owner, int x, int y, SlotID IID, EGarrisonType Upg=EGarrisonType::UP, const CStackInstance * Creature=nullptr); friend class CGarrisonInt; }; @@ -87,7 +93,7 @@ public: void setArmy(const CArmedInstance *army, bool bottomGarrison); void addSplitBtn(CButton * button); - void createSet(std::vector &ret, const CCreatureSet * set, int posX, int distance, int posY, int Upg ); + void createSet(std::vector &ret, const CCreatureSet * set, int posX, int distance, int posY, CGarrisonSlot::EGarrisonType Upg ); void createSlots(); void recreateSlots();