From a0a5fec1aed3acead2cf574925ed61fa225fc570 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Sat, 25 Apr 2020 18:40:32 +0200 Subject: [PATCH] Mainmenu: add 'mobile_friendly' filter --- builtin/mainmenu/common.lua | 12 ++++--- builtin/mainmenu/tab_online.lua | 55 ++++++++++++++++++++++-------- src/script/lua_api/l_mainmenu.cpp | 7 ++++ textures/base/online_mobile.png | Bin 0 -> 192 bytes textures/base/online_pc.png | Bin 0 -> 219 bytes 5 files changed, 54 insertions(+), 20 deletions(-) create mode 100644 textures/base/online_mobile.png create mode 100644 textures/base/online_pc.png diff --git a/builtin/mainmenu/common.lua b/builtin/mainmenu/common.lua index bce0be73..80240b1f 100644 --- a/builtin/mainmenu/common.lua +++ b/builtin/mainmenu/common.lua @@ -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 diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index 989c6aea..cfa03126 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -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 -------------------------------------------------------------------------------- diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index e8219ff9..5485ccac 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -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()); diff --git a/textures/base/online_mobile.png b/textures/base/online_mobile.png new file mode 100644 index 0000000000000000000000000000000000000000..242af644789a7d780b2a5a982f34d08b0dc27865 GIT binary patch literal 192 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0L3?#3!&-4XSJOMr-u0UGFI5IeO&j0`atEHc< z1o9b6g8YIR9G=}s19Fl)T^vIy7?TqcI9!<=^p-ii&{7fTa&0ITWfqDMZE#Is+{7R* z)~LZIvSCV1<9~+_jGhhu?KvI@Z>VSea{M2&2a`hoT6b{?Q3=rlJ_aq9CDJx6u~{p8 kF0iFo_2C@f9VHA5-x}mu5<@070c~UOboFyt=akR{0FLoHE&u=k literal 0 HcmV?d00001 diff --git a/textures/base/online_pc.png b/textures/base/online_pc.png new file mode 100644 index 0000000000000000000000000000000000000000..6f42d2f173e4667524f31e6678bc6220c60ca566 GIT binary patch literal 219 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0L3?#3!&-4XSJOMr-u0UGFI5IeO&j0`atEHc< z1o9b6g8YIR9G=}s19ECTT^vIy7~fuDWMeiIaC_)3!nO0lC2bKV+t`H@f}eO4H%t<{ zX?pmGh~@_V4~#a?gPd OVeoYIb6Mw<&;$V05KQL) literal 0 HcmV?d00001