add tab views
This commit is contained in:
parent
a844c7ec5e
commit
1397b08bcb
|
@ -5,31 +5,53 @@ computers.show_formspec = computers.formspec.show_formspec
|
||||||
|
|
||||||
function computers.load_gui(pos, node, clicker)
|
function computers.load_gui(pos, node, clicker)
|
||||||
--minetest.chat_send_all("test")
|
--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 = {
|
local formspec = {
|
||||||
formspec_version = 4,
|
formspec_version = 4,
|
||||||
{
|
{
|
||||||
type = "size",
|
type = "size",
|
||||||
w = 10,
|
w = 10,
|
||||||
h = 10,
|
h = 12,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "label",
|
type = "no_prepend"
|
||||||
x = 1,
|
},
|
||||||
y = 1,
|
{
|
||||||
label = "test label",
|
type = "bgcolor",
|
||||||
|
bgcolor = "black",
|
||||||
|
fullscreen = "neither"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type = "button",
|
type = "button",
|
||||||
x = 1,
|
x = 0,
|
||||||
y = 2,
|
y = 0,
|
||||||
w = 5,
|
w = 2,
|
||||||
h = 2,
|
h = 1,
|
||||||
name = "test_btn",
|
name = "terminal_btn",
|
||||||
label = "test btn",
|
label = "Terminal",
|
||||||
on_event = function(form, player, element)
|
on_event = function(form, player, element)
|
||||||
local cindex = futil.get_index_by_name(form, "test_btn")
|
select_btn(form, "terminal")
|
||||||
form[cindex] = {type = "label", x=1, y=3, label = "test button label"}
|
--[[ 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
|
return form
|
||||||
end,
|
end,
|
||||||
|
@ -39,6 +61,92 @@ function computers.load_gui(pos, node, clicker)
|
||||||
bgimg_hovered = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff90",
|
bgimg_hovered = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff90",
|
||||||
bgimg_middle = "4,4",
|
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",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -43,11 +43,15 @@ end
|
||||||
function computers.formspec.convert_to_ast(form)
|
function computers.formspec.convert_to_ast(form)
|
||||||
local styles = {}
|
local styles = {}
|
||||||
|
|
||||||
|
|
||||||
local function rfind(fs)
|
local function rfind(fs)
|
||||||
for key, val in pairs(fs) do
|
for key, val in pairs(fs) do
|
||||||
if type(val) == "table" and val.type and val.type:find("container") then
|
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
|
elseif type(val) == "table" and val.props then
|
||||||
table.insert(styles, {type = "style", selectors = val.selectors or {val.name}, props = val.props})
|
table.insert(styles, {type = "style", selectors = val.selectors or {val.name}, props = val.props})
|
||||||
end
|
end
|
||||||
|
@ -68,8 +72,8 @@ function computers.formspec.show_formspec(player, formname, fs)
|
||||||
playername = player:get_player_name()
|
playername = player:get_player_name()
|
||||||
end
|
end
|
||||||
if type(fs) == "table" then
|
if type(fs) == "table" then
|
||||||
|
registered_astk[playername] = table.copy(fs)
|
||||||
formspec = formspec_ast.unparse(computers.formspec.convert_to_ast(fs))
|
formspec = formspec_ast.unparse(computers.formspec.convert_to_ast(fs))
|
||||||
registered_astk[playername] = fs
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.show_formspec(playername, formname, formspec)
|
minetest.show_formspec(playername, formname, formspec)
|
||||||
|
|
Loading…
Reference in New Issue