mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
GUI: restore the Pause Menu after closing the Settings Menu
This commit is contained in:
parent
893a74f9d7
commit
6f3735281f
5 changed files with 29 additions and 16 deletions
|
@ -518,7 +518,7 @@ local function get_formspec(dialogdata)
|
||||||
|
|
||||||
("button[0,%f;%f,0.8;back;%s]"):format(
|
("button[0,%f;%f,0.8;back;%s]"):format(
|
||||||
tabsize.height + 0.2, back_w,
|
tabsize.height + 0.2, back_w,
|
||||||
INIT == "pause_menu" and fgettext("Exit") or fgettext("Back")),
|
fgettext("Back")),
|
||||||
|
|
||||||
("box[%f,%f;%f,0.8;#0000008C]"):format(
|
("box[%f,%f;%f,0.8;#0000008C]"):format(
|
||||||
back_w + 0.2, tabsize.height + 0.2, checkbox_w),
|
back_w + 0.2, tabsize.height + 0.2, checkbox_w),
|
||||||
|
|
|
@ -215,7 +215,6 @@ void GameFormSpec::deleteFormspec()
|
||||||
m_formspec->drop();
|
m_formspec->drop();
|
||||||
m_formspec = nullptr;
|
m_formspec = nullptr;
|
||||||
}
|
}
|
||||||
m_formname.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameFormSpec::~GameFormSpec() {
|
GameFormSpec::~GameFormSpec() {
|
||||||
|
@ -227,8 +226,10 @@ GameFormSpec::~GameFormSpec() {
|
||||||
bool GameFormSpec::handleEmptyFormspec(const std::string &formspec, const std::string &formname)
|
bool GameFormSpec::handleEmptyFormspec(const std::string &formspec, const std::string &formname)
|
||||||
{
|
{
|
||||||
if (formspec.empty()) {
|
if (formspec.empty()) {
|
||||||
if (m_formspec && (formname.empty() || formname == m_formname)) {
|
GUIModalMenu *menu = g_menumgr.tryGetTopMenu();
|
||||||
m_formspec->quitMenu();
|
if (menu && (formname.empty() || formname == menu->getName())) {
|
||||||
|
// `m_formspec` will be fixed up in `GameFormSpec::update()`
|
||||||
|
menu->quitMenu();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -245,10 +246,11 @@ void GameFormSpec::showFormSpec(const std::string &formspec, const std::string &
|
||||||
TextDestPlayerInventory *txt_dst =
|
TextDestPlayerInventory *txt_dst =
|
||||||
new TextDestPlayerInventory(m_client, formname);
|
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(),
|
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
||||||
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
||||||
m_client->getSoundManager());
|
m_client->getSoundManager());
|
||||||
|
m_formspec->setName(formname);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameFormSpec::showCSMFormSpec(const std::string &formspec, const std::string &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 =
|
LocalScriptingFormspecHandler *txt_dst =
|
||||||
new LocalScriptingFormspecHandler(formname, m_client->getScript());
|
new LocalScriptingFormspecHandler(formname, m_client->getScript());
|
||||||
|
|
||||||
m_formname = formname;
|
|
||||||
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
||||||
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
||||||
m_client->getSoundManager());
|
m_client->getSoundManager());
|
||||||
|
m_formspec->setName(formname);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameFormSpec::showPauseMenuFormSpec(const std::string &formspec, const std::string &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.
|
// the in-game settings formspec.
|
||||||
// Neither CSM nor the server must be allowed to mess with it.
|
// 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;
|
return;
|
||||||
|
|
||||||
FormspecFormSource *fs_src = new FormspecFormSource(formspec);
|
FormspecFormSource *fs_src = new FormspecFormSource(formspec);
|
||||||
LocalScriptingFormspecHandler *txt_dst =
|
LocalScriptingFormspecHandler *txt_dst =
|
||||||
new LocalScriptingFormspecHandler(formname, m_pause_script.get());
|
new LocalScriptingFormspecHandler(formname, m_pause_script.get());
|
||||||
|
|
||||||
m_formname = formname;
|
GUIFormSpecMenu *fs = nullptr;
|
||||||
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
GUIFormSpecMenu::create(fs, m_client, m_rendering_engine->get_gui_env(),
|
||||||
// Ignore formspec prepend.
|
// Ignore formspec prepend.
|
||||||
&m_input->joystick, fs_src, txt_dst, "",
|
&m_input->joystick, fs_src, txt_dst, "",
|
||||||
m_client->getSoundManager());
|
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)
|
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);
|
&m_client->getEnv().getClientMap(), nodepos);
|
||||||
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, m_client);
|
TextDest *txt_dst = new TextDestNodeMetadata(nodepos, m_client);
|
||||||
|
|
||||||
m_formname = "";
|
|
||||||
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
||||||
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
||||||
m_client->getSoundManager());
|
m_client->getSoundManager());
|
||||||
|
@ -336,7 +342,7 @@ void GameFormSpec::showPlayerInventory()
|
||||||
}
|
}
|
||||||
|
|
||||||
TextDest *txt_dst = new TextDestPlayerInventory(m_client);
|
TextDest *txt_dst = new TextDestPlayerInventory(m_client);
|
||||||
m_formname = "";
|
|
||||||
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
|
||||||
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
&m_input->joystick, fs_src, txt_dst, m_client->getFormspecPrepend(),
|
||||||
m_client->getSoundManager());
|
m_client->getSoundManager());
|
||||||
|
|
|
@ -55,9 +55,9 @@ private:
|
||||||
InputHandler *m_input;
|
InputHandler *m_input;
|
||||||
std::unique_ptr<PauseMenuScripting> m_pause_script;
|
std::unique_ptr<PauseMenuScripting> m_pause_script;
|
||||||
|
|
||||||
// Default: "". If other than "": Empty show_formspec packets will only
|
/// The currently open formspec that is not a submenu of the pause menu
|
||||||
// close the formspec when the formname matches
|
/// FIXME: Layering is already managed by `GUIModalMenu` (`g_menumgr`), hence this
|
||||||
std::string m_formname;
|
/// variable should be removed in long-term.
|
||||||
GUIFormSpecMenu *m_formspec = nullptr;
|
GUIFormSpecMenu *m_formspec = nullptr;
|
||||||
|
|
||||||
bool handleEmptyFormspec(const std::string &formspec, const std::string &formname);
|
bool handleEmptyFormspec(const std::string &formspec, const std::string &formname);
|
||||||
|
|
|
@ -77,7 +77,7 @@ void GUIVolumeChange::regenerateGui(v2u32 screensize)
|
||||||
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
|
core::rect<s32> rect(0, 0, 100 * s, 30 * s);
|
||||||
rect = rect + v2s32(size.X / 2 - 100 * s / 2, size.Y / 2 + 55 * s);
|
rect = rect + v2s32(size.X / 2 - 100 * s / 2, size.Y / 2 + 55 * s);
|
||||||
GUIButton::addButton(Environment, rect, m_tsrc, this, ID_soundExitButton,
|
GUIButton::addButton(Environment, rect, m_tsrc, this, ID_soundExitButton,
|
||||||
wstrgettext("Exit").c_str());
|
wstrgettext("Back").c_str());
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
core::rect<s32> rect(0, 0, 300 * s, 20 * s);
|
core::rect<s32> rect(0, 0, 300 * s, 20 * s);
|
||||||
|
|
|
@ -76,6 +76,13 @@ public:
|
||||||
return m_stack.size();
|
return m_stack.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GUIModalMenu *tryGetTopMenu() const
|
||||||
|
{
|
||||||
|
if (m_stack.empty())
|
||||||
|
return nullptr;
|
||||||
|
return dynamic_cast<GUIModalMenu *>(m_stack.back());
|
||||||
|
}
|
||||||
|
|
||||||
void deleteFront()
|
void deleteFront()
|
||||||
{
|
{
|
||||||
m_stack.front()->setVisible(false);
|
m_stack.front()->setVisible(false);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue