Skip to content

Commit

Permalink
Close formspecs with empty string for pause menu / CSM too (tmp)
Browse files Browse the repository at this point in the history
  • Loading branch information
grorp committed Jan 7, 2025
1 parent 6f6a10b commit b9297ed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
8 changes: 5 additions & 3 deletions builtin/common/settings/dlg_settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,7 @@ local function get_formspec(dialogdata)

"box[0,0;", tostring(tabsize.width), ",", tostring(tabsize.height), ";#0000008C]",

("%s[0,%f;%f,0.8;back;%s]"):format(
INIT == "pause_menu" and "button_exit" or "button",
("button[0,%f;%f,0.8;back;%s]"):format(
tabsize.height + 0.2, back_w, fgettext("Back")),

("box[%f,%f;%f,0.8;#0000008C]"):format(
Expand Down Expand Up @@ -672,7 +671,7 @@ local function buttonhandler(this, fields)
dialogdata.rightscroll = core.explode_scrollbar_event(fields.rightscroll).value or dialogdata.rightscroll
dialogdata.query = fields.search_query

-- "quit" is for the pause menu env
-- "fields.quit" is for the pause menu env
if fields.back or fields.quit then
this:delete()
return true
Expand Down Expand Up @@ -800,6 +799,9 @@ else
dialog.data.page_id = update_filtered_pages("")
dialog.delete = function()
dialog = nil
-- only needed for the "fields.back" case, in the "fields.quit"
-- case it's a no-op
core.show_formspec("__builtin:settings", "")
end

core.show_formspec("__builtin:settings", get_formspec(dialog.data))
Expand Down
42 changes: 31 additions & 11 deletions src/client/game_formspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,30 +218,43 @@ GameFormSpec::~GameFormSpec() {
this->deleteFormspec();
}

void GameFormSpec::showFormSpec(const std::string &formspec, const std::string &formname)
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();
}
} else {
FormspecFormSource *fs_src =
new FormspecFormSource(formspec);
TextDestPlayerInventory *txt_dst =
new TextDestPlayerInventory(m_client, formname);

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());
return true;
}
return false;
}

void GameFormSpec::showFormSpec(const std::string &formspec, const std::string &formname)
{
if (handleEmptyFormspec(formspec, formname))
return;

FormspecFormSource *fs_src =
new FormspecFormSource(formspec);
TextDestPlayerInventory *txt_dst =
new TextDestPlayerInventory(m_client, formname);

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());
}

void GameFormSpec::showCSMFormSpec(const std::string &formspec, const std::string &formname)
{
if (handleEmptyFormspec(formspec, formname))
return;

FormspecFormSource *fs_src = new FormspecFormSource(formspec);
LocalFormspecHandler *txt_dst =
new LocalFormspecHandler(formname, m_client, nullptr);

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());
Expand All @@ -252,13 +265,20 @@ void GameFormSpec::showPauseMenuFormSpec(const std::string &formspec, const std:
// The pause menu env is a trusted context like the mainmenu env and provides
// the in-game settings formspec.
// Neither CSM nor the server must be allowed to mess with it.

if (handleEmptyFormspec(formspec, formname))
return;

FormspecFormSource *fs_src = new FormspecFormSource(formspec);
LocalFormspecHandler *txt_dst =
new LocalFormspecHandler(formname, nullptr, m_pause_script.get());

m_formname = formname;
GUIFormSpecMenu::create(m_formspec, m_client, m_rendering_engine->get_gui_env(),
// Ignore formspec prepend.
&m_input->joystick, fs_src, txt_dst, "",
m_client->getSoundManager());

// FIXME: can't enable this for now because "fps_max_unfocused" also applies
// when the game is paused, making the settings menu much less enjoyable.
// m_formspec->doPause = true;
Expand Down
2 changes: 2 additions & 0 deletions src/client/game_formspec.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@ struct GameFormSpec
std::string m_formname;
GUIFormSpecMenu *m_formspec = nullptr;

bool handleEmptyFormspec(const std::string &formspec, const std::string &formname);

void deleteFormspec();
};

0 comments on commit b9297ed

Please sign in to comment.