Luanti 5.11.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;
16struct MapDrawControl;
17struct PointedThing;
18
19/*
20 * This object intend to contain the core UI elements
21 * It includes:
22 * - status texts
23 * - debug texts
24 * - chat texts
25 * - hud flags
26 */
27class GameUI
28{
29 // Temporary between coding time to move things here
30 friend class Game;
31
32 // Permit unittests to access members directly
33 friend class TestGameUI;
34
35public:
36 GameUI();
37 ~GameUI() = default;
38
39 // Flags that can, or may, change during main game loop
40 struct Flags
41 {
42 bool show_chat = true;
43 bool show_hud = true;
44 bool show_minimal_debug = false;
45 bool show_basic_debug = false;
46 bool show_profiler_graph = false;
47 };
48
49 void init();
50 void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
51 const CameraOrientation &cam, const PointedThing &pointed_old,
52 const GUIChatConsole *chat_console, float dtime);
53
54 void initFlags();
55 const Flags &getFlags() const { return m_flags; }
56
57 inline void setInfoText(const std::wstring &str) { m_infotext = str; }
58 inline void clearInfoText() { m_infotext.clear(); }
59
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
69 {
71 }
72 void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
73 void updateChatSize();
74
75 void updateProfiler();
76
78 void toggleHud();
79 void toggleProfiler();
80
81 void clearText();
82
83private:
85
86 float m_drawtime_avg = 0;
87
88 gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
89 gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
90
91 gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
92 std::wstring m_infotext;
93
94 gui::IGUIStaticText *m_guitext_status = nullptr;
95 std::wstring m_statustext;
96 float m_statustext_time = 0.0f;
98
99 gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text
101 core::rect<s32> m_current_chat_size{0, 0, 0, 0};
102
103 gui::IGUIStaticText *m_guitext_profiler = nullptr; // Profiler text
106};
Definition client.h:104
Definition enriched_string.h:29
Definition guiChatConsole.h:15
Definition gameui.h:28
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
Definition gameui.cpp:226
u8 m_profiler_current_page
Definition gameui.h:104
void toggleProfiler()
Definition gameui.cpp:305
void initFlags()
Definition gameui.cpp:215
gui::IGUIStaticText * m_guitext_chat
Definition gameui.h:99
void showTranslatedStatusText(const char *str)
Definition gameui.cpp:221
gui::IGUIStaticText * m_guitext_info
Definition gameui.h:91
gui::IGUIStaticText * m_guitext
Definition gameui.h:88
float m_statustext_time
Definition gameui.h:96
void clearInfoText()
Definition gameui.h:58
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:87
void updateChatSize()
Definition gameui.cpp:233
~GameUI()=default
void updateProfiler()
Definition gameui.cpp:256
std::wstring m_infotext
Definition gameui.h:92
void showStatusText(const std::wstring &str)
Definition gameui.h:60
u32 m_recent_chat_count
Definition gameui.h:100
gui::IGUIStaticText * m_guitext2
Definition gameui.h:89
void toggleHud()
Definition gameui.cpp:296
gui::IGUIStaticText * m_guitext_status
Definition gameui.h:94
void setInfoText(const std::wstring &str)
Definition gameui.h:57
std::wstring m_statustext
Definition gameui.h:95
float m_drawtime_avg
Definition gameui.h:86
const u8 m_profiler_max_page
Definition gameui.h:105
video::SColor m_statustext_initial_color
Definition gameui.h:97
void clearStatusText()
Definition gameui.h:66
void toggleChat(Client *client)
Definition gameui.cpp:282
core::rect< s32 > m_current_chat_size
Definition gameui.h:101
bool isChatVisible()
Definition gameui.h:68
void init()
Definition gameui.cpp:42
gui::IGUIStaticText * m_guitext_profiler
Definition gameui.h:103
Flags m_flags
Definition gameui.h:84
void clearText()
Definition gameui.cpp:321
GameUI()
Definition gameui.cpp:34
const Flags & getFlags() const
Definition gameui.h:55
Definition game.cpp:487
Definition test_gameui.cpp:10
Definition activeobjectmgr.cpp:11
Definition clientmap.h:30
Definition game.h:31
Definition gameui.h:41
bool show_basic_debug
Definition gameui.h:45
bool show_hud
Definition gameui.h:43
bool show_minimal_debug
Definition gameui.h:44
bool show_profiler_graph
Definition gameui.h:46
bool show_chat
Definition gameui.h:42
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