From 733d3182bde69f949851970c08bf09b328deaa53 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Mon, 1 Dec 2014 00:58:00 +0100 Subject: Display serverlist flags as icons --- builtin/mainmenu/common.lua | 62 +++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 19 deletions(-) (limited to 'builtin/mainmenu/common.lua') 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 @@ -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 -------------------------------------------------------------------------------- -- cgit v1.2.3