Switch between pages

This commit is contained in:
swagtoy 2024-06-27 02:06:36 -04:00
parent a13cf23432
commit 96ea24ffef
5 changed files with 27 additions and 9 deletions

@ -107,7 +107,12 @@ function dialog_create(name, spec, buttonhandler, eventhandler)
minetest.show_formspec(name, spec({}))
end
function core.show_settings()
load(true, false)
show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS")
load(true, false)
function core.show_settings(page_id)
if not page_id then
show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS", {})
else
show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS", {page_id = page_id})
end
end

@ -756,6 +756,6 @@ function create_settings_dlg()
return dlg
end
function show_settings_client_formspec(name)
minetest.show_formspec(name or "dlg_settings", get_formspec({}))
function show_settings_client_formspec(name, data)
minetest.show_formspec(name or "dlg_settings", get_formspec(data))
end

@ -198,8 +198,14 @@ struct LocalFormspecHandler : public TextDest
if (g_settings->existsLocal(i.first) && g_settings->get(i.first) != i.second)
{
g_settings->set(i.first, i.second);
//std::cout << "Setting " << i.first << " set!" << std::endl;
}
if (i.first.rfind("page_", 0) == 0)
{
m_client->getScript()->show_settings(i.first.substr(5));
std::cout << "Found ..." << m_client << std::endl;
}
//std::cout << "Setting " << i.first << " set!" << std::endl;
}
return;
}

@ -310,7 +310,7 @@ void ScriptApiClient::show_pause_menu(bool is_singleplayer, bool is_touchscreen,
lua_pop(L, 1);
}
void ScriptApiClient::show_settings()
void ScriptApiClient::show_settings(const std::string& page)
{
SCRIPTAPI_PRECHECKHEADER
@ -319,7 +319,14 @@ void ScriptApiClient::show_settings()
lua_getglobal(L, "core");
lua_getfield(L, -1, "show_settings");
PCALL_RES(lua_pcall(L, 0, 0, error_handler));
if (page != "")
{
lua_pushstring(L, page.c_str());
}
else
lua_pushnil(L);
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
lua_pop(L, 1);
}

@ -61,7 +61,7 @@ class ScriptApiClient : virtual public ScriptApiBase
bool on_inventory_open(Inventory *inventory);
void show_pause_menu(bool is_singleplayer, bool is_touchscreen, const std::string& server_address);
void show_settings();
void show_settings(const std::string& page = "");
void setEnv(ClientEnvironment *env);
};