From 484d03334cc5fe0de8f7e79788434035319e8fc9 Mon Sep 17 00:00:00 2001 From: Dydzio Date: Sat, 15 Jul 2023 23:11:21 +0200 Subject: [PATCH] New garrison interface layout: Reversed two rows + labels below slot --- client/widgets/CGarrisonInt.cpp | 52 ++++++++++++++++++++-------- client/widgets/CGarrisonInt.h | 22 ++++++++---- client/windows/CKingdomInterface.cpp | 2 +- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/client/widgets/CGarrisonInt.cpp b/client/widgets/CGarrisonInt.cpp index 9725017e5..9083db69e 100644 --- a/client/widgets/CGarrisonInt.cpp +++ b/client/widgets/CGarrisonInt.cpp @@ -410,7 +410,19 @@ CGarrisonSlot::CGarrisonSlot(CGarrisonInt * Owner, int x, int y, SlotID IID, CGa pos.h = 64; } - stackCount = std::make_shared(pos.w, pos.h, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, ETextAlignment::BOTTOMRIGHT, Colors::WHITE); + int labelPosW = pos.w; + int labelPosH = pos.h; + + if(Owner->layout == CGarrisonInt::EGarrisonIntSlotsLayout::REVERSED_TWO_ROWS) //labels under icon + { + labelPosW = pos.w / 2 + 1; + labelPosH += 7; + } + ETextAlignment labelAlignment = Owner->layout == CGarrisonInt::EGarrisonIntSlotsLayout::REVERSED_TWO_ROWS + ? ETextAlignment::CENTER + : ETextAlignment::BOTTOMRIGHT; + + stackCount = std::make_shared(labelPosW, labelPosH, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, labelAlignment, Colors::WHITE); update(); } @@ -488,7 +500,7 @@ void CGarrisonInt::addSplitBtn(std::shared_ptr button) void CGarrisonInt::createSlots() { int distance = interx + (smallIcons ? 32 : 58); - for(int i=0; i<2; i++) + for(int i = 0; i < 2; i++) { std::vector> garrisonSlots; garrisonSlots.resize(7); @@ -499,14 +511,26 @@ void CGarrisonInt::createSlots() garrisonSlots[elem.first.getNum()] = std::make_shared(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++) + for(int j = 0; j < 7; j++) { if(!garrisonSlots[j]) garrisonSlots[j] = std::make_shared(this, i*garOffset.x + (j*distance), i*garOffset.y, SlotID(j), static_cast(i), nullptr); - if(twoRows && j>=4) + + if(layout == EGarrisonIntSlotsLayout::TWO_ROWS && j >= 4) { garrisonSlots[j]->moveBy(Point(-126, 37)); } + else if(layout == EGarrisonIntSlotsLayout::REVERSED_TWO_ROWS) + { + if(j >= 3) + { + garrisonSlots[j]->moveBy(Point(-90, 49)); + } + else + { + garrisonSlots[j]->moveBy(Point(36, 0)); + } + } } vstd::concatenate(availableSlots, garrisonSlots); } @@ -646,16 +670,16 @@ void CGarrisonInt::bulkSmartSplitStack(const CGarrisonSlot * selected) } CGarrisonInt::CGarrisonInt(int x, int y, int inx, const Point & garsOffset, - const CArmedInstance * s1, const CArmedInstance * s2, - bool _removableUnits, bool smallImgs, bool _twoRows) - : highlighted(nullptr), - inSplittingMode(false), - interx(inx), - garOffset(garsOffset), - pb(false), - smallIcons(smallImgs), - removableUnits(_removableUnits), - twoRows(_twoRows) + const CArmedInstance * s1, const CArmedInstance * s2, + bool _removableUnits, bool smallImgs, EGarrisonIntSlotsLayout _layout) + : highlighted(nullptr), + inSplittingMode(false), + interx(inx), + garOffset(garsOffset), + pb(false), + smallIcons(smallImgs), + removableUnits(_removableUnits), + layout(_layout) { OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE); diff --git a/client/widgets/CGarrisonInt.h b/client/widgets/CGarrisonInt.h index 975fa5139..f2aaa521c 100644 --- a/client/widgets/CGarrisonInt.h +++ b/client/widgets/CGarrisonInt.h @@ -81,6 +81,13 @@ class CGarrisonInt :public CIntObject bool checkSelected(const CGarrisonSlot * selected, TQuantity min = 0) const; public: + enum class EGarrisonIntSlotsLayout + { + ONE_ROW, + TWO_ROWS, + REVERSED_TWO_ROWS + }; + int interx; ///< Space between slots Point garOffset; ///< Offset between garrisons (not used if only one hero) std::vector> splitButtons; ///< May be empty if no buttons @@ -89,9 +96,10 @@ public: bool pb, smallIcons, ///< true - 32x32 imgs, false - 58x64 removableUnits, ///< player Can remove units from up - twoRows, ///< slots Will be placed in 2 rows owned[2]; ///< player Owns up or down army ([0] upper, [1] lower) + EGarrisonIntSlotsLayout layout; + void selectSlot(CGarrisonSlot * slot); ///< @param slot null = deselect const CGarrisonSlot * getSelection() const; @@ -123,13 +131,13 @@ public: /// @param s1, s2 Top and bottom armies /// @param _removableUnits You can take units from top /// @param smallImgs Units images size 64x58 or 32x32 - /// @param _twoRows Display slots in 2 row (1st row = 4 slots, 2nd = 3 slots) + /// @param _layout - when TWO_ROWS - Display slots in 2 rows (1st row = 4 slots, 2nd = 3 slots), REVERSED_TWO_ROWS = 3 slots in 1st row CGarrisonInt(int x, int y, int inx, - const Point & garsOffset, - const CArmedInstance * s1, const CArmedInstance * s2 = nullptr, - bool _removableUnits = true, - bool smallImgs = false, - bool _twoRows = false); + const Point & garsOffset, + const CArmedInstance * s1, const CArmedInstance * s2 = nullptr, + bool _removableUnits = true, + bool smallImgs = false, + EGarrisonIntSlotsLayout _layout = EGarrisonIntSlotsLayout::ONE_ROW); }; class CGarrisonHolder diff --git a/client/windows/CKingdomInterface.cpp b/client/windows/CKingdomInterface.cpp index 1369ad42c..00a68986a 100644 --- a/client/windows/CKingdomInterface.cpp +++ b/client/windows/CKingdomInterface.cpp @@ -772,7 +772,7 @@ CTownItem::CTownItem(const CGTownInstance * Town) hall = std::make_shared( 69, 31, town, true); fort = std::make_shared(111, 31, town, false); - garr = std::make_shared(313, 3, 4, Point(232,0), town->getUpperArmy(), town->visitingHero, true, true, true); + garr = std::make_shared(313, 3, 4, Point(232,0), town->getUpperArmy(), town->visitingHero, true, true, CGarrisonInt::EGarrisonIntSlotsLayout::TWO_ROWS); heroes = std::make_shared(town, Point(244,6), Point(475,6), garr, false); size_t iconIndex = town->town->clientInfo.icons[town->hasFort()][town->builded >= CGI->settings()->getInteger(EGameSettings::TOWNS_BUILDINGS_PER_TURN_CAP)];