forked from Mirrorlandia_minetest/minetest
Display serverlist flags as icons
This commit is contained in:
parent
94a5a86493
commit
733d3182bd
@ -23,6 +23,17 @@ menudata = {}
|
|||||||
-- Menu helper functions
|
-- Menu helper functions
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
local function render_client_count(n)
|
||||||
|
if n > 99 then
|
||||||
|
return '99+'
|
||||||
|
elseif n >= 0 then
|
||||||
|
return tostring(n)
|
||||||
|
else
|
||||||
|
return '?'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function render_favorite(spec,render_details)
|
function render_favorite(spec,render_details)
|
||||||
local text = ""
|
local text = ""
|
||||||
@ -49,40 +60,53 @@ function render_favorite(spec,render_details)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local details = ""
|
local details = ""
|
||||||
if spec.password == true then
|
|
||||||
details = details .. "*"
|
if spec.clients ~= nil and spec.clients_max ~= nil then
|
||||||
|
local clients_color = ''
|
||||||
|
local clients_percent = 100 * spec.clients / spec.clients_max
|
||||||
|
|
||||||
|
-- Choose a color depending on how many clients are connected
|
||||||
|
-- (relatively to clients_max)
|
||||||
|
if spec.clients == 0 then
|
||||||
|
clients_color = '' -- 0 players: default/white
|
||||||
|
elseif spec.clients == spec.clients_max then
|
||||||
|
clients_color = '#dd5b5b' -- full server: red (darker)
|
||||||
|
elseif clients_percent <= 60 then
|
||||||
|
clients_color = '#a1e587' -- 0-60%: green
|
||||||
|
elseif clients_percent <= 90 then
|
||||||
|
clients_color = '#ffdc97' -- 60-90%: yellow
|
||||||
else
|
else
|
||||||
details = details .. "_"
|
clients_color = '#ffba97' -- 90-100%: orange
|
||||||
|
end
|
||||||
|
|
||||||
|
details = details ..
|
||||||
|
clients_color .. ',' ..
|
||||||
|
render_client_count(spec.clients) .. ',' ..
|
||||||
|
'/,' ..
|
||||||
|
render_client_count(spec.clients_max) .. ','
|
||||||
|
else
|
||||||
|
details = details .. ',?,/,?,'
|
||||||
end
|
end
|
||||||
|
|
||||||
if spec.creative then
|
if spec.creative then
|
||||||
details = details .. "C"
|
details = details .. "1,"
|
||||||
else
|
else
|
||||||
details = details .. "_"
|
details = details .. "0,"
|
||||||
end
|
end
|
||||||
|
|
||||||
if spec.damage then
|
if spec.damage then
|
||||||
details = details .. "D"
|
details = details .. "1,"
|
||||||
else
|
else
|
||||||
details = details .. "_"
|
details = details .. "0,"
|
||||||
end
|
end
|
||||||
|
|
||||||
if spec.pvp then
|
if spec.pvp then
|
||||||
details = details .. "P"
|
details = details .. "1,"
|
||||||
else
|
else
|
||||||
details = details .. "_"
|
details = details .. "0,"
|
||||||
end
|
|
||||||
details = details .. " "
|
|
||||||
|
|
||||||
local playercount = ""
|
|
||||||
|
|
||||||
if spec.clients ~= nil and
|
|
||||||
spec.clients_max ~= nil then
|
|
||||||
playercount = string.format("%03d",spec.clients) .. "/" ..
|
|
||||||
string.format("%03d",spec.clients_max) .. " "
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return playercount .. core.formspec_escape(details) .. text
|
return details .. text
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
@ -54,8 +54,27 @@ local function get_formspec(tabview, name, tabdata)
|
|||||||
";]"
|
";]"
|
||||||
|
|
||||||
--favourites
|
--favourites
|
||||||
|
local function image_column(tooltip, flagname)
|
||||||
|
return "image," ..
|
||||||
|
"tooltip=" .. core.formspec_escape(tooltip) .. "," ..
|
||||||
|
"0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," ..
|
||||||
|
"1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png")
|
||||||
|
end
|
||||||
|
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("Creative mode", "creative") .. ";" ..
|
||||||
|
image_column("Damage enabled", "damage") .. ",padding=0.25;" ..
|
||||||
|
image_column("PvP enabled", "pvp") .. ",padding=0.25;" ..
|
||||||
|
"text]" -- name
|
||||||
|
else
|
||||||
|
retval = retval .. "tablecolumns[text]"
|
||||||
|
end
|
||||||
retval = retval ..
|
retval = retval ..
|
||||||
"textlist[1,0.35;7.5,3.35;favourites;"
|
"table[1,0.35;7.5,3.35;favourites;"
|
||||||
|
|
||||||
if #menudata.favorites > 0 then
|
if #menudata.favorites > 0 then
|
||||||
retval = retval .. render_favorite(menudata.favorites[1],render_details)
|
retval = retval .. render_favorite(menudata.favorites[1],render_details)
|
||||||
@ -83,11 +102,11 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fields["favourites"] ~= nil then
|
if fields["favourites"] ~= nil then
|
||||||
local event = core.explode_textlist_event(fields["favourites"])
|
local event = core.explode_table_event(fields["favourites"])
|
||||||
if event.type == "DCL" then
|
if event.type == "DCL" then
|
||||||
if event.index <= #menudata.favorites then
|
if event.row <= #menudata.favorites then
|
||||||
gamedata.address = menudata.favorites[event.index].address
|
gamedata.address = menudata.favorites[event.row].address
|
||||||
gamedata.port = menudata.favorites[event.index].port
|
gamedata.port = menudata.favorites[event.row].port
|
||||||
gamedata.playername = fields["te_name"]
|
gamedata.playername = fields["te_name"]
|
||||||
if fields["te_pwd"] ~= nil then
|
if fields["te_pwd"] ~= nil then
|
||||||
gamedata.password = fields["te_pwd"]
|
gamedata.password = fields["te_pwd"]
|
||||||
@ -95,8 +114,8 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
gamedata.selected_world = 0
|
gamedata.selected_world = 0
|
||||||
|
|
||||||
if menudata.favorites ~= nil then
|
if menudata.favorites ~= nil then
|
||||||
gamedata.servername = menudata.favorites[event.index].name
|
gamedata.servername = menudata.favorites[event.row].name
|
||||||
gamedata.serverdescription = menudata.favorites[event.index].description
|
gamedata.serverdescription = menudata.favorites[event.row].description
|
||||||
end
|
end
|
||||||
|
|
||||||
if gamedata.address ~= nil and
|
if gamedata.address ~= nil and
|
||||||
@ -110,9 +129,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if event.type == "CHG" then
|
if event.type == "CHG" then
|
||||||
if event.index <= #menudata.favorites then
|
if event.row <= #menudata.favorites then
|
||||||
local address = menudata.favorites[event.index].address
|
local address = menudata.favorites[event.row].address
|
||||||
local port = menudata.favorites[event.index].port
|
local port = menudata.favorites[event.row].port
|
||||||
|
|
||||||
if address ~= nil and
|
if address ~= nil and
|
||||||
port ~= nil then
|
port ~= nil then
|
||||||
@ -120,7 +139,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
core.setting_set("remote_port",port)
|
core.setting_set("remote_port",port)
|
||||||
end
|
end
|
||||||
|
|
||||||
tabdata.fav_selected = event.index
|
tabdata.fav_selected = event.row
|
||||||
end
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@ -130,7 +149,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
if fields["key_up"] ~= nil or
|
if fields["key_up"] ~= nil or
|
||||||
fields["key_down"] ~= nil then
|
fields["key_down"] ~= nil then
|
||||||
|
|
||||||
local fav_idx = core.get_textlist_index("favourites")
|
local fav_idx = core.get_table_index("favourites")
|
||||||
|
|
||||||
if fav_idx ~= nil then
|
if fav_idx ~= nil then
|
||||||
if fields["key_up"] ~= nil and fav_idx > 1 then
|
if fields["key_up"] ~= nil and fav_idx > 1 then
|
||||||
@ -174,7 +193,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if fields["btn_delete_favorite"] ~= nil then
|
if fields["btn_delete_favorite"] ~= nil then
|
||||||
local current_favourite = core.get_textlist_index("favourites")
|
local current_favourite = core.get_table_index("favourites")
|
||||||
if current_favourite == nil then return end
|
if current_favourite == nil then return end
|
||||||
core.delete_favorite(current_favourite)
|
core.delete_favorite(current_favourite)
|
||||||
menudata.favorites = core.get_favorites()
|
menudata.favorites = core.get_favorites()
|
||||||
@ -194,7 +213,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
gamedata.address = fields["te_address"]
|
gamedata.address = fields["te_address"]
|
||||||
gamedata.port = fields["te_port"]
|
gamedata.port = fields["te_port"]
|
||||||
|
|
||||||
local fav_idx = core.get_textlist_index("favourites")
|
local fav_idx = core.get_table_index("favourites")
|
||||||
|
|
||||||
if fav_idx ~= nil and fav_idx <= #menudata.favorites and
|
if fav_idx ~= nil and fav_idx <= #menudata.favorites and
|
||||||
menudata.favorites[fav_idx].address == fields["te_address"] and
|
menudata.favorites[fav_idx].address == fields["te_address"] and
|
||||||
|
BIN
textures/base/pack/blank.png
Normal file
BIN
textures/base/pack/blank.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 95 B |
BIN
textures/base/pack/server_flags_creative.png
Normal file
BIN
textures/base/pack/server_flags_creative.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 255 B |
BIN
textures/base/pack/server_flags_damage.png
Normal file
BIN
textures/base/pack/server_flags_damage.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 774 B |
BIN
textures/base/pack/server_flags_pvp.png
Normal file
BIN
textures/base/pack/server_flags_pvp.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.0 KiB |
Loading…
Reference in New Issue
Block a user