From 45e7a800575f6d96ea307d99f1945aeb6c22a4e1 Mon Sep 17 00:00:00 2001 From: Desour Date: Wed, 9 Aug 2023 02:21:29 +0200 Subject: [PATCH] Get rid of guiroot The guienvironment already provides a root gui element, we don't need to add another one. (For CGUIEnvironment, the env itself is the root element.) --- src/client/clientlauncher.cpp | 12 ++---------- src/client/game.cpp | 8 ++++---- src/client/gameui.cpp | 2 ++ src/gui/guiFormSpecMenu.cpp | 6 +++--- src/gui/mainmenumanager.h | 2 +- 5 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index 72452f9c289f..b7b58cff6540 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -42,7 +42,6 @@ with this program; if not, write to the Free Software Foundation, Inc., /* mainmenumanager.h */ gui::IGUIEnvironment *guienv = nullptr; -gui::IGUIStaticText *guiroot = nullptr; MainMenuManager g_menumgr; bool isMenuActive() @@ -218,14 +217,6 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) m_rendering_engine->get_gui_env()->clear(); - /* - We need some kind of a root node to be able to add - custom gui elements directly on the screen. - Otherwise they won't be automatically drawn. - */ - guiroot = m_rendering_engine->get_gui_env()->addStaticText(L"", - core::rect(0, 0, 10000, 10000)); - bool game_has_run = launch_game(error_message, reconnect_requested, start_data, cmd_args); @@ -556,7 +547,8 @@ void ClientLauncher::main_menu(MainMenuData *menudata) #endif /* show main menu */ - GUIEngine mymenu(&input->joystick, guiroot, m_rendering_engine, &g_menumgr, menudata, *kill); + GUIEngine mymenu(&input->joystick, m_rendering_engine->get_gui_env()->getRootGUIElement(), + m_rendering_engine, &g_menumgr, menudata, *kill); /* leave scene manager in a clean state */ m_rendering_engine->get_scene_manager()->clear(); diff --git a/src/client/game.cpp b/src/client/game.cpp index 32787cad3486..8a91d352fea2 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1806,19 +1806,19 @@ inline bool Game::handleCallbacks() } if (g_gamecallback->changepassword_requested) { - (new GUIPasswordChange(guienv, guiroot, -1, + (new GUIPasswordChange(guienv, guienv->getRootGUIElement(), -1, &g_menumgr, client, texture_src))->drop(); g_gamecallback->changepassword_requested = false; } if (g_gamecallback->changevolume_requested) { - (new GUIVolumeChange(guienv, guiroot, -1, + (new GUIVolumeChange(guienv, guienv->getRootGUIElement(), -1, &g_menumgr, texture_src))->drop(); g_gamecallback->changevolume_requested = false; } if (g_gamecallback->keyconfig_requested) { - (new GUIKeyChangeMenu(guienv, guiroot, -1, + (new GUIKeyChangeMenu(guienv, guienv->getRootGUIElement(), -1, &g_menumgr, texture_src))->drop(); g_gamecallback->keyconfig_requested = false; } @@ -4142,7 +4142,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, } if (isMenuActive()) - guiroot->bringToFront(formspec); + m_rendering_engine->get_gui_env()->getRootGUIElement()->bringToFront(formspec); } while (false); /* diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index d448eadd6147..4cc68fa10ce6 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -53,6 +53,8 @@ GameUI::GameUI() } void GameUI::init() { + IGUIElement *guiroot = guienv->getRootGUIElement(); + // First line of debug text m_guitext = gui::StaticText::add(guienv, utf8_to_wide(PROJECT_NAME_C).c_str(), core::rect(0, 0, 0, 0), false, true, guiroot); diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index 578456139706..f15f39582efa 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -139,9 +139,9 @@ void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client, TextDest *txt_dest, const std::string &formspecPrepend, ISoundManager *sound_manager) { if (cur_formspec == nullptr) { - cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr, - client, guienv, client->getTextureSource(), sound_manager, fs_src, - txt_dest, formspecPrepend); + cur_formspec = new GUIFormSpecMenu(joystick, guienv->getRootGUIElement(), + -1, &g_menumgr, client, guienv, client->getTextureSource(), sound_manager, + fs_src, txt_dest, formspecPrepend); cur_formspec->doPause = false; /* diff --git a/src/gui/mainmenumanager.h b/src/gui/mainmenumanager.h index 76d3573405b0..b86d1892ac26 100644 --- a/src/gui/mainmenumanager.h +++ b/src/gui/mainmenumanager.h @@ -38,8 +38,8 @@ class IGameCallback virtual void signalKeyConfigChange() = 0; }; +// FIXME: do we really need this global variable? extern gui::IGUIEnvironment *guienv; -extern gui::IGUIStaticText *guiroot; // Handler for the modal menus