From b02ecf6c7c12a7b807b50eb47605d82cd71df46b Mon Sep 17 00:00:00 2001 From: outlying Date: Tue, 13 Jan 2026 21:19:24 +0100 Subject: [PATCH] Split inside character bank --- Core.lua | 111 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/Core.lua b/Core.lua index 8814722..1486016 100644 --- a/Core.lua +++ b/Core.lua @@ -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 @@ -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 @@ -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) @@ -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}) @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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) \ No newline at end of file +f:SetScript("OnUpdate", f.OnUpdate)