TextManager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreString.h>
  17. #include <OgreSingleton.h>
  18. #include <tinyxml.h>
  19. /**
  20. * The text manager.
  21. */
  22. class TextManager : public Ogre::Singleton<TextManager>{
  23. public:
  24. /**
  25. * Constructor.
  26. */
  27. TextManager();
  28. /**
  29. * Destructor.
  30. */
  31. virtual ~TextManager();
  32. /**
  33. * Initializes the commands for the text manager.
  34. */
  35. void InitCmd();
  36. /**
  37. * Sets the language for texts.
  38. *
  39. * @param language[in] Language identifier. Must be the name of one of
  40. * the folders in the data/text/.
  41. */
  42. void SetLanguage(const Ogre::String& language);
  43. /**
  44. * Retrieves the currently set language.
  45. *
  46. * @return The current language.
  47. */
  48. const Ogre::String& GetLanguage();
  49. /**
  50. * Adds text.
  51. *
  52. * @param name[in] Text name or identifier.
  53. * @param node[in] Text node in an XML file.
  54. */
  55. void AddText(const Ogre::String& name, TiXmlNode* node);
  56. /**
  57. * Adds a text dialog.
  58. *
  59. * @param name[in] Text name or identifier.
  60. * @param node[in] Text node in an XML file.
  61. * @param width[in] Text width.
  62. * @param height[in] Text height.
  63. */
  64. void AddDialog(
  65. const Ogre::String& name, TiXmlNode* node,
  66. const float width, const float height
  67. );
  68. /**
  69. * Retrieves a text by name.
  70. *
  71. * @param name[in] Text name or identifier.
  72. * @return Text node in an XML file, or NULL if there is none.
  73. */
  74. TiXmlNode* GetText(const Ogre::String& name) const;
  75. /**
  76. * Retrieves a dialog and it's dimensions by name.
  77. *
  78. * @param name[in] Text name or identifier.
  79. * @param width[out] The text width will be saved here. It won't change
  80. * if the dialog is not found.
  81. * @param height[out] The text height will be saved here. It won't
  82. * change if the dialog is not found.
  83. * @return Text node in an XML file, or NULL if there is none.
  84. */
  85. TiXmlNode* GetDialog(
  86. const Ogre::String& name, float &width, float& height
  87. ) const;
  88. /**
  89. * Deletes all texts in the manager.
  90. */
  91. void UnloadTexts();
  92. private:
  93. /**
  94. * The language for the texts.
  95. */
  96. Ogre::String language_;
  97. /**
  98. * A text.
  99. */
  100. struct Text{
  101. /**
  102. * Name or identifier of the text.
  103. */
  104. Ogre::String name;
  105. /**
  106. * Text node in an XML file.
  107. */
  108. TiXmlNode* node;
  109. };
  110. /**
  111. * The list of texts in the manager.
  112. */
  113. std::vector<Text> texts_;
  114. /**
  115. * A dialog.
  116. */
  117. struct Dialog{
  118. /**
  119. * Name or identifier of the text.
  120. */
  121. Ogre::String name;
  122. /**
  123. * Text node in an XML file.
  124. */
  125. TiXmlNode* node;
  126. /**
  127. * The text width.
  128. */
  129. float width;
  130. /**
  131. * The text height.
  132. */
  133. float height;
  134. };
  135. /**
  136. * The list of dialogs in the manager.
  137. */
  138. std::vector<Dialog> dialogs_;
  139. };