gameui.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 "util/enriched_string.h"
  20. #include "util/pointedthing.h"
  21. #include "game.h"
  22. using namespace irr;
  23. class Client;
  24. struct MapDrawControl;
  25. /*
  26. * This object intend to contain the core UI elements
  27. * It includes:
  28. * - status texts
  29. * - debug texts
  30. * - chat texts
  31. * - hud flags
  32. */
  33. class GameUI
  34. {
  35. // Temporary between coding time to move things here
  36. friend class Game;
  37. // Permit unittests to access members directly
  38. friend class TestGameUI;
  39. public:
  40. GameUI() = default;
  41. ~GameUI() = default;
  42. // Flags that can, or may, change during main game loop
  43. struct Flags
  44. {
  45. bool show_chat = true;
  46. bool show_hud = true;
  47. bool show_minimap = true;
  48. bool show_debug = true;
  49. bool show_profiler_graph = true;
  50. };
  51. void init();
  52. void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
  53. const CameraOrientation &cam, const PointedThing &pointed_old,
  54. float dtime);
  55. void initFlags();
  56. const Flags &getFlags() const { return m_flags; }
  57. void showMinimap(bool show);
  58. inline void setInfoText(const std::wstring &str) { m_infotext = str; }
  59. inline void clearInfoText() { m_infotext.clear(); }
  60. inline void showStatusText(const std::wstring &str)
  61. {
  62. m_statustext = str;
  63. m_statustext_time = 0.0f;
  64. }
  65. void showTranslatedStatusText(const char *str);
  66. inline void clearStatusText() { m_statustext.clear(); }
  67. void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
  68. void updateProfiler();
  69. void toggleChat();
  70. void toggleHud();
  71. void toggleProfiler();
  72. private:
  73. Flags m_flags;
  74. gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
  75. gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
  76. gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
  77. std::wstring m_infotext;
  78. gui::IGUIStaticText *m_guitext_status = nullptr;
  79. std::wstring m_statustext;
  80. float m_statustext_time = 0.0f;
  81. gui::IGUIStaticText *m_guitext_chat; // Chat text
  82. gui::IGUIStaticText *m_guitext_profiler; // Profiler text
  83. u8 m_profiler_current_page = 0;
  84. const u8 m_profiler_max_page = 3;
  85. };