gameui.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. Minetest
  3. Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
  4. Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU Lesser General Public License as published by
  7. the Free Software Foundation; either version 2.1 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public License along
  14. with this program; if not, write to the Free Software Foundation, Inc.,
  15. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #pragma once
  18. #include <IGUIEnvironment.h>
  19. #include "gui/guiFormSpecMenu.h"
  20. #include "util/enriched_string.h"
  21. #include "util/pointedthing.h"
  22. #include "game.h"
  23. using namespace irr;
  24. class Client;
  25. class GUIChatConsole;
  26. struct MapDrawControl;
  27. /*
  28. * This object intend to contain the core UI elements
  29. * It includes:
  30. * - status texts
  31. * - debug texts
  32. * - chat texts
  33. * - hud flags
  34. */
  35. class GameUI
  36. {
  37. // Temporary between coding time to move things here
  38. friend class Game;
  39. // Permit unittests to access members directly
  40. friend class TestGameUI;
  41. public:
  42. GameUI();
  43. ~GameUI() = default;
  44. // Flags that can, or may, change during main game loop
  45. struct Flags
  46. {
  47. bool show_chat = true;
  48. bool show_hud = true;
  49. bool show_minimap = false;
  50. bool show_debug = true;
  51. bool show_profiler_graph = false;
  52. };
  53. void init();
  54. void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
  55. const CameraOrientation &cam, const PointedThing &pointed_old,
  56. const GUIChatConsole *chat_console, float dtime);
  57. void initFlags();
  58. const Flags &getFlags() const { return m_flags; }
  59. void showMinimap(bool show);
  60. inline void setInfoText(const std::wstring &str) { m_infotext = str; }
  61. inline void clearInfoText() { m_infotext.clear(); }
  62. inline void showStatusText(const std::wstring &str)
  63. {
  64. m_statustext = str;
  65. m_statustext_time = 0.0f;
  66. }
  67. void showTranslatedStatusText(const char *str);
  68. inline void clearStatusText() { m_statustext.clear(); }
  69. const bool isChatVisible()
  70. {
  71. return m_flags.show_chat && m_recent_chat_count != 0 && m_profiler_current_page == 0;
  72. }
  73. void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
  74. void updateProfiler();
  75. void toggleChat();
  76. void toggleHud();
  77. void toggleProfiler();
  78. GUIFormSpecMenu *&updateFormspec(const std::string &formname)
  79. {
  80. m_formname = formname;
  81. return m_formspec;
  82. }
  83. const std::string &getFormspecName() { return m_formname; }
  84. GUIFormSpecMenu *&getFormspecGUI() { return m_formspec; }
  85. void deleteFormspec();
  86. private:
  87. Flags m_flags;
  88. gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
  89. gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
  90. gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
  91. std::wstring m_infotext;
  92. gui::IGUIStaticText *m_guitext_status = nullptr;
  93. std::wstring m_statustext;
  94. float m_statustext_time = 0.0f;
  95. video::SColor m_statustext_initial_color;
  96. gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text
  97. u32 m_recent_chat_count = 0;
  98. gui::IGUIStaticText *m_guitext_profiler = nullptr; // Profiler text
  99. u8 m_profiler_current_page = 0;
  100. const u8 m_profiler_max_page = 3;
  101. // Default: "". If other than "": Empty show_formspec packets will only
  102. // close the formspec when the formname matches
  103. std::string m_formname;
  104. GUIFormSpecMenu *m_formspec = nullptr;
  105. };