Display serverlist flags as icons

master
Kahrl 2014-12-01 00:58:00 +01:00
parent 94a5a86493
commit 733d3182bd
6 changed files with 77 additions and 34 deletions

View File

@ -23,6 +23,17 @@ menudata = {}
-- 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)
local text = ""
@ -49,40 +60,53 @@ function render_favorite(spec,render_details)
end
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
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 .. "_"
details = details .. ',?,/,?,'
end
if spec.creative then
details = details .. "C"
details = details .. "1,"
else
details = details .. "_"
details = details .. "0,"
end
if spec.damage then
details = details .. "D"
details = details .. "1,"
else
details = details .. "_"
details = details .. "0,"
end
if spec.pvp then
details = details .. "P"
details = details .. "1,"
else
details = details .. "_"
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) .. " "
details = details .. "0,"
end
return playercount .. core.formspec_escape(details) .. text
return details .. text
end
--------------------------------------------------------------------------------

View File

@ -52,10 +52,29 @@ local function get_formspec(tabview, name, tabdata)
retval = retval ..
";]"
--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 ..
"textlist[1,0.35;7.5,3.35;favourites;"
"table[1,0.35;7.5,3.35;favourites;"
if #menudata.favorites > 0 then
retval = retval .. render_favorite(menudata.favorites[1],render_details)
@ -83,11 +102,11 @@ local function main_button_handler(tabview, fields, name, tabdata)
end
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.index <= #menudata.favorites then
gamedata.address = menudata.favorites[event.index].address
gamedata.port = menudata.favorites[event.index].port
if event.row <= #menudata.favorites then
gamedata.address = menudata.favorites[event.row].address
gamedata.port = menudata.favorites[event.row].port
gamedata.playername = fields["te_name"]
if fields["te_pwd"] ~= nil then
gamedata.password = fields["te_pwd"]
@ -95,8 +114,8 @@ local function main_button_handler(tabview, fields, name, tabdata)
gamedata.selected_world = 0
if menudata.favorites ~= nil then
gamedata.servername = menudata.favorites[event.index].name
gamedata.serverdescription = menudata.favorites[event.index].description
gamedata.servername = menudata.favorites[event.row].name
gamedata.serverdescription = menudata.favorites[event.row].description
end
if gamedata.address ~= nil and
@ -110,9 +129,9 @@ local function main_button_handler(tabview, fields, name, tabdata)
end
if event.type == "CHG" then
if event.index <= #menudata.favorites then
local address = menudata.favorites[event.index].address
local port = menudata.favorites[event.index].port
if event.row <= #menudata.favorites then
local address = menudata.favorites[event.row].address
local port = menudata.favorites[event.row].port
if address ~= nil and
port ~= nil then
@ -120,7 +139,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
core.setting_set("remote_port",port)
end
tabdata.fav_selected = event.index
tabdata.fav_selected = event.row
end
return true
@ -130,7 +149,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
if fields["key_up"] ~= nil or
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 fields["key_up"] ~= nil and fav_idx > 1 then
@ -174,7 +193,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
end
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
core.delete_favorite(current_favourite)
menudata.favorites = core.get_favorites()
@ -194,7 +213,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
gamedata.address = fields["te_address"]
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
menudata.favorites[fav_idx].address == fields["te_address"] and

Binary file not shown.

After

Width:  |  Height:  |  Size: 95 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 774 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB