瀏覽代碼

Improve creature numbers handling in castle interface bottom left part

Dydzio 2 年之前
父節點
當前提交
e7a774c465
共有 3 個文件被更改,包括 61 次插入16 次删除
  1. 7 3
      client/CPlayerInterface.cpp
  2. 49 10
      client/windows/CCastleInterface.cpp
  3. 5 3
      client/windows/CCastleInterface.h

+ 7 - 3
client/CPlayerInterface.cpp

@@ -1220,9 +1220,13 @@ void CPlayerInterface::availableCreaturesChanged( const CGDwelling *town )
 	EVENT_HANDLER_CALLED_BY_CLIENT;
 	if (const CGTownInstance * townObj = dynamic_cast<const CGTownInstance*>(town))
 	{
-		CFortScreen *fs = dynamic_cast<CFortScreen*>(GH.topInt().get());
-		if (fs)
-			fs->creaturesChanged();
+		CFortScreen * fortScreen = dynamic_cast<CFortScreen*>(GH.topInt().get());
+		CCastleInterface * castleInterface = dynamic_cast<CCastleInterface*>(GH.topInt().get());
+
+		if (fortScreen)
+			fortScreen->creaturesChangedEventHandler();
+		else if(castleInterface)
+			castleInterface->creaturesChangedEventHandler();
 
 		for(auto isa : GH.listInt)
 		{

+ 49 - 10
client/windows/CCastleInterface.cpp

@@ -45,6 +45,18 @@
 
 #include <SDL_events.h>
 
+static bool useCompactCreatureBox()
+{
+	//TODO: add UI for easier access
+	return settings["session"]["compactCreatureInfo"].isNumber() ? settings["session"]["compactCreatureInfo"].Bool() : false;
+}
+
+static bool useAvailableAmountAsCreatureLabel()
+{
+	//TODO: add UI for easier access
+	return settings["session"]["availableCreaturesAsLabel"].isNumber() ? settings["session"]["availableCreaturesAsLabel"].Bool() : false;
+}
+
 CBuildingRect::CBuildingRect(CCastleBuildings * Par, const CGTownInstance * Town, const CStructure * Str)
 	: CShowableAnim(0, 0, Str->defName, CShowableAnim::BASE, BUILDING_FRAME_TIME),
 	  parent(Par),
@@ -834,7 +846,10 @@ void CCastleBuildings::enterCastleGate()
 void CCastleBuildings::enterDwelling(int level)
 {
 	assert(level >= 0 && level < town->creatures.size());
-	auto recruitCb = [=](CreatureID id, int count){ LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level); };
+	auto recruitCb = [=](CreatureID id, int count)
+	{
+		LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level);
+	};
 	GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, -87);
 }
 
@@ -966,10 +981,10 @@ void CCastleBuildings::openTownHall()
 	GH.pushIntT<CHallInterface>(town);
 }
 
-CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact, bool ShowAvailable):
+CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact, bool _showAvailable):
 	town(Town),
 	level(Level),
-	showAvailable(ShowAvailable)
+	showAvailable(_showAvailable)
 {
 	OBJECT_CONSTRUCTION_CAPTURING(255-DISPOSE);
 	pos += position;
@@ -990,7 +1005,7 @@ CCreaInfo::CCreaInfo(Point position, const CGTownInstance * Town, int Level, boo
 	if(showAvailable)
 		value = boost::lexical_cast<std::string>(town->creatures[level].first);
 	else
-		value = boost::lexical_cast<std::string>(town->creatureGrowth(level));
+		value = std::string("+") + boost::lexical_cast<std::string>(town->creatureGrowth(level));
 
 	if(compact)
 	{
@@ -1015,7 +1030,7 @@ void CCreaInfo::update()
 		if(showAvailable)
 			value = boost::lexical_cast<std::string>(town->creatures[level].first);
 		else
-			value = boost::lexical_cast<std::string>(town->creatureGrowth(level));
+			value = std::string("+") + boost::lexical_cast<std::string>(town->creatureGrowth(level));
 
 		if(value != label->getText())
 			label->setText(value);
@@ -1042,10 +1057,12 @@ void CCreaInfo::clickLeft(tribool down, bool previousState)
 	if(previousState && (!down))
 	{
 		int offset = LOCPLINT->castleInt? (-87) : 0;
+
 		auto recruitCb = [=](CreatureID id, int count)
 		{
 			LOCPLINT->cb->recruitCreatures(town, town->getUpperArmy(), id, count, level);
 		};
+
 		GH.pushIntT<CRecruitmentWindow>(town, level, town, recruitCb, offset);
 	}
 }
@@ -1072,6 +1089,11 @@ void CCreaInfo::clickRight(tribool down, bool previousState)
 	}
 }
 
+bool CCreaInfo::getShowAvailable()
+{
+	return showAvailable;
+}
+
 CTownInfo::CTownInfo(int posX, int posY, const CGTownInstance * Town, bool townHall)
 	: town(Town),
 	building(nullptr)
@@ -1248,11 +1270,15 @@ void CCastleInterface::recreateIcons()
 
 	creainfo.clear();
 
+	//TODO: GUI option for these
+	bool compactCreatureInfo = useCompactCreatureBox();
+	bool useAvailableCreaturesForLabel = useAvailableAmountAsCreatureLabel();
+
 	for(size_t i=0; i<4; i++)
-		creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 459), town, (int)i));
+		creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 459), town, (int)i, compactCreatureInfo, useAvailableCreaturesForLabel));
 
 	for(size_t i=0; i<4; i++)
-		creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 507), town, (int)i+4));
+		creainfo.push_back(std::make_shared<CCreaInfo>(Point(14+55*(int)i, 507), town, (int)i+4, compactCreatureInfo, useAvailableCreaturesForLabel));
 }
 
 void CCastleInterface::keyPressed(const SDL_KeyboardEvent & key)
@@ -1279,6 +1305,17 @@ void CCastleInterface::keyPressed(const SDL_KeyboardEvent & key)
 	}
 }
 
+void CCastleInterface::creaturesChangedEventHandler()
+{
+	for(auto creatureInfoBox : creainfo)
+	{
+		if(creatureInfoBox->getShowAvailable())
+		{
+			creatureInfoBox->update();
+		}
+	}
+}
+
 CHallInterface::CBuildingBox::CBuildingBox(int x, int y, const CGTownInstance * Town, const CBuilding * Building):
 	town(Town),
 	building(Building)
@@ -1593,10 +1630,12 @@ std::string CFortScreen::getBgName(const CGTownInstance * town)
 		return "TPCASTL8";
 }
 
-void CFortScreen::creaturesChanged()
+void CFortScreen::creaturesChangedEventHandler()
 {
 	for(auto & elem : recAreas)
-		elem->creaturesChanged();
+		elem->creaturesChangedEventHandler();
+
+	LOCPLINT->castleInt->creaturesChangedEventHandler();
 }
 
 CFortScreen::RecruitArea::RecruitArea(int posX, int posY, const CGTownInstance * Town, int Level):
@@ -1686,7 +1725,7 @@ void CFortScreen::RecruitArea::hover(bool on)
 		GH.statusbar->clear();
 }
 
-void CFortScreen::RecruitArea::creaturesChanged()
+void CFortScreen::RecruitArea::creaturesChangedEventHandler()
 {
 	if(availableCount)
 	{

+ 5 - 3
client/windows/CCastleInterface.h

@@ -186,12 +186,13 @@ class CCreaInfo : public CIntObject
 	std::string genGrowthText();
 
 public:
-	CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact=false, bool showAvailable=false);
+	CCreaInfo(Point position, const CGTownInstance * Town, int Level, bool compact=false, bool _showAvailable=false);
 
 	void update();
 	void hover(bool on) override;
 	void clickLeft(tribool down, bool previousState) override;
 	void clickRight(tribool down, bool previousState) override;
+	bool getShowAvailable();
 };
 
 /// Town hall and fort icons for town screen
@@ -250,6 +251,7 @@ public:
 	void addBuilding(BuildingID bid);
 	void removeBuilding(BuildingID bid);
 	void recreateIcons();
+	void creaturesChangedEventHandler();
 };
 
 /// Hall window where you can build things
@@ -339,7 +341,7 @@ class CFortScreen : public CStatusbarWindow
 	public:
 		RecruitArea(int posX, int posY, const CGTownInstance *town, int level);
 
-		void creaturesChanged();
+		void creaturesChangedEventHandler();
 		void hover(bool on) override;
 		void clickLeft(tribool down, bool previousState) override;
 		void clickRight(tribool down, bool previousState) override;
@@ -354,7 +356,7 @@ class CFortScreen : public CStatusbarWindow
 public:
 	CFortScreen(const CGTownInstance * town);
 
-	void creaturesChanged();
+	void creaturesChangedEventHandler();
 };
 
 /// The mage guild screen where you can see which spells you have