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] 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 if element and element.on_event then
--on_event(form, player, element) --on_event(form, player, element)
local form = element.on_event( 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 if form then computers.formspec.show_formspec(player, formname, form) end
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 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) local function select_btn(form, btn)
--to hardcoded --to hardcoded
for _, obtn in pairs(form.tabs) do for _, obtn in pairs(form.tabs) do
@ -170,63 +177,78 @@ function computers.gui.load(pos, node, clicker)
state = 1, state = 1,
x = 0, x = 0,
y = 1, y = 1,
--[[
hardcoded background for now, need to build in custom element support
into hypertext to map to formspec elements
]]
{ {
type = "background", type = "background",
x = 0, x = 0,
y = 0, y = 0,
w = 10, w = 10,
h = 11, h = 10,
texture_name = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70" texture_name = "[combine:16x16^[noalpha^[colorize:#ffffff70"
}, },
{ {
type = "label", type = "hypertext",
x = 1, name = "browser_content",
y = 1.5, x = 0,
label = "browser pane", 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", type = "background",
x = 1, x = 0,
y = 2, y = 10,
w = 5, w = 10,
h = 2, h = 1,
name = "test_btn", texture_name = "[combine:16x16^[noalpha"
label = "test btn", },
on_event = function(_, player, element) {
--local cindex = futil.get_index_by_name(form, "browser_ctn") type = "box",
--local eindex = futil.get_index_by_name(form[cindex], "test_btn") x = 0,
--form[cindex][eindex] = {type = "label", x=1, y=3, label = "test button label"} y = 10,
local form = computers.gui.add_tab(player, "Tname", { w = 10,
type = "container", h = 1,
name = "tname_ctn", color = "#ffffff"
state = 1, },
x = 0, {
y = 1, type = "field",
{ x = 0,
type = "background", y = 10,
x = 0, w = 10,
y = 0, h = 1,
w = 10, name = "browser_url",
h = 11, close_on_enter = false,
texture_name = "kuto_button.png^[combine:16x16^[noalpha^[colorize:#ffffff70" pwd = "",
}, props = {
{ border = false,
type = "label", },
x = 1, on_event = function(form, player, element, value, fields)
y = 1.5, --minetest.chat_send_all("url entered")
label = "Tname pane", computers.api.chat_send_player(player, "[computers]: networking not currently supported")
},
})
return form return form
end, 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()) table.insert(fs.tabs, tname:lower())
return fs return fs
end end
--[[ minetest.register_on_player_receive_fields(function(player, formname, fields)
minetest.chat_send_all(dump(fields))
end) ]]