From 733d3182bde69f949851970c08bf09b328deaa53 Mon Sep 17 00:00:00 2001 From: Kahrl Date: Mon, 1 Dec 2014 00:58:00 +0100 Subject: [PATCH] Display serverlist flags as icons --- builtin/mainmenu/common.lua | 62 +++++++++++++------ builtin/mainmenu/tab_multiplayer.lua | 49 ++++++++++----- textures/base/pack/blank.png | Bin 0 -> 95 bytes textures/base/pack/server_flags_creative.png | Bin 0 -> 255 bytes textures/base/pack/server_flags_damage.png | Bin 0 -> 774 bytes textures/base/pack/server_flags_pvp.png | Bin 0 -> 1056 bytes 6 files changed, 77 insertions(+), 34 deletions(-) create mode 100644 textures/base/pack/blank.png create mode 100644 textures/base/pack/server_flags_creative.png create mode 100644 textures/base/pack/server_flags_damage.png create mode 100644 textures/base/pack/server_flags_pvp.png 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 -------------------------------------------------------------------------------- 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 new file mode 100644 index 0000000000000000000000000000000000000000..85e02501df1560d359a473f544224481a83c9aa7 GIT binary patch literal 95 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga%mF?ju0VQumF+E%TuG2$FoVOh l8)-lem#2$k2#0KP0+7wbzn(P^qK@>OScC`?^5`Nfx-4>Oj@ z<$Q3=SSWOmbqSY`;HnGnd4gTe~DWM4f DYM5_d literal 0 HcmV?d00001 diff --git a/textures/base/pack/server_flags_damage.png b/textures/base/pack/server_flags_damage.png new file mode 100644 index 0000000000000000000000000000000000000000..f35eb7292425d1c9b1103855548c71f7e40aaa78 GIT binary patch literal 774 zcmV+h1Nr=kP)-zjO9J_dM>?>m3{im0ZP$I6hD;43Pv2QwSj-SX#tF5G*Y$6de^z zk;=+qrqR;ELSeuc7LpVWh#5#EBvm9qqRz~D+_U%D=j;^c4vHYb9~OJTTK~V+zqZ2| z_qPs3r_~Hh6uN_6x0qRYu5SMG$^zW_`heIH2L5YfE@OH=%DY3Fn}-EAMAjDl+$+pQ~2DZgtAccm>GFAm?i zS2;I6-|X&R(>t?yqJPy}Hvyd%xGse*_lf~T}UjH0tL3cz(iDRi9bKbKZcZJ&QM zD~|Nn48Pbkbt~8~C7B$6?}OtY9EYwezHCdm&u=vwblV^V6b7NR5P81o$lBfmIX&oo z+w69Hq5!M|#(>tK3mT=72)BjjfdzCiu4zJ5?CG0whwMskKUD=u3QB{uP>e+i13>_J zUdJehIDsT1$VQOmpGm8fWF@Z2Qb1LKDWNE!;njj#Luu-sB!f7GIK^g}kpI42{slOO z=Yi`$S=A&@LKuQJ;MiJJDadk&Gt^3q8jb#vPhY*hy*pPIJFajM4hXkCWDwLA#OhY# z4MsU68Ov$*;-%J$qOa7Oq1N7HmK_wv)W@oTvaF}CPEALU)~l-|HH)MC>S3+#ibbee zrhGP4m4kt;_KJ$yMp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