فهرست منبع

New garrison interface layout: Reversed two rows + labels below slot

Dydzio 2 سال پیش
والد
کامیت
484d03334c
3فایلهای تغییر یافته به همراه54 افزوده شده و 22 حذف شده
  1. 38 14
      client/widgets/CGarrisonInt.cpp
  2. 15 7
      client/widgets/CGarrisonInt.h
  3. 1 1
      client/windows/CKingdomInterface.cpp

+ 38 - 14
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<CLabel>(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<CLabel>(labelPosW, labelPosH, owner->smallIcons ? FONT_TINY : FONT_MEDIUM, labelAlignment, Colors::WHITE);
 
 	update();
 }
@@ -488,7 +500,7 @@ void CGarrisonInt::addSplitBtn(std::shared_ptr<CButton> 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<std::shared_ptr<CGarrisonSlot>> garrisonSlots;
 		garrisonSlots.resize(7);
@@ -499,14 +511,26 @@ void CGarrisonInt::createSlots()
 				garrisonSlots[elem.first.getNum()] = std::make_shared<CGarrisonSlot>(this, i*garOffset.x + (elem.first.getNum()*distance), i*garOffset.y, elem.first, static_cast<CGarrisonSlot::EGarrisonType>(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<CGarrisonSlot>(this, i*garOffset.x + (j*distance), i*garOffset.y, SlotID(j), static_cast<CGarrisonSlot::EGarrisonType>(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);
 

+ 15 - 7
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<std::shared_ptr<CButton>> 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

+ 1 - 1
client/windows/CKingdomInterface.cpp

@@ -772,7 +772,7 @@ CTownItem::CTownItem(const CGTownInstance * Town)
 	hall = std::make_shared<CTownInfo>( 69, 31, town, true);
 	fort = std::make_shared<CTownInfo>(111, 31, town, false);
 
-	garr = std::make_shared<CGarrisonInt>(313, 3, 4, Point(232,0), town->getUpperArmy(), town->visitingHero, true, true, true);
+	garr = std::make_shared<CGarrisonInt>(313, 3, 4, Point(232,0), town->getUpperArmy(), town->visitingHero, true, true, CGarrisonInt::EGarrisonIntSlotsLayout::TWO_ROWS);
 	heroes = std::make_shared<HeroSlots>(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)];