diff --git a/client/widgets/CGarrisonInt.cpp b/client/widgets/CGarrisonInt.cpp index d90594714..5b18a06ac 100644 --- a/client/widgets/CGarrisonInt.cpp +++ b/client/widgets/CGarrisonInt.cpp @@ -405,38 +405,34 @@ void CGarrisonInt::addSplitBtn(CButton * button) button->block(getSelection() == nullptr); } -void CGarrisonInt::createSet(std::vector &ret, const CCreatureSet * set, int posX, int posY, int distance, CGarrisonSlot::EGarrisonType Upg ) -{ - ret.resize(7); - - if (set) - { - for(auto & elem : set->Slots()) - { - ret[elem.first.getNum()] = new CGarrisonSlot(this, posX + (elem.first.getNum()*distance), posY, elem.first, Upg, elem.second); - } - } - - for(int i=0; ipos.x -= 126; - ret[i]->pos.y += 37; - }; -} - void CGarrisonInt::createSlots() { OBJ_CONSTRUCTION_CAPTURING_ALL; - - int width = smallIcons? 32 : 58; - - createSet(slotsUp, armedObjs[0], 0, 0, width+interx, CGarrisonSlot::EGarrisonType::UP); - createSet(slotsDown, armedObjs[1], garOffset.x, garOffset.y, width+interx, CGarrisonSlot::EGarrisonType::DOWN); + int distance = interx + (smallIcons? 32 : 58); + for(int i=0; i<2; i++) + { + std::vector garrisonSlots; + garrisonSlots.resize(7); + if (armedObjs[i]) + { + for(auto & elem : armedObjs[i]->Slots()) + { + garrisonSlots[elem.first.getNum()] = new CGarrisonSlot(this, i*garOffset.x + (elem.first.getNum()*distance), i*garOffset.y, elem.first, static_cast(i), elem.second); + } + } + for(int j=0; j<7; j++) + { + if(!garrisonSlots[j]) + garrisonSlots[j] = new CGarrisonSlot(this, i*garOffset.x + (j*distance), i*garOffset.y, SlotID(j), static_cast(i), nullptr); + if (twoRows && j>=4) + { + garrisonSlots[j]->pos.x -= 326; + garrisonSlots[j]->pos.y += 37; + } + } + std::copy(garrisonSlots.begin(), garrisonSlots.end(), std::back_inserter(availableSlots)); + logGlobal->infoStream()<block(true); - for(CGarrisonSlot * slot : slotsUp) + for(CGarrisonSlot * slot : availableSlots) slot->update(); - for(CGarrisonSlot * slot : slotsDown) - slot->update(); } void CGarrisonInt::splitClick() @@ -514,12 +508,7 @@ void CGarrisonInt::setSplittingMode(bool on) if (inSplittingMode || on) { - for(CGarrisonSlot * slot : slotsUp) - { - if(slot!=getSelection()) - slot->setHighlight( ( on && (slot->our() || slot->ally()) && (slot->creature == nullptr || slot->creature == getSelection()->creature))); - } - for(CGarrisonSlot * slot : slotsDown) + for(CGarrisonSlot * slot : availableSlots) { if(slot!=getSelection()) slot->setHighlight( ( on && (slot->our() || slot->ally()) && (slot->creature == nullptr || slot->creature == getSelection()->creature))); diff --git a/client/widgets/CGarrisonInt.h b/client/widgets/CGarrisonInt.h index 4fe8efe43..f74c4c3f5 100644 --- a/client/widgets/CGarrisonInt.h +++ b/client/widgets/CGarrisonInt.h @@ -84,12 +84,12 @@ public: twoRows, ///< slots Will be placed in 2 rows owned[2]; ///< player Owns up or down army ([0] upper, [1] lower) - std::vector slotsUp, slotsDown; ///< Slots of upper and lower garrison + std::vector availableSlots; ///< Slots of upper and lower garrison + const CArmedInstance *armedObjs[2]; ///< [0] is upper, [1] is down 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, CGarrisonSlot::EGarrisonType Upg ); void createSlots(); void recreateSlots();