Persist text inputs in mainmenu local tab

Co-authored-by: archfan <33993466+archfan7411@users.noreply.github.com>
This commit is contained in:
Montandalar 2023-08-15 02:17:53 +10:00 committed by GitHub
parent 2c987b66c1
commit 7b3ed32003
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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")