Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert some of the recent gui changes #13744

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1776,6 +1776,7 @@ float Client::mediaReceiveProgress()
}

struct TextureUpdateArgs {
gui::IGUIEnvironment *guienv;
u64 last_time_ms;
u16 last_percent;
std::wstring text_base;
Expand All @@ -1801,7 +1802,7 @@ void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progres
targs->last_time_ms = time_ms;
std::wostringstream strm;
strm << targs->text_base << L" " << targs->last_percent << L"%...";
m_rendering_engine->draw_load_screen(strm.str(), targs->tsrc, 0,
m_rendering_engine->draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0,
72 + (u16) ((18. / 100.) * (double) targs->last_percent));
}
}
Expand All @@ -1821,19 +1822,19 @@ void Client::afterContentReceived()
// Rebuild inherited images and recreate textures
infostream<<"- Rebuilding images and textures"<<std::endl;
m_rendering_engine->draw_load_screen(wstrgettext("Loading textures..."),
m_tsrc, 0, 70);
guienv, m_tsrc, 0, 70);
m_tsrc->rebuildImagesAndTextures();

// Rebuild shaders
infostream<<"- Rebuilding shaders"<<std::endl;
m_rendering_engine->draw_load_screen(wstrgettext("Rebuilding shaders..."),
m_tsrc, 0, 71);
guienv, m_tsrc, 0, 71);
m_shsrc->rebuildShaders();

// Update node aliases
infostream<<"- Updating node aliases"<<std::endl;
m_rendering_engine->draw_load_screen(wstrgettext("Initializing nodes..."),
m_tsrc, 0, 72);
guienv, m_tsrc, 0, 72);
m_nodedef->updateAliases(m_itemdef);
for (const auto &path : getTextureDirs()) {
TextureOverrideSource override_source(path + DIR_DELIM + "override.txt");
Expand All @@ -1846,6 +1847,7 @@ void Client::afterContentReceived()
// Update node textures and assign shaders to each tile
infostream<<"- Updating node textures"<<std::endl;
TextureUpdateArgs tu_args;
tu_args.guienv = guienv;
tu_args.last_time_ms = porting::getTimeMs();
tu_args.last_percent = 0;
tu_args.text_base = wstrgettext("Initializing nodes");
Expand All @@ -1862,7 +1864,7 @@ void Client::afterContentReceived()
if (m_mods_loaded)
m_script->on_client_ready(m_env.getLocalPlayer());

m_rendering_engine->draw_load_screen(wstrgettext("Done!"), m_tsrc, 0, 100);
m_rendering_engine->draw_load_screen(wstrgettext("Done!"), guienv, m_tsrc, 0, 100);
infostream<<"Client::afterContentReceived() done"<<std::endl;
}

Expand Down
15 changes: 12 additions & 3 deletions src/client/clientlauncher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ 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()
Expand Down Expand Up @@ -134,7 +136,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args)
m_rendering_engine->get_scene_manager()->getParameters()->
setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true);

gui::IGUIEnvironment *guienv = m_rendering_engine->get_gui_env();
guienv = m_rendering_engine->get_gui_env();
skin = guienv->getSkin();
skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255));
skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0));
Expand Down Expand Up @@ -216,6 +218,14 @@ 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<s32>(0, 0, 10000, 10000));

bool game_has_run = launch_game(error_message, reconnect_requested,
start_data, cmd_args);

Expand Down Expand Up @@ -546,8 +556,7 @@ void ClientLauncher::main_menu(MainMenuData *menudata)
#endif

/* show main menu */
GUIEngine mymenu(&input->joystick, m_rendering_engine->get_gui_env()->getRootGUIElement(),
m_rendering_engine, &g_menumgr, menudata, *kill);
GUIEngine mymenu(&input->joystick, guiroot, m_rendering_engine, &g_menumgr, menudata, *kill);

/* leave scene manager in a clean state */
m_rendering_engine->get_scene_manager()->clear();
Expand Down
19 changes: 6 additions & 13 deletions src/client/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1530,9 +1530,7 @@ bool Game::createClient(const GameStartData &start_data)

bool Game::initGui()
{
auto guienv = m_rendering_engine->get_gui_env();

m_game_ui->init(guienv);
m_game_ui->init();

// Remove stale "recent" chat messages from previous connections
chat_backend->clearRecentChat();
Expand Down Expand Up @@ -1727,11 +1725,11 @@ bool Game::getServerContent(bool *aborted)
if (!client->itemdefReceived()) {
progress = 25;
m_rendering_engine->draw_load_screen(wstrgettext("Item definitions..."),
texture_src, dtime, progress);
guienv, texture_src, dtime, progress);
} else if (!client->nodedefReceived()) {
progress = 30;
m_rendering_engine->draw_load_screen(wstrgettext("Node definitions..."),
texture_src, dtime, progress);
guienv, texture_src, dtime, progress);
} else {
std::ostringstream message;
std::fixed(message);
Expand All @@ -1756,7 +1754,7 @@ bool Game::getServerContent(bool *aborted)
}

progress = 30 + client->mediaReceiveProgress() * 35 + 0.5;
m_rendering_engine->draw_load_screen(utf8_to_wide(message.str()),
m_rendering_engine->draw_load_screen(utf8_to_wide(message.str()), guienv,
texture_src, dtime, progress);
}
}
Expand Down Expand Up @@ -1807,9 +1805,6 @@ inline bool Game::handleCallbacks()
return false;
}

auto guienv = m_rendering_engine->get_gui_env();
auto guiroot = guienv->getRootGUIElement();

if (g_gamecallback->changepassword_requested) {
(new GUIPasswordChange(guienv, guiroot, -1,
&g_menumgr, client, texture_src))->drop();
Expand Down Expand Up @@ -1954,8 +1949,6 @@ void Game::updateStats(RunStats *stats, const FpsControl &draw_times,

void Game::processUserInput(f32 dtime)
{
auto guienv = m_rendering_engine->get_gui_env();

// Reset input if window not active or some menu is active
if (!device->isWindowActive() || isMenuActive() || guienv->hasFocus(gui_chat_console)) {
if(m_game_focused) {
Expand Down Expand Up @@ -4149,7 +4142,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime,
}

if (isMenuActive())
m_rendering_engine->get_gui_env()->getRootGUIElement()->bringToFront(formspec);
guiroot->bringToFront(formspec);
} while (false);

/*
Expand Down Expand Up @@ -4289,7 +4282,7 @@ void FpsControl::limit(IrrlichtDevice *device, f32 *dtime)

void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool draw_sky)
{
m_rendering_engine->draw_load_screen(wstrgettext(msg), texture_src,
m_rendering_engine->draw_load_screen(wstrgettext(msg), guienv, texture_src,
dtime, percent, draw_sky);
}

Expand Down
11 changes: 7 additions & 4 deletions src/client/gameui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ inline static const char *yawToDirectionString(int yaw)
return direction[yaw];
}

void GameUI::init(gui::IGUIEnvironment *guienv)
GameUI::GameUI()
{
if (guienv->getSkin())
if (guienv && guienv->getSkin())
m_statustext_initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT);
else
m_statustext_initial_color = video::SColor(255, 0, 0, 0);

gui::IGUIElement *guiroot = guienv->getRootGUIElement();

}
void GameUI::init()
{
// First line of debug text
m_guitext = gui::StaticText::add(guienv, utf8_to_wide(PROJECT_NAME_C).c_str(),
core::rect<s32>(0, 0, 0, 0), false, true, guiroot);
Expand Down
7 changes: 5 additions & 2 deletions src/client/gameui.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class GameUI
friend class TestGameUI;

public:
GameUI();
~GameUI() = default;

// Flags that can, or may, change during main game loop
struct Flags
{
Expand All @@ -60,7 +63,7 @@ class GameUI
bool show_profiler_graph = false;
};

void init(gui::IGUIEnvironment *m_guienv);
void init();
void update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
const CameraOrientation &cam, const PointedThing &pointed_old,
const GUIChatConsole *chat_console, float dtime);
Expand Down Expand Up @@ -118,7 +121,7 @@ class GameUI
gui::IGUIStaticText *m_guitext_status = nullptr;
std::wstring m_statustext;
float m_statustext_time = 0.0f;
video::SColor m_statustext_initial_color = video::SColor(255, 0, 0, 0);
video::SColor m_statustext_initial_color;

gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text
u32 m_recent_chat_count = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/client/renderingengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,9 @@ bool RenderingEngine::setWindowIcon()
Additionally, a progressbar can be drawn when percent is set between 0 and 100.
*/
void RenderingEngine::draw_load_screen(const std::wstring &text,
ITextureSource *tsrc, float dtime, int percent, bool sky)
gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime,
int percent, bool sky)
{
gui::IGUIEnvironment *guienv = get_gui_env();
v2u32 screensize = getWindowSize();

v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight());
Expand Down
3 changes: 2 additions & 1 deletion src/client/renderingengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ class RenderingEngine
return m_device->getGUIEnvironment();
}

void draw_load_screen(const std::wstring &text, ITextureSource *tsrc,
void draw_load_screen(const std::wstring &text,
gui::IGUIEnvironment *guienv, ITextureSource *tsrc,
float dtime = 0, int percent = 0, bool sky = true);

void draw_scene(video::SColor skycolor, bool show_hud,
Expand Down
6 changes: 3 additions & 3 deletions src/gui/guiFormSpecMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, guienv->getRootGUIElement(),
-1, &g_menumgr, client, guienv, client->getTextureSource(), sound_manager,
fs_src, txt_dest, formspecPrepend);
cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr,
client, guienv, client->getTextureSource(), sound_manager, fs_src,
txt_dest, formspecPrepend);
cur_formspec->doPause = false;

/*
Expand Down
3 changes: 3 additions & 0 deletions src/gui/mainmenumanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ class IGameCallback
virtual void signalKeyConfigChange() = 0;
};

extern gui::IGUIEnvironment *guienv;
extern gui::IGUIStaticText *guiroot;

// Handler for the modal menus

class MainMenuManager : public IMenuManager
Expand Down
12 changes: 5 additions & 7 deletions src/gui/touchscreengui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client/keycode.h"
#include "client/renderingengine.h"
#include "util/numeric.h"
#include "guiButton.h"

#include <iostream>
#include <algorithm>
Expand Down Expand Up @@ -154,8 +153,8 @@ void AutoHideButtonBar::init(ISimpleTextureSource *tsrc,

rect<int> starter_rect = rect<s32>(UpperLeft.X, UpperLeft.Y, LowerRight.X, LowerRight.Y);

IGUIButton *starter_gui_button = GUIButton::addButton(m_guienv, starter_rect,
m_texturesource, nullptr, button_id, L"", nullptr);
IGUIButton *starter_gui_button = m_guienv->addButton(starter_rect, nullptr,
button_id, L"", nullptr);

m_starter.gui_button = starter_gui_button;
m_starter.gui_button->grab();
Expand Down Expand Up @@ -239,8 +238,8 @@ void AutoHideButtonBar::addButton(touch_gui_button_id button_id, const wchar_t *
current_button = rect<s32>(m_upper_left.X, y_start, m_lower_right.Y, y_end);
}

IGUIButton *btn_gui_button = GUIButton::addButton(m_guienv, current_button,
m_texturesource, nullptr, button_id, caption, nullptr);
IGUIButton *btn_gui_button = m_guienv->addButton(current_button, nullptr, button_id,
caption, nullptr);

std::shared_ptr<button_info> btn(new button_info);
btn->gui_button = btn_gui_button;
Expand Down Expand Up @@ -414,8 +413,7 @@ TouchScreenGUI::TouchScreenGUI(IrrlichtDevice *device, IEventReceiver *receiver)
void TouchScreenGUI::initButton(touch_gui_button_id id, const rect<s32> &button_rect,
const std::wstring &caption, bool immediate_release, float repeat_delay)
{
IGUIButton *btn_gui_button = GUIButton::addButton(m_guienv, button_rect,
m_texturesource, nullptr, id, caption.c_str());
IGUIButton *btn_gui_button = m_guienv->addButton(button_rect, nullptr, id, caption.c_str());

button_info *btn = &m_buttons[id];
btn->gui_button = btn_gui_button;
Expand Down