Originally Posted by tonyis3l33t
|
I understand, what you mean.
Anyway here is something i scrapped up.. Doesn't work really how i want it to be, i just want it be parented to ContainerFrame1 (Backpack). I want the "one bag" to act without having to use all the togglebags etc etc.
Lua Code:
local function CheckSlots()
local numBags = 1
for i = 1, NUM_BAG_FRAMES do
local bagName = "ContainerFrame"..i+1
if _G[bagName]:IsShown() and not _G[bagName.."BackgroundTop"]:GetTexture():find("Bank") then
numBags = numBags + 1
end
end
return numBags
end
local Spacing = 4
local bu, con, bag, col, row
local buttons, bankbuttons = {}, {}
local MoveButtons = function(table, frame, extraHeight)
local columns = ceil(sqrt(#table))
local iconSize = 32
col, row = 0, 0
for i = 1, #table do
bu = table[i]
bu:ClearAllPoints()
bu:SetPoint("TOPLEFT", frame, "TOPLEFT", col * (iconSize + Spacing) + 3, -1 * row * (iconSize + Spacing) - 3)
if(col > (columns - 2)) then
col = 0
row = row + 1
else
col = col + 1
end
end
frame:SetHeight((row + (col==0 and 0 or 1)) * (iconSize + Spacing) + 19 + (extraHeight or 0))
frame:SetWidth(columns * iconSize + Spacing * (columns - 1) + 6)
col, row = 0, 0
end
local BagHolder = CreateFrame("Button", "BagsHolder", UIParent)
BagHolder:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -30, 30)
BagHolder:SetFrameStrata("HIGH")
BagHolder:Hide()
local ReanchorButtons = function()
table.wipe(buttons)
for f = 1, CheckSlots() do
con = "ContainerFrame"..f
for i = GetContainerNumSlots(_G[con]:GetID()), 1, -1 do
bu = _G[con.."Item"..i]
tinsert(buttons, bu)
end
end
MoveButtons(buttons, BagHolder)
BagHolder:Show()
end
local CloseBags = function()
BagHolder:Hide()
for i = 0, 11 do
CloseBag(i)
end
end
local CloseBags2 = function()
BagHolder:Hide()
end
local OpenBags = function()
for i = 0, 4 do
OpenBag(i)
end
end
local ToggleBags = function()
if(IsBagOpen(0)) then
CloseBags()
else
OpenBags()
end
end
for i = 1, 5 do
local bag = _G["ContainerFrame"..i]
hooksecurefunc(bag, "Show", ReanchorButtons)
hooksecurefunc(bag, "Hide", CloseBags2)
end
ToggleBackpack = ToggleBags
ToggleBag = ToggleBags
OpenAllBags = OpenBags
OpenBackpack = OpenBags
CloseAllBags = CloseBags