1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-01 17:38:41 +00:00

GUI: restore the Pause Menu after closing the Settings Menu

This commit is contained in:
SmallJoker 2025-05-02 21:26:34 +02:00 committed by GitHub
parent 893a74f9d7
commit 6f3735281f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 29 additions and 16 deletions

View file

@ -215,7 +215,6 @@ void GameFormSpec::deleteFormspec()
m_formspec->drop();
m_formspec = nullptr;
}
m_formname.clear();
}
GameFormSpec::~GameFormSpec() {
@ -227,8 +226,10 @@ GameFormSpec::~GameFormSpec() {
bool GameFormSpec::handleEmptyFormspec(const std::string &formspec, const std::string &formname)
{
if (formspec.empty()) {
if (m_formspec && (formname.empty() || formname == m_formname)) {
m_formspec->quitMenu();
GUIModalMenu *menu = g_menumgr.tryGetTopMenu();
if (menu && (formname.empty() || formname == menu->getName())) {
// `m_formspec` will be fixed up in `GameFormSpec::update()`
menu->quitMenu();
}
return true;
}
@ -245,10 +246,11 @@ void GameFormSpec::showFormSpec(const std::string &formspec, const std::string &
TextDestPlayerInventory *txt_dst =
new TextDestPlayerInventory(m_client, formname);
m_formname = formname;
// Replace the currently open formspec
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
m_client->getSoundManager());
m_formspec->setName(formname);
}
void GameFormSpec::showCSMFormSpec(const std::string &formspec, const std::string &formname)
@ -260,10 +262,10 @@ void GameFormSpec::showCSMFormSpec(const std::string &formspec, const std::strin
LocalScriptingFormspecHandler *txt_dst =
new LocalScriptingFormspecHandler(formname, m_client->getScript());
m_formname = formname;
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
m_client->getSoundManager());
m_formspec->setName(formname);
}
void GameFormSpec::showPauseMenuFormSpec(const std::string &formspec, const std::string &formname)
@ -272,20 +274,25 @@ void GameFormSpec::showPauseMenuFormSpec(const std::string &formspec, const std:
// the in-game settings formspec.
// Neither CSM nor the server must be allowed to mess with it.
if (handleEmptyFormspec(formspec, formname))
// If we send updated formspec contents, we can either (1) recycle the old
// GUIFormSpecMenu or (2) close the old and open a new one. This is option 2.
(void)handleEmptyFormspec("", formname);
if (formspec.empty())
return;
FormspecFormSource *fs_src = new FormspecFormSource(formspec);
LocalScriptingFormspecHandler *txt_dst =
new LocalScriptingFormspecHandler(formname, m_pause_script.get());
m_formname = formname;
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
GUIFormSpecMenu *fs = nullptr;
GUIFormSpecMenu::create(fs, m_client, m_rendering_engine->get_gui_env(),
// Ignore formspec prepend.
&m_input->joystick, fs_src, txt_dst, "",
m_client->getSoundManager());
m_formspec->doPause = true;
fs->setName(formname);
fs->doPause = true;
fs->drop(); // 1 reference held by `g_menumgr`
}
void GameFormSpec::showNodeFormspec(const std::string &formspec, const v3s16 &nodepos)
@ -299,7 +306,6 @@ void GameFormSpec::showNodeFormspec(const std::string &formspec, const v3s16 &no
&m_client->getEnv().getClientMap(), nodepos);
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, m_client);
m_formname = "";
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
m_client->getSoundManager());
@ -336,7 +342,7 @@ void GameFormSpec::showPlayerInventory()
}
TextDest *txt_dst = new TextDestPlayerInventory(m_client);
m_formname = "";
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
m_client->getSoundManager());