diff options
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/common/misc_helpers.lua | 2 | ||||
-rw-r--r-- | builtin/mainmenu/common.lua | 8 | ||||
-rw-r--r-- | builtin/mainmenu/dlg_contentstore.lua | 10 | ||||
-rw-r--r-- | builtin/mainmenu/dlg_delete_content.lua | 13 | ||||
-rw-r--r-- | builtin/mainmenu/dlg_delete_world.lua | 12 | ||||
-rw-r--r-- | builtin/mainmenu/dlg_register.lua | 123 | ||||
-rw-r--r-- | builtin/mainmenu/init.lua | 2 | ||||
-rw-r--r-- | builtin/mainmenu/tab_about.lua | 9 | ||||
-rw-r--r-- | builtin/mainmenu/tab_online.lua | 57 | ||||
-rw-r--r-- | builtin/mainmenu/tab_settings.lua | 16 | ||||
-rw-r--r-- | builtin/settingtypes.txt | 6 |
11 files changed, 209 insertions, 49 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index f8a905c7b..1043675f6 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -254,7 +254,7 @@ local formspec_escapes = { } function core.formspec_escape(text) -- Use explicit character set instead of dot here because it doubles the performance - return text and text:gsub("[\\%[%];,]", formspec_escapes) + return text and string.gsub(text, "[\\%[%];,]", formspec_escapes) end diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 8db8bb8d1..dcccb2b2a 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -242,3 +242,11 @@ function menu_worldmt_legacy(selected) end end end + +function confirmation_formspec(message, confirm_id, confirm_label, cancel_id, cancel_label) + return "size[10,2.5,true]" .. + "label[0.5,0.5;" .. message .. "]" .. + "style[" .. confirm_id .. ";bgcolor=red]" .. + "button[0.5,1.5;2.5,0.5;" .. confirm_id .. ";" .. confirm_label .. "]" .. + "button[7.0,1.5;2.5,0.5;" .. cancel_id .. ";" .. cancel_label .. "]" +end diff --git a/builtin/mainmenu/dlg_contentstore.lua b/builtin/mainmenu/dlg_contentstore.lua index 924c66400..554728913 100644 --- a/builtin/mainmenu/dlg_contentstore.lua +++ b/builtin/mainmenu/dlg_contentstore.lua @@ -488,12 +488,10 @@ local confirm_overwrite = {} function confirm_overwrite.get_formspec() local package = confirm_overwrite.package - return "size[11.5,4.5,true]" .. - "label[2,2;" .. - fgettext("\"$1\" already exists. Would you like to overwrite it?", package.name) .. "]".. - "style[install;bgcolor=red]" .. - "button[3.25,3.5;2.5,0.5;install;" .. fgettext("Overwrite") .. "]" .. - "button[5.75,3.5;2.5,0.5;cancel;" .. fgettext("Cancel") .. "]" + return confirmation_formspec( + fgettext("\"$1\" already exists. Would you like to overwrite it?", package.name), + 'install', fgettext("Overwrite"), + 'cancel', fgettext("Cancel")) end function confirm_overwrite.handle_submit(this, fields) diff --git a/builtin/mainmenu/dlg_delete_content.lua b/builtin/mainmenu/dlg_delete_content.lua index a24171541..4463825f7 100644 --- a/builtin/mainmenu/dlg_delete_content.lua +++ b/builtin/mainmenu/dlg_delete_content.lua @@ -18,15 +18,10 @@ -------------------------------------------------------------------------------- local function delete_content_formspec(dialogdata) - local retval = - "size[11.5,4.5,true]" .. - "label[2,2;" .. - fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name) .. "]".. - "style[dlg_delete_content_confirm;bgcolor=red]" .. - "button[3.25,3.5;2.5,0.5;dlg_delete_content_confirm;" .. fgettext("Delete") .. "]" .. - "button[5.75,3.5;2.5,0.5;dlg_delete_content_cancel;" .. fgettext("Cancel") .. "]" - - return retval + return confirmation_formspec( + fgettext("Are you sure you want to delete \"$1\"?", dialogdata.content.name), + 'dlg_delete_content_confirm', fgettext("Delete"), + 'dlg_delete_content_cancel', fgettext("Cancel")) end -------------------------------------------------------------------------------- diff --git a/builtin/mainmenu/dlg_delete_world.lua b/builtin/mainmenu/dlg_delete_world.lua index 33e7bc945..67c0612bd 100644 --- a/builtin/mainmenu/dlg_delete_world.lua +++ b/builtin/mainmenu/dlg_delete_world.lua @@ -17,14 +17,10 @@ local function delete_world_formspec(dialogdata) - local retval = - "size[10,2.5,true]" .. - "label[0.5,0.5;" .. - fgettext("Delete World \"$1\"?", dialogdata.delete_name) .. "]" .. - "style[world_delete_confirm;bgcolor=red]" .. - "button[0.5,1.5;2.5,0.5;world_delete_confirm;" .. fgettext("Delete") .. "]" .. - "button[7.0,1.5;2.5,0.5;world_delete_cancel;" .. fgettext("Cancel") .. "]" - return retval + return confirmation_formspec( + fgettext("Delete World \"$1\"?", dialogdata.delete_name), + 'world_delete_confirm', fgettext("Delete"), + 'world_delete_cancel', fgettext("Cancel")) end local function delete_world_buttonhandler(this, fields) diff --git a/builtin/mainmenu/dlg_register.lua b/builtin/mainmenu/dlg_register.lua new file mode 100644 index 000000000..a7658249c --- /dev/null +++ b/builtin/mainmenu/dlg_register.lua @@ -0,0 +1,123 @@ +--Minetest +--Copyright (C) 2022 rubenwardy +-- +--This program is free software; you can redistribute it and/or modify +--it under the terms of the GNU Lesser General Public License as published by +--the Free Software Foundation; either version 2.1 of the License, or +--(at your option) any later version. +-- +--This program is distributed in the hope that it will be useful, +--but WITHOUT ANY WARRANTY; without even the implied warranty of +--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +--GNU Lesser General Public License for more details. +-- +--You should have received a copy of the GNU Lesser General Public License along +--with this program; if not, write to the Free Software Foundation, Inc., +--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +-------------------------------------------------------------------------------- + +local function register_formspec(dialogdata) + local title = fgettext("Joining $1", dialogdata.server and dialogdata.server.name or dialogdata.address) + local buttons_y = 4 + 1.3 + if dialogdata.error then + buttons_y = buttons_y + 0.8 + end + + local retval = { + "formspec_version[4]", + "size[8,", tostring(buttons_y + 1.175), "]", + "set_focus[", (dialogdata.name ~= "" and "password" or "name"), "]", + "label[0.375,0.8;", title, "]", + "field[0.375,1.575;7.25,0.8;name;", core.formspec_escape(fgettext("Name")), ";", + core.formspec_escape(dialogdata.name), "]", + "pwdfield[0.375,2.875;7.25,0.8;password;", core.formspec_escape(fgettext("Password")), "]", + "pwdfield[0.375,4.175;7.25,0.8;password_2;", core.formspec_escape(fgettext("Confirm Password")), "]" + } + + if dialogdata.error then + table.insert_all(retval, { + "box[0.375,", tostring(buttons_y - 0.9), ";7.25,0.6;darkred]", + "label[0.625,", tostring(buttons_y - 0.6), ";", core.formspec_escape(dialogdata.error), "]", + }) + end + + table.insert_all(retval, { + "container[0.375,", tostring(buttons_y), "]", + "button[0,0;2.5,0.8;dlg_register_confirm;", fgettext("Register"), "]", + "button[4.75,0;2.5,0.8;dlg_register_cancel;", fgettext("Cancel"), "]", + "container_end[]", + }) + + return table.concat(retval, "") +end + +-------------------------------------------------------------------------------- +local function register_buttonhandler(this, fields) + this.data.name = fields.name + this.data.error = nil + + if fields.dlg_register_confirm or fields.key_enter then + if fields.name == "" then + this.data.error = fgettext("Missing name") + return true + end + if fields.password ~= fields.password_2 then + this.data.error = fgettext("Passwords do not match") + return true + end + + gamedata.playername = fields.name + gamedata.password = fields.password + gamedata.address = this.data.address + gamedata.port = this.data.port + gamedata.allow_login_or_register = "register" + gamedata.selected_world = 0 + + assert(gamedata.address and gamedata.port) + + local server = this.data.server + if server then + serverlistmgr.add_favorite(server) + gamedata.servername = server.name + gamedata.serverdescription = server.description + else + gamedata.servername = "" + gamedata.serverdescription = "" + + serverlistmgr.add_favorite({ + address = gamedata.address, + port = gamedata.port, + }) + end + + core.settings:set("name", fields.name) + core.settings:set("address", gamedata.address) + core.settings:set("remote_port", gamedata.port) + + core.start() + end + + if fields["dlg_register_cancel"] then + this:delete() + return true + end + + return false +end + +-------------------------------------------------------------------------------- +function create_register_dialog(address, port, server) + assert(address) + assert(type(port) == "number") + + local retval = dialog_create("dlg_register", + register_formspec, + register_buttonhandler, + nil) + retval.data.address = address + retval.data.port = port + retval.data.server = server + retval.data.name = core.settings:get("name") or "" + return retval +end diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index 943454677..2ffae74b5 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -17,6 +17,7 @@ mt_color_grey = "#AAAAAA" mt_color_blue = "#6389FF" +mt_color_lightblue = "#99CCFF" mt_color_green = "#72FF63" mt_color_dark_green = "#25C191" mt_color_orange = "#FF8800" @@ -43,6 +44,7 @@ dofile(menupath .. DIR_DELIM .. "dlg_contentstore.lua") dofile(menupath .. DIR_DELIM .. "dlg_create_world.lua") dofile(menupath .. DIR_DELIM .. "dlg_delete_content.lua") dofile(menupath .. DIR_DELIM .. "dlg_delete_world.lua") +dofile(menupath .. DIR_DELIM .. "dlg_register.lua") dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua") local tabs = {} diff --git a/builtin/mainmenu/tab_about.lua b/builtin/mainmenu/tab_about.lua index 3336786ba..2a2ed7bc4 100644 --- a/builtin/mainmenu/tab_about.lua +++ b/builtin/mainmenu/tab_about.lua @@ -140,7 +140,9 @@ return { fgettext("Active renderer:") .. "\n" .. core.formspec_escape(core.get_screen_info().render_info) .. "]" - if PLATFORM ~= "Android" then + if PLATFORM == "Android" then + fs = fs .. "button[0,4;3.5,1;share_debug;" .. fgettext("Share debug log") .. "]" + else fs = fs .. "tooltip[userdata;" .. fgettext("Opens the directory that contains user-provided worlds, games, mods,\n" .. "and texture packs in a file manager / explorer.") .. "]" @@ -154,6 +156,11 @@ return { core.open_url("https://www.minetest.net") end + if fields.share_debug then + local path = core.get_user_path() .. DIR_DELIM .. "debug.txt" + core.share_file(path) + end + if fields.userdata then core.open_dir(core.get_user_path()) end diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index fb7409864..a8e1eb2ef 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -87,27 +87,34 @@ local function get_formspec(tabview, name, tabdata) "field[4.25,0.5;1.25,0.75;te_port;;" .. core.formspec_escape(core.settings:get("remote_port")) .. "]" .. - -- Name / Password - "label[0.25,1.55;" .. fgettext("Name") .. "]" .. - "label[3,1.55;" .. fgettext("Password") .. "]" .. - "field[0.25,1.75;2.75,0.75;te_name;;" .. - core.formspec_escape(core.settings:get("name")) .. "]" .. - "pwdfield[3,1.75;2.5,0.75;te_pwd;]" .. - -- Description Background - "label[0.25,2.75;" .. fgettext("Server Description") .. "]" .. - "box[0.25,3;5.25,2.75;#999999]".. + "label[0.25,1.6;" .. fgettext("Server Description") .. "]" .. + "box[0.25,1.85;5.25,2.7;#999999]".. + + -- Name / Password + "container[0,4.8]" .. + "label[0.25,0;" .. fgettext("Name") .. "]" .. + "label[3,0;" .. fgettext("Password") .. "]" .. + "field[0.25,0.2;2.625,0.75;te_name;;" .. core.formspec_escape(core.settings:get("name")) .. "]" .. + "pwdfield[2.875,0.2;2.625,0.75;te_pwd;]" .. + "container_end[]" .. -- Connect - "button[3,6;2.5,0.75;btn_mp_connect;" .. fgettext("Connect") .. "]" + "button[3,6;2.5,0.75;btn_mp_login;" .. fgettext("Login") .. "]" + + if core.settings:get_bool("enable_split_login_register") then + retval = retval .. "button[0.25,6;2.5,0.75;btn_mp_register;" .. fgettext("Register") .. "]" + end if tabdata.selected then if gamedata.fav then - retval = retval .. "button[0.25,6;2.5,0.75;btn_delete_favorite;" .. - fgettext("Del. Favorite") .. "]" + retval = retval .. "tooltip[btn_delete_favorite;" .. fgettext("Remove favorite") .. "]" + retval = retval .. "style[btn_delete_favorite;padding=6]" + retval = retval .. "image_button[5,1.3;0.5,0.5;" .. defaulttexturedir .. + "server_favorite_delete.png;btn_delete_favorite;]" end if gamedata.serverdescription then - retval = retval .. "textarea[0.25,3;5.25,2.75;;;" .. + retval = retval .. "textarea[0.25,1.85;5.2,2.75;;;" .. core.formspec_escape(gamedata.serverdescription) .. "]" end end @@ -339,12 +346,15 @@ local function main_button_handler(tabview, fields, name, tabdata) return true end - if (fields.btn_mp_connect or fields.key_enter) + if (fields.btn_mp_login or fields.key_enter) and fields.te_address ~= "" and fields.te_port then gamedata.playername = fields.te_name gamedata.password = fields.te_pwd gamedata.address = fields.te_address gamedata.port = tonumber(fields.te_port) + + local enable_split_login_register = core.settings:get_bool("enable_split_login_register") + gamedata.allow_login_or_register = enable_split_login_register and "login" or "any" gamedata.selected_world = 0 local idx = core.get_table_index("servers") @@ -381,6 +391,25 @@ local function main_button_handler(tabview, fields, name, tabdata) return true end + if fields.btn_mp_register and fields.te_address ~= "" and fields.te_port then + local idx = core.get_table_index("servers") + local server = idx and tabdata.lookup[idx] + if server and (server.address ~= fields.te_address or server.port ~= tonumber(fields.te_port)) then + server = nil + end + + if server and not is_server_protocol_compat_or_error( + server.proto_min, server.proto_max) then + return true + end + + local dlg = create_register_dialog(fields.te_address, tonumber(fields.te_port), server) + dlg:set_parent(tabview) + tabview:hide() + dlg:show() + return true + end + return false end diff --git a/builtin/mainmenu/tab_settings.lua b/builtin/mainmenu/tab_settings.lua index 880978800..8307ca7e2 100644 --- a/builtin/mainmenu/tab_settings.lua +++ b/builtin/mainmenu/tab_settings.lua @@ -160,7 +160,7 @@ local function formspec(tabview, name, tabdata) .. getSettingIndex.NodeHighlighting() .. "]" .. "dropdown[0.25,3.6;3.5;dd_leaves_style;" .. dd_options.leaves[1] .. ";" .. getSettingIndex.Leaves() .. "]" .. - "box[4,0;3.75,4.5;#999999]" .. + "box[4,0;3.75,4.9;#999999]" .. "label[4.25,0.1;" .. fgettext("Texturing:") .. "]" .. "dropdown[4.25,0.55;3.5;dd_filters;" .. dd_options.filters[1] .. ";" .. getSettingIndex.Filter() .. "]" .. @@ -169,9 +169,6 @@ local function formspec(tabview, name, tabdata) "label[4.25,2.15;" .. fgettext("Antialiasing:") .. "]" .. "dropdown[4.25,2.6;3.5;dd_antialiasing;" .. dd_options.antialiasing[1] .. ";" .. getSettingIndex.Antialiasing() .. "]" .. - "label[4.25,3.45;" .. fgettext("Screen:") .. "]" .. - "checkbox[4.25,3.6;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";" - .. dump(core.settings:get_bool("autosave_screensize")) .. "]" .. "box[8,0;3.75,4.5;#999999]" local video_driver = core.settings:get("video_driver") @@ -203,10 +200,15 @@ local function formspec(tabview, name, tabdata) if core.settings:get("touchscreen_threshold") ~= nil then tab_string = tab_string .. - "label[4.3,4.2;" .. fgettext("Touchthreshold: (px)") .. "]" .. - "dropdown[4.25,4.65;3.5;dd_touchthreshold;0,10,20,30,40,50;" .. + "label[4.25,3.5;" .. fgettext("Touch threshold (px):") .. "]" .. + "dropdown[4.25,3.95;3.5;dd_touchthreshold;0,10,20,30,40,50;" .. ((tonumber(core.settings:get("touchscreen_threshold")) / 10) + 1) .. - "]box[4.0,4.5;3.75,1.0;#999999]" + "]" + else + tab_string = tab_string .. + "label[4.25,3.65;" .. fgettext("Screen:") .. "]" .. + "checkbox[4.25,3.9;cb_autosave_screensize;" .. fgettext("Autosave Screen Size") .. ";" + .. dump(core.settings:get_bool("autosave_screensize")) .. "]" end if shaders_enabled then diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt index a6a2b9c77..0bed1071c 100644 --- a/builtin/settingtypes.txt +++ b/builtin/settingtypes.txt @@ -1045,9 +1045,9 @@ serverlist_file (Serverlist file) string favoriteservers.json # 0 to disable queueing and -1 to make the queue size unlimited. max_out_chat_queue_size (Maximum size of the out chat queue) int 20 -# Enable register confirmation when connecting to server. -# If disabled, new account will be registered automatically. -enable_register_confirmation (Enable register confirmation) bool true +# If enabled, account registration is separate from login in the UI. +# If disabled, new accounts will be registered automatically when logging in. +enable_split_login_register (Enable split login/register) bool true [*Advanced] |