summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2015-03-11 18:48:20 +0100
committerWuzzy <almikes@aol.com>2015-03-11 18:48:20 +0100
commit0b23c7999a8d660dff81423996ab5fef7812bdbd (patch)
treebadd8f6e100ac166d4799da01f925418ed89fd43
parent77ca4362d627f5820049c2d39fec242f49e00f0a (diff)
Implement showing help entry
-rw-r--r--init.lua69
1 files changed, 53 insertions, 16 deletions
diff --git a/init.lua b/init.lua
index 00763ea..ccd7b86 100644
--- a/init.lua
+++ b/init.lua
@@ -50,8 +50,22 @@ doc.new_entry("one", "o1", {
population = "10000000",
},
})
-doc.new_entry("one", "o2", {name="O2"})
-doc.new_entry("one", "o3", {name="O3"})
+doc.new_entry("one", "o2", {
+ name="O2",
+ data = {
+ description = "This is a test description 2.",
+ time = 100,
+ population = "50000",
+ },
+})
+doc.new_entry("one", "o3", {
+ name="O3",
+ data = {
+ description = "Third try description.",
+ time = 1,
+ population = "10000000",
+ },
+})
function doc.show_doc(playername)
local formspec = doc.formspec_core()..doc.formspec_main()
@@ -74,28 +88,42 @@ function doc.formspec_main()
return formstring
end
-function doc.formspec_category(id, playername)
+function doc.generate_entry_list(id, playername)
local formstring
- if id == nil then
- formstring = "label[0,0;You haven't selected a help topic yet. Please select one in the category list first.]"
- formstring = formstring .. "button[0,1;3,1;doc_button_goto_main;Go to category list]"
- else
- formstring = "label[0,0;Current help topic: "..doc.data.categories[id].def.name.."]"
- formstring = formstring .. "label[0,0.5;Available entries:]"
- formstring = formstring .. "textlist[0,1;11,7;doc_catlist;"
+ if doc.data.players[playername].entry_textlist == nil then
+ local entry_textlist = "textlist[0,1;11,7;doc_catlist;"
local counter = 0
+ doc.data.players[playername].entry_ids = {}
for eid,entry in pairs(doc.data.categories[id].entries) do
- formstring = formstring .. entry.name .. ","
+ table.insert(doc.data.players[playername].entry_ids, eid)
+ entry_textlist = entry_textlist .. entry.name .. ","
counter = counter + 1
end
if counter >= 1 then
- formstring = string.sub(formstring, 1, #formstring-1)
+ entry_textlist = string.sub(entry_textlist, 1, #entry_textlist-1)
end
local catsel = doc.data.players[playername].catsel
if catsel then
- formstring = formstring .. ";"..doc.data.players[playername].catsel
+ entry_textlist = entry_textlist .. ";"..catsel
end
- formstring = formstring .. "]"
+ entry_textlist = entry_textlist .. "]"
+ doc.data.players[playername].entry_textlist = entry_textlist
+ formstring = entry_textlist
+ else
+ formstring = doc.data.players[playername].entry_textlist
+ end
+ return formstring
+end
+
+function doc.formspec_category(id, playername)
+ local formstring
+ if id == nil then
+ formstring = "label[0,0;You haven't selected a help topic yet. Please select one in the category list first.]"
+ formstring = formstring .. "button[0,1;3,1;doc_button_goto_main;Go to category list]"
+ else
+ formstring = "label[0,0;Current help topic: "..doc.data.categories[id].def.name.."]"
+ formstring = formstring .. "label[0,0.5;Available entries:]"
+ formstring = formstring .. doc.generate_entry_list(id, playername)
formstring = formstring .. "button[0,8;3,1;doc_button_goto_entry;Show entry]"
end
return formstring
@@ -145,14 +173,23 @@ function doc.process_form(player,formname,fields)
if fields["doc_button_category_"..id] then
local formspec = doc.formspec_core(2)..doc.formspec_category(id, playername)
doc.data.players[playername].catsel = nil
+ doc.data.players[playername].category = id
minetest.show_formspec(playername, "doc:category", formspec)
break
end
end
elseif(formname == "doc:category") then
if fields["doc_button_goto_entry"] then
- local formspec = doc.formspec_core(3)..doc.formspec_entry("one", "o1")
- minetest.show_formspec(playername, "doc:entry", formspec)
+ local cid = doc.data.players[playername].category
+ if cid ~= nil then
+ local eid = nil
+ local eids, catsel = doc.data.players[playername].entry_ids, doc.data.players[playername].catsel
+ if eids ~= nil and catsel ~= nil then
+ eid = eids[catsel]
+ end
+ local formspec = doc.formspec_core(3)..doc.formspec_entry(cid, eid)
+ minetest.show_formspec(playername, "doc:entry", formspec)
+ end
end
if fields["doc_catlist"] then
local event = minetest.explode_textlist_event(fields["doc_catlist"])