From 11abe53d2b13da83d292b1cdfb29881049768265 Mon Sep 17 00:00:00 2001 From: Maksim Date: Sat, 23 Apr 2022 09:36:46 +0300 Subject: [PATCH] Builtin: MainMenu update, other minor fixes Update dlg_create_world_default.lua --- builtin/common/information_formspecs.lua | 5 +- builtin/common/misc_helpers.lua | 10 ++-- builtin/mainmenu/dlg_create_world_default.lua | 14 ++++- builtin/mainmenu/tab_local.lua | 4 +- builtin/mainmenu/tab_local_default.lua | 4 +- builtin/mainmenu/tab_online.lua | 54 ++++++++---------- textures/base/pack/search.png | Bin 241 -> 273 bytes 7 files changed, 49 insertions(+), 42 deletions(-) diff --git a/builtin/common/information_formspecs.lua b/builtin/common/information_formspecs.lua index 0d79d17e9..0994f2793 100644 --- a/builtin/common/information_formspecs.lua +++ b/builtin/common/information_formspecs.lua @@ -4,6 +4,7 @@ local COLOR_GRAY = "#BBB" local LIST_FORMSPEC = [[ size[13,6.5] + background9[0,0;14,8;bg_common.png;true;40] label[0,-0.1;%s] tablecolumns[color;tree;text;text] table[0,0.5;12.8,5.5;list;%s;0] @@ -12,14 +13,14 @@ local LIST_FORMSPEC = [[ local LIST_FORMSPEC_DESCRIPTION = [[ size[13,7.5] + background9[0,0;14,8;bg_common.png;true;40] label[0,-0.1;%s] tablecolumns[color;tree;text;text] table[0,0.5;12.8,4.8;list;%s;%i] box[0,5.5;12.8,1.5;#000] - label[0.3,5.5;%s] + textarea[0.3,5.5;13.05,1.9;;%s;] button_exit[5,7;3,1;quit;%s] ]] --- textarea[0.3,5.5;13.05,1.9;;;%s] -- label for compatibility with 0.4 local formspec_escape = core.formspec_escape local check_player_privs = core.check_player_privs diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua index 698349659..797fd7195 100644 --- a/builtin/common/misc_helpers.lua +++ b/builtin/common/misc_helpers.lua @@ -250,11 +250,11 @@ end function core.formspec_escape(text) if text ~= nil then - text = string.gsub(text,"\\","\\\\") - text = string.gsub(text,"%]","\\]") - text = string.gsub(text,"%[","\\[") - text = string.gsub(text,";","\\;") - text = string.gsub(text,",","\\,") + text = text:gsub("\\", "\\\\") + text = text:gsub("%]", "\\]") + text = text:gsub("%[", "\\[") + text = text:gsub(";", "\\;") + text = text:gsub(",", "\\,") end return text end diff --git a/builtin/mainmenu/dlg_create_world_default.lua b/builtin/mainmenu/dlg_create_world_default.lua index 6ed6c993f..15ce190b0 100644 --- a/builtin/mainmenu/dlg_create_world_default.lua +++ b/builtin/mainmenu/dlg_create_world_default.lua @@ -94,8 +94,20 @@ local function create_world_buttonhandler(this, fields) end if gameindex ~= 0 then + -- For unnamed worlds use the generated name 'World ', + -- where the number increments: it is set to 1 larger than the largest + -- generated name number found. if worldname == "" then - worldname = "World " .. math.random(1000, 9999) + menudata.worldlist:set_filtercriteria(nil) -- to count all existing worlds + local worldnum_max = 0 + for _, world in ipairs(menudata.worldlist:get_list()) do + -- Match "World 1" and "World 1 a" (but not "World 1a") + local worldnum = world.name:match("^World (%d+)$") or world.name:match("^World (%d+) ") + if worldnum then + worldnum_max = math.max(worldnum_max, tonumber(worldnum)) + end + end + worldname = "World " .. worldnum_max + 1 end core.settings:set("fixed_map_seed", fields["te_seed"]) diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index 0d72783f0..866e00db7 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -157,6 +157,7 @@ local function get_formspec() "image_button[7.2,3.09;4,0.83;" .. esc(defaulttexturedir) .. creative_bg .. ";;;true;false]" .. + "style[cb_creative_mode;content_offset=0]" .. "image_button[7.2,3.09;4,0.83;" .. esc(defaulttexturedir) .. creative_checkbox .. ";cb_creative_mode;;true;false]" .. @@ -166,8 +167,7 @@ local function get_formspec() "table[0,0;6.28,4.64;sp_worlds;" .. menu_render_worldlist() .. ";" .. index .. "]" - - if PLATFORM ~= "Android" and PLATFORM ~= "iOS" then + if not mobile then retval = retval .. "checkbox[6.6,5;cb_server;".. fgettext("Create Server") ..";" .. dump(core.settings:get_bool("enable_server")) .. "]" diff --git a/builtin/mainmenu/tab_local_default.lua b/builtin/mainmenu/tab_local_default.lua index 36946e77b..ec8c50402 100644 --- a/builtin/mainmenu/tab_local_default.lua +++ b/builtin/mainmenu/tab_local_default.lua @@ -17,6 +17,7 @@ local lang = core.settings:get("language") if not lang or lang == "" then lang = os.getenv("LANG") end +local mobile = PLATFORM == "Android" or PLATFORM == "iOS" local esc = core.formspec_escape @@ -105,6 +106,7 @@ local function get_formspec() "image_button[7.2,3.09;4,0.83;" .. esc(defaulttexturedir) .. creative_bg .. ";;;true;false]" .. + "style[cb_creative_mode;content_offset=0]" .. "image_button[7.2,3.09;4,0.83;" .. esc(defaulttexturedir) .. creative_checkbox .. ";cb_creative_mode;;true;false]" .. @@ -121,7 +123,7 @@ local function get_formspec() esc(defaulttexturedir) .. "gift_btn_pressed.png]" end - if PLATFORM ~= "Android" and PLATFORM ~= "iOS" then + if not mobile then retval = retval .. "checkbox[6.6,5;cb_server;".. fgettext("Create Server") ..";" .. dump(core.settings:get_bool("enable_server")) .. "]" diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index b056f282b..bcb34e0a9 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -19,6 +19,10 @@ local password_save = core.settings:get_bool("password_save") local password_tmp = "" +local esc = core.formspec_escape +local lower = utf8.lower +local mobile = PLATFORM == "Android" or PLATFORM == "iOS" + local function get_formspec(tabview, name, tabdata) -- Update the cached supported proto info, -- it may have changed after a change by the settings menu. @@ -34,27 +38,23 @@ local function get_formspec(tabview, name, tabdata) tabdata.search_for = "" end - local esc = core.formspec_escape - local search_panel - if PLATFORM == "Android" or PLATFORM == "iOS" then + if mobile then search_panel = - "field[0.2,0.1;5.19,1;te_search;;" .. esc(tabdata.search_for) .. "]" .. - "style[btn_mp_search;content_offset=0]" .. - "image_button[4.89,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. "search.png") .. + "field[0.2,0.1;5.1,1;Dte_search;;" .. esc(tabdata.search_for) .. "]" .. + "image_button[4.87,-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") .. + "image_button[5.62,-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 .. + "image_button[6.37,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. (serverlistmgr.mobile_only and "online_mobile" or "online_pc") .. ".png") .. ";btn_mp_mobile;;true;false]" else search_panel = - "field[0.2,0.1;5.8,1;te_search;;" .. esc(tabdata.search_for) .. "]" .. - "style[btn_mp_search;content_offset=0]" .. - "image_button[5.5,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. "search.png") .. + "field[0.2,0.1;5.8,1;Dte_search;;" .. esc(tabdata.search_for) .. "]" .. + "image_button[5.62,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. "search.png") .. ";btn_mp_search;;true;false]" .. - "image_button[6.26,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. "refresh.png") .. + "image_button[6.37,-0.13;0.83,0.83;" .. esc(defaulttexturedir .. "refresh.png") .. ";btn_mp_refresh;;true;false]" end @@ -280,16 +280,19 @@ local function main_button_handler(tabview, fields, name, tabdata) return true end - if fields.btn_mp_clear then - tabdata.search_for = "" - menudata.search_result = nil + if fields.btn_mp_refresh or fields.btn_mp_mobile then + if fields.btn_mp_mobile then + serverlistmgr.mobile_only = not serverlistmgr.mobile_only + end + serverlistmgr.sync() return true end - if fields.btn_mp_search or fields.key_enter_field == "te_search" then + if (fields.Dte_search or fields.btn_mp_search) and not + (fields.btn_mp_connect or fields.key_enter) then tabdata.selected = 1 - local input = fields.te_search:lower() - tabdata.search_for = fields.te_search + local input = lower(fields.Dte_search) + tabdata.search_for = fields.Dte_search if #serverlistmgr.servers < 2 then return true @@ -317,13 +320,13 @@ local function main_button_handler(tabview, fields, name, tabdata) for k = 1, #keywords do local keyword = keywords[k] if server.name then - local sername = server.name:lower() + local sername = lower(server.name) local _, count = sername:gsub(keyword, keyword) found = found + count * 4 end if server.description then - local desc = server.description:lower() + local desc = lower(server.description) local _, count = desc:gsub(keyword, keyword) found = found + count * 2 end @@ -347,17 +350,6 @@ local function main_button_handler(tabview, fields, name, tabdata) return true end - if fields.btn_mp_refresh then - serverlistmgr.sync() - return true - end - - if fields.btn_mp_mobile then - serverlistmgr.mobile_only = not serverlistmgr.mobile_only - serverlistmgr.sync() - return true - end - if (fields.btn_mp_connect or fields.key_enter) and fields.te_address ~= "" and fields.te_port then gamedata.playername = fields.te_name diff --git a/textures/base/pack/search.png b/textures/base/pack/search.png index 200cb19ec30df124dd2ce675a00a7388c0e35744..729487f37fcf27669490082b18a903c909aec113 100644 GIT binary patch delta 245 zcmVIYTfniR7LT)>rAJpS@?*aOu0sMp! zpnahP-~cRBr^UKYzp9kc5grGw%pfyyQ7UiTW8CrIsD^!|-V+ss~LRY9X v1;-Q^8G446!4lX-SZ~yNE7zO7{yTgCf}7V(DkwOl00000NkvXXu0mjf&C+a7 delta 213 zcmV;`04o2H0`UQmB!3A|OjJex|NkBy9{>OUC?)0V00001bW%=J06^y0W&i*HmPtfG zRCr$1)Ugc%F$jfW%TgLfVVV?|eLM;!`lrm@HR0hpQi9~>Ym9lqhK>6)OUaX9eTY1zRp@acF)?3 P00000NkvXXu0mjfg{)j+