improve browser tab default

This commit is contained in:
unknown 2022-02-19 16:06:17 -05:00
parent fa1f4894af
commit 8267c4d71f
4 changed files with 127 additions and 47 deletions

View File

@ -0,0 +1,18 @@
<global margin=20>
<normal></normal>
<center><bigger>Welcome to ARPANET</bigger></center>
<big>How to use it</big>
<normal>on the bottom of this pane is field input which allows you to enter site urls</normal>
<normal>example: <mono><style color=blue>domain</style></mono></normal>
<normal>example: <mono><style color=blue>domain/demo_page.page</style></mono></normal>
<normal></normal>
<big>Try it out</big>
<action name=demo_link _href=demo_page>test url</action>
<normal></normal>
<big>How can I host my own sites?</big>
<normal>you will need to set up the server node</normal>
<normal>put your webfiles in there in hypertext format in the public_html folder</normal>
<normal>domainname/ and domainname/folder/ will connect to the indexpage file found in the DIR</normal>
<normal></normal>

7
computers/demo_page.page Normal file
View File

@ -0,0 +1,7 @@
<global margin=20>
<normal></normal>
<center><bigger>Welcome to Demo Page</bigger></center>
<normal></normal>
<action name=default_link _href=default_page>go back</action>
<normal></normal>

View File

@ -117,6 +117,9 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
btn_override or keys[1]
)
--minetest.chat_send_all(keys[1])
--minetest.chat_send_all(fields[keys[1]])
if element and element.on_event then
--on_event(form, player, element)
local form = element.on_event(
@ -129,4 +132,30 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if form then computers.formspec.show_formspec(player, formname, form) end
end
end)
end)
--[[
yes, i know this isnt perfect
requires a name field in the subtags
returns a table keyed by the name field with sub tables containing the other sub tags
]]
function computers.formspec.get_hypertext_subtags(hypertext, tag)
local adata = {}
for a in string.gmatch(hypertext, "<"..tag..".->.-</"..tag..">") do
local len = #tag+1
local tags = string.split(string.sub(a:split(">")[1], len, -1), " ")
local name
local storage = {}
for _, tag_string in pairs(tags) do
local split = tag_string:split("=")
if split[1] == "name" then
name = split[2]
else
storage[split[1]] = split[2]
end
end
adata[name] = storage
end
--minetest.chat_send_all(dump(adata))
return adata
end

View File

@ -2,6 +2,13 @@ computers.gui = {}
local futil = computers.formspec
local f = io.open(computers.modpath .. "/default_page.page")
local default_page = f:read("*all")
f:close()
f = io.open(computers.modpath .. "/demo_page.page")
local demo_page = f:read("*all")
f:close()
local function select_btn(form, btn)
--to hardcoded
for _, obtn in pairs(form.tabs) do
@ -170,63 +177,78 @@ function computers.gui.load(pos, node, clicker)
state = 1,
x = 0,
y = 1,
--[[
hardcoded background for now, need to build in custom element support
into hypertext to map to formspec elements
]]
{
type = "background",
x = 0,
y = 0,
w = 10,
h = 11,
texture_name = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70"
h = 10,
texture_name = "[combine:16x16^[noalpha^[colorize:#ffffff70"
},
{
type = "label",
x = 1,
y = 1.5,
label = "browser pane",
type = "hypertext",
name = "browser_content",
x = 0,
y = 0,
w = 10,
h = 10,
text = default_page,
on_event = function(form, player, element, value, fields)
--minetest.chat_send_all("reached")
--hard coding some network stuff for now
local name = value:split(":")[2]
local tags = futil.get_hypertext_subtags(element.text, "action")
if tags[name] and tags[name]._href and tags[name]._href == "demo_page" then
--minetest.chat_send_all(tags[name]._href)
element.text = demo_page
elseif tags[name] and tags[name]._href and tags[name]._href == "default_page" then
element.text = default_page
end
return form
end
},
{
type = "button",
x = 1,
y = 2,
w = 5,
h = 2,
name = "test_btn",
label = "test btn",
on_event = function(_, player, element)
--local cindex = futil.get_index_by_name(form, "browser_ctn")
--local eindex = futil.get_index_by_name(form[cindex], "test_btn")
--form[cindex][eindex] = {type = "label", x=1, y=3, label = "test button label"}
local form = computers.gui.add_tab(player, "Tname", {
type = "container",
name = "tname_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 = "Tname pane",
},
})
type = "background",
x = 0,
y = 10,
w = 10,
h = 1,
texture_name = "[combine:16x16^[noalpha"
},
{
type = "box",
x = 0,
y = 10,
w = 10,
h = 1,
color = "#ffffff"
},
{
type = "field",
x = 0,
y = 10,
w = 10,
h = 1,
name = "browser_url",
close_on_enter = false,
pwd = "",
props = {
border = false,
},
on_event = function(form, player, element, value, fields)
--minetest.chat_send_all("url entered")
computers.api.chat_send_player(player, "[computers]: networking not currently supported")
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",
}
}
},
},
}
@ -292,4 +314,8 @@ function computers.gui.add_tab(player, tname, tab)
table.insert(fs.tabs, tname:lower())
return fs
end
end
--[[ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.chat_send_all(dump(fields))
end) ]]