From 0cbf96cc839e1b8202ad782420c9b50fa14ad052 Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Mon, 28 Aug 2023 22:36:54 +0100 Subject: [PATCH] Use formspec version 6 in the main menu (#13761) --- builtin/fstk/buttonbar.lua | 26 ++++++++-------- builtin/fstk/tabview.lua | 2 +- builtin/mainmenu/init.lua | 3 +- builtin/mainmenu/tab_about.lua | 2 +- builtin/mainmenu/tab_content.lua | 3 +- builtin/mainmenu/tab_local.lua | 53 +++++++++++++++++++++----------- builtin/mainmenu/tab_online.lua | 2 +- 7 files changed, 54 insertions(+), 37 deletions(-) diff --git a/builtin/fstk/buttonbar.lua b/builtin/fstk/buttonbar.lua index 465588324..b7b46572a 100644 --- a/builtin/fstk/buttonbar.lua +++ b/builtin/fstk/buttonbar.lua @@ -22,8 +22,9 @@ local function buttonbar_formspec(self) return "" end - local formspec = string.format("box[%f,%f;%f,%f;%s]", - self.pos.x,self.pos.y ,self.size.x,self.size.y,self.bgcolor) + local formspec = "style_type[box;noclip=true]" .. + string.format("box[%f,%f;%f,%f;%s]", self.pos.x, self.pos.y, self.size.x, self.size.y, self.bgcolor) .. + "style_type[box;noclip=false]" for i=self.startbutton,#self.buttons,1 do local btn_name = self.buttons[i].name @@ -31,18 +32,18 @@ local function buttonbar_formspec(self) if self.orientation == "horizontal" then btn_pos.x = self.pos.x + --base pos - (i - self.startbutton) * self.btn_size + --button offset + (i - self.startbutton) * self.btn_size * 1.25 + --button offset self.btn_initial_offset else - btn_pos.x = self.pos.x + (self.btn_size * 0.05) + btn_pos.x = self.pos.x + self.size.x / 2 - self.btn_size / 2 end if self.orientation == "vertical" then btn_pos.y = self.pos.y + --base pos - (i - self.startbutton) * self.btn_size + --button offset + (i - self.startbutton) * self.btn_size * 1.25 + --button offset self.btn_initial_offset else - btn_pos.y = self.pos.y + (self.btn_size * 0.05) + btn_pos.y = self.pos.y + self.size.y / 2 - self.btn_size / 2 end if (self.orientation == "vertical" and @@ -195,16 +196,17 @@ function buttonbar_create(name, cbf_buttonhandler, pos, orientation, size) self.have_move_buttons = false self.hidden = false - if self.orientation == "horizontal" then - self.btn_size = self.size.y - else - self.btn_size = self.size.x + if self.btn_initial_offset == nil then + self.btn_initial_offset = 0.375 end - if (self.btn_initial_offset == nil) then - self.btn_initial_offset = self.btn_size * 0.05 + if self.orientation == "horizontal" then + self.btn_size = self.size.y - 2*0.1 + else + self.btn_size = self.size.x - 2*0.1 end + self.userbuttonhandler = cbf_buttonhandler self.buttons = {} diff --git a/builtin/fstk/tabview.lua b/builtin/fstk/tabview.lua index 63c205d6e..7e2323e65 100644 --- a/builtin/fstk/tabview.lua +++ b/builtin/fstk/tabview.lua @@ -42,7 +42,7 @@ local function add_tab(self,tab) event_handler = tab.cbf_events, get_formspec = tab.cbf_formspec, tabsize = tab.tabsize, - formspec_version = tab.formspec_version, + formspec_version = tab.formspec_version or 6, on_change = tab.on_change, tabdata = {}, } diff --git a/builtin/mainmenu/init.lua b/builtin/mainmenu/init.lua index ede90ffa7..e299cb343 100644 --- a/builtin/mainmenu/init.lua +++ b/builtin/mainmenu/init.lua @@ -115,8 +115,7 @@ local function init_globals() mm_game_theme.init() -- Create main tabview - local tv_main = tabview_create("maintab", {x = 12, y = 5.4}, {x = 0, y = 0}) - -- note: size would be 15.5,7.1 in real coordinates mode + local tv_main = tabview_create("maintab", {x = 15.5, y = 7.1}, {x = 0, y = 0}) tv_main:set_autosave_tab(true) tv_main:add(tabs.local_game) diff --git a/builtin/mainmenu/tab_about.lua b/builtin/mainmenu/tab_about.lua index e0d984a6c..4eb1c8b55 100644 --- a/builtin/mainmenu/tab_about.lua +++ b/builtin/mainmenu/tab_about.lua @@ -194,7 +194,7 @@ return { fs = fs .. "button[0.5,5.1;4.5,0.8;userdata;" .. fgettext("Open User Data Directory") .. "]" end - return fs, "size[15.5,7.1,false]real_coordinates[true]" + return fs end, cbf_button_handler = function(this, fields, name, tabdata) if fields.homepage then diff --git a/builtin/mainmenu/tab_content.lua b/builtin/mainmenu/tab_content.lua index 4d25f33eb..fac7a8a8f 100644 --- a/builtin/mainmenu/tab_content.lua +++ b/builtin/mainmenu/tab_content.lua @@ -148,8 +148,7 @@ local function get_formspec(tabview, name, tabdata) end end - return table.concat(retval), - "size[15.5,7.1,false]real_coordinates[true]" + return table.concat(retval) end local function handle_doubleclick(pkg) diff --git a/builtin/mainmenu/tab_local.lua b/builtin/mainmenu/tab_local.lua index 9bd8986ba..15958597d 100644 --- a/builtin/mainmenu/tab_local.lua +++ b/builtin/mainmenu/tab_local.lua @@ -83,7 +83,7 @@ function singleplayer_refresh_gamebar() local btnbar = buttonbar_create("game_button_bar", game_buttonbar_button_handler, - {x=-0.3,y=5.9}, "horizontal", {x=12.4,y=1.15}) + {x=0,y=7.475}, "horizontal", {x=15.5,y=1.25}) for _, game in ipairs(pkgmgr.games) do local btn_name = "game_btnbar_" .. game.id @@ -155,8 +155,8 @@ local function get_formspec(tabview, name, tabdata) local creative, damage, host = "", "", "" -- Y offsets for game settings checkboxes - local y = -0.2 - local yo = 0.45 + local y = 0.2 + local yo = 0.5625 if disabled_settings["creative_mode"] == nil then creative = "checkbox[0,"..y..";cb_creative_mode;".. fgettext("Creative Mode") .. ";" .. @@ -175,41 +175,58 @@ local function get_formspec(tabview, name, tabdata) end retval = retval .. - "button[3.9,3.8;2.8,1;world_delete;".. fgettext("Delete") .. "]" .. - "button[6.55,3.8;2.8,1;world_configure;".. fgettext("Select Mods") .. "]" .. - "button[9.2,3.8;2.8,1;world_create;".. fgettext("New") .. "]" .. - "label[3.9,-0.05;".. fgettext("Select World:") .. "]".. + "container[5.25,4.75]" .. + "button[0,0;3.125,0.85;world_delete;".. fgettext("Delete") .. "]" .. + "button[3.375,0;3.125,0.85;world_configure;".. fgettext("Select Mods") .. "]" .. + "button[6.75,0;3.125,0.85;world_create;".. fgettext("New") .. "]" .. + "container_end[]" .. + "container[0.375,0.375]" .. creative .. damage .. host .. - "textlist[3.9,0.4;7.9,3.45;sp_worlds;" .. + "container_end[]" .. + "container[5.25,0.375]" .. + "label[0,0.2;".. fgettext("Select World:") .. "]".. + "textlist[0,0.5;9.875,3.6;sp_worlds;" .. menu_render_worldlist() .. - ";" .. index .. "]" + ";" .. index .. "]" .. + "container_end[]" if core.settings:get_bool("enable_server") and disabled_settings["enable_server"] == nil then retval = retval .. - "button[7.9,4.75;4.1,1;play;".. fgettext("Host Game") .. "]" .. + "button[11.025,5.85;4.1,0.85;play;".. fgettext("Host Game") .. "]" .. + "container[0.375,0.375]" .. "checkbox[0,"..y..";cb_server_announce;" .. fgettext("Announce Server") .. ";" .. - dump(core.settings:get_bool("server_announce")) .. "]" .. - "field[0.3,2.85;3.8,0.5;te_playername;" .. fgettext("Name") .. ";" .. - core.formspec_escape(current_name) .. "]" .. - "pwdfield[0.3,4.05;3.8,0.5;te_passwd;" .. fgettext("Password") .. "]" + dump(core.settings:get_bool("server_announce")) .. "]" + + y = y + yo + 0.35 + + retval = retval .. "field[0," .. y .. ";4.5,0.75;te_playername;" .. fgettext("Name") .. ";" .. + core.formspec_escape(current_name) .. "]" + + y = y + 1.15 + 0.25 + + retval = retval .. "pwdfield[0," .. y .. ";4.5,0.75;te_passwd;" .. fgettext("Password") .. "]" + + y = y + 1.15 + 0.25 local bind_addr = core.settings:get("bind_address") if bind_addr ~= nil and bind_addr ~= "" then retval = retval .. - "field[0.3,5.25;2.5,0.5;te_serveraddr;" .. fgettext("Bind Address") .. ";" .. + "field[0," .. y .. ";3,0.75;te_serveraddr;" .. fgettext("Bind Address") .. ";" .. core.formspec_escape(core.settings:get("bind_address")) .. "]" .. - "field[2.85,5.25;1.25,0.5;te_serverport;" .. fgettext("Port") .. ";" .. + "field[3.25," .. y .. ";1.25,0.75;te_serverport;" .. fgettext("Port") .. ";" .. core.formspec_escape(current_port) .. "]" else retval = retval .. - "field[0.3,5.25;3.8,0.5;te_serverport;" .. fgettext("Server Port") .. ";" .. + "field[0," .. y .. ";4.5,0.75;te_serverport;" .. fgettext("Server Port") .. ";" .. core.formspec_escape(current_port) .. "]" end + + retval = retval .. "container_end[]" else retval = retval .. - "button[7.9,4.75;4.1,1;play;" .. fgettext("Play Game") .. "]" + "button[11.025,5.85;4.1,0.85;play;" .. fgettext("Play Game") .. "]" end return retval diff --git a/builtin/mainmenu/tab_online.lua b/builtin/mainmenu/tab_online.lua index 1b1a0a71a..8a0de4eda 100644 --- a/builtin/mainmenu/tab_online.lua +++ b/builtin/mainmenu/tab_online.lua @@ -180,7 +180,7 @@ local function get_formspec(tabview, name, tabdata) retval = retval .. ";0]" end - return retval, "size[15.5,7.1,false]real_coordinates[true]" + return retval end --------------------------------------------------------------------------------