]> git.lizzy.rs Git - minetest.git/commitdiff
Serverlist: Add ping indicators (#5164)
authorkilbith <kilbith@users.noreply.github.com>
Fri, 3 Feb 2017 13:53:43 +0000 (14:53 +0100)
committerZeno- <kde.psych@gmail.com>
Fri, 3 Feb 2017 13:53:43 +0000 (23:53 +1000)
builtin/mainmenu/common.lua
builtin/mainmenu/tab_multiplayer.lua
builtin/mainmenu/tab_simple_main.lua
src/script/lua_api/l_mainmenu.cpp
textures/base/pack/server_ping_1.png [new file with mode: 0644]
textures/base/pack/server_ping_2.png [new file with mode: 0644]
textures/base/pack/server_ping_3.png [new file with mode: 0644]
textures/base/pack/server_ping_4.png [new file with mode: 0644]

index 5e3df086467f64ff4badf375964fab9e7d37f4b7..17d910e8b7f426243306be61f64e2f8beeab66be 100644 (file)
@@ -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
index f8edeaddd8ad8a2f30761843c4e173b95cb89ad9..033ba38d8d5e0ba91e18c3bee2c0f03a80777eba 100644 (file)
@@ -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;" ..  -- "/"
index a773a491240a804431300901ea036232d4f1ab62..23820aab7a1f6a9e3cf22b135a945aadacb8e59c 100644 (file)
@@ -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;" ..  -- "/"
index 4a2484613f790ff439249a29ad8a120df2f82aa6..de8890b11878671f7987e527ac5176474dce3d4a 100644 (file)
@@ -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 (file)
index 0000000..ba5bba1
Binary files /dev/null and b/textures/base/pack/server_ping_1.png differ
diff --git a/textures/base/pack/server_ping_2.png b/textures/base/pack/server_ping_2.png
new file mode 100644 (file)
index 0000000..8dca0be
Binary files /dev/null and b/textures/base/pack/server_ping_2.png differ
diff --git a/textures/base/pack/server_ping_3.png b/textures/base/pack/server_ping_3.png
new file mode 100644 (file)
index 0000000..c2cab01
Binary files /dev/null and b/textures/base/pack/server_ping_3.png differ
diff --git a/textures/base/pack/server_ping_4.png b/textures/base/pack/server_ping_4.png
new file mode 100644 (file)
index 0000000..03b4b5b
Binary files /dev/null and b/textures/base/pack/server_ping_4.png differ