diff options
author | Wuzzy <almikes@aol.com> | 2016-11-07 14:12:49 +0100 |
---|---|---|
committer | Wuzzy <almikes@aol.com> | 2016-11-07 14:12:49 +0100 |
commit | d9a903f890b5d54a252c4d18ff52d3b38247e8ac (patch) | |
tree | edcb1f79f3e7ce3f09fe7026af38304819a147bd /init.lua | |
parent | 900daaacbff495bf21913bc04187f7e00837a5a4 (diff) |
Add support for up to 32 categories
Diffstat (limited to 'init.lua')
-rw-r--r-- | init.lua | 44 |
1 files changed, 33 insertions, 11 deletions
@@ -20,6 +20,10 @@ doc.VERSION.STRING = doc.VERSION.MAJOR.."."..doc.VERSION.MINOR.."."..doc.VERSION local doc_intro = string.format(S("This is the Documentation System, Version %s."), doc.VERSION.STRING) +local CATEGORYFIELDSIZE = { + WIDTH = 4, + HEIGHT = 8, +} doc.data = {} doc.data.categories = {} @@ -479,18 +483,36 @@ function doc.formspec_main() if doc.get_category_count() >= 1 then formstring = formstring .. F("Please select a category you wish to learn more about:").."]" local y = 1 - for c=1,#doc.data.category_order do - local id = doc.data.category_order[c] - local data = doc.data.categories[id] - -- Category buton - local button = "button[0,"..y..";3,1;doc_button_category_"..id..";"..minetest.formspec_escape(data.def.name).."]" - local tooltip = "" - -- Optional description - if data.def.description ~= nil then - tooltip = "tooltip[doc_button_category_"..id..";"..minetest.formspec_escape(data.def.description).."]" + local x = 1 + if #doc.data.category_order <= (CATEGORYFIELDSIZE.WIDTH * CATEGORYFIELDSIZE.HEIGHT) then + for c=1,#doc.data.category_order do + local id = doc.data.category_order[c] + local data = doc.data.categories[id] + -- Category buton + local button = "button["..((x-1)*3)..","..y..";3,1;doc_button_category_"..id..";"..minetest.formspec_escape(data.def.name).."]" + local tooltip = "" + -- Optional description + if data.def.description ~= nil then + tooltip = "tooltip[doc_button_category_"..id..";"..minetest.formspec_escape(data.def.description).."]" + end + formstring = formstring .. button .. tooltip + y = y + 1 + if y > CATEGORYFIELDSIZE.HEIGHT then + x = x + 1 + y = 1 + end + end + else + formstring = formstring .. "textlist[0,1;11,7;doc_mainlist;" + for c=1,#doc.data.category_order do + local id = doc.data.category_order[c] + local data = doc.data.categories[id] + formstring = formstring .. minetest.formspec_escape(data.def.name) + if c < #doc.data.category_order then + formstring = formstring .. "," + end end - formstring = formstring .. button .. tooltip - y = y + 1 + formstring = formstring .. ";]" end end return formstring |