Mainmenu: add 'mobile_friendly' filter

master
MoNTE48 2020-04-25 18:40:32 +02:00
parent cdc24b4fe7
commit a0a5fec1ae
5 changed files with 54 additions and 20 deletions

View File

@ -57,18 +57,20 @@ function image_column(tooltip)
end
--------------------------------------------------------------------------------
function order_favorite_list(list)
function order_favorite_list(list, mobile)
local res = {}
-- orders the multicraft list before support
for i = 1, #list do
local fav = list[i]
if fav.server_id == "multicraft" then
if (mobile and fav.mobile_friendly or not mobile) and
fav.server_id == "multicraft" then
res[#res + 1] = fav
end
end
for i = 1, #list do
local fav = list[i]
if is_server_protocol_compat(fav.proto_min, fav.proto_max) and
if (mobile and fav.mobile_friendly or not mobile) and
is_server_protocol_compat(fav.proto_min, fav.proto_max) and
fav.server_id ~= "multicraft" then
res[#res + 1] = fav
end
@ -216,7 +218,7 @@ function menu_handle_key_up_down(fields, textlist, settingname)
end
--------------------------------------------------------------------------------
function asyncOnlineFavourites()
function asyncOnlineFavourites(mobile)
if not menudata.public_known then
menudata.public_known = {{
name = fgettext("Loading..."),
@ -239,7 +241,7 @@ function asyncOnlineFavourites()
nil,
function(result)
menudata.public_downloading = nil
local favs = order_favorite_list(result)
local favs = order_favorite_list(result, mobile)
if favs[1] then
menudata.public_known = favs
menudata.favorites = menudata.public_known

View File

@ -18,6 +18,7 @@
--------------------------------------------------------------------------------
local password_save = core.settings:get_bool("password_save")
local password_tmp = ""
local mobile_only = PLATFORM == "Android" or PLATFORM == "iOS"
local function get_formspec(_, _, tabdata)
-- Update the cached supported proto info,
@ -34,49 +35,67 @@ local function get_formspec(_, _, tabdata)
tabdata.search_for = ""
end
local esc = core.formspec_escape
local search_panel
if PLATFORM == "Android" or PLATFORM == "iOS" then
search_panel =
"field[0.2,0.1;5.19,1;te_search;;" .. esc(tabdata.search_for) .. "]" ..
"image_button[4.89,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. "search.png")
.. ";btn_mp_search;;true;false]" ..
"image_button[5.59,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. "refresh.png")
.. ";btn_mp_refresh;;true;false]" ..
"image_button[6.29,-0.13;0.83,0.83;" .. esc(defaulttexturedir ..
(not mobile_only and "online_pc" or "online_mobile") .. ".png")
.. ";btn_mp_mobile;;true;false]"
else
search_panel =
"field[0.2,0.1;5.8,1;te_search;;" .. core.formspec_escape(tabdata.search_for) .. "]" ..
"image_button[5.5,-0.13;0.83,0.83;" .. core.formspec_escape(defaulttexturedir .. "search.png")
.. ";btn_mp_search;;true;false]" ..
"image_button[6.26,-0.13;0.83,0.83;" .. core.formspec_escape(defaulttexturedir .. "refresh.png")
.. ";btn_mp_refresh;;true;false]"
end
local retval =
-- Search
"field[0.2,0.1;5.8,1;te_search;;" .. core.formspec_escape(tabdata.search_for) .. "]" ..
"image_button[5.5,-0.13;0.83,0.83;" .. core.formspec_escape(defaulttexturedir .. "search.png")
.. ";btn_mp_search;;true;false]" ..
"image_button[6.26,-0.13;0.83,0.83;" .. core.formspec_escape(defaulttexturedir .. "refresh.png")
.. ";btn_mp_refresh;;true;false]" ..
search_panel ..
-- Address / Port
"label[7.1,-0.3;" .. fgettext("Address") .. ":" .. "]" ..
"label[10.15,-0.3;" .. fgettext("Port") .. ":" .. "]" ..
"field[7.4,0.6;3.2,0.5;te_address;;" ..
core.formspec_escape(core.settings:get("address")) .. "]" ..
esc(core.settings:get("address")) .. "]" ..
"field[10.45,0.6;1.95,0.5;te_port;;" ..
core.formspec_escape(core.settings:get("remote_port")) .. "]" ..
esc(core.settings:get("remote_port")) .. "]" ..
-- Name
"label[7.1,0.85;" .. fgettext("Name") .. ":" .. "]" ..
"label[10.15,0.85;" .. fgettext("Password") .. ":" .. "]" ..
"field[7.4,1.75;3.2,0.5;te_name;;" ..
core.formspec_escape(core.settings:get("name")) .. "]" ..
esc(core.settings:get("name")) .. "]" ..
-- Description Background
"box[7.1,2.1;4.8,2.65;#999999]" ..
-- Connect
"image_button[8.8,4.88;3.3,0.9;" ..
core.formspec_escape(defaulttexturedir .. "blank.png")
esc(defaulttexturedir .. "blank.png")
.. ";btn_mp_connect;;true;false]" ..
"tooltip[btn_mp_connect;".. fgettext("Connect") .. "]"
local pwd = password_save and core.formspec_escape(core.settings:get("password")) or password_tmp
local pwd = password_save and esc(core.settings:get("password")) or password_tmp
-- Password
retval = retval .. "pwdfield[10.45,1.8;1.95,0.39;te_pwd;;" .. pwd .. "]"
if tabdata.fav_selected and fav_selected then
if gamedata.fav then
retval = retval .. "image_button[7.1,4.91;0.83,0.83;" .. core.formspec_escape(defaulttexturedir .. "trash.png")
retval = retval .. "image_button[7.1,4.91;0.83,0.83;" .. esc(defaulttexturedir .. "trash.png")
.. ";btn_delete_favorite;;true;false]"
end
if fav_selected.description then
retval = retval .. "textarea[7.5,2.2;4.8,3;;" ..
core.formspec_escape((gamedata.serverdescription or ""), true) .. ";]"
esc((gamedata.serverdescription or ""), true) .. ";]"
end
end
@ -257,7 +276,7 @@ local function main_button_handler(_, fields, _, tabdata)
if not current_favourite then return end
core.delete_favorite(current_favourite)
asyncOnlineFavourites()
asyncOnlineFavourites(mobile_only)
tabdata.fav_selected = nil
return true
@ -324,7 +343,13 @@ local function main_button_handler(_, fields, _, tabdata)
end
if fields.btn_mp_refresh then
asyncOnlineFavourites()
asyncOnlineFavourites(mobile_only)
return true
end
if fields.btn_mp_mobile then
mobile_only = not mobile_only
asyncOnlineFavourites(mobile_only)
return true
end
@ -377,7 +402,7 @@ end
local function on_change(type)
if type == "LEAVE" then return end
asyncOnlineFavourites()
asyncOnlineFavourites(mobile_only)
end
--------------------------------------------------------------------------------

View File

@ -531,6 +531,13 @@ int ModApiMainMenu::l_get_favorites(lua_State *L)
lua_settable(L, top_lvl2);
}
if (servers[i]["mobile_friendly"].asString().size()) {
lua_pushstring(L,"mobile_friendly");
std::string topush = servers[i]["mobile_friendly"].asString();
lua_pushstring(L,topush.c_str());
lua_settable(L, top_lvl2);
}
if (servers[i]["proto_min"].asString().size()) {
lua_pushstring(L,"proto_min");
lua_pushinteger(L,servers[i]["proto_min"].asInt());

Binary file not shown.

After

Width:  |  Height:  |  Size: 192 B

BIN
textures/base/online_pc.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 B