Skip to content
Permalink
Browse files

Mainmenu: Improve "Join Game" tab (#11078)

  • Loading branch information
sfan5 committed Mar 20, 2021
1 parent 0571991 commit 042131d91d0f61d1252d240aa799f3b12b509cfe
@@ -14,6 +14,9 @@ https://www.apache.org/licenses/LICENSE-2.0.html
Textures by Zughy are under CC BY-SA 4.0
https://creativecommons.org/licenses/by-sa/4.0/

textures/base/pack/server_public.png is under CC-BY 4.0, taken from Twitter's Twemoji set
https://creativecommons.org/licenses/by/4.0/

Authors of media files
-----------------------
Everything not listed in here:
@@ -39,10 +42,10 @@ erlehmann:
misc/minetest.svg
textures/base/pack/logo.png

JRottm
JRottm:
textures/base/pack/player_marker.png

srifqi
srifqi:
textures/base/pack/chat_hide_btn.png
textures/base/pack/chat_show_btn.png
textures/base/pack/joystick_bg.png
@@ -58,6 +61,9 @@ Zughy:
textures/base/pack/cdb_update.png
textures/base/pack/cdb_viewonline.png

appgurueu:
textures/base/pack/server_incompatible.png

License of Minetest source code
-------------------------------

@@ -58,26 +58,20 @@ end

--------------------------------------------------------------------------------
local function get_formspec(self)
local formspec = ""
if self.hidden or (self.parent ~= nil and self.parent.hidden) then
return ""
end
local tab = self.tablist[self.last_tab_index]

if not self.hidden and (self.parent == nil or not self.parent.hidden) then
local content, prepend = tab.get_formspec(self, tab.name, tab.tabdata, tab.tabsize)

if self.parent == nil then
local tsize = self.tablist[self.last_tab_index].tabsize or
{width=self.width, height=self.height}
formspec = formspec ..
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
dump(self.fixed_size))
end
formspec = formspec .. self:tab_header()
formspec = formspec ..
self.tablist[self.last_tab_index].get_formspec(
self,
self.tablist[self.last_tab_index].name,
self.tablist[self.last_tab_index].tabdata,
self.tablist[self.last_tab_index].tabsize
)
if self.parent == nil and not prepend then
local tsize = tab.tabsize or {width=self.width, height=self.height}
prepend = string.format("size[%f,%f,%s]", tsize.width, tsize.height,
dump(self.fixed_size))
end

local formspec = (prepend or "") .. self:tab_header() .. content
return formspec
end

@@ -97,14 +91,9 @@ local function handle_buttons(self,fields)
return true
end

if self.tablist[self.last_tab_index].button_handler ~= nil then
return
self.tablist[self.last_tab_index].button_handler(
self,
fields,
self.tablist[self.last_tab_index].name,
self.tablist[self.last_tab_index].tabdata
)
local tab = self.tablist[self.last_tab_index]
if tab.button_handler ~= nil then
return tab.button_handler(self, fields, tab.name, tab.tabdata)
end

return false
@@ -122,14 +111,9 @@ local function handle_events(self,event)
return true
end

if self.tablist[self.last_tab_index].evt_handler ~= nil then
return
self.tablist[self.last_tab_index].evt_handler(
self,
event,
self.tablist[self.last_tab_index].name,
self.tablist[self.last_tab_index].tabdata
)
local tab = self.tablist[self.last_tab_index]
if tab.evt_handler ~= nil then
return tab.evt_handler(self, event, tab.name, tab.tabdata)
end

return false
@@ -14,29 +14,24 @@
--You should have received a copy of the GNU Lesser General Public License along
--with this program; if not, write to the Free Software Foundation, Inc.,
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------------

-- Global menu data
--------------------------------------------------------------------------------
menudata = {}

--------------------------------------------------------------------------------
-- Local cached values
--------------------------------------------------------------------------------
local min_supp_proto, max_supp_proto

function common_update_cached_supp_proto()
min_supp_proto = core.get_min_supp_proto()
max_supp_proto = core.get_max_supp_proto()
end
common_update_cached_supp_proto()
--------------------------------------------------------------------------------

-- Menu helper functions
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
local function render_client_count(n)
if n > 99 then return '99+'
elseif n >= 0 then return tostring(n)
if n > 999 then return '99+'
elseif n >= 0 then return tostring(n)
else return '?' end
end

@@ -50,21 +45,7 @@ local function configure_selected_world_params(idx)
end
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 ..
(flagname and "server_flags_" .. flagname .. ".png" or "blank.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


--------------------------------------------------------------------------------
function render_serverlist_row(spec, is_favorite)
function render_serverlist_row(spec)
local text = ""
if spec.name then
text = text .. core.formspec_escape(spec.name:trim())
@@ -75,31 +56,29 @@ function render_serverlist_row(spec, is_favorite)
end
end

local grey_out = not is_server_protocol_compat(spec.proto_min, spec.proto_max)
local grey_out = not spec.is_compatible

local details
if is_favorite then
details = "1,"
else
details = "0,"
end
local details = {}

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,"
if spec.lag or spec.ping then
local lag = (spec.lag or 0) * 1000 + (spec.ping or 0) * 250
if lag <= 125 then
table.insert(details, "1")
elseif lag <= 175 then
table.insert(details, "2")
elseif lag <= 250 then
table.insert(details, "3")
else
details = details .. "5,"
table.insert(details, "4")
end
else
details = details .. "0,"
table.insert(details, "0")
end

if spec.clients and spec.clients_max then
table.insert(details, ",")

local color = (grey_out and "#aaaaaa") or ((spec.is_favorite and "#ddddaa") or "#ffffff")
if spec.clients and (spec.clients_max or 0) > 0 then
local clients_percent = 100 * spec.clients / spec.clients_max

-- Choose a color depending on how many clients are connected
@@ -110,38 +89,35 @@ function render_serverlist_row(spec, is_favorite)
elseif clients_percent <= 60 then clients_color = '#a1e587' -- 0-60%: green
elseif clients_percent <= 90 then clients_color = '#ffdc97' -- 60-90%: yellow
elseif clients_percent == 100 then clients_color = '#dd5b5b' -- full server: red (darker)
else clients_color = '#ffba97' -- 90-100%: orange
else clients_color = '#ffba97' -- 90-100%: orange
end

details = details .. clients_color .. ',' ..
render_client_count(spec.clients) .. ',/,' ..
render_client_count(spec.clients_max) .. ','

elseif grey_out then
details = details .. '#aaaaaa,?,/,?,'
table.insert(details, clients_color)
table.insert(details, render_client_count(spec.clients) .. " / " ..
render_client_count(spec.clients_max))
else
details = details .. ',?,/,?,'
table.insert(details, color)
table.insert(details, "?")
end

if spec.creative then
details = details .. "1,"
else
details = details .. "0,"
end

if spec.damage then
details = details .. "1,"
table.insert(details, "1") -- creative icon
else
details = details .. "0,"
table.insert(details, "0")
end

if spec.pvp then
details = details .. "1,"
table.insert(details, "2") -- pvp icon
elseif spec.damage then
table.insert(details, "1") -- heart icon
else
details = details .. "0,"
table.insert(details, "0")
end

return details .. (grey_out and '#aaaaaa,' or ',') .. text
table.insert(details, color)
table.insert(details, text)

return table.concat(details, ",")
end

--------------------------------------------------------------------------------
@@ -150,14 +126,13 @@ os.tempfolder = function()
return temp .. DIR_DELIM .. "MT_" .. math.random(0, 10000)
end

--------------------------------------------------------------------------------
os.tmpname = function()
local path = os.tempfolder()
io.open(path, "w"):close()
return path
end

--------------------------------------------------------------------------------

function menu_render_worldlist()
local retval = ""
local current_worldlist = menudata.worldlist:get_list()
@@ -171,7 +146,6 @@ function menu_render_worldlist()
return retval
end

--------------------------------------------------------------------------------
function menu_handle_key_up_down(fields, textlist, settingname)
local oldidx, newidx = core.get_textlist_index(textlist), 1
if fields.key_up or fields.key_down then
@@ -188,7 +162,6 @@ function menu_handle_key_up_down(fields, textlist, settingname)
return false
end

--------------------------------------------------------------------------------
function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transparency)
local textlines = core.wrap_text(text, textlen, true)
local retval = "textlist[" .. xpos .. "," .. ypos .. ";" .. width ..
@@ -206,15 +179,14 @@ function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transp
return retval
end

--------------------------------------------------------------------------------
function is_server_protocol_compat(server_proto_min, server_proto_max)
if (not server_proto_min) or (not server_proto_max) then
-- There is no info. Assume the best and act as if we would be compatible.
return true
end
return min_supp_proto <= server_proto_max and max_supp_proto >= server_proto_min
end
--------------------------------------------------------------------------------

function is_server_protocol_compat_or_error(server_proto_min, server_proto_max)
if not is_server_protocol_compat(server_proto_min, server_proto_max) then
local server_prot_ver_info, client_prot_ver_info
@@ -242,7 +214,7 @@ function is_server_protocol_compat_or_error(server_proto_min, server_proto_max)

return true
end
--------------------------------------------------------------------------------

function menu_worldmt(selected, setting, value)
local world = menudata.worldlist:get_list()[selected]
if world then

0 comments on commit 042131d

Please sign in to comment.