add is_visible_func to page definition to allow differen per-player buttons
This commit is contained in:
parent
cbd843311a
commit
a66b9a7299
2
API.md
2
API.md
@ -13,6 +13,7 @@ smart_inventory.register_page({
|
||||
smartfs_callback = function,
|
||||
sequence = number,
|
||||
on_button_click = function,
|
||||
is_visible_func = function,
|
||||
})
|
||||
```
|
||||
- name - unique short name, used for identification
|
||||
@ -22,6 +23,7 @@ smart_inventory.register_page({
|
||||
- smartfs_callback(state) - smartfs callback function See [smartfs documentation](https://github.com/minetest-mods/smartfs/blob/master/docs) and existing pages implementations for reference.
|
||||
- sequence - The buttons are sorted by this number (crafting=10, creative=15, player=20)
|
||||
- on_button_click(state) - function called each page button click
|
||||
- is_visible_func(state) - function for dynamic page enabelling. Should return bool value.
|
||||
|
||||
### Get the definition for registered smart_inventory page
|
||||
```smart_inventory.get_registered_page(pagename)```
|
||||
|
@ -52,6 +52,7 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
|
||||
for _, def in ipairs(smart_inventory.registered_pages) do
|
||||
assert(def.smartfs_callback, "Callback function needed")
|
||||
assert(def.name, "Name is needed")
|
||||
if not def.is_visible_func or def.is_visible_func(state) then
|
||||
local tabdef = {}
|
||||
local label
|
||||
if not def.label then
|
||||
@ -76,6 +77,7 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
|
||||
tab_controller:tab_add(def.name, tabdef)
|
||||
button_x = button_x + 1
|
||||
end
|
||||
end
|
||||
tab_controller:set_active(smart_inventory.registered_pages[1].name)
|
||||
end)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user