Item & PlayerInventoryUI: Bags now have the ability to filter items by groups
This commit is contained in:
@@ -544,8 +544,7 @@ core.register_allow_player_inventory_action(function(player, action, inventory,
|
||||
end
|
||||
|
||||
-- We receive the item that the player wants to place in the equipment slot.
|
||||
local itemStack = inventory:get_stack(inventoryInfo.listname, inventoryInfo.index)
|
||||
assert(itemStack ~= nil)
|
||||
local itemStack = inventoryInfo.stack
|
||||
|
||||
if core.get_item_group(itemStack:get_name(), equipGroup) == inventoryInfo.index then
|
||||
return
|
||||
@@ -555,6 +554,90 @@ core.register_allow_player_inventory_action(function(player, action, inventory,
|
||||
end
|
||||
end)
|
||||
|
||||
---Checks if the inventory list is an inventory list of bags.
|
||||
---@param listName string
|
||||
---@return boolean
|
||||
local function isBagInventoryList(listName)
|
||||
if listName == 'inventory_back' or listName == 'inventory_left_thigh' or listName == 'inventory_right_thigh' then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
---Returns the copy ItemStack of the bag whose inventory is expanded in the specified inventory list.
|
||||
---@param inventory InvRef
|
||||
---@param listName string
|
||||
---@return ItemStack
|
||||
local function getBagSlotListName(inventory, listName)
|
||||
local bagSlotName = string.match(listName, 'inventory_(%S+)')
|
||||
assert(bagSlotName ~= nil)
|
||||
|
||||
local bagItem = inventory:get_stack('equip_'..bagSlotName, 1)
|
||||
assert(not bagItem:is_empty())
|
||||
|
||||
return bagItem
|
||||
end
|
||||
|
||||
-- We check whether an item contains allow or disallow item groups
|
||||
-- to ensure that only allow items are placed in bags.
|
||||
core.register_allow_player_inventory_action(function(player, action, inventory, inventoryInfo)
|
||||
if action == 'move' and isBagInventoryList(inventoryInfo.to_list) then
|
||||
local bagItem = getBagSlotListName(inventory, inventoryInfo.to_list)
|
||||
local movableItemName = inventory:get_stack(inventoryInfo.from_list, inventoryInfo.from_index):get_name()
|
||||
|
||||
local bagSetting = Smc.getItemDefinition(bagItem).settings
|
||||
local allowedGroups, disallowedGroups = bagSetting._itemstack_inventory_allowed_groups, bagSetting._itemstack_inventory_disallowed_groups
|
||||
|
||||
if allowedGroups ~= nil then
|
||||
for _, group in ipairs(allowedGroups) do
|
||||
if core.get_item_group(movableItemName, group) > 0 then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
if disallowedGroups ~= nil then
|
||||
for _, group in ipairs(disallowedGroups) do
|
||||
if core.get_item_group(movableItemName, group) > 0 then
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
elseif action == 'put' then
|
||||
local bagItem = getBagSlotListName(inventory, inventoryInfo.listname)
|
||||
local movableItemName = inventoryInfo.stack
|
||||
|
||||
local bagSetting = Smc.getItemDefinition(bagItem).settings
|
||||
local allowedGroups, disallowedGroups = bagSetting._itemstack_inventory_allowed_groups, bagSetting._itemstack_inventory_disallowed_groups
|
||||
|
||||
if allowedGroups ~= nil then
|
||||
for _, group in ipairs(allowedGroups) do
|
||||
if core.get_item_group(movableItemName, group) > 0 then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
if disallowedGroups ~= nil then
|
||||
for _, group in ipairs(disallowedGroups) do
|
||||
if core.get_item_group(movableItemName, group) > 0 then
|
||||
return 0
|
||||
end
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
---Returns the name of the inventory list that will contain the items in the bag.
|
||||
---@param equipList string
|
||||
---@return string
|
||||
|
||||
Reference in New Issue
Block a user