Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 70 additions & 41 deletions Core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ end
a second argument to be replaced with something better
]]

local function FindEmptySlot(exclude, isGuildBank, sourceBagIndex, sourceSlotIndex)
local function FindEmptySlot(exclude, isGuildBank, sourceBagIndex, sourceSlotIndex, forceBankScope)

local function isExcluded(bag, slot)
for _, pair in ipairs(exclude) do
Expand All @@ -118,21 +118,29 @@ local function FindEmptySlot(exclude, isGuildBank, sourceBagIndex, sourceSlotInd
bags = ContainerScope.PERSONAL_WITH_REGENTS
end

if sourceBagIndex == Enum.BagIndex.Reagentbank then
bags = ContainerScope.BANK_REGENTS_WITH_BANK
end

if ns.containsValue(ContainerScope.BANK, sourceBagIndex) then
bags = ContainerScope.BANK
end

if ns.containsValue(ContainerScope.WARBAND_BANK, sourceBagIndex) then
bags = { sourceBagIndex }
end

if isGuildBank then
bags = { sourceBagIndex }
end
if sourceBagIndex == Enum.BagIndex.Reagentbank then
bags = ContainerScope.BANK_REGENTS_WITH_BANK
end

if ns.containsValue(ContainerScope.BANK, sourceBagIndex) then
bags = ContainerScope.BANK
end

if ns.containsValue(ContainerScope.WARBAND_BANK, sourceBagIndex) then
bags = { sourceBagIndex }
end

if isGuildBank then
bags = { sourceBagIndex }
end

if forceBankScope then
if ns.containsValue(ContainerScope.BANK, sourceBagIndex) or sourceBagIndex == Enum.BagIndex.Reagentbank then
bags = ContainerScope.BANK
else
bags = { sourceBagIndex }
end
end

for _, bag in ipairs(bags) do
local maxSlots = nil
Expand Down Expand Up @@ -169,7 +177,7 @@ end
@return done (bool) - true if all is split, false in case of potential more items to split
]]

local function AutomaticSplit(isGuildBank, sourceBagIndex, sourceSlotIndex, targetStacksSize)
local function AutomaticSplit(isGuildBank, sourceBagIndex, sourceSlotIndex, targetStacksSize, forceBankScope)
ns.Log.debug("Splitting " .. ns.location_string(isGuildBank, sourceBagIndex, sourceSlotIndex))
local itemInfo = CollectItemInfo(isGuildBank, sourceBagIndex, sourceSlotIndex)

Expand Down Expand Up @@ -199,7 +207,7 @@ local function AutomaticSplit(isGuildBank, sourceBagIndex, sourceSlotIndex, targ
end
end

local destBag, destSlot = FindEmptySlot(excluded, isGuildBank, sourceBagIndex, sourceSlotIndex)
local destBag, destSlot = FindEmptySlot(excluded, isGuildBank, sourceBagIndex, sourceSlotIndex, forceBankScope)

if destBag and destSlot then
table.insert(excluded, {destBag, destSlot})
Expand Down Expand Up @@ -246,12 +254,12 @@ end

local coroutineAutomaticSplit = nil

local function StartAutomaticSplitSession(isGuildBank, sourceBagIndex, sourceSlotIndex, targetStacksSize)
coroutineAutomaticSplit = coroutine.create(function ()
AutomaticSplit(isGuildBank, sourceBagIndex, sourceSlotIndex, targetStacksSize)
ClearDialog()
end)
end
local function StartAutomaticSplitSession(isGuildBank, sourceBagIndex, sourceSlotIndex, targetStacksSize, forceBankScope)
coroutineAutomaticSplit = coroutine.create(function ()
AutomaticSplit(isGuildBank, sourceBagIndex, sourceSlotIndex, targetStacksSize, forceBankScope)
ClearDialog()
end)
end

--[[
Detector function to figure out clicked bag-slot combination based on parent UI element
Expand All @@ -260,7 +268,7 @@ end
so tab 1 in bank is 1, the same as bag 1 player is carrying.
]]

local function SourceLocation(parent)
local function SourceLocation(parent)
local parentName = parent:GetName()
local parentParentName = nil
local parentParentParentName = nil
Expand All @@ -273,9 +281,10 @@ local function SourceLocation(parent)
parentParentParentName = parent:GetParent():GetParent():GetName()
end

local isGuildBank = false
local bagIndex = parent:GetParent():GetID()
local slotIndex = parent:GetID()
local isGuildBank = false
local bagIndex = parent:GetParent():GetID()
local slotIndex = parent:GetID()
local forceBankScope = false

local locationBagIndex, locationSlotIndex = nil, nil
if parent and parent:GetItemLocation() and parent:GetItemLocation():GetBagAndSlot() then
Expand Down Expand Up @@ -317,14 +326,34 @@ local function SourceLocation(parent)
bagIndex, slotIndex = parent:GetItemLocation():GetBagAndSlot()
end

-- Blizzard Warband bank
if BankFrame and BankFrame:IsVisible() and BankFrame:GetActiveBankType() == Enum.BankType.Account then
bagIndex = parent:GetBankTabID()
slotIndex = parent:GetContainerSlotID()
end

return isGuildBank, bagIndex, slotIndex
end
-- Blizzard personal bank (ensure auto-split stays in bank slots)
if BankFrame
and BankFrame:IsVisible()
and BankFrame:GetActiveBankType() == Enum.BankType.Character
and ns.isParentNameInHierarchy(parent, "BankFrame") then
forceBankScope = true
local bankBagId = parent.GetBagID and parent:GetBagID()
local bankSlotId = parent.GetSlotID and parent:GetSlotID()
if bankBagId and bankSlotId then
bagIndex = bankBagId
slotIndex = bankSlotId
elseif locationBagIndex and locationSlotIndex then
bagIndex = locationBagIndex
slotIndex = locationSlotIndex
else
bagIndex = Enum.BagIndex.Bank
slotIndex = parent:GetID()
end
end

-- Blizzard Warband bank
if BankFrame and BankFrame:IsVisible() and BankFrame:GetActiveBankType() == Enum.BankType.Account then
bagIndex = parent:GetBankTabID()
slotIndex = parent:GetContainerSlotID()
end

return isGuildBank, bagIndex, slotIndex, forceBankScope
end

-- Overrides standard function for split dialog

Expand All @@ -341,7 +370,7 @@ local function OpenFrame(self, maxStack, parent, anchor, anchorTo, stackCount)
end)
dialog.editBox:SetFocus()

local isGuildBank, bagIndex, slotIndex = SourceLocation(parent)
local isGuildBank, bagIndex, slotIndex, forceBankScope = SourceLocation(parent)

dialog.splitButton:SetScript("OnClick", function()
parent.SplitStack(parent, dialog:GetValue()) -- original behaviour
Expand All @@ -350,9 +379,9 @@ local function OpenFrame(self, maxStack, parent, anchor, anchorTo, stackCount)

dialog.autoSplitButton:SetScript("OnClick", function ()
DisableDialog()
StartAutomaticSplitSession(isGuildBank, bagIndex, slotIndex, dialog:GetValue())
end)
end
StartAutomaticSplitSession(isGuildBank, bagIndex, slotIndex, dialog:GetValue(), forceBankScope)
end)
end

-- Init block

Expand Down Expand Up @@ -403,4 +432,4 @@ f:RegisterEvent("ADDON_LOADED")
f:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_SHOW")
f:RegisterEvent("PLAYER_INTERACTION_MANAGER_FRAME_HIDE")
f:SetScript("OnEvent", f.OnEvent)
f:SetScript("OnUpdate", f.OnUpdate)
f:SetScript("OnUpdate", f.OnUpdate)