mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Tweak main menu server list behavior (#15736)
Co-authored-by: Lars Mueller <appgurulars@gmx.de>
This commit is contained in:
parent
567b9a997a
commit
eb797c502a
2 changed files with 28 additions and 10 deletions
|
@ -21,7 +21,7 @@ local function clients_list_formspec(dialogdata)
|
||||||
"size[6,9.5]",
|
"size[6,9.5]",
|
||||||
TOUCH_GUI and "padding[0.01,0.01]" or "",
|
TOUCH_GUI and "padding[0.01,0.01]" or "",
|
||||||
"hypertext[0,0;6,1.5;;<global margin=5 halign=center valign=middle>",
|
"hypertext[0,0;6,1.5;;<global margin=5 halign=center valign=middle>",
|
||||||
fgettext("This is the list of clients connected to\n$1",
|
fgettext("Players connected to\n$1",
|
||||||
"<b>" .. core.hypertext_escape(servername) .. "</b>") .. "]",
|
"<b>" .. core.hypertext_escape(servername) .. "</b>") .. "]",
|
||||||
"textlist[0.5,1.5;5,6.8;;" .. fmt_formspec_list(clients_list) .. "]",
|
"textlist[0.5,1.5;5,6.8;;" .. fmt_formspec_list(clients_list) .. "]",
|
||||||
"button[1.5,8.5;3,0.8;quit;OK]"
|
"button[1.5,8.5;3,0.8;quit;OK]"
|
||||||
|
|
|
@ -190,10 +190,10 @@ local function get_formspec(tabview, name, tabdata)
|
||||||
local max_clients = 5
|
local max_clients = 5
|
||||||
if #clients_list > max_clients then
|
if #clients_list > max_clients then
|
||||||
retval = retval .. "tooltip[btn_view_clients;" ..
|
retval = retval .. "tooltip[btn_view_clients;" ..
|
||||||
fgettext("Clients:\n$1", table.concat(clients_list, "\n", 1, max_clients)) .. "\n..." .. "]"
|
fgettext("Players:\n$1", table.concat(clients_list, "\n", 1, max_clients)) .. "\n..." .. "]"
|
||||||
else
|
else
|
||||||
retval = retval .. "tooltip[btn_view_clients;" ..
|
retval = retval .. "tooltip[btn_view_clients;" ..
|
||||||
fgettext("Clients:\n$1", table.concat(clients_list, "\n")) .. "]"
|
fgettext("Players:\n$1", table.concat(clients_list, "\n")) .. "]"
|
||||||
end
|
end
|
||||||
retval = retval .. "style[btn_view_clients;padding=6]"
|
retval = retval .. "style[btn_view_clients;padding=6]"
|
||||||
retval = retval .. "image_button[4.5,1.3;0.5,0.5;" .. core.formspec_escape(defaulttexturedir ..
|
retval = retval .. "image_button[4.5,1.3;0.5,0.5;" .. core.formspec_escape(defaulttexturedir ..
|
||||||
|
@ -391,12 +391,15 @@ local function matches_query(server, query)
|
||||||
return name_matches and 50 or description_matches and 0
|
return name_matches and 50 or description_matches and 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function search_server_list(input)
|
local function search_server_list(input, tabdata)
|
||||||
menudata.search_result = nil
|
menudata.search_result = nil
|
||||||
if #serverlistmgr.servers < 2 then
|
if #serverlistmgr.servers < 2 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
tabdata.pre_search_selection = tabdata.pre_search_selection or find_selected_server()
|
||||||
|
|
||||||
-- setup the search query
|
-- setup the search query
|
||||||
local query = parse_search_input(input)
|
local query = parse_search_input(input)
|
||||||
if not query then
|
if not query then
|
||||||
|
@ -419,11 +422,23 @@ local function search_server_list(input)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local current_server = find_selected_server()
|
||||||
|
|
||||||
table.sort(search_result, function(a, b)
|
table.sort(search_result, function(a, b)
|
||||||
return a.points > b.points
|
return a.points > b.points
|
||||||
end)
|
end)
|
||||||
menudata.search_result = search_result
|
menudata.search_result = search_result
|
||||||
|
|
||||||
|
-- Keep current selection if it's in search results
|
||||||
|
if current_server then
|
||||||
|
for _, server in ipairs(search_result) do
|
||||||
|
if server.address == current_server.address and
|
||||||
|
server.port == current_server.port then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Find first compatible server (favorite or public)
|
-- Find first compatible server (favorite or public)
|
||||||
for _, server in ipairs(search_result) do
|
for _, server in ipairs(search_result) do
|
||||||
if is_server_protocol_compat(server.proto_min, server.proto_max) then
|
if is_server_protocol_compat(server.proto_min, server.proto_max) then
|
||||||
|
@ -434,6 +449,7 @@ local function search_server_list(input)
|
||||||
-- If no compatible server found, clear selection
|
-- If no compatible server found, clear selection
|
||||||
set_selected_server(nil)
|
set_selected_server(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function main_button_handler(tabview, fields, name, tabdata)
|
local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
if fields.te_name then
|
if fields.te_name then
|
||||||
gamedata.playername = fields.te_name
|
gamedata.playername = fields.te_name
|
||||||
|
@ -471,6 +487,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
end
|
end
|
||||||
if event.type == "CHG" then
|
if event.type == "CHG" then
|
||||||
set_selected_server(server)
|
set_selected_server(server)
|
||||||
|
tabdata.pre_search_selection = nil
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -484,11 +501,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
if fields.btn_delete_favorite then
|
if fields.btn_delete_favorite then
|
||||||
local idx = core.get_table_index("servers")
|
local idx = core.get_table_index("servers")
|
||||||
if not idx then return end
|
if not idx then return end
|
||||||
local server = tabdata.lookup[idx]
|
|
||||||
if not server then return end
|
|
||||||
|
|
||||||
serverlistmgr.delete_favorite(server)
|
serverlistmgr.delete_favorite(tabdata.lookup[idx])
|
||||||
set_selected_server(server)
|
set_selected_server(tabdata.lookup[idx+1])
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -516,13 +531,16 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
if fields.btn_mp_clear then
|
if fields.btn_mp_clear then
|
||||||
tabdata.search_for = ""
|
tabdata.search_for = ""
|
||||||
menudata.search_result = nil
|
menudata.search_result = nil
|
||||||
set_selected_server(nil)
|
if tabdata.pre_search_selection then
|
||||||
|
set_selected_server(tabdata.pre_search_selection)
|
||||||
|
tabdata.pre_search_selection = nil
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if fields.btn_mp_search or fields.key_enter_field == "te_search" then
|
if fields.btn_mp_search or fields.key_enter_field == "te_search" then
|
||||||
tabdata.search_for = fields.te_search
|
tabdata.search_for = fields.te_search
|
||||||
search_server_list(fields.te_search)
|
search_server_list(fields.te_search, tabdata)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue