]> git.lizzy.rs Git - minetest.git/blob - src/client/gameui.h
GameUI refactor (part 6/X): Move Game::guitext_profiler & showStatusTextSimple to...
[minetest.git] / src / client / gameui.h
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
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21 #pragma once
22
23 #include <IGUIEnvironment.h>
24 #include "util/enriched_string.h"
25 #include "util/pointedthing.h"
26 #include "game.h"
27
28 using namespace irr;
29 class Client;
30 struct MapDrawControl;
31
32 class GameUI
33 {
34         // Temporary between coding time to move things here
35         friend class Game;
36
37         // Permit unittests to access members directly
38         friend class TestGameUI;
39
40 public:
41         GameUI() = default;
42         ~GameUI() = default;
43
44         // Flags that can, or may, change during main game loop
45         struct Flags
46         {
47                 bool show_chat;
48                 bool show_hud;
49                 bool show_minimap;
50                 bool force_fog_off;
51                 bool show_debug;
52                 bool show_profiler_graph;
53                 bool disable_camera_update;
54         };
55
56         void init();
57         void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
58                         const CameraOrientation &cam, const PointedThing &pointed_old,
59                         float dtime);
60
61         void initFlags();
62         const Flags &getFlags() const { return m_flags; }
63
64         void showMinimap(bool show);
65
66         inline void setInfoText(const std::wstring &str) { m_infotext = str; }
67         inline void clearInfoText() { m_infotext.clear(); }
68
69         inline void showStatusText(const std::wstring &str)
70         {
71                 m_statustext = str;
72                 m_statustext_time = 0.0f;
73         }
74         void showTranslatedStatusText(const char *str);
75         inline void clearStatusText() { m_statustext.clear(); }
76
77         void setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
78                         u32 profiler_current_page);
79
80         void updateProfiler(u32 profiler_current_page, u32 profiler_max_page);
81
82 private:
83         Flags m_flags;
84
85         gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
86         gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
87
88         gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
89         std::wstring m_infotext;
90
91         gui::IGUIStaticText *m_guitext_status = nullptr;
92         std::wstring m_statustext;
93         float m_statustext_time = 0.0f;
94
95         gui::IGUIStaticText *m_guitext_chat; // Chat text
96         gui::IGUIStaticText *m_guitext_profiler; // Profiler text
97 };