2023-06-17 22:52:42 +02:00
|
|
|
/*
|
|
|
|
* MetaString.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_BEGIN
|
|
|
|
|
2023-06-18 17:59:04 +02:00
|
|
|
class JsonNode;
|
2023-11-02 22:01:49 +02:00
|
|
|
class ArtifactID;
|
2023-06-17 22:52:42 +02:00
|
|
|
class CreatureID;
|
|
|
|
class CStackBasicDescriptor;
|
2023-09-15 10:06:06 +02:00
|
|
|
class JsonSerializeFormat;
|
2023-11-02 22:01:49 +02:00
|
|
|
class MapObjectID;
|
|
|
|
class MapObjectSubID;
|
|
|
|
class PlayerColor;
|
|
|
|
class SecondarySkill;
|
|
|
|
class SpellID;
|
2024-10-25 22:41:19 +02:00
|
|
|
class FactionID;
|
2023-11-08 16:13:08 +02:00
|
|
|
class GameResID;
|
2023-06-17 22:52:42 +02:00
|
|
|
using TQuantity = si32;
|
|
|
|
|
2023-06-18 12:51:11 +02:00
|
|
|
/// Strings classes that can be used as replacement in MetaString
|
2023-06-18 11:18:25 +02:00
|
|
|
enum class EMetaText : uint8_t
|
|
|
|
{
|
|
|
|
GENERAL_TXT = 1,
|
|
|
|
ARRAY_TXT,
|
|
|
|
ADVOB_TXT,
|
|
|
|
JK_TXT
|
|
|
|
};
|
|
|
|
|
2023-06-18 12:51:11 +02:00
|
|
|
/// Class for string formatting tools that also support transfer over network with localization using language of local install
|
|
|
|
/// Can be used to compose resulting text from multiple line segments and with placeholder replacement
|
2023-06-17 22:52:42 +02:00
|
|
|
class DLL_LINKAGE MetaString
|
|
|
|
{
|
|
|
|
private:
|
2023-06-18 11:18:25 +02:00
|
|
|
enum class EMessage : uint8_t
|
|
|
|
{
|
|
|
|
APPEND_RAW_STRING,
|
|
|
|
APPEND_LOCAL_STRING,
|
2023-06-18 12:51:11 +02:00
|
|
|
APPEND_TEXTID_STRING,
|
2023-06-18 11:18:25 +02:00
|
|
|
APPEND_NUMBER,
|
|
|
|
REPLACE_RAW_STRING,
|
|
|
|
REPLACE_LOCAL_STRING,
|
2023-06-18 12:51:11 +02:00
|
|
|
REPLACE_TEXTID_STRING,
|
2023-06-18 11:18:25 +02:00
|
|
|
REPLACE_NUMBER,
|
2024-05-21 19:00:13 +02:00
|
|
|
REPLACE_POSITIVE_NUMBER,
|
2024-06-23 22:48:19 +02:00
|
|
|
APPEND_EOL
|
2023-06-18 11:18:25 +02:00
|
|
|
};
|
2023-06-17 22:52:42 +02:00
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
std::vector<EMessage> message;
|
2023-06-17 22:52:42 +02:00
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
std::vector<std::pair<EMetaText,ui32> > localStrings;
|
2023-06-17 22:52:42 +02:00
|
|
|
std::vector<std::string> exactStrings;
|
2023-06-18 12:51:11 +02:00
|
|
|
std::vector<std::string> stringsTextID;
|
2023-06-17 22:52:42 +02:00
|
|
|
std::vector<int64_t> numbers;
|
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
std::string getLocalString(const std::pair<EMetaText, ui32> & txt) const;
|
|
|
|
|
|
|
|
public:
|
2023-06-18 12:51:11 +02:00
|
|
|
/// Creates MetaString and appends provided raw string to it
|
|
|
|
static MetaString createFromRawString(const std::string & value);
|
|
|
|
/// Creates MetaString and appends provided text ID string to it
|
|
|
|
static MetaString createFromTextID(const std::string & value);
|
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
/// Appends local string to resulting string
|
|
|
|
void appendLocalString(EMetaText type, ui32 serial);
|
|
|
|
/// Appends raw string, without translation to resulting string
|
2023-06-18 12:51:11 +02:00
|
|
|
void appendRawString(const std::string & value);
|
|
|
|
/// Appends text ID that will be translated in output
|
|
|
|
void appendTextID(const std::string & value);
|
2023-06-18 11:18:25 +02:00
|
|
|
/// Appends specified number to resulting string
|
|
|
|
void appendNumber(int64_t value);
|
|
|
|
|
2024-02-01 18:22:11 +02:00
|
|
|
void appendName(const ArtifactID& id);
|
2023-11-02 22:01:49 +02:00
|
|
|
void appendName(const SpellID& id);
|
|
|
|
void appendName(const PlayerColor& id);
|
|
|
|
void appendName(const CreatureID & id, TQuantity count);
|
2024-07-16 02:01:55 +02:00
|
|
|
void appendName(const GameResID& id);
|
2023-11-02 22:01:49 +02:00
|
|
|
void appendNameSingular(const CreatureID & id);
|
|
|
|
void appendNamePlural(const CreatureID & id);
|
2024-05-21 19:00:13 +02:00
|
|
|
void appendEOL();
|
2023-11-02 22:01:49 +02:00
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
/// Replaces first '%s' placeholder in string with specified local string
|
|
|
|
void replaceLocalString(EMetaText type, ui32 serial);
|
|
|
|
/// Replaces first '%s' placeholder in string with specified fixed, untranslated string
|
2023-06-18 12:51:11 +02:00
|
|
|
void replaceRawString(const std::string & txt);
|
2024-06-24 03:23:26 +02:00
|
|
|
/// Replaces first '%s' placeholder with string ID that will be translated in output
|
2023-06-18 12:51:11 +02:00
|
|
|
void replaceTextID(const std::string & value);
|
2023-06-18 11:18:25 +02:00
|
|
|
/// Replaces first '%d' placeholder in string with specified number
|
|
|
|
void replaceNumber(int64_t txt);
|
|
|
|
/// Replaces first '%+d' placeholder in string with specified number using '+' sign as prefix
|
|
|
|
void replacePositiveNumber(int64_t txt);
|
|
|
|
|
2023-11-02 22:01:49 +02:00
|
|
|
void replaceName(const ArtifactID & id);
|
2024-10-25 22:41:19 +02:00
|
|
|
void replaceName(const FactionID& id);
|
2023-11-02 22:01:49 +02:00
|
|
|
void replaceName(const MapObjectID& id);
|
|
|
|
void replaceName(const PlayerColor& id);
|
|
|
|
void replaceName(const SecondarySkill& id);
|
|
|
|
void replaceName(const SpellID& id);
|
2023-11-08 16:13:08 +02:00
|
|
|
void replaceName(const GameResID& id);
|
2023-11-02 22:01:49 +02:00
|
|
|
|
2023-06-18 11:18:25 +02:00
|
|
|
/// Replaces first '%s' placeholder with singular or plural name depending on creatures count
|
2023-11-02 22:01:49 +02:00
|
|
|
void replaceName(const CreatureID & id, TQuantity count);
|
|
|
|
void replaceNameSingular(const CreatureID & id);
|
|
|
|
void replaceNamePlural(const CreatureID & id);
|
2023-06-18 11:18:25 +02:00
|
|
|
/// Replaces first '%s' placeholder with singular or plural name depending on creatures count
|
2023-11-02 22:01:49 +02:00
|
|
|
void replaceName(const CStackBasicDescriptor & stack);
|
2023-06-18 11:18:25 +02:00
|
|
|
|
|
|
|
/// erases any existing content in the string
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
///used to handle loot from creature bank
|
2023-06-18 12:51:11 +02:00
|
|
|
std::string buildList() const;
|
2023-06-18 11:18:25 +02:00
|
|
|
|
|
|
|
/// Convert all stored values into a single, user-readable string
|
|
|
|
std::string toString() const;
|
|
|
|
|
|
|
|
/// Returns true if current string is empty
|
|
|
|
bool empty() const;
|
|
|
|
|
2023-06-18 23:25:21 +02:00
|
|
|
bool operator == (const MetaString & other) const;
|
|
|
|
|
2023-06-18 17:59:04 +02:00
|
|
|
void jsonSerialize(JsonNode & dest) const;
|
|
|
|
void jsonDeserialize(const JsonNode & dest);
|
2023-09-15 10:06:06 +02:00
|
|
|
|
|
|
|
void serializeJson(JsonSerializeFormat & handler);
|
2023-06-18 17:59:04 +02:00
|
|
|
|
2024-01-20 20:34:51 +02:00
|
|
|
template <typename Handler> void serialize(Handler & h)
|
2023-06-17 22:52:42 +02:00
|
|
|
{
|
|
|
|
h & exactStrings;
|
|
|
|
h & localStrings;
|
2023-06-18 12:51:11 +02:00
|
|
|
h & stringsTextID;
|
2023-06-17 22:52:42 +02:00
|
|
|
h & message;
|
|
|
|
h & numbers;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
VCMI_LIB_NAMESPACE_END
|