aboutsummaryrefslogtreecommitdiff
path: root/builtin/mainmenu
diff options
context:
space:
mode:
authorrubenwardy <rw@rubenwardy.com>2022-06-05 16:47:38 +0100
committerGitHub <noreply@github.com>2022-06-05 17:47:38 +0200
commit03d86ea0b4900cd0394649597d278d465512d629 (patch)
treed2e5414acea951ea42400b5a87b5ee9a8296a3f3 /builtin/mainmenu
parent21323ef1ff02dd714330a8c9d8235f047e1dacf8 (diff)
downloadminetest-03d86ea0b4900cd0394649597d278d465512d629.tar.gz
minetest-03d86ea0b4900cd0394649597d278d465512d629.tar.bz2
minetest-03d86ea0b4900cd0394649597d278d465512d629.zip
Add register dialog to separate login/register (#12185)
New users find Minetest's account system confusing. This change moves username/password to a new dialog, with login and register buttons added to the Join Game tab. The old registration confirmation dialog is removed in favour of the new dialog. Fixes #8138
Diffstat (limited to 'builtin/mainmenu')
-rw-r--r--builtin/mainmenu/dlg_register.lua123
-rw-r--r--builtin/mainmenu/init.lua2
-rw-r--r--builtin/mainmenu/tab_online.lua57
3 files changed, 168 insertions, 14 deletions
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 8e716c2eb..d073f5a57 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_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