mirror of
https://github.com/minetest/minetest.git
synced 2024-09-12 00:26:50 +02:00
Mainmenu: Improve "Join Game" tab (#11078)
This commit is contained in:
parent
05719913ac
commit
042131d91d
10
LICENSE.txt
10
LICENSE.txt
@ -14,6 +14,9 @@ https://www.apache.org/licenses/LICENSE-2.0.html
|
|||||||
Textures by Zughy are under CC BY-SA 4.0
|
Textures by Zughy are under CC BY-SA 4.0
|
||||||
https://creativecommons.org/licenses/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
|
Authors of media files
|
||||||
-----------------------
|
-----------------------
|
||||||
Everything not listed in here:
|
Everything not listed in here:
|
||||||
@ -39,10 +42,10 @@ erlehmann:
|
|||||||
misc/minetest.svg
|
misc/minetest.svg
|
||||||
textures/base/pack/logo.png
|
textures/base/pack/logo.png
|
||||||
|
|
||||||
JRottm
|
JRottm:
|
||||||
textures/base/pack/player_marker.png
|
textures/base/pack/player_marker.png
|
||||||
|
|
||||||
srifqi
|
srifqi:
|
||||||
textures/base/pack/chat_hide_btn.png
|
textures/base/pack/chat_hide_btn.png
|
||||||
textures/base/pack/chat_show_btn.png
|
textures/base/pack/chat_show_btn.png
|
||||||
textures/base/pack/joystick_bg.png
|
textures/base/pack/joystick_bg.png
|
||||||
@ -58,6 +61,9 @@ Zughy:
|
|||||||
textures/base/pack/cdb_update.png
|
textures/base/pack/cdb_update.png
|
||||||
textures/base/pack/cdb_viewonline.png
|
textures/base/pack/cdb_viewonline.png
|
||||||
|
|
||||||
|
appgurueu:
|
||||||
|
textures/base/pack/server_incompatible.png
|
||||||
|
|
||||||
License of Minetest source code
|
License of Minetest source code
|
||||||
-------------------------------
|
-------------------------------
|
||||||
|
|
||||||
|
@ -58,26 +58,20 @@ end
|
|||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function get_formspec(self)
|
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
|
if self.parent == nil and not prepend then
|
||||||
local tsize = self.tablist[self.last_tab_index].tabsize or
|
local tsize = tab.tabsize or {width=self.width, height=self.height}
|
||||||
{width=self.width, height=self.height}
|
prepend = string.format("size[%f,%f,%s]", tsize.width, tsize.height,
|
||||||
formspec = formspec ..
|
|
||||||
string.format("size[%f,%f,%s]",tsize.width,tsize.height,
|
|
||||||
dump(self.fixed_size))
|
dump(self.fixed_size))
|
||||||
end
|
end
|
||||||
formspec = formspec .. self:tab_header()
|
|
||||||
formspec = formspec ..
|
local formspec = (prepend or "") .. self:tab_header() .. content
|
||||||
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
|
|
||||||
)
|
|
||||||
end
|
|
||||||
return formspec
|
return formspec
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -97,14 +91,9 @@ local function handle_buttons(self,fields)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.tablist[self.last_tab_index].button_handler ~= nil then
|
local tab = self.tablist[self.last_tab_index]
|
||||||
return
|
if tab.button_handler ~= nil then
|
||||||
self.tablist[self.last_tab_index].button_handler(
|
return tab.button_handler(self, fields, tab.name, tab.tabdata)
|
||||||
self,
|
|
||||||
fields,
|
|
||||||
self.tablist[self.last_tab_index].name,
|
|
||||||
self.tablist[self.last_tab_index].tabdata
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
@ -122,14 +111,9 @@ local function handle_events(self,event)
|
|||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
if self.tablist[self.last_tab_index].evt_handler ~= nil then
|
local tab = self.tablist[self.last_tab_index]
|
||||||
return
|
if tab.evt_handler ~= nil then
|
||||||
self.tablist[self.last_tab_index].evt_handler(
|
return tab.evt_handler(self, event, tab.name, tab.tabdata)
|
||||||
self,
|
|
||||||
event,
|
|
||||||
self.tablist[self.last_tab_index].name,
|
|
||||||
self.tablist[self.last_tab_index].tabdata
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -14,14 +14,11 @@
|
|||||||
--You should have received a copy of the GNU Lesser General Public License along
|
--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.,
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- Global menu data
|
-- Global menu data
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
menudata = {}
|
menudata = {}
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- Local cached values
|
-- Local cached values
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
local min_supp_proto, max_supp_proto
|
local min_supp_proto, max_supp_proto
|
||||||
|
|
||||||
function common_update_cached_supp_proto()
|
function common_update_cached_supp_proto()
|
||||||
@ -29,13 +26,11 @@ function common_update_cached_supp_proto()
|
|||||||
max_supp_proto = core.get_max_supp_proto()
|
max_supp_proto = core.get_max_supp_proto()
|
||||||
end
|
end
|
||||||
common_update_cached_supp_proto()
|
common_update_cached_supp_proto()
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- Menu helper functions
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
-- Menu helper functions
|
||||||
|
|
||||||
local function render_client_count(n)
|
local function render_client_count(n)
|
||||||
if n > 99 then return '99+'
|
if n > 999 then return '99+'
|
||||||
elseif n >= 0 then return tostring(n)
|
elseif n >= 0 then return tostring(n)
|
||||||
else return '?' end
|
else return '?' end
|
||||||
end
|
end
|
||||||
@ -50,21 +45,7 @@ local function configure_selected_world_params(idx)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
function render_serverlist_row(spec)
|
||||||
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)
|
|
||||||
local text = ""
|
local text = ""
|
||||||
if spec.name then
|
if spec.name then
|
||||||
text = text .. core.formspec_escape(spec.name:trim())
|
text = text .. core.formspec_escape(spec.name:trim())
|
||||||
@ -75,31 +56,29 @@ function render_serverlist_row(spec, is_favorite)
|
|||||||
end
|
end
|
||||||
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
|
local details = {}
|
||||||
if is_favorite then
|
|
||||||
details = "1,"
|
|
||||||
else
|
|
||||||
details = "0,"
|
|
||||||
end
|
|
||||||
|
|
||||||
if spec.ping then
|
if spec.lag or spec.ping then
|
||||||
local ping = spec.ping * 1000
|
local lag = (spec.lag or 0) * 1000 + (spec.ping or 0) * 250
|
||||||
if ping <= 50 then
|
if lag <= 125 then
|
||||||
details = details .. "2,"
|
table.insert(details, "1")
|
||||||
elseif ping <= 100 then
|
elseif lag <= 175 then
|
||||||
details = details .. "3,"
|
table.insert(details, "2")
|
||||||
elseif ping <= 250 then
|
elseif lag <= 250 then
|
||||||
details = details .. "4,"
|
table.insert(details, "3")
|
||||||
else
|
else
|
||||||
details = details .. "5,"
|
table.insert(details, "4")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
details = details .. "0,"
|
table.insert(details, "0")
|
||||||
end
|
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
|
local clients_percent = 100 * spec.clients / spec.clients_max
|
||||||
|
|
||||||
-- Choose a color depending on how many clients are connected
|
-- Choose a color depending on how many clients are connected
|
||||||
@ -113,35 +92,32 @@ function render_serverlist_row(spec, is_favorite)
|
|||||||
else clients_color = '#ffba97' -- 90-100%: orange
|
else clients_color = '#ffba97' -- 90-100%: orange
|
||||||
end
|
end
|
||||||
|
|
||||||
details = details .. clients_color .. ',' ..
|
table.insert(details, clients_color)
|
||||||
render_client_count(spec.clients) .. ',/,' ..
|
table.insert(details, render_client_count(spec.clients) .. " / " ..
|
||||||
render_client_count(spec.clients_max) .. ','
|
render_client_count(spec.clients_max))
|
||||||
|
|
||||||
elseif grey_out then
|
|
||||||
details = details .. '#aaaaaa,?,/,?,'
|
|
||||||
else
|
else
|
||||||
details = details .. ',?,/,?,'
|
table.insert(details, color)
|
||||||
|
table.insert(details, "?")
|
||||||
end
|
end
|
||||||
|
|
||||||
if spec.creative then
|
if spec.creative then
|
||||||
details = details .. "1,"
|
table.insert(details, "1") -- creative icon
|
||||||
else
|
else
|
||||||
details = details .. "0,"
|
table.insert(details, "0")
|
||||||
end
|
|
||||||
|
|
||||||
if spec.damage then
|
|
||||||
details = details .. "1,"
|
|
||||||
else
|
|
||||||
details = details .. "0,"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if spec.pvp then
|
if spec.pvp then
|
||||||
details = details .. "1,"
|
table.insert(details, "2") -- pvp icon
|
||||||
|
elseif spec.damage then
|
||||||
|
table.insert(details, "1") -- heart icon
|
||||||
else
|
else
|
||||||
details = details .. "0,"
|
table.insert(details, "0")
|
||||||
end
|
end
|
||||||
|
|
||||||
return details .. (grey_out and '#aaaaaa,' or ',') .. text
|
table.insert(details, color)
|
||||||
|
table.insert(details, text)
|
||||||
|
|
||||||
|
return table.concat(details, ",")
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@ -150,14 +126,13 @@ os.tempfolder = function()
|
|||||||
return temp .. DIR_DELIM .. "MT_" .. math.random(0, 10000)
|
return temp .. DIR_DELIM .. "MT_" .. math.random(0, 10000)
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
os.tmpname = function()
|
os.tmpname = function()
|
||||||
local path = os.tempfolder()
|
local path = os.tempfolder()
|
||||||
io.open(path, "w"):close()
|
io.open(path, "w"):close()
|
||||||
return path
|
return path
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
function menu_render_worldlist()
|
function menu_render_worldlist()
|
||||||
local retval = ""
|
local retval = ""
|
||||||
local current_worldlist = menudata.worldlist:get_list()
|
local current_worldlist = menudata.worldlist:get_list()
|
||||||
@ -171,7 +146,6 @@ function menu_render_worldlist()
|
|||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function menu_handle_key_up_down(fields, textlist, settingname)
|
function menu_handle_key_up_down(fields, textlist, settingname)
|
||||||
local oldidx, newidx = core.get_textlist_index(textlist), 1
|
local oldidx, newidx = core.get_textlist_index(textlist), 1
|
||||||
if fields.key_up or fields.key_down then
|
if fields.key_up or fields.key_down then
|
||||||
@ -188,7 +162,6 @@ function menu_handle_key_up_down(fields, textlist, settingname)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transparency)
|
function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transparency)
|
||||||
local textlines = core.wrap_text(text, textlen, true)
|
local textlines = core.wrap_text(text, textlen, true)
|
||||||
local retval = "textlist[" .. xpos .. "," .. ypos .. ";" .. width ..
|
local retval = "textlist[" .. xpos .. "," .. ypos .. ";" .. width ..
|
||||||
@ -206,7 +179,6 @@ function text2textlist(xpos, ypos, width, height, tl_name, textlen, text, transp
|
|||||||
return retval
|
return retval
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function is_server_protocol_compat(server_proto_min, server_proto_max)
|
function is_server_protocol_compat(server_proto_min, server_proto_max)
|
||||||
if (not server_proto_min) or (not server_proto_max) then
|
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.
|
-- There is no info. Assume the best and act as if we would be compatible.
|
||||||
@ -214,7 +186,7 @@ function is_server_protocol_compat(server_proto_min, server_proto_max)
|
|||||||
end
|
end
|
||||||
return min_supp_proto <= server_proto_max and max_supp_proto >= server_proto_min
|
return min_supp_proto <= server_proto_max and max_supp_proto >= server_proto_min
|
||||||
end
|
end
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function is_server_protocol_compat_or_error(server_proto_min, server_proto_max)
|
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
|
if not is_server_protocol_compat(server_proto_min, server_proto_max) then
|
||||||
local server_prot_ver_info, client_prot_ver_info
|
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
|
return true
|
||||||
end
|
end
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
function menu_worldmt(selected, setting, value)
|
function menu_worldmt(selected, setting, value)
|
||||||
local world = menudata.worldlist:get_list()[selected]
|
local world = menudata.worldlist:get_list()[selected]
|
||||||
if world then
|
if world then
|
||||||
|
@ -15,17 +15,50 @@
|
|||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
--with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
local function get_sorted_servers()
|
||||||
|
local servers = {
|
||||||
|
fav = {},
|
||||||
|
public = {},
|
||||||
|
incompatible = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
local favs = serverlistmgr.get_favorites()
|
||||||
|
local taken_favs = {}
|
||||||
|
local result = menudata.search_result or serverlistmgr.servers
|
||||||
|
for _, server in ipairs(result) do
|
||||||
|
server.is_favorite = false
|
||||||
|
for index, fav in ipairs(favs) do
|
||||||
|
if server.address == fav.address and server.port == fav.port then
|
||||||
|
taken_favs[index] = true
|
||||||
|
server.is_favorite = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
server.is_compatible = is_server_protocol_compat(server.proto_min, server.proto_max)
|
||||||
|
if server.is_favorite then
|
||||||
|
table.insert(servers.fav, server)
|
||||||
|
elseif server.is_compatible then
|
||||||
|
table.insert(servers.public, server)
|
||||||
|
else
|
||||||
|
table.insert(servers.incompatible, server)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if not menudata.search_result then
|
||||||
|
for index, fav in ipairs(favs) do
|
||||||
|
if not taken_favs[index] then
|
||||||
|
table.insert(servers.fav, fav)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return servers
|
||||||
|
end
|
||||||
|
|
||||||
local function get_formspec(tabview, name, tabdata)
|
local function get_formspec(tabview, name, tabdata)
|
||||||
-- Update the cached supported proto info,
|
-- Update the cached supported proto info,
|
||||||
-- it may have changed after a change by the settings menu.
|
-- it may have changed after a change by the settings menu.
|
||||||
common_update_cached_supp_proto()
|
common_update_cached_supp_proto()
|
||||||
local selected
|
|
||||||
if menudata.search_result then
|
|
||||||
selected = menudata.search_result[tabdata.selected]
|
|
||||||
else
|
|
||||||
selected = serverlistmgr.servers[tabdata.selected]
|
|
||||||
end
|
|
||||||
|
|
||||||
if not tabdata.search_for then
|
if not tabdata.search_for then
|
||||||
tabdata.search_for = ""
|
tabdata.search_for = ""
|
||||||
@ -33,96 +66,106 @@ local function get_formspec(tabview, name, tabdata)
|
|||||||
|
|
||||||
local retval =
|
local retval =
|
||||||
-- Search
|
-- Search
|
||||||
"field[0.15,0.075;5.91,1;te_search;;" .. core.formspec_escape(tabdata.search_for) .. "]" ..
|
"field[0.25,0.25;7,0.75;te_search;;" .. core.formspec_escape(tabdata.search_for) .. "]" ..
|
||||||
"image_button[5.63,-.165;.83,.83;" .. core.formspec_escape(defaulttexturedir .. "search.png") .. ";btn_mp_search;]" ..
|
"container[7.25,0.25]" ..
|
||||||
"image_button[6.3,-.165;.83,.83;" .. core.formspec_escape(defaulttexturedir .. "clear.png") .. ";btn_mp_clear;]" ..
|
"image_button[0,0;0.75,0.75;" .. core.formspec_escape(defaulttexturedir .. "search.png") .. ";btn_mp_search;]" ..
|
||||||
"image_button[6.97,-.165;.83,.83;" .. core.formspec_escape(defaulttexturedir .. "refresh.png")
|
"image_button[0.75,0;0.75,0.75;" .. core.formspec_escape(defaulttexturedir .. "clear.png") .. ";btn_mp_clear;]" ..
|
||||||
.. ";btn_mp_refresh;]" ..
|
"image_button[1.5,0;0.75,0.75;" .. core.formspec_escape(defaulttexturedir .. "refresh.png") .. ";btn_mp_refresh;]" ..
|
||||||
|
"tooltip[btn_mp_clear;" .. fgettext("Clear") .. "]" ..
|
||||||
|
"tooltip[btn_mp_search;" .. fgettext("Search") .. "]" ..
|
||||||
|
"tooltip[btn_mp_refresh;" .. fgettext("Refresh") .. "]" ..
|
||||||
|
"container_end[]" ..
|
||||||
|
|
||||||
|
"container[9.75,0]" ..
|
||||||
|
"box[0,0;5.75,7;#666666]" ..
|
||||||
|
|
||||||
-- Address / Port
|
-- Address / Port
|
||||||
"label[7.75,-0.25;" .. fgettext("Address / Port") .. "]" ..
|
"label[0.25,0.35;" .. fgettext("Address") .. "]" ..
|
||||||
"field[8,0.65;3.25,0.5;te_address;;" ..
|
"label[4.25,0.35;" .. fgettext("Port") .. "]" ..
|
||||||
|
"field[0.25,0.5;4,0.75;te_address;;" ..
|
||||||
core.formspec_escape(core.settings:get("address")) .. "]" ..
|
core.formspec_escape(core.settings:get("address")) .. "]" ..
|
||||||
"field[11.1,0.65;1.4,0.5;te_port;;" ..
|
"field[4.25,0.5;1.25,0.75;te_port;;" ..
|
||||||
core.formspec_escape(core.settings:get("remote_port")) .. "]" ..
|
core.formspec_escape(core.settings:get("remote_port")) .. "]" ..
|
||||||
|
|
||||||
-- Name / Password
|
-- Name / Password
|
||||||
"label[7.75,0.95;" .. fgettext("Name / Password") .. "]" ..
|
"label[0.25,1.55;" .. fgettext("Name") .. "]" ..
|
||||||
"field[8,1.85;2.9,0.5;te_name;;" ..
|
"label[3,1.55;" .. fgettext("Password") .. "]" ..
|
||||||
|
"field[0.25,1.75;2.75,0.75;te_name;;" ..
|
||||||
core.formspec_escape(core.settings:get("name")) .. "]" ..
|
core.formspec_escape(core.settings:get("name")) .. "]" ..
|
||||||
"pwdfield[10.73,1.85;1.77,0.5;te_pwd;]" ..
|
"pwdfield[3,1.75;2.5,0.75;te_pwd;]" ..
|
||||||
|
|
||||||
-- Description Background
|
-- Description Background
|
||||||
"box[7.73,2.25;4.25,2.6;#999999]"..
|
"label[0.25,2.75;" .. fgettext("Server Description") .. "]" ..
|
||||||
|
"box[0.25,3;5.25,2.75;#999999]"..
|
||||||
|
|
||||||
-- Connect
|
-- Connect
|
||||||
"button[9.88,4.9;2.3,1;btn_mp_connect;" .. fgettext("Connect") .. "]"
|
"button[3,6;2.5,0.75;btn_mp_connect;" .. fgettext("Connect") .. "]"
|
||||||
|
|
||||||
if tabdata.selected and selected then
|
if tabdata.selected then
|
||||||
if gamedata.fav then
|
if gamedata.fav then
|
||||||
retval = retval .. "button[7.73,4.9;2.3,1;btn_delete_favorite;" ..
|
retval = retval .. "button[0.25,6;2.5,0.75;btn_delete_favorite;" ..
|
||||||
fgettext("Del. Favorite") .. "]"
|
fgettext("Del. Favorite") .. "]"
|
||||||
end
|
end
|
||||||
if selected.description then
|
if gamedata.serverdescription then
|
||||||
retval = retval .. "textarea[8.1,2.3;4.23,2.9;;;" ..
|
retval = retval .. "textarea[0.25,3;5.25,2.75;;;" ..
|
||||||
core.formspec_escape((gamedata.serverdescription or ""), true) .. "]"
|
core.formspec_escape(gamedata.serverdescription) .. "]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--favorites
|
retval = retval .. "container_end[]"
|
||||||
|
|
||||||
|
-- Table
|
||||||
retval = retval .. "tablecolumns[" ..
|
retval = retval .. "tablecolumns[" ..
|
||||||
image_column(fgettext("Favorite"), "favorite") .. ";" ..
|
"image,tooltip=" .. fgettext("Ping") .. "," ..
|
||||||
image_column(fgettext("Ping")) .. ",padding=0.25;" ..
|
"0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," ..
|
||||||
"color,span=3;" ..
|
"1=" .. core.formspec_escape(defaulttexturedir .. "server_ping_4.png") .. "," ..
|
||||||
"text,align=right;" .. -- clients
|
"2=" .. core.formspec_escape(defaulttexturedir .. "server_ping_3.png") .. "," ..
|
||||||
"text,align=center,padding=0.25;" .. -- "/"
|
"3=" .. core.formspec_escape(defaulttexturedir .. "server_ping_2.png") .. "," ..
|
||||||
"text,align=right,padding=0.25;" .. -- clients_max
|
"4=" .. core.formspec_escape(defaulttexturedir .. "server_ping_1.png") .. "," ..
|
||||||
image_column(fgettext("Creative mode"), "creative") .. ",padding=1;" ..
|
"5=" .. core.formspec_escape(defaulttexturedir .. "server_favorite.png") .. "," ..
|
||||||
image_column(fgettext("Damage enabled"), "damage") .. ",padding=0.25;" ..
|
"6=" .. core.formspec_escape(defaulttexturedir .. "server_public.png") .. "," ..
|
||||||
--~ PvP = Player versus Player
|
"7=" .. core.formspec_escape(defaulttexturedir .. "server_incompatible.png") .. ";" ..
|
||||||
image_column(fgettext("PvP enabled"), "pvp") .. ",padding=0.25;" ..
|
|
||||||
"color,span=1;" ..
|
"color,span=1;" ..
|
||||||
"text,padding=1]" ..
|
"text,align=inline;"..
|
||||||
"table[-0.15,0.6;7.75,5.15;favorites;"
|
"color,span=1;" ..
|
||||||
|
"text,align=inline,width=4.25;" ..
|
||||||
|
"image,tooltip=" .. fgettext("Creative mode") .. "," ..
|
||||||
|
"0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," ..
|
||||||
|
"1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_creative.png") .. "," ..
|
||||||
|
"align=inline,padding=0.25,width=1.5;" ..
|
||||||
|
--~ PvP = Player versus Player
|
||||||
|
"image,tooltip=" .. fgettext("Damage / PvP") .. "," ..
|
||||||
|
"0=" .. core.formspec_escape(defaulttexturedir .. "blank.png") .. "," ..
|
||||||
|
"1=" .. core.formspec_escape(defaulttexturedir .. "server_flags_damage.png") .. "," ..
|
||||||
|
"2=" .. core.formspec_escape(defaulttexturedir .. "server_flags_pvp.png") .. "," ..
|
||||||
|
"align=inline,padding=0.25,width=1.5;" ..
|
||||||
|
"color,align=inline,span=1;" ..
|
||||||
|
"text,align=inline,padding=1]" ..
|
||||||
|
"table[0.25,1;9.25,5.75;servers;"
|
||||||
|
|
||||||
if menudata.search_result then
|
local servers = get_sorted_servers()
|
||||||
local favs = serverlistmgr.get_favorites()
|
|
||||||
for i = 1, #menudata.search_result do
|
|
||||||
local server = menudata.search_result[i]
|
|
||||||
for fav_id = 1, #favs do
|
|
||||||
if server.address == favs[fav_id].address and
|
|
||||||
server.port == favs[fav_id].port then
|
|
||||||
server.is_favorite = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if i ~= 1 then
|
local dividers = {
|
||||||
retval = retval .. ","
|
fav = "5,#ffff00," .. fgettext("Favorites") .. ",,,0,0,,",
|
||||||
end
|
public = "6,#4bdd42," .. fgettext("Public Servers") .. ",,,0,0,,",
|
||||||
|
incompatible = "7,"..mt_color_grey.."," .. fgettext("Incompatible Servers") .. ",,,0,0,,"
|
||||||
|
}
|
||||||
|
local order = {"fav", "public", "incompatible"}
|
||||||
|
|
||||||
retval = retval .. render_serverlist_row(server, server.is_favorite)
|
tabdata.lookup = {} -- maps row number to server
|
||||||
end
|
local rows = {}
|
||||||
elseif #serverlistmgr.servers > 0 then
|
for _, section in ipairs(order) do
|
||||||
local favs = serverlistmgr.get_favorites()
|
local section_servers = servers[section]
|
||||||
if #favs > 0 then
|
if next(section_servers) ~= nil then
|
||||||
for i = 1, #favs do
|
rows[#rows + 1] = dividers[section]
|
||||||
for j = 1, #serverlistmgr.servers do
|
for _, server in ipairs(section_servers) do
|
||||||
if serverlistmgr.servers[j].address == favs[i].address and
|
tabdata.lookup[#rows + 1] = server
|
||||||
serverlistmgr.servers[j].port == favs[i].port then
|
rows[#rows + 1] = render_serverlist_row(server)
|
||||||
table.insert(serverlistmgr.servers, i, table.remove(serverlistmgr.servers, j))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if favs[i].address ~= serverlistmgr.servers[i].address then
|
|
||||||
table.insert(serverlistmgr.servers, i, favs[i])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
retval = retval .. render_serverlist_row(serverlistmgr.servers[1], (#favs > 0))
|
retval = retval .. table.concat(rows, ",")
|
||||||
for i = 2, #serverlistmgr.servers do
|
|
||||||
retval = retval .. "," .. render_serverlist_row(serverlistmgr.servers[i], (i <= #favs))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if tabdata.selected then
|
if tabdata.selected then
|
||||||
retval = retval .. ";" .. tabdata.selected .. "]"
|
retval = retval .. ";" .. tabdata.selected .. "]"
|
||||||
@ -130,136 +173,17 @@ local function get_formspec(tabview, name, tabdata)
|
|||||||
retval = retval .. ";0]"
|
retval = retval .. ";0]"
|
||||||
end
|
end
|
||||||
|
|
||||||
return retval
|
return retval, "size[15.5,7,false]real_coordinates[true]"
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
local function main_button_handler(tabview, fields, name, tabdata)
|
|
||||||
local serverlist = menudata.search_result or serverlistmgr.servers
|
|
||||||
|
|
||||||
if fields.te_name then
|
local function search_server_list(input)
|
||||||
gamedata.playername = fields.te_name
|
|
||||||
core.settings:set("name", fields.te_name)
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields.favorites then
|
|
||||||
local event = core.explode_table_event(fields.favorites)
|
|
||||||
local fav = serverlist[event.row]
|
|
||||||
|
|
||||||
if event.type == "DCL" then
|
|
||||||
if event.row <= #serverlist then
|
|
||||||
if not is_server_protocol_compat_or_error(
|
|
||||||
fav.proto_min, fav.proto_max) then
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
gamedata.address = fav.address
|
|
||||||
gamedata.port = fav.port
|
|
||||||
gamedata.playername = fields.te_name
|
|
||||||
gamedata.selected_world = 0
|
|
||||||
|
|
||||||
if fields.te_pwd then
|
|
||||||
gamedata.password = fields.te_pwd
|
|
||||||
end
|
|
||||||
|
|
||||||
gamedata.servername = fav.name
|
|
||||||
gamedata.serverdescription = fav.description
|
|
||||||
|
|
||||||
if gamedata.address and gamedata.port then
|
|
||||||
core.settings:set("address", gamedata.address)
|
|
||||||
core.settings:set("remote_port", gamedata.port)
|
|
||||||
core.start()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if event.type == "CHG" then
|
|
||||||
if event.row <= #serverlist then
|
|
||||||
gamedata.fav = false
|
|
||||||
local favs = serverlistmgr.get_favorites()
|
|
||||||
local address = fav.address
|
|
||||||
local port = fav.port
|
|
||||||
gamedata.serverdescription = fav.description
|
|
||||||
|
|
||||||
for i = 1, #favs do
|
|
||||||
if fav.address == favs[i].address and
|
|
||||||
fav.port == favs[i].port then
|
|
||||||
gamedata.fav = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if address and port then
|
|
||||||
core.settings:set("address", address)
|
|
||||||
core.settings:set("remote_port", port)
|
|
||||||
end
|
|
||||||
tabdata.selected = event.row
|
|
||||||
end
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields.key_up or fields.key_down then
|
|
||||||
local fav_idx = core.get_table_index("favorites")
|
|
||||||
local fav = serverlist[fav_idx]
|
|
||||||
|
|
||||||
if fav_idx then
|
|
||||||
if fields.key_up and fav_idx > 1 then
|
|
||||||
fav_idx = fav_idx - 1
|
|
||||||
elseif fields.key_down and fav_idx < #serverlistmgr.servers then
|
|
||||||
fav_idx = fav_idx + 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
fav_idx = 1
|
|
||||||
end
|
|
||||||
|
|
||||||
if not serverlistmgr.servers or not fav then
|
|
||||||
tabdata.selected = 0
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
local address = fav.address
|
|
||||||
local port = fav.port
|
|
||||||
gamedata.serverdescription = fav.description
|
|
||||||
if address and port then
|
|
||||||
core.settings:set("address", address)
|
|
||||||
core.settings:set("remote_port", port)
|
|
||||||
end
|
|
||||||
|
|
||||||
tabdata.selected = fav_idx
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields.btn_delete_favorite then
|
|
||||||
local current_favorite = core.get_table_index("favorites")
|
|
||||||
if not current_favorite then return end
|
|
||||||
|
|
||||||
serverlistmgr.delete_favorite(serverlistmgr.servers[current_favorite])
|
|
||||||
serverlistmgr.sync()
|
|
||||||
tabdata.selected = nil
|
|
||||||
|
|
||||||
core.settings:set("address", "")
|
|
||||||
core.settings:set("remote_port", "30000")
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields.btn_mp_clear then
|
|
||||||
tabdata.search_for = ""
|
|
||||||
menudata.search_result = nil
|
menudata.search_result = nil
|
||||||
return true
|
|
||||||
end
|
|
||||||
|
|
||||||
if fields.btn_mp_search or fields.key_enter_field == "te_search" then
|
|
||||||
tabdata.selected = 1
|
|
||||||
local input = fields.te_search:lower()
|
|
||||||
tabdata.search_for = fields.te_search
|
|
||||||
|
|
||||||
if #serverlistmgr.servers < 2 then
|
if #serverlistmgr.servers < 2 then
|
||||||
return true
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
menudata.search_result = {}
|
|
||||||
|
|
||||||
-- setup the keyword list
|
-- setup the keyword list
|
||||||
local keywords = {}
|
local keywords = {}
|
||||||
for word in input:gmatch("%S+") do
|
for word in input:gmatch("%S+") do
|
||||||
@ -268,10 +192,11 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if #keywords == 0 then
|
if #keywords == 0 then
|
||||||
menudata.search_result = nil
|
return
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
menudata.search_result = {}
|
||||||
|
|
||||||
-- Search the serverlist
|
-- Search the serverlist
|
||||||
local search_result = {}
|
local search_result = {}
|
||||||
for i = 1, #serverlistmgr.servers do
|
for i = 1, #serverlistmgr.servers do
|
||||||
@ -297,16 +222,115 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
table.insert(search_result, server)
|
table.insert(search_result, server)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if #search_result > 0 then
|
|
||||||
|
if #search_result == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
table.sort(search_result, function(a, b)
|
table.sort(search_result, function(a, b)
|
||||||
return a.points > b.points
|
return a.points > b.points
|
||||||
end)
|
end)
|
||||||
menudata.search_result = search_result
|
menudata.search_result = search_result
|
||||||
local first_server = search_result[1]
|
|
||||||
core.settings:set("address", first_server.address)
|
|
||||||
core.settings:set("remote_port", first_server.port)
|
|
||||||
gamedata.serverdescription = first_server.description
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function set_selected_server(tabdata, idx, server)
|
||||||
|
-- reset selection
|
||||||
|
if idx == nil or server == nil then
|
||||||
|
tabdata.selected = nil
|
||||||
|
|
||||||
|
core.settings:set("address", "")
|
||||||
|
core.settings:set("remote_port", "30000")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local address = server.address
|
||||||
|
local port = server.port
|
||||||
|
gamedata.serverdescription = server.description
|
||||||
|
|
||||||
|
gamedata.fav = false
|
||||||
|
for _, fav in ipairs(serverlistmgr.get_favorites()) do
|
||||||
|
if address == fav.address and port == fav.port then
|
||||||
|
gamedata.fav = true
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if address and port then
|
||||||
|
core.settings:set("address", address)
|
||||||
|
core.settings:set("remote_port", port)
|
||||||
|
end
|
||||||
|
tabdata.selected = idx
|
||||||
|
end
|
||||||
|
|
||||||
|
local function main_button_handler(tabview, fields, name, tabdata)
|
||||||
|
if fields.te_name then
|
||||||
|
gamedata.playername = fields.te_name
|
||||||
|
core.settings:set("name", fields.te_name)
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields.servers then
|
||||||
|
local event = core.explode_table_event(fields.servers)
|
||||||
|
local server = tabdata.lookup[event.row]
|
||||||
|
|
||||||
|
if server then
|
||||||
|
if event.type == "DCL" then
|
||||||
|
if not is_server_protocol_compat_or_error(
|
||||||
|
server.proto_min, server.proto_max) then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
gamedata.address = server.address
|
||||||
|
gamedata.port = server.port
|
||||||
|
gamedata.playername = fields.te_name
|
||||||
|
gamedata.selected_world = 0
|
||||||
|
|
||||||
|
if fields.te_pwd then
|
||||||
|
gamedata.password = fields.te_pwd
|
||||||
|
end
|
||||||
|
|
||||||
|
gamedata.servername = server.name
|
||||||
|
gamedata.serverdescription = server.description
|
||||||
|
|
||||||
|
if gamedata.address and gamedata.port then
|
||||||
|
core.settings:set("address", gamedata.address)
|
||||||
|
core.settings:set("remote_port", gamedata.port)
|
||||||
|
core.start()
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
if event.type == "CHG" then
|
||||||
|
set_selected_server(tabdata, event.row, server)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields.btn_delete_favorite then
|
||||||
|
local idx = core.get_table_index("servers")
|
||||||
|
if not idx then return end
|
||||||
|
local server = tabdata.lookup[idx]
|
||||||
|
if not server then return end
|
||||||
|
|
||||||
|
serverlistmgr.delete_favorite(server)
|
||||||
|
-- the server at [idx+1] will be at idx once list is refreshed
|
||||||
|
set_selected_server(tabdata, idx, tabdata.lookup[idx+1])
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields.btn_mp_clear then
|
||||||
|
tabdata.search_for = ""
|
||||||
|
menudata.search_result = nil
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if fields.btn_mp_search or fields.key_enter_field == "te_search" then
|
||||||
|
tabdata.search_for = fields.te_search
|
||||||
|
search_server_list(fields.te_search:lower())
|
||||||
|
if menudata.search_result then
|
||||||
|
-- first server in row 2 due to header
|
||||||
|
set_selected_server(tabdata, 2, menudata.search_result[1])
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -322,20 +346,22 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
gamedata.address = fields.te_address
|
gamedata.address = fields.te_address
|
||||||
gamedata.port = tonumber(fields.te_port)
|
gamedata.port = tonumber(fields.te_port)
|
||||||
gamedata.selected_world = 0
|
gamedata.selected_world = 0
|
||||||
local fav_idx = core.get_table_index("favorites")
|
|
||||||
local fav = serverlist[fav_idx]
|
|
||||||
|
|
||||||
if fav_idx and fav_idx <= #serverlist and
|
local idx = core.get_table_index("servers")
|
||||||
fav.address == gamedata.address and
|
local server = idx and tabdata.lookup[idx]
|
||||||
fav.port == gamedata.port then
|
|
||||||
|
|
||||||
serverlistmgr.add_favorite(fav)
|
set_selected_server(tabdata)
|
||||||
|
|
||||||
gamedata.servername = fav.name
|
if server and server.address == gamedata.address and
|
||||||
gamedata.serverdescription = fav.description
|
server.port == gamedata.port then
|
||||||
|
|
||||||
|
serverlistmgr.add_favorite(server)
|
||||||
|
|
||||||
|
gamedata.servername = server.name
|
||||||
|
gamedata.serverdescription = server.description
|
||||||
|
|
||||||
if not is_server_protocol_compat_or_error(
|
if not is_server_protocol_compat_or_error(
|
||||||
fav.proto_min, fav.proto_max) then
|
server.proto_min, server.proto_max) then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@ -354,6 +380,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
|
|||||||
core.start()
|
core.start()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -362,7 +389,6 @@ local function on_change(type, old_tab, new_tab)
|
|||||||
serverlistmgr.sync()
|
serverlistmgr.sync()
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
return {
|
return {
|
||||||
name = "online",
|
name = "online",
|
||||||
caption = fgettext("Join Game"),
|
caption = fgettext("Join Game"),
|
||||||
|
Before Width: | Height: | Size: 916 B After Width: | Height: | Size: 916 B |
BIN
textures/base/pack/server_incompatible.png
Normal file
BIN
textures/base/pack/server_incompatible.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 385 B |
BIN
textures/base/pack/server_public.png
Normal file
BIN
textures/base/pack/server_public.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 492 B |
Loading…
Reference in New Issue
Block a user