diff options
author | Wuzzy <almikes@aol.com> | 2015-03-11 13:30:00 +0100 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2015-03-11 13:30:00 +0100 |
commit | 41eb204305e529851aad45df70a0e6b0070b7cce (patch) | |
tree | c73cc77dde0e24ef0eb80346a8d1ad12d669176f /init.lua |
First mock-up
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/init.lua b/init.lua new file mode 100644 index 0000000..f55e5c5 --- /dev/null +++ b/init.lua @@ -0,0 +1,83 @@ +doc = {} + +doc.VERSION = {} +doc.VERSION.MAJOR = 0 +doc.VERSION.MINOR = 1 +doc.VERSION.PATCH = 0 +doc.VERSION.STRING = "0.1.0" + + +doc.data = {} +doc.data.categories = {} +doc.data.entries = {} + + +function doc.new_category(id, def) + if doc.data.categories[id] ~= nil and id ~= nil then + doc.data.categories[id] = def + end +end + +function doc.new_entry(def) + if doc.data.entries[id] ~= nil and id ~= nil then + doc.data.entries[id] = def + end +end + +function doc.show_doc(playername) + local formspec = doc.formspec_core()..doc.formspec_main() + minetest.show_formspec(playername, "doc:main", formspec) +end + +function doc.formspec_core(tab) + if tab == nil then tab = 1 else tab = tostring(tab) end + return "size[12,9]tabheader[0,0;doc_header;Main,Category,Entry;"..tab..";true;false]" +end + +function doc.formspec_main() + return "label[0,1;Main]" +end + +function doc.formspec_category() + return "label[0,1;Category]" +end + +function doc.formspec_entry() + return "label[0,1;Entry]" +end + +function doc.process_form(player,formname,fields) + local playername = player:get_player_name() + --[[ process clicks on the tab header ]] + if(formname == "doc:main" or formname == "doc:category" or formname == "doc:entry") then + if fields.doc_header ~= nil then + local tab = tonumber(fields.doc_header) + local formspec, subformname, contents + if(tab==1) then + contents = doc.formspec_main() + subformname = "main" + elseif(tab==2) then + contents = doc.formspec_category() + subformname = "category" + elseif(tab==3) then + contents = doc.formspec_entry() + subformname = "entry" + end + formspec = doc.formspec_core(tab)..contents + minetest.show_formspec(playername, "doc:" .. subformname, formspec) + return + end + end +end + +minetest.register_on_player_receive_fields(doc.process_form) + +minetest.register_chatcommand("doc", { + params = "", + description = "Show in-game documentation system.", + privs = {}, + func = function(playername, param) + doc.show_doc(playername) + end, + } +) |