UiManager.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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 <OgreRenderQueueListener.h>
  17. #include <OgreSingleton.h>
  18. #include <OgreUTFString.h>
  19. #include <tinyxml.h>
  20. #include "Manager.h"
  21. #include "UiFont.h"
  22. #include "UiWidget.h"
  23. /**
  24. * The UI manager.
  25. */
  26. class UiManager :
  27. public Manager, public Ogre::RenderQueueListener, public Ogre::Singleton<UiManager>
  28. {
  29. public:
  30. /**
  31. * Constructor.
  32. */
  33. UiManager();
  34. /**
  35. * Destructor.
  36. */
  37. virtual ~UiManager();
  38. /**
  39. * Initializes the manager.
  40. *
  41. * Loads all available fonts and screens from _fonts.xml and
  42. * screens.xml, respectably.
  43. */
  44. void Initialise();
  45. /**
  46. * Handles an input event.
  47. *
  48. * @param[in] event Event to handle.
  49. */
  50. void Input(const VGears::Event& event) override;
  51. /**
  52. * Updates the elements in the manager with debug information.
  53. */
  54. void UpdateDebug() override;
  55. /**
  56. * Handles resizing events.
  57. */
  58. void OnResize();
  59. /**
  60. * Clears all field UI elements in the manager.
  61. */
  62. void ClearField() override;
  63. /**
  64. * Clears all battle UI elements in the manager.
  65. */
  66. void ClearBattle() override;
  67. /**
  68. * Clears all world map UI elements in the manager.
  69. */
  70. void ClearWorld() override;
  71. /**
  72. * Adds a font to the manager.
  73. *
  74. * @param[in] font The font to add.
  75. */
  76. void AddFont(UiFont* font);
  77. /**
  78. * Retrieves a font by name.
  79. *
  80. * @param[in] name Name of the font.
  81. * @return The font by the specified name, or NULL if there is none.
  82. */
  83. UiFont* GetFont(const Ogre::String& name);
  84. /**
  85. * Adds a prototype to the manager.
  86. *
  87. * @param[in] name The prototype manager.
  88. * @param[in] prototype The prototyme, as an XML node.
  89. * @todo What exactly is a prototype here?
  90. */
  91. void AddPrototype(const Ogre::String& name, TiXmlNode* prototype);
  92. /**
  93. * Retrieves a prototype by name.
  94. *
  95. * @param[in] name Name of the prototype.
  96. * @return The prototype by the specified name, or NULL if there is
  97. * none.
  98. * @todo What exactly is a prototype here?
  99. */
  100. TiXmlNode* GetPrototype(const Ogre::String& name) const;
  101. /**
  102. * Adds a UI widget to the manager.
  103. *
  104. * @param[in] widget The widget to add.
  105. */
  106. void AddWidget(UiWidget* widget);
  107. /**
  108. * Retrieves a UI widget by name.
  109. *
  110. * @param[in] name Name of the widget.
  111. * @return The widget by the specified name, or NULL if there is none.
  112. */
  113. UiWidget* GetWidget(const Ogre::String& name);
  114. /**
  115. * Retrieves a UI widget by name.
  116. *
  117. * @param[in] name Name of the widget.
  118. * @return The widget by the specified name, or NULL if there is none.
  119. */
  120. UiWidget* ScriptGetWidget(const char* name);
  121. /**
  122. * Sets the colours of the background of every window.
  123. *
  124. * They are applied to all the existing window backgrounds (widgets marked with
  125. * UiWidget::SetWindowBackground), and to the ones created later.
  126. *
  127. * @param[in] r1 Red component for the top-left corner (0-1).
  128. * @param[in] g1 Green component for the top-left corner (0-1).
  129. * @param[in] b1 Blue component for the top-left corner (0-1).
  130. * @param[in] r2 Red component for the top-right corner (0-1).
  131. * @param[in] g2 Green component for the top-right corner (0-1).
  132. * @param[in] b2 Blue component for the top-right corner (0-1).
  133. * @param[in] r3 Red component for the bottom-right corner (0-1).
  134. * @param[in] g3 Green component for the bottom-right corner (0-1).
  135. * @param[in] b3 Blue component for the bottom-right corner (0-1).
  136. * @param[in] r4 Red component for the bottom-left corner (0-1).
  137. * @param[in] g4 Green component for the bottom-left corner (0-1).
  138. * @param[in] b4 Blue component for the bottom-left corner (0-1).
  139. */
  140. void SetWindowColours(
  141. const float r1, const float g1, const float b1,
  142. const float r2, const float g2, const float b2,
  143. const float r3, const float g3, const float b3,
  144. const float r4, const float g4, const float b4
  145. );
  146. /**
  147. * Applies the window colours to a widget if it is a window background, and to its
  148. * children. Does nothing until the colours have been set.
  149. *
  150. * @param[in] widget The widget.
  151. */
  152. void ApplyWindowColours(UiWidget* widget);
  153. /**
  154. * Updates the render queue.
  155. *
  156. * @param[in] queueGroupId The queue group ID.
  157. * @param[in] invocation Unused.
  158. * @param[in] skipThisInvocation Unused.
  159. */
  160. void renderQueueStarted(
  161. Ogre::uint8 queueGroupId, const Ogre::String& invocation,
  162. bool& skipThisInvocation
  163. );
  164. private:
  165. /**
  166. * Updates the field UI elements in the manager.
  167. */
  168. void UpdateField() override;
  169. /**
  170. * Updates the battle UI elements in the manager.
  171. */
  172. void UpdateBattle() override;
  173. /**
  174. * Updates the world map UI elements in the manager.
  175. */
  176. void UpdateWorld() override;
  177. /**
  178. * List of fonts in the manager.
  179. */
  180. std::vector<UiFont*> fonts_;
  181. /**
  182. * A UI prototype.
  183. *
  184. * @todo What exactly is a prototype here?
  185. */
  186. struct UiPrototype{
  187. /**
  188. * The prototype node.
  189. */
  190. Ogre::String name;
  191. /**
  192. * The prototype structure as an XML node.
  193. */
  194. TiXmlNode* node;
  195. };
  196. /**
  197. * List of prototypes.
  198. */
  199. std::vector<UiPrototype> prototypes_;
  200. /**
  201. * List of widgets.
  202. */
  203. std::vector<UiWidget*> widgets_;
  204. /**
  205. * Colours of the windows (RGB of the top-left, top-right, bottom-right and bottom-left
  206. * corners). Only used if window_colours_set_.
  207. */
  208. float window_colours_[12];
  209. /**
  210. * Indicates if the window colours were set.
  211. */
  212. bool window_colours_set_ = false;
  213. };