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 | |
parent | 94a5a8649375bfe7085be6d9aa624e22e5262a57 (diff) | |
download | minetest-733d3182bde69f949851970c08bf09b328deaa53.tar.gz minetest-733d3182bde69f949851970c08bf09b328deaa53.tar.bz2 minetest-733d3182bde69f949851970c08bf09b328deaa53.zip |
Display serverlist flags as icons
-rw-r--r-- | builtin/mainmenu/common.lua | 62 | ||||
-rw-r--r-- | builtin/mainmenu/tab_multiplayer.lua | 49 | ||||
-rw-r--r-- | textures/base/pack/blank.png | bin | 0 -> 95 bytes | |||
-rw-r--r-- | textures/base/pack/server_flags_creative.png | bin | 0 -> 255 bytes | |||
-rw-r--r-- | textures/base/pack/server_flags_damage.png | bin | 0 -> 774 bytes | |||
-rw-r--r-- | textures/base/pack/server_flags_pvp.png | bin | 0 -> 1056 bytes |
6 files changed, 77 insertions, 34 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 -------------------------------------------------------------------------------- diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index b235eaecf..887568fae 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -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 diff --git a/textures/base/pack/blank.png b/textures/base/pack/blank.png Binary files differnew file mode 100644 index 000000000..85e02501d --- /dev/null +++ b/textures/base/pack/blank.png diff --git a/textures/base/pack/server_flags_creative.png b/textures/base/pack/server_flags_creative.png Binary files differnew file mode 100644 index 000000000..267f5d3e7 --- /dev/null +++ b/textures/base/pack/server_flags_creative.png diff --git a/textures/base/pack/server_flags_damage.png b/textures/base/pack/server_flags_damage.png Binary files differnew file mode 100644 index 000000000..f35eb7292 --- /dev/null +++ b/textures/base/pack/server_flags_damage.png diff --git a/textures/base/pack/server_flags_pvp.png b/textures/base/pack/server_flags_pvp.png Binary files differnew file mode 100644 index 000000000..5c3d86bc0 --- /dev/null +++ b/textures/base/pack/server_flags_pvp.png |