Add sfinv.get_homepage_name(player)
Also sets creative:all as default inventory page Fixes #1423
This commit is contained in:
parent
7998de671f
commit
0ff09e018d
@ -411,6 +411,7 @@ Sfinv API
|
|||||||
If context is nil, it is either found or created.
|
If context is nil, it is either found or created.
|
||||||
* sfinv.get_formspec(player, context) - builds current page's formspec
|
* sfinv.get_formspec(player, context) - builds current page's formspec
|
||||||
* sfinv.get_nav_fs(player, context, nav, current_idx) - see above
|
* sfinv.get_nav_fs(player, context, nav, current_idx) - see above
|
||||||
|
* sfinv.get_homepage_name(player) - get the page name of the first page to show to a player
|
||||||
* sfinv.make_formspec(player, context, content, show_inv, size) - adds a theme to a formspec
|
* sfinv.make_formspec(player, context, content, show_inv, size) - adds a theme to a formspec
|
||||||
* show_inv, defaults to false. Whether to show the player's main inventory
|
* show_inv, defaults to false. Whether to show the player's main inventory
|
||||||
* size, defaults to `size[8,8.6]` if not specified
|
* size, defaults to `size[8,8.6]` if not specified
|
||||||
@ -422,7 +423,6 @@ Sfinv API
|
|||||||
|
|
||||||
* pages - table of pages[pagename] = def
|
* pages - table of pages[pagename] = def
|
||||||
* pages_unordered - array table of pages in order of addition (used to build navigation tabs).
|
* pages_unordered - array table of pages in order of addition (used to build navigation tabs).
|
||||||
* homepage_name - name of default page
|
|
||||||
* contexts - contexts[playername] = player_context
|
* contexts - contexts[playername] = player_context
|
||||||
* enabled - set to false to disable. Good for inventory rehaul mods like unified inventory
|
* enabled - set to false to disable. Good for inventory rehaul mods like unified inventory
|
||||||
|
|
||||||
|
@ -169,3 +169,12 @@ creative.register_tab("all", "All", minetest.registered_items)
|
|||||||
creative.register_tab("nodes", "Nodes", minetest.registered_nodes)
|
creative.register_tab("nodes", "Nodes", minetest.registered_nodes)
|
||||||
creative.register_tab("tools", "Tools", minetest.registered_tools)
|
creative.register_tab("tools", "Tools", minetest.registered_tools)
|
||||||
creative.register_tab("craftitems", "Items", minetest.registered_craftitems)
|
creative.register_tab("craftitems", "Items", minetest.registered_craftitems)
|
||||||
|
|
||||||
|
local old_homepage_name = sfinv.get_homepage_name
|
||||||
|
function sfinv.get_homepage_name(player)
|
||||||
|
if minetest.setting_getbool("creative_mode") then
|
||||||
|
return "creative:all"
|
||||||
|
else
|
||||||
|
return old_homepage_name(player)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
sfinv = {
|
sfinv = {
|
||||||
pages = {},
|
pages = {},
|
||||||
pages_unordered = {},
|
pages_unordered = {},
|
||||||
homepage_name = "sfinv:crafting",
|
|
||||||
contexts = {},
|
contexts = {},
|
||||||
enabled = true
|
enabled = true
|
||||||
}
|
}
|
||||||
@ -57,6 +56,10 @@ function sfinv.make_formspec(player, context, content, show_inv, size)
|
|||||||
return table.concat(tmp, "")
|
return table.concat(tmp, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function sfinv.get_homepage_name(player)
|
||||||
|
return "sfinv:crafting"
|
||||||
|
end
|
||||||
|
|
||||||
function sfinv.get_formspec(player, context)
|
function sfinv.get_formspec(player, context)
|
||||||
-- Generate navigation tabs
|
-- Generate navigation tabs
|
||||||
local nav = {}
|
local nav = {}
|
||||||
@ -81,7 +84,7 @@ function sfinv.get_formspec(player, context)
|
|||||||
return page:get(player, context)
|
return page:get(player, context)
|
||||||
else
|
else
|
||||||
local old_page = context.page
|
local old_page = context.page
|
||||||
context.page = sfinv.homepage_name
|
context.page = sfinv.get_homepage_name(player)
|
||||||
assert(sfinv.pages[context.page], "[sfinv] Invalid homepage")
|
assert(sfinv.pages[context.page], "[sfinv] Invalid homepage")
|
||||||
minetest.log("warning", "[sfinv] Couldn't find " .. dump(old_page) .. " so using switching to homepage")
|
minetest.log("warning", "[sfinv] Couldn't find " .. dump(old_page) .. " so using switching to homepage")
|
||||||
return sfinv.get_formspec(player, context)
|
return sfinv.get_formspec(player, context)
|
||||||
@ -94,7 +97,7 @@ function sfinv.set_player_inventory_formspec(player, context)
|
|||||||
context = sfinv.contexts[name]
|
context = sfinv.contexts[name]
|
||||||
if not context then
|
if not context then
|
||||||
context = {
|
context = {
|
||||||
page = sfinv.homepage_name
|
page = sfinv.get_homepage_name(player)
|
||||||
}
|
}
|
||||||
sfinv.contexts[name] = context
|
sfinv.contexts[name] = context
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user