Implement invtab ordering

This commit is contained in:
Wuzzy 2022-08-12 21:26:51 +02:00
parent 4f9725fe46
commit db8db66c20
4 changed files with 48 additions and 2 deletions

View File

@ -140,6 +140,24 @@ In that case, it can only be reached by a function call.
### `rp_formspec.set_invtab_order(order)`
Overrides the order in which the invtabs are shown, starting
with the top tab.
* `order`: List of invtab IDs to order.
`order` can contain unknown invtab IDs, they will be ignored.
Any invtab not listed in `order` will be added at the end
in a non-predictable order.
If this function is called multiple times, the last
time this function is called is the one that actually
takes effect. If you want to override the order set
by another mod, depend on this mod first.
### `rp_formspec.registered_invpages`
Table which lists all registered invpages.

View File

@ -291,13 +291,27 @@ local function get_invtabs()
for o=1, #registered_invtabs_order do
local tabname = registered_invtabs_order[o]
local def = rp_formspec.registered_invtabs[tabname]
form = form .. rp_formspec.tab(tabx, taby, "_rp_formspec_tab_"..tabname, def.icon, def.tooltip)
taby = taby + tabplus
if def then
form = form .. rp_formspec.tab(tabx, taby, "_rp_formspec_tab_"..tabname, def.icon, def.tooltip)
taby = taby + tabplus
end
end
invtabs_cached = form
return form
end
function rp_formspec.set_invtab_order(order)
registered_invtabs_order = table.copy(order)
local already_ordered = {}
for o=1, #order do
already_ordered[order[o]] = true
end
for k,v in pairs(rp_formspec.registered_invtabs) do
if not already_ordered[k] then
table.insert(registered_invtabs_order, k)
end
end
end
-- Pages

View File

@ -0,0 +1,11 @@
-- Set the order of inventory menu tabs
rp_formspec.set_invtab_order({
"rp_crafting:crafting",
"rp_armor:armor",
"rp_achievements:achievements",
"rp_player_skins:player_skins",
"rp_creative:creative",
})
-- Note: If you want to override this order, depend
-- on this mod and call this function again.

View File

@ -0,0 +1,3 @@
name = rp_formspec_config
description = Some configuration tweaks for rp_formspec
depends = rp_formspec, rp_crafting, rp_creative, rp_player_skins, rp_armor, rp_achievements