From 7b3ed3200325ce913a6a2d884ae1ba1ccb08aad5 Mon Sep 17 00:00:00 2001 From: Montandalar Date: Tue, 15 Aug 2023 02:17:53 +1000 Subject: [PATCH] Persist text inputs in mainmenu local tab Co-authored-by: archfan <33993466+archfan7411@users.noreply.github.com> --- builtin/mainmenu/tab_local.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index de121e65b..9bd8986ba 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -23,6 +23,10 @@ local valid_disabled_settings = { ["enable_server"]=true, } +-- Name and port stored to persist when updating the formspec +local current_name = core.settings:get("name") +local current_port = core.settings:get("port") + -- Currently chosen game in gamebar for theming and filtering function current_game() local last_game_id = core.settings:get("menu_last_game") @@ -188,7 +192,7 @@ local function get_formspec(tabview, name, tabdata) "checkbox[0,"..y..";cb_server_announce;" .. fgettext("Announce Server") .. ";" .. dump(core.settings:get_bool("server_announce")) .. "]" .. "field[0.3,2.85;3.8,0.5;te_playername;" .. fgettext("Name") .. ";" .. - core.formspec_escape(core.settings:get("name")) .. "]" .. + core.formspec_escape(current_name) .. "]" .. "pwdfield[0.3,4.05;3.8,0.5;te_passwd;" .. fgettext("Password") .. "]" local bind_addr = core.settings:get("bind_address") @@ -197,11 +201,11 @@ local function get_formspec(tabview, name, tabdata) "field[0.3,5.25;2.5,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" .. core.formspec_escape(core.settings:get("bind_address")) .. "]" .. "field[2.85,5.25;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" .. - core.formspec_escape(core.settings:get("port")) .. "]" + core.formspec_escape(current_port) .. "]" else retval = retval .. "field[0.3,5.25;3.8,0.5;te_serverport;" .. fgettext("Server Port") .. ";" .. - core.formspec_escape(core.settings:get("port")) .. "]" + core.formspec_escape(current_port) .. "]" end else retval = retval .. @@ -221,6 +225,14 @@ local function main_button_handler(this, fields, name, tabdata) local world_doubleclick = false + if fields["te_playername"] then + current_name = fields["te_playername"] + end + + if fields["te_serverport"] then + current_port = fields["te_serverport"] + end + if fields["sp_worlds"] ~= nil then local event = core.explode_textlist_event(fields["sp_worlds"]) local selected = core.get_textlist_index("sp_worlds")