-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobogui.lua
More file actions
79 lines (63 loc) · 2.26 KB
/
Copy pathrobogui.lua
File metadata and controls
79 lines (63 loc) · 2.26 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
local turtlegui = turtlebot.gui;
-- GUI
-- turtlegui GUI START ==================================================
-- a simple table of entries: [guiName] = {getForm = ... , show = ... , response = ... , guidata = ...}
turtlegui.register = function(def)
turtlegui[def.guiName] = {
getForm = def.getForm,
show = def.show,
response = def.response,
guidata = def.guidata or {}
}
end
minetest.register_on_player_receive_fields(
function(player, formname, fields)
local gui = turtlegui[formname];
if gui then gui.response(player,formname,fields) end
end
)
-- turtlegui GUI END ====================================================
local help_address = {}; -- array containing current page name for player
local help_pages = {
["main"] = {
" === ROBOT HELP - MAIN SCREEN === ","",
"[Commands reference] display list of robot commands",
"[Lua basics] short introduction to lua","",
"INSTRUCTIONS: double click links marked with []",
"------------------------------------------","",
"basic_robot version " .. basic_robot.version,
"(c) 2016 rnd",
},
}
for k,v in pairs(help_pages) do
local pages = help_pages[k]; for i = 1,#pages do pages[i] = minetest.formspec_escape(pages[i]) end
end
local show_help = function(pname) --formname: help
local address = help_address[pname] or "main";
--minetest.chat_send_all("D DISPLAY HELP for ".. address )
local pages = help_pages[address];
local content = table.concat(pages,",")
local size = 9; local vsize = 8.75;
local form = "size[" .. size .. "," .. size .. "] textlist[-0.25,-0.25;" .. (size+1) .. "," .. (vsize+1) .. ";wiki;".. content .. ";1]";
--minetest.chat_send_all("D " .. form)
minetest.show_formspec(pname, "help", form)
return
end
turtlegui["help"] = {
response = function(player,formname,fields)
local name = player:get_player_name()
local fsel = fields.wiki;
if fsel and string.sub(fsel,1,3) == "DCL" then
local sel = tonumber(string.sub(fsel,5)) or 1; -- selected line
local address = help_address[name] or "main";
local pages = help_pages[address];
local link = string.match(pages[sel] or "", "\\%[([%w%s]+)\\%]")
if help_pages[link] then
help_address[name] = link;
show_help(name)
end
end
end,
getForm = function(player_name) end,
show = show_help,
};