2
0
Эх сурвалжийг харах

Implement numeric creature descriptions with config toggle on/off

Dydzio 2 жил өмнө
parent
commit
8248feebf7

+ 11 - 1
client/widgets/MiscWidgets.cpp

@@ -29,6 +29,7 @@
 #include "../../lib/CGeneralTextHandler.h"
 #include "../../lib/CModHandler.h"
 #include "../../lib/CGameState.h"
+#include "../../lib/CConfigHandler.h"
 
 void CHoverableArea::hover (bool on)
 {
@@ -253,7 +254,16 @@ void CArmyTooltip::init(const InfoAboutArmy &army)
 		{
 			//if =0 - we have no information about stack size at all
 			if(slot.second.count)
-				subtitle = CGI->generaltexth->arraytxt[171 + 3*(slot.second.count)];
+			{
+				if(settings["adventure"]["numericStackQuantities"].Bool())
+				{
+					subtitle = CCreature::getQuantityRangeStringForId((CCreature::CreatureQuantityId)slot.second.count);
+				}
+				else
+				{
+					subtitle = CGI->generaltexth->arraytxt[171 + 3*(slot.second.count)];
+				}
+			}
 		}
 
 		subtitles.push_back(std::make_shared<CLabel>(slotsPos[slot.first.getNum()].x + 17, slotsPos[slot.first.getNum()].y + 41, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, subtitle));

+ 5 - 1
config/schemas/settings.json

@@ -128,7 +128,7 @@
 			"type" : "object",
 			"additionalProperties" : false,
 			"default": {},
-			"required" : [ "heroSpeed", "enemySpeed", "scrollSpeed", "heroReminder", "quickCombat" ],
+			"required" : [ "heroSpeed", "enemySpeed", "scrollSpeed", "heroReminder", "quickCombat", "numericStackQuantities" ],
 			"properties" : {
 				"heroSpeed" : {
 					"type" : "number",
@@ -149,6 +149,10 @@
 				"quickCombat" : {
 					"type" : "boolean",
 					"default" : false
+				},
+				"numericStackQuantities" : {
+					"type": "boolean",
+					"default": true
 				}
 			}
 		},

+ 38 - 10
lib/CCreatureHandler.cpp

@@ -171,25 +171,53 @@ int32_t CCreature::getCost(int32_t resIndex) const
 		return 0;
 }
 
-int CCreature::getQuantityID(const int & quantity)
+CCreature::CreatureQuantityId CCreature::getQuantityID(const int & quantity)
 {
 	if (quantity<5)
-		return 1;
+		return CCreature::CreatureQuantityId::FEW;
 	if (quantity<10)
-		return 2;
+		return CCreature::CreatureQuantityId::SEVERAL;
 	if (quantity<20)
-		return 3;
+		return CCreature::CreatureQuantityId::PACK;
 	if (quantity<50)
-		return 4;
+		return CCreature::CreatureQuantityId::LOTS;
 	if (quantity<100)
-		return 5;
+		return CCreature::CreatureQuantityId::HORDE;
 	if (quantity<250)
-		return 6;
+		return CCreature::CreatureQuantityId::THRONG;
 	if (quantity<500)
-		return 7;
+		return CCreature::CreatureQuantityId::SWARM;
 	if (quantity<1000)
-		return 8;
-	return 9;
+		return CCreature::CreatureQuantityId::ZOUNDS;
+
+	return CCreature::CreatureQuantityId::LEGION;
+}
+
+std::string CCreature::getQuantityRangeStringForId(const CCreature::CreatureQuantityId & quantityId)
+{
+	switch(quantityId)
+	{
+		case CCreature::CreatureQuantityId::FEW:
+			return "1-4";
+		case CCreature::CreatureQuantityId::SEVERAL:
+			return "5-9";
+		case CCreature::CreatureQuantityId::PACK:
+			return "10-19";
+		case CCreature::CreatureQuantityId::LOTS:
+			return "20-49";
+		case CCreature::CreatureQuantityId::HORDE:
+			return "50-99";
+		case CCreature::CreatureQuantityId::THRONG:
+			return "100-249";
+		case CCreature::CreatureQuantityId::SWARM:
+			return "250-499";
+		case CCreature::CreatureQuantityId::ZOUNDS:
+			return "500-999";
+		case CCreature::CreatureQuantityId::LEGION:
+			return "1000+";
+		default:
+			return "[ERROR]";
+	}
 }
 
 int CCreature::estimateCreatureCount(ui32 countID)

+ 15 - 1
lib/CCreatureHandler.h

@@ -61,6 +61,19 @@ public:
 	std::string smallIconName;
 	std::string largeIconName;
 
+	enum class CreatureQuantityId
+	{
+		FEW = 1,
+		SEVERAL,
+		PACK,
+		LOTS,
+		HORDE,
+		THRONG,
+		SWARM,
+		ZOUNDS,
+		LEGION
+	};
+
 	struct CreatureAnimation
 	{
 		struct RayColor {
@@ -176,7 +189,8 @@ public:
 	bool isGood () const;
 	bool isEvil () const;
 	si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought
-	static int getQuantityID(const int & quantity); //1 - a few, 2 - several, 3 - pack, 4 - lots, 5 - horde, 6 - throng, 7 - swarm, 8 - zounds, 9 - legion
+	static CCreature::CreatureQuantityId getQuantityID(const int & quantity);
+	static std::string getQuantityRangeStringForId(const CCreature::CreatureQuantityId & quantityId);
 	static int estimateCreatureCount(ui32 countID); //reverse version of above function, returns middle of range
 	bool isMyUpgrade(const CCreature *anotherCre) const;
 

+ 19 - 7
lib/CCreatureSet.cpp

@@ -10,6 +10,7 @@
 #include "StdInc.h"
 #include "CCreatureSet.h"
 
+#include "CConfigHandler.h"
 #include "CCreatureHandler.h"
 #include "VCMI_Lib.h"
 #include "CModHandler.h"
@@ -372,9 +373,15 @@ std::string CCreatureSet::getRoughAmount(SlotID slot, int mode) const
 {
 	/// Mode represent return string format
 	/// "Pack" - 0, "A pack of" - 1, "a pack of" - 2
-	int quantity = CCreature::getQuantityID(getStackCount(slot));
-	if(quantity)
-		return VLC->generaltexth->arraytxt[(174 + mode) + 3*CCreature::getQuantityID(getStackCount(slot))];
+	CCreature::CreatureQuantityId quantity = CCreature::getQuantityID(getStackCount(slot));
+
+	if((int)quantity)
+	{
+		if(settings["adventure"]["numericStackQuantities"].Bool())
+			return CCreature::getQuantityRangeStringForId(quantity);
+
+		return VLC->generaltexth->arraytxt[(174 + mode) + 3*(int)quantity];
+	}
 	return "";
 }
 
@@ -700,7 +707,7 @@ void CStackInstance::init()
 	setNodeType(STACK_INSTANCE);
 }
 
-int CStackInstance::getQuantityID() const
+CCreature::CreatureQuantityId CStackInstance::getQuantityID() const
 {
 	return CCreature::getQuantityID(count);
 }
@@ -814,10 +821,15 @@ void CStackInstance::setArmyObj(const CArmedInstance * ArmyObj)
 
 std::string CStackInstance::getQuantityTXT(bool capitalized) const
 {
-	int quantity = getQuantityID();
+	CCreature::CreatureQuantityId quantity = getQuantityID();
 
-	if (quantity)
-		return VLC->generaltexth->arraytxt[174 + quantity*3 - 1 - capitalized];
+	if ((int)quantity)
+	{
+		if(settings["adventure"]["numericStackQuantities"].Bool())
+			return CCreature::getQuantityRangeStringForId(quantity);
+
+		return VLC->generaltexth->arraytxt[174 + (int)quantity*3 - 1 - capitalized];
+	}
 	else
 		return "";
 }

+ 2 - 2
lib/CCreatureSet.h

@@ -27,7 +27,7 @@ class DLL_LINKAGE CStackBasicDescriptor
 {
 public:
 	const CCreature *type;
-	TQuantity count;
+	TQuantity count; //exact quantity or quantity ID from CCreature::getQuantityID when getting info about enemy army
 
 	CStackBasicDescriptor();
 	CStackBasicDescriptor(CreatureID id, TQuantity Count);
@@ -93,7 +93,7 @@ public:
 	std::string bonusToGraphics(const std::shared_ptr<Bonus>& bonus) const; //file name of graphics from StackSkills , in future possibly others
 
 	virtual ui64 getPower() const;
-	int getQuantityID() const;
+	CCreature::CreatureQuantityId getQuantityID() const;
 	std::string getQuantityTXT(bool capitalized = true) const;
 	virtual int getExpRank() const;
 	virtual int getLevel() const; //different for regular stack and commander

+ 1 - 1
lib/CGameState.cpp

@@ -3101,7 +3101,7 @@ ArmyDescriptor::ArmyDescriptor(const CArmedInstance *army, bool detailed)
 		if(detailed)
 			(*this)[elem.first] = *elem.second;
 		else
-			(*this)[elem.first] = CStackBasicDescriptor(elem.second->type, elem.second->getQuantityID());
+			(*this)[elem.first] = CStackBasicDescriptor(elem.second->type, (int)elem.second->getQuantityID());
 	}
 }
 

+ 5 - 1
lib/mapObjects/CGTownInstance.cpp

@@ -14,6 +14,7 @@
 #include "../spells/CSpellHandler.h"
 
 #include "../NetPacks.h"
+#include "../CConfigHandler.h"
 #include "../CGeneralTextHandler.h"
 #include "../CModHandler.h"
 #include "../IGameCallback.h"
@@ -203,7 +204,10 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
 		bd.player = h->tempOwner;
 		bd.text.addTxt(MetaString::GENERAL_TXT, 421); //Much to your dismay, the %s is guarded by %s %s. Do you wish to fight the guards?
 		bd.text.addReplacement(ID == Obj::CREATURE_GENERATOR1 ? MetaString::CREGENS : MetaString::CREGENS4, subID);
-		bd.text.addReplacement(MetaString::ARRAY_TXT, 173 + Slots().begin()->second->getQuantityID()*3);
+		if(settings["adventure"]["numericStackQuantities"].Bool())
+			bd.text.addReplacement(CCreature::getQuantityRangeStringForId(Slots().begin()->second->getQuantityID()));
+		else
+			bd.text.addReplacement(MetaString::ARRAY_TXT, 173 + (int)Slots().begin()->second->getQuantityID()*3);
 		bd.text.addReplacement(*Slots().begin()->second);
 		cb->showBlockingDialog(&bd);
 		return;

+ 7 - 3
lib/mapObjects/MiscObjects.cpp

@@ -15,6 +15,7 @@
 #include "../NetPacks.h"
 #include "../CGeneralTextHandler.h"
 #include "../CSoundBase.h"
+#include "../CConfigHandler.h"
 #include "../CModHandler.h"
 #include "../CHeroHandler.h"
 #include "../CSkillHandler.h"
@@ -101,9 +102,12 @@ std::string CGCreature::getHoverText(PlayerColor player) const
 
 	std::string hoverName;
 	MetaString ms;
-	int pom = stacks.begin()->second->getQuantityID();
-	pom = 172 + 3*pom;
-	ms.addTxt(MetaString::ARRAY_TXT,pom);
+	CCreature::CreatureQuantityId monsterQuantityId = stacks.begin()->second->getQuantityID();
+	int quantityTextIndex = 172 + 3 * (int)monsterQuantityId;
+	if(settings["adventure"]["numericStackQuantities"].Bool())
+		ms << CCreature::getQuantityRangeStringForId(monsterQuantityId);
+	else
+		ms.addTxt(MetaString::ARRAY_TXT, quantityTextIndex);
 	ms << " " ;
 	ms.addTxt(MetaString::CRE_PL_NAMES,subID);
 	ms.toString(hoverName);