MetaString.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * MetaString.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. VCMI_LIB_NAMESPACE_BEGIN
  12. class CreatureID;
  13. class CStackBasicDescriptor;
  14. using TQuantity = si32;
  15. enum class EMetaText : uint8_t
  16. {
  17. GENERAL_TXT = 1,
  18. OBJ_NAMES,
  19. RES_NAMES,
  20. ART_NAMES,
  21. ARRAY_TXT,
  22. CRE_PL_NAMES,
  23. CREGENS,
  24. MINE_NAMES,
  25. MINE_EVNTS,
  26. ADVOB_TXT,
  27. ART_EVNTS,
  28. SPELL_NAME,
  29. SEC_SKILL_NAME,
  30. CRE_SING_NAMES,
  31. CREGENS4,
  32. COLOR,
  33. ART_DESCR,
  34. JK_TXT
  35. };
  36. class DLL_LINKAGE MetaString
  37. {
  38. private:
  39. enum class EMessage : uint8_t
  40. {
  41. APPEND_RAW_STRING,
  42. APPEND_LOCAL_STRING,
  43. APPEND_NUMBER,
  44. REPLACE_RAW_STRING,
  45. REPLACE_LOCAL_STRING,
  46. REPLACE_NUMBER,
  47. REPLACE_POSITIVE_NUMBER
  48. };
  49. std::vector<EMessage> message;
  50. std::vector<std::pair<EMetaText,ui32> > localStrings;
  51. std::vector<std::string> exactStrings;
  52. std::vector<int64_t> numbers;
  53. std::string getLocalString(const std::pair<EMetaText, ui32> & txt) const;
  54. public:
  55. /// Appends local string to resulting string
  56. void appendLocalString(EMetaText type, ui32 serial);
  57. /// Appends raw string, without translation to resulting string
  58. void appendRawString(std::string value);
  59. /// Appends specified number to resulting string
  60. void appendNumber(int64_t value);
  61. /// Replaces first '%s' placeholder in string with specified local string
  62. void replaceLocalString(EMetaText type, ui32 serial);
  63. /// Replaces first '%s' placeholder in string with specified fixed, untranslated string
  64. void replaceRawString(const std::string &txt);
  65. /// Replaces first '%d' placeholder in string with specified number
  66. void replaceNumber(int64_t txt);
  67. /// Replaces first '%+d' placeholder in string with specified number using '+' sign as prefix
  68. void replacePositiveNumber(int64_t txt);
  69. /// Replaces first '%s' placeholder with singular or plural name depending on creatures count
  70. void replaceCreatureName(const CreatureID & id, TQuantity count);
  71. /// Replaces first '%s' placeholder with singular or plural name depending on creatures count
  72. void replaceCreatureName(const CStackBasicDescriptor &stack);
  73. /// erases any existing content in the string
  74. void clear();
  75. ///used to handle loot from creature bank
  76. std::string buildList () const;
  77. /// Convert all stored values into a single, user-readable string
  78. std::string toString() const;
  79. /// Returns true if current string is empty
  80. bool empty() const;
  81. template <typename Handler> void serialize(Handler & h, const int version)
  82. {
  83. h & exactStrings;
  84. h & localStrings;
  85. h & message;
  86. h & numbers;
  87. }
  88. };
  89. VCMI_LIB_NAMESPACE_END