1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-04-13 11:40:38 +02:00

Implement numeric creature descriptions with config toggle on/off

This commit is contained in:
Dydzio 2023-01-14 15:55:08 +01:00
parent 5e72ef76cf
commit 8248feebf7
9 changed files with 103 additions and 27 deletions

View File

@ -29,6 +29,7 @@
#include "../../lib/CGeneralTextHandler.h" #include "../../lib/CGeneralTextHandler.h"
#include "../../lib/CModHandler.h" #include "../../lib/CModHandler.h"
#include "../../lib/CGameState.h" #include "../../lib/CGameState.h"
#include "../../lib/CConfigHandler.h"
void CHoverableArea::hover (bool on) 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 =0 - we have no information about stack size at all
if(slot.second.count) 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)); 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));

View File

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

View File

@ -171,25 +171,53 @@ int32_t CCreature::getCost(int32_t resIndex) const
return 0; return 0;
} }
int CCreature::getQuantityID(const int & quantity) CCreature::CreatureQuantityId CCreature::getQuantityID(const int & quantity)
{ {
if (quantity<5) if (quantity<5)
return 1; return CCreature::CreatureQuantityId::FEW;
if (quantity<10) if (quantity<10)
return 2; return CCreature::CreatureQuantityId::SEVERAL;
if (quantity<20) if (quantity<20)
return 3; return CCreature::CreatureQuantityId::PACK;
if (quantity<50) if (quantity<50)
return 4; return CCreature::CreatureQuantityId::LOTS;
if (quantity<100) if (quantity<100)
return 5; return CCreature::CreatureQuantityId::HORDE;
if (quantity<250) if (quantity<250)
return 6; return CCreature::CreatureQuantityId::THRONG;
if (quantity<500) if (quantity<500)
return 7; return CCreature::CreatureQuantityId::SWARM;
if (quantity<1000) if (quantity<1000)
return 8; return CCreature::CreatureQuantityId::ZOUNDS;
return 9;
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) int CCreature::estimateCreatureCount(ui32 countID)

View File

@ -61,6 +61,19 @@ public:
std::string smallIconName; std::string smallIconName;
std::string largeIconName; std::string largeIconName;
enum class CreatureQuantityId
{
FEW = 1,
SEVERAL,
PACK,
LOTS,
HORDE,
THRONG,
SWARM,
ZOUNDS,
LEGION
};
struct CreatureAnimation struct CreatureAnimation
{ {
struct RayColor { struct RayColor {
@ -176,7 +189,8 @@ public:
bool isGood () const; bool isGood () const;
bool isEvil () const; bool isEvil () const;
si32 maxAmount(const std::vector<si32> &res) const; //how many creatures can be bought 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 static int estimateCreatureCount(ui32 countID); //reverse version of above function, returns middle of range
bool isMyUpgrade(const CCreature *anotherCre) const; bool isMyUpgrade(const CCreature *anotherCre) const;

View File

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

View File

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

View File

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

View File

@ -14,6 +14,7 @@
#include "../spells/CSpellHandler.h" #include "../spells/CSpellHandler.h"
#include "../NetPacks.h" #include "../NetPacks.h"
#include "../CConfigHandler.h"
#include "../CGeneralTextHandler.h" #include "../CGeneralTextHandler.h"
#include "../CModHandler.h" #include "../CModHandler.h"
#include "../IGameCallback.h" #include "../IGameCallback.h"
@ -203,7 +204,10 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const
bd.player = h->tempOwner; 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.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(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); bd.text.addReplacement(*Slots().begin()->second);
cb->showBlockingDialog(&bd); cb->showBlockingDialog(&bd);
return; return;

View File

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