diff options
author | Kahrl <kahrl@gmx.net> | 2014-12-01 00:58:00 +0100 |
---|---|---|
committer | Kahrl <kahrl@gmx.net> | 2014-12-13 00:33:38 +0100 |
commit | 733d3182bde69f949851970c08bf09b328deaa53 (patch) | |
tree | 6de4c49dfe345725faaf7a87d4de00b07e570fd2 /builtin/mainmenu/common.lua | |
parent | 94a5a8649375bfe7085be6d9aa624e22e5262a57 (diff) | |
download | minetest-733d3182bde69f949851970c08bf09b328deaa53.tar.gz minetest-733d3182bde69f949851970c08bf09b328deaa53.tar.bz2 minetest-733d3182bde69f949851970c08bf09b328deaa53.zip |
Display serverlist flags as icons
Diffstat (limited to 'builtin/mainmenu/common.lua')
-rw-r--r-- | builtin/mainmenu/common.lua | 62 |
1 files changed, 43 insertions, 19 deletions
diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index c555ec92f..d2994e19b 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -24,6 +24,17 @@ menudata = {} -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- +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 -------------------------------------------------------------------------------- |