1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +00:00

Display serverlist flags as icons

This commit is contained in:
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
--------------------------------------------------------------------------------