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,
|
smartfs_callback = function,
|
||||||
sequence = number,
|
sequence = number,
|
||||||
on_button_click = function,
|
on_button_click = function,
|
||||||
|
is_visible_func = function,
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
- name - unique short name, used for identification
|
- 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.
|
- 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)
|
- sequence - The buttons are sorted by this number (crafting=10, creative=15, player=20)
|
||||||
- on_button_click(state) - function called each page button click
|
- 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
|
### Get the definition for registered smart_inventory page
|
||||||
```smart_inventory.get_registered_page(pagename)```
|
```smart_inventory.get_registered_page(pagename)```
|
||||||
|
@ -52,29 +52,31 @@ local inventory_form = smartfs.create("smart_inventory:main", function(state)
|
|||||||
for _, def in ipairs(smart_inventory.registered_pages) do
|
for _, def in ipairs(smart_inventory.registered_pages) do
|
||||||
assert(def.smartfs_callback, "Callback function needed")
|
assert(def.smartfs_callback, "Callback function needed")
|
||||||
assert(def.name, "Name is needed")
|
assert(def.name, "Name is needed")
|
||||||
local tabdef = {}
|
if not def.is_visible_func or def.is_visible_func(state) then
|
||||||
local label
|
local tabdef = {}
|
||||||
if not def.label then
|
local label
|
||||||
label = ""
|
if not def.label then
|
||||||
else
|
label = ""
|
||||||
label = def.label
|
else
|
||||||
end
|
label = def.label
|
||||||
tabdef.button = state:button(button_x,11.2,1,1,def.name.."_button",label)
|
|
||||||
if def.icon then
|
|
||||||
tabdef.button:setImage(def.icon)
|
|
||||||
end
|
|
||||||
tabdef.button:setTooltip(def.tooltip)
|
|
||||||
tabdef.button:onClick(function(self)
|
|
||||||
tab_controller:set_active(def.name)
|
|
||||||
if def.on_button_click then
|
|
||||||
def.on_button_click(tabdef.viewstate)
|
|
||||||
end
|
end
|
||||||
end)
|
tabdef.button = state:button(button_x,11.2,1,1,def.name.."_button",label)
|
||||||
tabdef.view = state:container(0,1,def.name.."_container")
|
if def.icon then
|
||||||
tabdef.viewstate = tabdef.view:getContainerState()
|
tabdef.button:setImage(def.icon)
|
||||||
def.smartfs_callback(tabdef.viewstate)
|
end
|
||||||
tab_controller:tab_add(def.name, tabdef)
|
tabdef.button:setTooltip(def.tooltip)
|
||||||
button_x = button_x + 1
|
tabdef.button:onClick(function(self)
|
||||||
|
tab_controller:set_active(def.name)
|
||||||
|
if def.on_button_click then
|
||||||
|
def.on_button_click(tabdef.viewstate)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
tabdef.view = state:container(0,1,def.name.."_container")
|
||||||
|
tabdef.viewstate = tabdef.view:getContainerState()
|
||||||
|
def.smartfs_callback(tabdef.viewstate)
|
||||||
|
tab_controller:tab_add(def.name, tabdef)
|
||||||
|
button_x = button_x + 1
|
||||||
|
end
|
||||||
end
|
end
|
||||||
tab_controller:set_active(smart_inventory.registered_pages[1].name)
|
tab_controller:set_active(smart_inventory.registered_pages[1].name)
|
||||||
end)
|
end)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user