mirror of
https://github.com/minetest/minetest.git
synced 2025-03-06 20:48:40 +01: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]",
|
||||
TOUCH_GUI and "padding[0.01,0.01]" or "",
|
||||
"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>") .. "]",
|
||||
"textlist[0.5,1.5;5,6.8;;" .. fmt_formspec_list(clients_list) .. "]",
|
||||
"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
|
||||
if #clients_list > max_clients then
|
||||
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
|
||||
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
|
||||
retval = retval .. "style[btn_view_clients;padding=6]"
|
||||
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
|
||||
end
|
||||
|
||||
local function search_server_list(input)
|
||||
local function search_server_list(input, tabdata)
|
||||
menudata.search_result = nil
|
||||
if #serverlistmgr.servers < 2 then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
tabdata.pre_search_selection = tabdata.pre_search_selection or find_selected_server()
|
||||
|
||||
-- setup the search query
|
||||
local query = parse_search_input(input)
|
||||
if not query then
|
||||
|
@ -419,11 +422,23 @@ local function search_server_list(input)
|
|||
return
|
||||
end
|
||||
|
||||
local current_server = find_selected_server()
|
||||
|
||||
table.sort(search_result, function(a, b)
|
||||
return a.points > b.points
|
||||
end)
|
||||
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)
|
||||
for _, server in ipairs(search_result) do
|
||||
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
|
||||
set_selected_server(nil)
|
||||
end
|
||||
|
||||
local function main_button_handler(tabview, fields, name, tabdata)
|
||||
if fields.te_name then
|
||||
gamedata.playername = fields.te_name
|
||||
|
@ -471,6 +487,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||
end
|
||||
if event.type == "CHG" then
|
||||
set_selected_server(server)
|
||||
tabdata.pre_search_selection = nil
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
@ -484,11 +501,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||
if fields.btn_delete_favorite then
|
||||
local idx = core.get_table_index("servers")
|
||||
if not idx then return end
|
||||
local server = tabdata.lookup[idx]
|
||||
if not server then return end
|
||||
|
||||
serverlistmgr.delete_favorite(server)
|
||||
set_selected_server(server)
|
||||
serverlistmgr.delete_favorite(tabdata.lookup[idx])
|
||||
set_selected_server(tabdata.lookup[idx+1])
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -516,13 +531,16 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||
if fields.btn_mp_clear then
|
||||
tabdata.search_for = ""
|
||||
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
|
||||
end
|
||||
|
||||
if fields.btn_mp_search or fields.key_enter_field == "te_search" then
|
||||
tabdata.search_for = fields.te_search
|
||||
search_server_list(fields.te_search)
|
||||
search_server_list(fields.te_search, tabdata)
|
||||
return true
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue