Add support for up to 32 categories
This commit is contained in:
parent
900daaacbf
commit
d9a903f890
44
init.lua
44
init.lua
@ -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 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 = {}
|
||||||
doc.data.categories = {}
|
doc.data.categories = {}
|
||||||
@ -479,18 +483,36 @@ function doc.formspec_main()
|
|||||||
if doc.get_category_count() >= 1 then
|
if doc.get_category_count() >= 1 then
|
||||||
formstring = formstring .. F("Please select a category you wish to learn more about:").."]"
|
formstring = formstring .. F("Please select a category you wish to learn more about:").."]"
|
||||||
local y = 1
|
local y = 1
|
||||||
for c=1,#doc.data.category_order do
|
local x = 1
|
||||||
local id = doc.data.category_order[c]
|
if #doc.data.category_order <= (CATEGORYFIELDSIZE.WIDTH * CATEGORYFIELDSIZE.HEIGHT) then
|
||||||
local data = doc.data.categories[id]
|
for c=1,#doc.data.category_order do
|
||||||
-- Category buton
|
local id = doc.data.category_order[c]
|
||||||
local button = "button[0,"..y..";3,1;doc_button_category_"..id..";"..minetest.formspec_escape(data.def.name).."]"
|
local data = doc.data.categories[id]
|
||||||
local tooltip = ""
|
-- Category buton
|
||||||
-- Optional description
|
local button = "button["..((x-1)*3)..","..y..";3,1;doc_button_category_"..id..";"..minetest.formspec_escape(data.def.name).."]"
|
||||||
if data.def.description ~= nil then
|
local tooltip = ""
|
||||||
tooltip = "tooltip[doc_button_category_"..id..";"..minetest.formspec_escape(data.def.description).."]"
|
-- 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
|
end
|
||||||
formstring = formstring .. button .. tooltip
|
else
|
||||||
y = y + 1
|
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 .. ";]"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return formstring
|
return formstring
|
||||||
|
Loading…
x
Reference in New Issue
Block a user