Mainmenu: Unify favorite servers with main serverlist
parent
fed5dd3b5d
commit
65db88d24e
|
@ -85,7 +85,7 @@ function order_favorite_list(list)
|
|||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
function render_favorite(spec,render_details)
|
||||
function render_favorite(spec, is_favorite)
|
||||
local text = ""
|
||||
|
||||
if spec.name ~= nil then
|
||||
|
@ -105,13 +105,15 @@ function render_favorite(spec,render_details)
|
|||
end
|
||||
end
|
||||
|
||||
if not render_details then
|
||||
return text
|
||||
end
|
||||
|
||||
local details = ""
|
||||
local grey_out = not is_server_protocol_compat(spec.proto_min, spec.proto_max)
|
||||
|
||||
if is_favorite then
|
||||
details = "1,"
|
||||
else
|
||||
details = "0,"
|
||||
end
|
||||
|
||||
if spec.clients ~= nil and spec.clients_max ~= nil then
|
||||
local clients_color = ''
|
||||
local clients_percent = 100 * spec.clients / spec.clients_max
|
||||
|
@ -253,15 +255,13 @@ function asyncOnlineFavourites()
|
|||
end,
|
||||
nil,
|
||||
function(result)
|
||||
if core.setting_getbool("public_serverlist") then
|
||||
local favs = order_favorite_list(result)
|
||||
if favs[1] then
|
||||
menudata.public_known = favs
|
||||
menudata.favorites = menudata.public_known
|
||||
menudata.favorites_is_public = true
|
||||
end
|
||||
core.event_handler("Refresh")
|
||||
local favs = order_favorite_list(result)
|
||||
if favs[1] then
|
||||
menudata.public_known = favs
|
||||
menudata.favorites = menudata.public_known
|
||||
menudata.favorites_is_public = true
|
||||
end
|
||||
core.event_handler("Refresh")
|
||||
end
|
||||
)
|
||||
end
|
||||
|
|
|
@ -20,65 +20,64 @@ local function get_formspec(tabview, name, tabdata)
|
|||
-- Update the cached supported proto info,
|
||||
-- it may have changed after a change by the settings menu.
|
||||
common_update_cached_supp_proto()
|
||||
local fav_selected = menudata.favorites[tabdata.fav_selected]
|
||||
|
||||
local render_details = core.is_yes(core.setting_getbool("public_serverlist"))
|
||||
|
||||
local retval =
|
||||
"label[7.75,-0.15;" .. fgettext("Address / Port :") .. "]" ..
|
||||
"label[7.75,1.05;" .. fgettext("Name / Password :") .. "]" ..
|
||||
"field[8,0.75;3.4,0.5;te_address;;" ..
|
||||
core.formspec_escape(core.setting_get("address")) .. "]" ..
|
||||
"field[11.25,0.75;1.3,0.5;te_port;;" ..
|
||||
core.formspec_escape(core.setting_get("remote_port")) .. "]" ..
|
||||
"checkbox[0,4.85;cb_public_serverlist;" .. fgettext("Public Serverlist") .. ";" ..
|
||||
dump(core.setting_getbool("public_serverlist")) .. "]"
|
||||
|
||||
if not core.setting_getbool("public_serverlist") then
|
||||
retval = retval ..
|
||||
"button[8,4.9;2,0.5;btn_delete_favorite;" .. fgettext("Delete") .. "]"
|
||||
end
|
||||
|
||||
retval = retval ..
|
||||
"button[10,4.9;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" ..
|
||||
"label[7.75,-0.15;" .. fgettext("Address / Port") .. "]" ..
|
||||
"label[7.75,1.05;" .. fgettext("Name / Password") .. "]" ..
|
||||
"field[8,0.75;3.3,0.5;te_address;;" ..
|
||||
core.formspec_escape(core.setting_get("address")) .. "]" ..
|
||||
"field[11.15,0.75;1.4,0.5;te_port;;" ..
|
||||
core.formspec_escape(core.setting_get("remote_port")) .. "]" ..
|
||||
"button[10.1,4.9;2,0.5;btn_mp_connect;" .. fgettext("Connect") .. "]" ..
|
||||
"field[8,1.95;2.95,0.5;te_name;;" ..
|
||||
core.formspec_escape(core.setting_get("name")) .. "]" ..
|
||||
core.formspec_escape(core.setting_get("name")) .. "]" ..
|
||||
"pwdfield[10.78,1.95;1.77,0.5;te_pwd;]" ..
|
||||
"box[7.73,2.35;4.3,2.28;#999999]" ..
|
||||
"textarea[8.1,2.4;4.26,2.6;;"
|
||||
|
||||
if tabdata.fav_selected ~= nil and
|
||||
menudata.favorites[tabdata.fav_selected] ~= nil and
|
||||
menudata.favorites[tabdata.fav_selected].description ~= nil then
|
||||
retval = retval ..
|
||||
core.formspec_escape(menudata.favorites[tabdata.fav_selected].description,true)
|
||||
end
|
||||
"box[7.73,2.35;4.3,2.28;#999999]"
|
||||
|
||||
retval = retval ..
|
||||
";]"
|
||||
if tabdata.fav_selected and fav_selected then
|
||||
if gamedata.fav then
|
||||
retval = retval .. "button[7.85,4.9;2.3,0.5;btn_delete_favorite;" ..
|
||||
fgettext("Del. Favorite") .. "]"
|
||||
end
|
||||
if fav_selected.description then
|
||||
retval = retval .. "textarea[8.1,2.4;4.26,2.6;;" ..
|
||||
core.formspec_escape((gamedata.serverdescription or ""), true) .. ";]"
|
||||
end
|
||||
end
|
||||
|
||||
--favourites
|
||||
if render_details then
|
||||
retval = retval .. "tablecolumns[" ..
|
||||
"color,span=3;" ..
|
||||
"text,align=right;" .. -- clients
|
||||
"text,align=center,padding=0.25;" .. -- "/"
|
||||
"text,align=right,padding=0.25;" .. -- clients_max
|
||||
image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" ..
|
||||
image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" ..
|
||||
image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" ..
|
||||
"color,span=1;" ..
|
||||
"text,padding=1]" -- name
|
||||
else
|
||||
retval = retval .. "tablecolumns[text]"
|
||||
end
|
||||
retval = retval ..
|
||||
"table[-0.15,-0.1;7.75,5;favourites;"
|
||||
retval = retval .. "tablecolumns[" ..
|
||||
image_column(fgettext("Favorite"), "favorite") .. ";" ..
|
||||
"color,span=3;" ..
|
||||
"text,align=right;" .. -- clients
|
||||
"text,align=center,padding=0.25;" .. -- "/"
|
||||
"text,align=right,padding=0.25;" .. -- clients_max
|
||||
image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" ..
|
||||
image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" ..
|
||||
image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" ..
|
||||
"color,span=1;" ..
|
||||
"text,padding=1]" ..
|
||||
"table[-0.15,-0.1;7.75,5.5;favourites;"
|
||||
|
||||
if #menudata.favorites > 0 then
|
||||
retval = retval .. render_favorite(menudata.favorites[1],render_details)
|
||||
|
||||
for i=2,#menudata.favorites,1 do
|
||||
retval = retval .. "," .. render_favorite(menudata.favorites[i],render_details)
|
||||
local favs = core.get_favorites("local")
|
||||
if #favs > 0 then
|
||||
for i = 1, #favs do
|
||||
for j = 1, #menudata.favorites do
|
||||
if menudata.favorites[j].address == favs[i].address and
|
||||
menudata.favorites[j].port == favs[i].port then
|
||||
table.insert(menudata.favorites, i, table.remove(menudata.favorites, j))
|
||||
end
|
||||
end
|
||||
if favs[i].address ~= menudata.favorites[i].address then
|
||||
table.insert(menudata.favorites, i, favs[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
retval = retval .. render_favorite(menudata.favorites[1], (#favs > 0))
|
||||
for i = 2, #menudata.favorites do
|
||||
retval = retval .. "," .. render_favorite(menudata.favorites[i], (i <= #favs))
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -100,9 +99,10 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||
|
||||
if fields["favourites"] ~= nil then
|
||||
local event = core.explode_table_event(fields["favourites"])
|
||||
local fav = menudata.favorites[event.row]
|
||||
|
||||
if event.type == "DCL" then
|
||||
if event.row <= #menudata.favorites then
|
||||
local fav = menudata.favorites[event.row]
|
||||
if menudata.favorites_is_public and
|
||||
not is_server_protocol_compat_or_error(
|
||||
fav.proto_min, fav.proto_max) then
|
||||
|
@ -131,8 +131,18 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||
|
||||
if event.type == "CHG" then
|
||||
if event.row <= #menudata.favorites then
|
||||
local address = menudata.favorites[event.row].address
|
||||
local port = menudata.favorites[event.row].port
|
||||
gamedata.fav = false
|
||||
local favs = core.get_favorites("local")
|
||||
local address = fav.address
|
||||
local port = fav.port
|
||||
gamedata.serverdescription = fav.description
|
||||
|
||||
for i = 1, #favs do
|
||||
if fav.address == favs[i].address and
|
||||
fav.port == favs[i].port then
|
||||
gamedata.fav = true
|
||||
end
|
||||
end
|
||||
|
||||
if address ~= nil and
|
||||
port ~= nil then
|
||||
|
@ -181,29 +191,16 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||
return true
|
||||
end
|
||||
|
||||
if fields["cb_public_serverlist"] ~= nil then
|
||||
core.setting_set("public_serverlist", fields["cb_public_serverlist"])
|
||||
|
||||
if core.setting_getbool("public_serverlist") then
|
||||
asyncOnlineFavourites()
|
||||
else
|
||||
menudata.favorites = core.get_favorites("local")
|
||||
menudata.favorites_is_public = false
|
||||
end
|
||||
tabdata.fav_selected = nil
|
||||
return true
|
||||
end
|
||||
|
||||
if fields["btn_delete_favorite"] ~= nil then
|
||||
if fields.btn_delete_favorite then
|
||||
local current_favourite = core.get_table_index("favourites")
|
||||
if current_favourite == nil then return end
|
||||
if not current_favourite then return end
|
||||
|
||||
core.delete_favorite(current_favourite)
|
||||
menudata.favorites = core.get_favorites("local")
|
||||
asyncOnlineFavourites()
|
||||
tabdata.fav_selected = nil
|
||||
|
||||
core.setting_set("address","")
|
||||
core.setting_set("remote_port","30000")
|
||||
|
||||
core.setting_set("address", "")
|
||||
core.setting_set("remote_port", "30000")
|
||||
return true
|
||||
end
|
||||
|
||||
|
@ -247,16 +244,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||
return false
|
||||
end
|
||||
|
||||
local function on_change(type,old_tab,new_tab)
|
||||
if type == "LEAVE" then
|
||||
return
|
||||
end
|
||||
if core.setting_getbool("public_serverlist") then
|
||||
asyncOnlineFavourites()
|
||||
else
|
||||
menudata.favorites = core.get_favorites("local")
|
||||
menudata.favorites_is_public = false
|
||||
end
|
||||
local function on_change(type, old_tab, new_tab)
|
||||
if type == "LEAVE" then return end
|
||||
asyncOnlineFavourites()
|
||||
end
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 916 B |
Loading…
Reference in New Issue