diff --git a/builtin/client/pause_menu.lua b/builtin/client/pause_menu.lua index bd867374e..873588437 100644 --- a/builtin/client/pause_menu.lua +++ b/builtin/client/pause_menu.lua @@ -88,9 +88,27 @@ Menu/inventory open: end function core.show_pause_menu(is_singleplayer, is_touchscreen, address) - minetest.show_formspec("MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address)) + minetest.show_formspec("builtin:MT_PAUSE_MENU", menu_formspec(is_singleplayer, is_touchscreen, address)) end +core.register_on_formspec_input(function(formname, fields) + if formname ~= "builtin:MT_PAUSE_MENU" then return end + + if fields.btn_continue then + core.unpause() + elseif fields.btn_key_config then + core.key_config() -- Don't want this + elseif fields.btn_change_password then + core.change_password() + elseif fields.btn_exit_menu then + core.disconnect() + elseif fields.btn_exit_os then + core.exit_to_os() + end + + minetest.log(dump(fields)) +end) + local scriptpath = core.get_builtin_path() local path = scriptpath.."mainmenu"..DIR_DELIM.."settings" @@ -109,6 +127,13 @@ end load(true, false) +local data = {data = {}} +core.register_on_formspec_input(function(formname, fields) + local this = data + --buttonhandler(this, fields) +end) + + function core.show_settings(page_id) if not page_id then show_settings_client_formspec("MT_PAUSE_MENU_SETTINGS", {}) diff --git a/builtin/mainmenu/settings/dlg_settings.lua b/builtin/mainmenu/settings/dlg_settings.lua index d8a96a1fb..71483d915 100644 --- a/builtin/mainmenu/settings/dlg_settings.lua +++ b/builtin/mainmenu/settings/dlg_settings.lua @@ -633,7 +633,7 @@ function write_settings_early() end -local function buttonhandler(this, fields) +function buttonhandler(this, fields) local dialogdata = this.data dialogdata.leftscroll = core.explode_scrollbar_event(fields.leftscroll).value or dialogdata.leftscroll dialogdata.rightscroll = core.explode_scrollbar_event(fields.rightscroll).value or dialogdata.rightscroll diff --git a/src/client/game.cpp b/src/client/game.cpp index 68ce6067d..2fa1e2fb3 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -149,48 +149,7 @@ struct LocalFormspecHandler : public TextDest void gotText(const StringMap &fields) { - if (m_formname == "MT_PAUSE_MENU") { - if (fields.find("btn_sound") != fields.end()) { - g_gamecallback->changeVolume(); - return; - } - - else if (fields.find("btn_key_config") != fields.end()) { - g_gamecallback->keyConfig(); - return; - } - - else if (fields.find("btn_settings") != fields.end()) { - g_gamecallback->showSettings(); - } - - else if (fields.find("btn_exit_menu") != fields.end()) { - g_gamecallback->disconnect(); - return; - } - - else if (fields.find("btn_exit_os") != fields.end()) { - g_gamecallback->exitToOS(); -#ifndef __ANDROID__ - RenderingEngine::get_raw_device()->closeDevice(); -#endif - return; - } - - else if (fields.find("btn_change_password") != fields.end()) { - g_gamecallback->changePassword(); - return; - } - - else { - g_gamecallback->unpause(); - return; - } - - return; - } - - if (m_formname == "MT_PAUSE_MENU_SETTINGS") + if (m_formname == "MT_PAUSE_MENU_SETTINGS" && false) { // Loop through settings for (auto i : fields) @@ -201,7 +160,7 @@ struct LocalFormspecHandler : public TextDest } if (i.first.rfind("page_", 0) == 0) { - m_client->getScript()->show_settings(i.first.substr(5)); + //m_client->getScript()->show_settings(i.first.substr(5)); } //std::cout << "Setting " << i.first << " set!" << std::endl; diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp index 32db7a528..5af8758d4 100644 --- a/src/script/cpp_api/s_client.cpp +++ b/src/script/cpp_api/s_client.cpp @@ -310,7 +310,7 @@ void ScriptApiClient::show_pause_menu(bool is_singleplayer, bool is_touchscreen, lua_pop(L, 1); } -void ScriptApiClient::show_settings(const std::string& page) +void ScriptApiClient::show_settings() { SCRIPTAPI_PRECHECKHEADER @@ -319,14 +319,7 @@ void ScriptApiClient::show_settings(const std::string& page) lua_getglobal(L, "core"); lua_getfield(L, -1, "show_settings"); - if (page != "") - { - lua_pushstring(L, page.c_str()); - } - else - lua_pushnil(L); - - PCALL_RES(lua_pcall(L, 1, 0, error_handler)); + PCALL_RES(lua_pcall(L, 0, 0, error_handler)); lua_pop(L, 1); } diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h index c0f8a4196..61efa40bd 100644 --- a/src/script/cpp_api/s_client.h +++ b/src/script/cpp_api/s_client.h @@ -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(const std::string& page = ""); + void show_settings(); void setEnv(ClientEnvironment *env); }; diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 912e212af..9d6cdf383 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -23,6 +23,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client/client.h" #include "client/clientevent.h" #include "client/sound.h" +#include "client/renderingengine.h" #include "client/clientenvironment.h" #include "common/c_content.h" #include "common/c_converter.h" @@ -178,6 +179,29 @@ int ModApiClient::l_disconnect(lua_State *L) return 1; } +// unpause() +int ModApiClient::l_unpause(lua_State *L) +{ + g_gamecallback->unpause(); + //lua_pushboolean(L, true); + return 1; +} + +int ModApiClient::l_exit_to_os(lua_State *L) +{ + g_gamecallback->exitToOS(); +#ifndef __ANDROID__ + RenderingEngine::get_raw_device()->closeDevice(); +#endif + return 1; +} + +int ModApiClient::l_key_config(lua_State *L) +{ + g_gamecallback->keyConfig(); + return 1; +} + // gettext(text) int ModApiClient::l_gettext(lua_State *L) { @@ -366,6 +390,9 @@ void ModApiClient::Initialize(lua_State *L, int top) API_FCT(gettext); API_FCT(get_node_or_nil); API_FCT(disconnect); + API_FCT(unpause); + API_FCT(exit_to_os); + API_FCT(key_config); API_FCT(get_meta); API_FCT(get_server_info); API_FCT(get_item_def); diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index c98e1bc9f..7f93d66ce 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -50,6 +50,15 @@ class ModApiClient : public ModApiBase // show_formspec(name, formspec) static int l_show_formspec(lua_State *L); + + // unpause() + static int l_unpause(lua_State *L); + + // exit_to_os() + static int l_exit_to_os(lua_State *L); + + // key_config() + static int l_key_config(lua_State *L); // send_respawn() static int l_send_respawn(lua_State *L);