Luanti 5.10.0-dev
 
Loading...
Searching...
No Matches
gameui.h
Go to the documentation of this file.
1// Luanti
2// SPDX-License-Identifier: LGPL-2.1-or-later
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#pragma once
7
8#include "irrlichttypes.h"
9#include <IGUIEnvironment.h>
10#include "game.h"
11
12using namespace irr;
13class Client;
14class EnrichedString;
15class GUIChatConsole;
16class GUIFormSpecMenu;
17struct MapDrawControl;
18struct PointedThing;
19
20/*
21 * This object intend to contain the core UI elements
22 * It includes:
23 * - status texts
24 * - debug texts
25 * - chat texts
26 * - hud flags
27 */
28class GameUI
29{
30 // Temporary between coding time to move things here
31 friend class Game;
32
33 // Permit unittests to access members directly
34 friend class TestGameUI;
35
36public:
37 GameUI();
38 ~GameUI() = default;
39
40 // Flags that can, or may, change during main game loop
41 struct Flags
42 {
43 bool show_chat = true;
44 bool show_hud = true;
45 bool show_minimal_debug = false;
46 bool show_basic_debug = false;
47 bool show_profiler_graph = false;
48 };
49
50 void init();
51 void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
52 const CameraOrientation &cam, const PointedThing &pointed_old,
53 const GUIChatConsole *chat_console, float dtime);
54
55 void initFlags();
56 const Flags &getFlags() const { return m_flags; }
57
58 inline void setInfoText(const std::wstring &str) { m_infotext = str; }
59 inline void clearInfoText() { m_infotext.clear(); }
60
61 inline void showStatusText(const std::wstring &str)
62 {
63 m_statustext = str;
64 m_statustext_time = 0.0f;
65 }
66 void showTranslatedStatusText(const char *str);
67 inline void clearStatusText() { m_statustext.clear(); }
68
70 {
72 }
73 void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
74 void updateChatSize();
75
76 void updateProfiler();
77
79 void toggleHud();
80 void toggleProfiler();
81
82 GUIFormSpecMenu *&updateFormspec(const std::string &formname)
83 {
84 m_formname = formname;
85 return m_formspec;
86 }
87
88 const std::string &getFormspecName() { return m_formname; }
90 void deleteFormspec();
91 void clearText();
92
93private:
95
96 float m_drawtime_avg = 0;
97
98 gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
99 gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
100
101 gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
102 std::wstring m_infotext;
103
104 gui::IGUIStaticText *m_guitext_status = nullptr;
105 std::wstring m_statustext;
106 float m_statustext_time = 0.0f;
108
109 gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text
111 core::rect<s32> m_current_chat_size{0, 0, 0, 0};
112
113 gui::IGUIStaticText *m_guitext_profiler = nullptr; // Profiler text
116
117 // Default: "". If other than "": Empty show_formspec packets will only
118 // close the formspec when the formname matches
119 std::string m_formname;
121};
Definition client.h:105
Definition enriched_string.h:29
Definition guiChatConsole.h:15
Definition guiFormSpecMenu.h:87
Definition gameui.h:29
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
Definition gameui.cpp:227
u8 m_profiler_current_page
Definition gameui.h:114
void toggleProfiler()
Definition gameui.cpp:306
GUIFormSpecMenu * m_formspec
Definition gameui.h:120
void initFlags()
Definition gameui.cpp:216
gui::IGUIStaticText * m_guitext_chat
Definition gameui.h:109
void showTranslatedStatusText(const char *str)
Definition gameui.cpp:222
gui::IGUIStaticText * m_guitext_info
Definition gameui.h:101
gui::IGUIStaticText * m_guitext
Definition gameui.h:98
float m_statustext_time
Definition gameui.h:106
void clearInfoText()
Definition gameui.h:59
void update(const RunStats &stats, Client *client, MapDrawControl *draw_control, const CameraOrientation &cam, const PointedThing &pointed_old, const GUIChatConsole *chat_console, float dtime)
Definition gameui.cpp:88
void updateChatSize()
Definition gameui.cpp:234
~GameUI()=default
void updateProfiler()
Definition gameui.cpp:257
std::wstring m_infotext
Definition gameui.h:102
void deleteFormspec()
Definition gameui.cpp:323
void showStatusText(const std::wstring &str)
Definition gameui.h:61
u32 m_recent_chat_count
Definition gameui.h:110
gui::IGUIStaticText * m_guitext2
Definition gameui.h:99
void toggleHud()
Definition gameui.cpp:297
gui::IGUIStaticText * m_guitext_status
Definition gameui.h:104
void setInfoText(const std::wstring &str)
Definition gameui.h:58
std::wstring m_statustext
Definition gameui.h:105
float m_drawtime_avg
Definition gameui.h:96
const u8 m_profiler_max_page
Definition gameui.h:115
video::SColor m_statustext_initial_color
Definition gameui.h:107
GUIFormSpecMenu *& getFormspecGUI()
Definition gameui.h:89
void clearStatusText()
Definition gameui.h:67
void toggleChat(Client *client)
Definition gameui.cpp:283
core::rect< s32 > m_current_chat_size
Definition gameui.h:111
bool isChatVisible()
Definition gameui.h:69
GUIFormSpecMenu *& updateFormspec(const std::string &formname)
Definition gameui.h:82
void init()
Definition gameui.cpp:43
const std::string & getFormspecName()
Definition gameui.h:88
gui::IGUIStaticText * m_guitext_profiler
Definition gameui.h:113
Flags m_flags
Definition gameui.h:94
void clearText()
Definition gameui.cpp:333
GameUI()
Definition gameui.cpp:35
const Flags & getFlags() const
Definition gameui.h:56
std::string m_formname
Definition gameui.h:119
Definition game.cpp:657
Definition test_gameui.cpp:10
Definition activeobjectmgr.cpp:11
Definition clientmap.h:30
Definition game.h:31
Definition gameui.h:42
bool show_basic_debug
Definition gameui.h:46
bool show_hud
Definition gameui.h:44
bool show_minimal_debug
Definition gameui.h:45
bool show_profiler_graph
Definition gameui.h:47
bool show_chat
Definition gameui.h:43
Definition clientmap.h:14
An active object or node which is selected by a ray on the map.
Definition pointedthing.h:22
Definition game.h:25