From 03b34cb3dd0647b3e378f00cdc7203e580c9dcc8 Mon Sep 17 00:00:00 2001 From: kilbith Date: Fri, 3 Feb 2017 14:53:43 +0100 Subject: [PATCH] Serverlist: Add ping indicators (#5164) --- builtin/mainmenu/common.lua | 21 ++++++++++++++++++++- builtin/mainmenu/tab_multiplayer.lua | 1 + builtin/mainmenu/tab_simple_main.lua | 1 + src/script/lua_api/l_mainmenu.cpp | 7 +++++++ textures/base/pack/server_ping_1.png | Bin 0 -> 251 bytes textures/base/pack/server_ping_2.png | Bin 0 -> 244 bytes textures/base/pack/server_ping_3.png | Bin 0 -> 245 bytes textures/base/pack/server_ping_4.png | Bin 0 -> 213 bytes 8 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 textures/base/pack/server_ping_1.png create mode 100644 textures/base/pack/server_ping_2.png create mode 100644 textures/base/pack/server_ping_3.png create mode 100644 textures/base/pack/server_ping_4.png diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index 5e3df086..17d910e8 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -54,7 +54,11 @@ end 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") + "1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_" .. flagname .. ".png") .. "," .. + "2=" .. core.formspec_escape(defaulttexturedir .. "server_ping_4.png") .. "," .. + "3=" .. core.formspec_escape(defaulttexturedir .. "server_ping_3.png") .. "," .. + "4=" .. core.formspec_escape(defaulttexturedir .. "server_ping_2.png") .. "," .. + "5=" .. core.formspec_escape(defaulttexturedir .. "server_ping_1.png") end -------------------------------------------------------------------------------- @@ -97,6 +101,21 @@ function render_serverlist_row(spec, is_favorite) details = "0," end + if spec.ping then + local ping = spec.ping * 1000 + if ping <= 50 then + details = details .. "2," + elseif ping <= 100 then + details = details .. "3," + elseif ping <= 250 then + details = details .. "4," + else + details = details .. "5," + end + else + details = details .. "0," + end + if spec.clients and spec.clients_max then local clients_color = '' local clients_percent = 100 * spec.clients / spec.clients_max diff --git a/builtin/mainmenu/tab_multiplayer.lua b/builtin/mainmenu/tab_multiplayer.lua index f8edeadd..033ba38d 100644 --- a/builtin/mainmenu/tab_multiplayer.lua +++ b/builtin/mainmenu/tab_multiplayer.lua @@ -69,6 +69,7 @@ local function get_formspec(tabview, name, tabdata) --favourites retval = retval .. "tablecolumns[" .. image_column(fgettext("Favorite"), "favorite") .. ";" .. + image_column(fgettext("Ping"), "") .. ",padding=0.25;" .. "color,span=3;" .. "text,align=right;" .. -- clients "text,align=center,padding=0.25;" .. -- "/" diff --git a/builtin/mainmenu/tab_simple_main.lua b/builtin/mainmenu/tab_simple_main.lua index a773a491..23820aab 100644 --- a/builtin/mainmenu/tab_simple_main.lua +++ b/builtin/mainmenu/tab_simple_main.lua @@ -43,6 +43,7 @@ local function get_formspec(tabview, name, tabdata) retval = retval .. "tablecolumns[" .. image_column(fgettext("Favorite"), "favorite") .. ";" .. + image_column(fgettext("Ping"), "") .. ",padding=0.25;" .. "color,span=3;" .. "text,align=right;" .. -- clients "text,align=center,padding=0.25;" .. -- "/" diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 4a248461..de8890b1 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -577,6 +577,13 @@ int ModApiMainMenu::l_get_favorites(lua_State *L) lua_settable(L, top_lvl2); } + if (servers[i].isMember("ping")) { + float ping = servers[i]["ping"].asFloat(); + lua_pushstring(L, "ping"); + lua_pushnumber(L, ping); + lua_settable(L, top_lvl2); + } + lua_settable(L, top); index++; } diff --git a/textures/base/pack/server_ping_1.png b/textures/base/pack/server_ping_1.png new file mode 100644 index 0000000000000000000000000000000000000000..ba5bba1e3da6f6ae3340b499b291ee4f2108b553 GIT binary patch literal 251 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)3BisC9v-11Q2-;1OBO zz`!jG!i)^F=12eq*-JcqUD+QpF$oxo&scjS6DZW->Eak-aXNX+h7Ab|SPTpUINBC4 zo;r2v|J12d{~!LLBNFj%zJ~aM+Z}un9$P0SNC<42C?YP9%5k~#vHt)07XLok?^NV0 zKgjw2^?ykT35hA|H72JpC?BqO9ydI9W7y@PKf}~(?`fc$7(8A5T-G@yGywn{!BX1* literal 0 HcmV?d00001 diff --git a/textures/base/pack/server_ping_2.png b/textures/base/pack/server_ping_2.png new file mode 100644 index 0000000000000000000000000000000000000000..8dca0be0d0a62de2046535079a018fb611b21388 GIT binary patch literal 244 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE({hRn3dtu2NdBf@Q5sC zVBi)8VMc~ob0mO*>?NMQuIvw)m;?+Nb1HK!fI^L)E{-7 zsZ*!^Pn|mT|KT4xA`$=QYlttn-N6^(v2|jC#2kx%pZ<3~*8eY@t>q^^=fnPg^BWr* z9e;Ki{fkhz>NZEO;pT}03ND)%domhZ4#n?!BB9L8%-r0%)FRBT8%SPZeV-s?@#Ff! h8eb8+#|_Wj7^06Fy0*SB+5mJ6gQu&X%Q~loCIIN+Rm=bY literal 0 HcmV?d00001 diff --git a/textures/base/pack/server_ping_3.png b/textures/base/pack/server_ping_3.png new file mode 100644 index 0000000000000000000000000000000000000000..c2cab017e10b3b6babfafe953cf663b7066cfa46 GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)3BisC9v-11Q2-;1OBO zz`!jG!i)^F=12eq*-JcqUD+QpF$ox`FVDZ(0u*ZUba4!^IDK{UUe3b~JZ|$3`A#^- zoWXflB+e-A=srfKc?W&NCd`&u@}d8b=&@IJELHrRoii^6@k_mKV-C3*dNtdRw}4-A zO6Er+-F?^jrKi-DG1R{P$ak(IvDvHT`A5-zs_&#+I-{ANeAh{@tmtJ**je0=vh%l8 jO_uVEbjAs%_ZPCRZ85nRx&ML#&@~L6u6{1-oD!M<0YFnr literal 0 HcmV?d00001 diff --git a/textures/base/pack/server_ping_4.png b/textures/base/pack/server_ping_4.png new file mode 100644 index 0000000000000000000000000000000000000000..03b4b5b83cf3c9dabc49234a31ec827a21bc02c2 GIT binary patch literal 213 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkEFdh=kcmmafO&R~Z75JE$pCP8H}kFA2s zxjVKBMq4GcBuOZAo=-{CJeQED$v0hL>UoO?I|Ug&H0fq8I(UC4&^887S3j3^P6