gameui.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "irrlichttypes.h"
  19. #include <IGUIEnvironment.h>
  20. #include "gui/guiFormSpecMenu.h"
  21. #include "util/enriched_string.h"
  22. #include "util/pointedthing.h"
  23. #include "game.h"
  24. using namespace irr;
  25. class Client;
  26. class GUIChatConsole;
  27. struct MapDrawControl;
  28. /*
  29. * This object intend to contain the core UI elements
  30. * It includes:
  31. * - status texts
  32. * - debug texts
  33. * - chat texts
  34. * - hud flags
  35. */
  36. class GameUI
  37. {
  38. // Temporary between coding time to move things here
  39. friend class Game;
  40. // Permit unittests to access members directly
  41. friend class TestGameUI;
  42. public:
  43. GameUI();
  44. ~GameUI() = default;
  45. // Flags that can, or may, change during main game loop
  46. struct Flags
  47. {
  48. bool show_chat = true;
  49. bool show_hud = true;
  50. bool show_minimap = false;
  51. bool show_minimal_debug = false;
  52. bool show_basic_debug = false;
  53. bool show_profiler_graph = false;
  54. };
  55. void init();
  56. void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
  57. const CameraOrientation &cam, const PointedThing &pointed_old,
  58. const GUIChatConsole *chat_console, float dtime);
  59. void initFlags();
  60. const Flags &getFlags() const { return m_flags; }
  61. void showMinimap(bool show);
  62. inline void setInfoText(const std::wstring &str) { m_infotext = str; }
  63. inline void clearInfoText() { m_infotext.clear(); }
  64. inline void showStatusText(const std::wstring &str)
  65. {
  66. m_statustext = str;
  67. m_statustext_time = 0.0f;
  68. }
  69. void showTranslatedStatusText(const char *str);
  70. inline void clearStatusText() { m_statustext.clear(); }
  71. bool isChatVisible()
  72. {
  73. return m_flags.show_chat && m_recent_chat_count != 0 && m_profiler_current_page == 0;
  74. }
  75. void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
  76. void updateChatSize();
  77. void updateProfiler();
  78. void toggleChat();
  79. void toggleHud();
  80. void toggleProfiler();
  81. GUIFormSpecMenu *&updateFormspec(const std::string &formname)
  82. {
  83. m_formname = formname;
  84. return m_formspec;
  85. }
  86. const std::string &getFormspecName() { return m_formname; }
  87. GUIFormSpecMenu *&getFormspecGUI() { return m_formspec; }
  88. void deleteFormspec();
  89. private:
  90. Flags m_flags;
  91. float m_drawtime_avg = 0;
  92. gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
  93. gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
  94. gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
  95. std::wstring m_infotext;
  96. gui::IGUIStaticText *m_guitext_status = nullptr;
  97. std::wstring m_statustext;
  98. float m_statustext_time = 0.0f;
  99. video::SColor m_statustext_initial_color;
  100. gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text
  101. u32 m_recent_chat_count = 0;
  102. core::rect<s32> m_current_chat_size{0, 0, 0, 0};
  103. gui::IGUIStaticText *m_guitext_profiler = nullptr; // Profiler text
  104. u8 m_profiler_current_page = 0;
  105. const u8 m_profiler_max_page = 3;
  106. // Default: "". If other than "": Empty show_formspec packets will only
  107. // close the formspec when the formname matches
  108. std::string m_formname;
  109. GUIFormSpecMenu *m_formspec = nullptr;
  110. };