parent
580508fa37
commit
fd047c4c99
@ -72,7 +72,7 @@ Now that you have located your element you can modify it.
|
|||||||
button1:setPos(4,0)
|
button1:setPos(4,0)
|
||||||
|
|
||||||
## Inventory Support
|
## Inventory Support
|
||||||
Smartfs supports adding a button to Inventory+ or Unified Inventory which will open one of your own custom forms. Use the smartfs.add\_to\_inventory(form, icon, title) function where form is the smartfs form linked to by the button, icon is the button image (only for unified inventory), and title is the button text (only for inventory+).
|
Smartfs supports adding a button to Sfinv, Inventory+, or Unified Inventory which will open one of your own custom forms. Use the smartfs.add\_to\_inventory(form, icon, title) function where form is the smartfs form linked to by the button, icon is the button image (only for unified inventory), and title is the button text (for inventory+ and sfinv).
|
||||||
|
|
||||||
smartfs.add_to_inventory(form, icon, title)
|
smartfs.add_to_inventory(form, icon, title)
|
||||||
|
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
unified_inventory?
|
unified_inventory?
|
||||||
inventory_plus?
|
inventory_plus?
|
||||||
|
sfinv?
|
||||||
|
54
smartfs.lua
54
smartfs.lua
@ -79,6 +79,8 @@ function smartfs.inventory_mod()
|
|||||||
return "unified_inventory"
|
return "unified_inventory"
|
||||||
elseif minetest.global_exists("inventory_plus") then
|
elseif minetest.global_exists("inventory_plus") then
|
||||||
return "inventory_plus"
|
return "inventory_plus"
|
||||||
|
elseif minetest.global_exists("sfinv") then
|
||||||
|
return "sfinv"
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end
|
end
|
||||||
@ -175,6 +177,56 @@ smartfs._ldef.inventory_plus = {
|
|||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-- Sfinv plugin
|
||||||
|
smartfs._ldef.sfinv = {
|
||||||
|
add_to_inventory = function(form, icon, title)
|
||||||
|
sfinv.register_page(form.name, {
|
||||||
|
title = title,
|
||||||
|
get = function(self, player, context)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
local state
|
||||||
|
if smartfs.inv[name] then
|
||||||
|
state = smartfs.inv[name]
|
||||||
|
else
|
||||||
|
local statelocation = smartfs._ldef.sfinv._make_state_location_(name)
|
||||||
|
state = smartfs._makeState_(form, nil, statelocation, name)
|
||||||
|
smartfs.inv[name] = state
|
||||||
|
if form.form_setup_callback(state) ~= false then
|
||||||
|
smartfs.inv[name] = state
|
||||||
|
else
|
||||||
|
return ""
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local fs = state:_buildFormspec_(false)
|
||||||
|
return sfinv.make_formspec(player, context, fs, true)
|
||||||
|
end,
|
||||||
|
on_player_receive_fields = function(self, player, _, fields)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if smartfs.inv[name] then
|
||||||
|
smartfs.inv[name]:_sfs_on_receive_fields_(name, fields)
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
on_leave = function(self, player)
|
||||||
|
local name = player:get_player_name()
|
||||||
|
if smartfs.inv[name] then
|
||||||
|
smartfs.inv[name].players:disconnect(name)
|
||||||
|
smartfs.inv[name] = nil
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
end,
|
||||||
|
_make_state_location_ = function(player)
|
||||||
|
return {
|
||||||
|
type = "inventory",
|
||||||
|
inventory_handles_fields = true,
|
||||||
|
player = player,
|
||||||
|
_show_ = function(state)
|
||||||
|
sfinv.set_player_inventory_formspec(minetest.get_player_by_name(state.location.player))
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
-- Show to player
|
-- Show to player
|
||||||
smartfs._ldef.player = {
|
smartfs._ldef.player = {
|
||||||
_make_state_location_ = function(player)
|
_make_state_location_ = function(player)
|
||||||
@ -347,7 +399,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
|||||||
smartfs.opened[name] = nil
|
smartfs.opened[name] = nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif smartfs.inv[name] and smartfs.inv[name].location.type == "inventory" then
|
elseif smartfs.inv[name] and smartfs.inv[name].location.type == "inventory" and not smartfs.inv[name].location.inventory_handles_fields then
|
||||||
local state = smartfs.inv[name]
|
local state = smartfs.inv[name]
|
||||||
state:_sfs_on_receive_fields_(name, fields)
|
state:_sfs_on_receive_fields_(name, fields)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user