mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-05 19:31:04 +00:00
GameUI refactor (part 7/7): Finish to include profiler things to GameUI
Other changes: * Add GameUI clarification comment * Move force_fog_off & disable_camera_update flags from GameUI to Game, it's not UI related * Properly init GameUI::Flags * Move toggleChat toggleHud & toggleProfiler to GameUI * Add gameui.cpp to LINT whitelist
This commit is contained in:
parent
02f82eca0b
commit
f40f4143df
4 changed files with 78 additions and 75 deletions
|
@ -204,8 +204,7 @@ void GameUI::showTranslatedStatusText(const char *str)
|
|||
delete[] wmsg;
|
||||
}
|
||||
|
||||
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
|
||||
u32 profiler_current_page)
|
||||
void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count)
|
||||
{
|
||||
setStaticText(m_guitext_chat, chat_text);
|
||||
|
||||
|
@ -228,15 +227,14 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
|
|||
|
||||
// Don't show chat if disabled or empty or profiler is enabled
|
||||
m_guitext_chat->setVisible(m_flags.show_chat &&
|
||||
recent_chat_count != 0 && profiler_current_page == 0);
|
||||
recent_chat_count != 0 && m_profiler_current_page == 0);
|
||||
}
|
||||
|
||||
void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page)
|
||||
void GameUI::updateProfiler()
|
||||
{
|
||||
if (profiler_current_page != 0) {
|
||||
if (m_profiler_current_page != 0) {
|
||||
std::ostringstream os(std::ios_base::binary);
|
||||
g_profiler->printPage(os, profiler_current_page,
|
||||
profiler_max_page);
|
||||
g_profiler->printPage(os, m_profiler_current_page, m_profiler_max_page);
|
||||
|
||||
std::wstring text = translate_string(utf8_to_wide(os.str()));
|
||||
setStaticText(m_guitext_profiler, text.c_str());
|
||||
|
@ -263,13 +261,39 @@ void GameUI::updateProfiler(u32 profiler_current_page, u32 profiler_max_page)
|
|||
m_guitext_profiler->setRelativePosition(core::rect<s32>(upper_left, lower_right));
|
||||
}
|
||||
|
||||
m_guitext_profiler->setVisible(profiler_current_page != 0);
|
||||
m_guitext_profiler->setVisible(m_profiler_current_page != 0);
|
||||
}
|
||||
|
||||
if (profiler_current_page != 0) {
|
||||
void GameUI::toggleChat()
|
||||
{
|
||||
m_flags.show_chat = !m_flags.show_chat;
|
||||
if (m_flags.show_chat)
|
||||
showTranslatedStatusText("Chat shown");
|
||||
else
|
||||
showTranslatedStatusText("Chat hidden");
|
||||
}
|
||||
|
||||
void GameUI::toggleHud()
|
||||
{
|
||||
m_flags.show_hud = !m_flags.show_hud;
|
||||
if (m_flags.show_hud)
|
||||
showTranslatedStatusText("HUD shown");
|
||||
else
|
||||
showTranslatedStatusText("HUD hidden");
|
||||
}
|
||||
|
||||
void GameUI::toggleProfiler()
|
||||
{
|
||||
m_profiler_current_page = (m_profiler_current_page + 1) % (m_profiler_max_page + 1);
|
||||
|
||||
// FIXME: This updates the profiler with incomplete values
|
||||
updateProfiler();
|
||||
|
||||
if (m_profiler_current_page != 0) {
|
||||
wchar_t buf[255];
|
||||
const wchar_t* str = wgettext("Profiler shown (page %d of %d)");
|
||||
swprintf(buf, sizeof(buf) / sizeof(wchar_t), str,
|
||||
profiler_current_page, profiler_max_page);
|
||||
m_profiler_current_page, m_profiler_max_page);
|
||||
delete[] str;
|
||||
showStatusText(buf);
|
||||
} else {
|
||||
|
|
|
@ -29,6 +29,14 @@ using namespace irr;
|
|||
class Client;
|
||||
struct MapDrawControl;
|
||||
|
||||
/*
|
||||
* This object intend to contain the core UI elements
|
||||
* It includes:
|
||||
* - status texts
|
||||
* - debug texts
|
||||
* - chat texts
|
||||
* - hud flags
|
||||
*/
|
||||
class GameUI
|
||||
{
|
||||
// Temporary between coding time to move things here
|
||||
|
@ -44,13 +52,11 @@ public:
|
|||
// Flags that can, or may, change during main game loop
|
||||
struct Flags
|
||||
{
|
||||
bool show_chat;
|
||||
bool show_hud;
|
||||
bool show_minimap;
|
||||
bool force_fog_off;
|
||||
bool show_debug;
|
||||
bool show_profiler_graph;
|
||||
bool disable_camera_update;
|
||||
bool show_chat = true;
|
||||
bool show_hud = true;
|
||||
bool show_minimap = true;
|
||||
bool show_debug = true;
|
||||
bool show_profiler_graph = true;
|
||||
};
|
||||
|
||||
void init();
|
||||
|
@ -74,15 +80,18 @@ public:
|
|||
void showTranslatedStatusText(const char *str);
|
||||
inline void clearStatusText() { m_statustext.clear(); }
|
||||
|
||||
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count,
|
||||
u32 profiler_current_page);
|
||||
void setChatText(const EnrichedString &chat_text, u32 recent_chat_count);
|
||||
|
||||
void updateProfiler(u32 profiler_current_page, u32 profiler_max_page);
|
||||
void updateProfiler();
|
||||
|
||||
void toggleChat();
|
||||
void toggleHud();
|
||||
void toggleProfiler();
|
||||
|
||||
private:
|
||||
Flags m_flags;
|
||||
|
||||
gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
|
||||
gui::IGUIStaticText *m_guitext = nullptr; // First line of debug text
|
||||
gui::IGUIStaticText *m_guitext2 = nullptr; // Second line of debug text
|
||||
|
||||
gui::IGUIStaticText *m_guitext_info = nullptr; // At the middle of the screen
|
||||
|
@ -93,5 +102,8 @@ private:
|
|||
float m_statustext_time = 0.0f;
|
||||
|
||||
gui::IGUIStaticText *m_guitext_chat; // Chat text
|
||||
|
||||
gui::IGUIStaticText *m_guitext_profiler; // Profiler text
|
||||
u8 m_profiler_current_page = 0;
|
||||
const u8 m_profiler_max_page = 3;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue