Skip to content

Commit

Permalink
Replace settings tab with button
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenwardy committed Aug 29, 2023
1 parent 3ec5799 commit d540289
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 30 deletions.
35 changes: 28 additions & 7 deletions builtin/fstk/tabview.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ local function get_formspec(self)

local content, prepend = tab.get_formspec(self, tab.name, tab.tabdata, tab.tabsize)

local tsize = tab.tabsize or {width=self.width, height=self.height}
if self.parent == nil and not prepend then
local tsize = tab.tabsize or {width=self.width, height=self.height}
prepend = string.format("size[%f,%f,%s]", tsize.width, tsize.height,
dump(self.fixed_size))

Expand All @@ -76,7 +76,25 @@ local function get_formspec(self)
end
end

local formspec = (prepend or "") .. self:tab_header() .. content
local end_button_size = 0.65

local tab_header_size = { width = tsize.width, height = 0.85 }
if self.end_button then
tab_header_size.width = tab_header_size.width - end_button_size - 0.1
end

local formspec = (prepend or "") .. self:tab_header(tab_header_size) .. content

if self.end_button then
formspec = formspec ..
"style[open_settings;noclip=true;border=false]" ..
("tooltip[%s;%s]"):format(self.end_button.name, self.end_button.label) ..
("image_button[%f,%f;%f,%f;%s;%s;]"):format(
self.width - end_button_size, -0.43 - end_button_size / 2,
end_button_size, end_button_size,
self.end_button.icon, self.end_button.name)
end

return formspec
end

Expand All @@ -91,8 +109,12 @@ local function handle_buttons(self,fields)
return true
end

if self.end_button and self.on_end_button and fields[self.end_button.name] then
return self:on_end_button()
end

if self.glb_btn_handler ~= nil and
self.glb_btn_handler(self,fields) then
self.glb_btn_handler(self, fields) then
return true
end

Expand Down Expand Up @@ -126,8 +148,7 @@ end


--------------------------------------------------------------------------------
local function tab_header(self)

local function tab_header(self, size)
local toadd = ""

for i=1,#self.tablist,1 do
Expand All @@ -138,8 +159,8 @@ local function tab_header(self)

toadd = toadd .. self.tablist[i].caption
end
return string.format("tabheader[%f,%f;%s;%s;%i;true;false]",
self.header_x, self.header_y, self.name, toadd, self.last_tab_index);
return string.format("tabheader[%f,%f;%f,%f;%s;%s;%i;true;false]",
self.header_x, self.header_y, size.width, size.height, self.name, toadd, self.last_tab_index)
end

--------------------------------------------------------------------------------
Expand Down
42 changes: 19 additions & 23 deletions builtin/mainmenu/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,13 @@ dofile(menupath .. DIR_DELIM .. "dlg_register.lua")
dofile(menupath .. DIR_DELIM .. "dlg_rename_modpack.lua")
dofile(menupath .. DIR_DELIM .. "dlg_version_info.lua")

local tabs = {}

tabs.settings = {
name = "settings",
caption = fgettext("Settings"),
cbf_formspec = function()
return "button[0.1,0.1;3,0.8;open_settings;" .. fgettext("Open Settings") .. "]"
end,
cbf_button_handler = function(tabview, fields)
if fields.open_settings then
local dlg = create_settings_dlg()
dlg:set_parent(tabview)
tabview:hide()
dlg:show()
return true
end
end,
local tabs = {
content = dofile(menupath .. DIR_DELIM .. "tab_content.lua"),
about = dofile(menupath .. DIR_DELIM .. "tab_about.lua"),
local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua"),
play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")
}

tabs.content = dofile(menupath .. DIR_DELIM .. "tab_content.lua")
tabs.about = dofile(menupath .. DIR_DELIM .. "tab_about.lua")
tabs.local_game = dofile(menupath .. DIR_DELIM .. "tab_local.lua")
tabs.play_online = dofile(menupath .. DIR_DELIM .. "tab_online.lua")

--------------------------------------------------------------------------------
local function main_event_handler(tabview, event)
if event == "MenuQuit" then
Expand Down Expand Up @@ -121,7 +104,6 @@ local function init_globals()
tv_main:add(tabs.local_game)
tv_main:add(tabs.play_online)
tv_main:add(tabs.content)
tv_main:add(tabs.settings)
tv_main:add(tabs.about)

tv_main:set_global_event_handler(main_event_handler)
Expand All @@ -132,6 +114,20 @@ local function init_globals()
tv_main:set_tab(last_tab)
end

tv_main.end_button = {
icon = defaulttexturedir .. "settings_btn.png",
label = fgettext("Settings"),
name = "open_settings",
}

tv_main.on_end_button = function(self)
local dlg = create_settings_dlg()
dlg:set_parent(self)
self:hide()
dlg:show()
return true
end

-- In case the folder of the last selected game has been deleted,
-- display "Minetest" as a header
if tv_main.current_tab == "local" and not game then
Expand Down

0 comments on commit d540289

Please sign in to comment.