-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathform.lua
46 lines (40 loc) · 1.29 KB
/
form.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
-- Form management
local forms = {}
formspeccer.newform = function(self,formname,formsize,prefs)
if forms[formname] ~= nil then
minetest.log("error","Form "..formname.." already exists!!")
return -- how to cleanly indicate error and prevent loading?
end
forms[formname] = 'size['..formsize..']'
if prefs then
local pstring = ''
for prefname,value in pairs(prefs) do
if prefname == "bgcolor" then
pstring = pstring .. "bgcolor["..lookupcolour(value).."]"
elseif prefname == "background" then
pstring = pstring .. "background["
pstring = pstring .. value.xy .. ';'
pstring = pstring .. value.wh .. ';'
pstring = pstring .. value.texture
if value.auto_clip ~= false then -- anything different from false, including nil
pstring = pstring .. ";true"
end
pstring = pstring .. "]"
end
end
forms[formname] = forms[formname] .. pstring
end
return formname
end
formspeccer.add_element = function(self,formname,element_string)
forms[formname] = forms[formname] .. element_string
end
formspeccer.to_string = function(self,formname)
return forms[formname]
end
formspeccer.show = function(self,player,formname)
minetest.show_formspec(player:get_player_name(),formname,forms[formname])
end
formspeccer.clear = function(self,formname)
forms[formname] = nil
end