Implement shift clicking items

This commit is contained in:
2025-03-30 15:03:43 +02:00
parent d10d295a80
commit 5e3161f35f
2 changed files with 75 additions and 61 deletions

View File

@@ -53,6 +53,7 @@ require("Cyka.fabricatorstack")
require("Cyka.quickbuy") require("Cyka.quickbuy")
require("Cyka.hotkeyrepair") require("Cyka.hotkeyrepair")
require("Cyka.xpticker") require("Cyka.xpticker")
require("Cyka.cursormacroer")
print(MyModGlobal.MOD_NAME .. " v" .. MyModGlobal.MOD_VERSION .. " loaded!") print(MyModGlobal.MOD_NAME .. " v" .. MyModGlobal.MOD_VERSION .. " loaded!")
@@ -70,64 +71,4 @@ LuaUserData.RegisterType("Barotrauma.ItemPrefab")
LuaUserData.RegisterType("Barotrauma.Location+StoreInfo") LuaUserData.RegisterType("Barotrauma.Location+StoreInfo")
LuaUserData.MakeMethodAccessible(Descriptors["Barotrauma.CargoManager"], "GetConfirmedSoldEntities") LuaUserData.MakeMethodAccessible(Descriptors["Barotrauma.CargoManager"], "GetConfirmedSoldEntities")
LuaUserData.RegisterType("Barotrauma.Items.Components.Repairable") LuaUserData.RegisterType("Barotrauma.Items.Components.Repairable")
LuaUserData.RegisterType("Barotrauma.VisualSlot")
-- -- Register necessary type to access VisualSlot
-- LuaUserData.RegisterType("Barotrauma.VisualSlot")
--
-- ---@return Barotrauma.VisualSlot|nil, Barotrauma.ItemInventory|nil, Barotrauma.Item|nil
-- local function getInventorySlotUnderCursor()
-- -- Make sure we have a controlled character
-- local controlledCharacter = Character.Controlled
-- if not controlledCharacter then return nil, nil, nil end
--
-- -- Check player inventory first
-- local charInventory = controlledCharacter.Inventory
-- if charInventory and charInventory.visualSlots then
-- for i, visualSlot in ipairs(charInventory.visualSlots) do
-- -- Check if mouse is over this slot
-- if visualSlot:MouseOn() then
-- local slot = charInventory.slots[i]
-- local item = nil
-- if #slot.items > 0 then
-- item = slot.items[1]
-- end
-- return visualSlot, charInventory, item
-- end
-- end
-- end
--
-- -- Check if selected item has inventory (containers, etc.)
-- local selectedItem = controlledCharacter.SelectedItem
-- if selectedItem and selectedItem.OwnInventory and selectedItem.OwnInventory.visualSlots then
-- local itemInv = selectedItem.OwnInventory
-- for i, visualSlot in ipairs(itemInv.visualSlots) do
-- if visualSlot:MouseOn() then
-- local slot = itemInv.slots[i]
-- local item = nil
-- if #slot.items > 0 then
-- item = slot.items[1]
-- end
-- return visualSlot, itemInv, item
-- end
-- end
-- end
--
-- -- Check open containers or other items with visible inventories
-- for item in Item.ItemList do
-- if item and item.OwnInventory and item.OwnInventory.visualSlots then
-- local itemInv = item.OwnInventory
-- for i, visualSlot in ipairs(itemInv.visualSlots) do
-- if visualSlot:MouseOn() then
-- local slot = itemInv.slots[i]
-- local slotItem = nil
-- if #slot.items > 0 then
-- slotItem = slot.items[1]
-- end
-- return visualSlot, itemInv, slotItem
-- end
-- end
-- end
-- end
--
-- return nil, nil, nil
-- end

View File

@@ -0,0 +1,73 @@
---@return Barotrauma.VisualSlot|nil, Barotrauma.ItemInventory|nil, Barotrauma.Item|nil
local function getInventorySlotUnderCursor()
-- Make sure we have a controlled character
local controlledCharacter = Character.Controlled
if not controlledCharacter then return nil, nil, nil end
-- Check player inventory first
local charInventory = controlledCharacter.Inventory
if charInventory and charInventory.visualSlots then
for i, visualSlot in ipairs(charInventory.visualSlots) do
-- Check if mouse is over this slot
if visualSlot:MouseOn() then
local slot = charInventory.slots[i]
local item = nil
if #slot.items > 0 then
item = slot.items[1]
end
return visualSlot, charInventory, item
end
end
end
-- Check if selected item has inventory (containers, etc.)
local selectedItem = controlledCharacter.SelectedItem
if selectedItem and selectedItem.OwnInventory and selectedItem.OwnInventory.visualSlots then
local itemInv = selectedItem.OwnInventory
for i, visualSlot in ipairs(itemInv.visualSlots) do
if visualSlot:MouseOn() then
local slot = itemInv.slots[i]
local item = nil
if #slot.items > 0 then
item = slot.items[1]
end
return visualSlot, itemInv, item
end
end
end
-- Check open containers or other items with visible inventories
for item in Item.ItemList do
if item and item.OwnInventory and item.OwnInventory.visualSlots then
local itemInv = item.OwnInventory
for i, visualSlot in ipairs(itemInv.visualSlots) do
if visualSlot:MouseOn() then
local slot = itemInv.slots[i]
local slotItem = nil
if #slot.items > 0 then
slotItem = slot.items[1]
end
return visualSlot, itemInv, slotItem
end
end
end
end
return nil, nil, nil
end
Hook.Patch("Barotrauma.Character", "ControlLocalPlayer", function(instance, ptable)
---@cast PlayerInput Barotrauma.PlayerInput
if not PlayerInput.IsShiftDown() then return end
if not PlayerInput.PrimaryMouseButtonClicked() then return end
MyModGlobal.debugPrint("Shift + Left Click detected")
local visualSlot, itemInv, item = getInventorySlotUnderCursor()
if not visualSlot or not itemInv or not item then
MyModGlobal.debugPrint("No inventory slot or item found")
return
end
MyModGlobal.debugPrint("Visual slot: " .. tostring(visualSlot))
MyModGlobal.debugPrint("Item inventory: " .. tostring(itemInv))
MyModGlobal.debugPrint("Item: " .. tostring(item))
end, Hook.HookMethodType.After)