add tab views

This commit is contained in:
unknown 2022-02-12 19:21:39 -05:00
parent a844c7ec5e
commit 1397b08bcb
2 changed files with 128 additions and 16 deletions

View File

@ -5,31 +5,53 @@ computers.show_formspec = computers.formspec.show_formspec
function computers.load_gui(pos, node, clicker)
--minetest.chat_send_all("test")
local function select_btn(form, btn)
--to hardcoded
for _, obtn in pairs({"terminal", "browser"}) do
local cindex = futil.get_index_by_name(form, obtn .. "_btn")
form[cindex].props.bgimg = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70"
form[cindex].props.bgimg_hovered = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff90"
cindex = futil.get_index_by_name(form, obtn .. "_ctn")
form[cindex].state = 1
end
local cindex = futil.get_index_by_name(form, btn .. "_btn")
form[cindex].props.bgimg = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff20"
form[cindex].props.bgimg_hovered = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff40"
local aindex = futil.get_index_by_name(form, btn .. "_ctn")
form[aindex].state = 0
end
local formspec = {
formspec_version = 4,
{
type = "size",
w = 10,
h = 10,
h = 12,
},
{
type = "label",
x = 1,
y = 1,
label = "test label",
type = "no_prepend"
},
{
type = "bgcolor",
bgcolor = "black",
fullscreen = "neither"
},
{
type = "button",
x = 1,
y = 2,
w = 5,
h = 2,
name = "test_btn",
label = "test btn",
x = 0,
y = 0,
w = 2,
h = 1,
name = "terminal_btn",
label = "Terminal",
on_event = function(form, player, element)
local cindex = futil.get_index_by_name(form, "test_btn")
form[cindex] = {type = "label", x=1, y=3, label = "test button label"}
select_btn(form, "terminal")
--[[ minetest.chat_send_all("delim")
minetest.chat_send_all("browser: " .. form[futil.get_index_by_name(form, "browser_ctn")].state)
minetest.chat_send_all("terminal: " .. form[futil.get_index_by_name(form, "terminal_ctn")].state) ]]
return form
end,
@ -39,6 +61,92 @@ function computers.load_gui(pos, node, clicker)
bgimg_hovered = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff90",
bgimg_middle = "4,4",
}
},
{
type = "button",
x = 2,
y = 0,
w = 2,
h = 1,
name = "browser_btn",
label = "Browser",
on_event = function(form, player, element)
select_btn(form, "browser")
--[[ minetest.chat_send_all("delim")
minetest.chat_send_all("browser: " .. form[futil.get_index_by_name(form, "browser_ctn")].state)
minetest.chat_send_all("terminal: " .. form[futil.get_index_by_name(form, "terminal_ctn")].state) ]]
return form
end,
props = {
border = false,
bgimg = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70",
bgimg_hovered = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff90",
bgimg_middle = "4,4",
}
},
{
type = "container",
name = "terminal_ctn",
state = 0,
x = 0,
y = 1,
{
type = "background",
x = 0,
y = 0,
w = 10,
h = 11,
texture_name = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70"
},
{
type = "label",
x = 1,
y = 1.5,
label = "terminal pane",
},
{
type = "button",
x = 1,
y = 2,
w = 5,
h = 2,
name = "test_btn",
label = "test btn",
on_event = function(form, player, element)
local cindex = futil.get_index_by_name(form, "test_btn")
form[cindex] = {type = "label", x=1, y=3, label = "test button label"}
return form
end,
props = {
border = false,
bgimg = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70",
bgimg_hovered = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff90",
bgimg_middle = "4,4",
}
}
},
{
type = "container",
name = "browser_ctn",
state = 1,
x = 0,
y = 1,
{
type = "background",
x = 0,
y = 0,
w = 10,
h = 11,
texture_name = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70"
},
{
type = "label",
x = 1,
y = 1.5,
label = "browser pane",
},
}
}

View File

@ -43,11 +43,15 @@ end
function computers.formspec.convert_to_ast(form)
local styles = {}
local function rfind(fs)
for key, val in pairs(fs) do
if type(val) == "table" and val.type and val.type:find("container") then
rfind(val)
if val.state and val.state == 1 then
--cant use nil so swaping in thing that will never render
fs[key] = {type = "label",x = 100,y = 100,label = "nil",}
else
rfind(val)
end
elseif type(val) == "table" and val.props then
table.insert(styles, {type = "style", selectors = val.selectors or {val.name}, props = val.props})
end
@ -68,8 +72,8 @@ function computers.formspec.show_formspec(player, formname, fs)
playername = player:get_player_name()
end
if type(fs) == "table" then
registered_astk[playername] = table.copy(fs)
formspec = formspec_ast.unparse(computers.formspec.convert_to_ast(fs))
registered_astk[playername] = fs
end
minetest.show_formspec(playername, formname, formspec)