06-09-11, 10:07 AM | #1 |
aBags help
Hello.
In FreeUI I still use aBags because I think it's awesome, but there's one big problem: you need to /reload every time you add or upgrade a bag, because aBags only runs its script to set up the frame once. I've tried again and again to make it automatically change when there's a new slot, but I just haven't been able to. I'd greatly appreciate it if someone could help me out here, really. Below is the script. Every time you open bags, ReanchorButtons is ran, but as you can see after the first time all it does is show the frame itself. The first time, ReanchorButtons triggers MoveButtons, which moves every button into place and sets the frame size. Code:
-- aBags by Alza, modified. local F, C, L = unpack(select(2, ...)) --[[ Get the number of bag and bank container slots used ]] local function CheckSlots() if GetContainerNumSlots(4) == 0 then if GetContainerNumSlots(3) == 0 then if GetContainerNumSlots(2) == 0 then if GetContainerNumSlots(1) == 0 then return 1 else return 2 end else return 3 end else return 4 end else return 5 end end local function CheckBankSlots() return GetNumBankSlots() + 1 end local function GetColumns() return CheckSlots() + 4 end -- [[ Local stuff ]] local Spacing = 4 -- local Columns = 9 local BankColumns = 13 local _G = getfenv(0) local bu, con, col, row local buttons, bankbuttons = {}, {} local firstopened, firstbankopened = 1, 1 --[[ Function to move buttons ]] local MoveButtons = function(table, frame, columns) col, row = 0, 0 for i = 1, #table do bu = table[i] bu:ClearAllPoints() bu:SetNormalTexture("") bu:SetPoint("TOPLEFT", frame, "TOPLEFT", col * (37 + Spacing) + 3, -1 * row * (37 + Spacing) - 3) bu.SetPoint = F.dummy 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)) * (37 + Spacing) + 19) frame:SetWidth(columns * 37 + Spacing * (columns - 1) + 6) col, row = 0, 0 end --[[ Bags ]] local holder = CreateFrame("Button", "aBagsHolder", UIParent) holder:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -49, 49) holder:SetFrameStrata("HIGH") holder:Hide() F.CreateBD(holder, .6) local ReanchorButtons = function() if(firstopened==1) then for f = 1, CheckSlots() do con = "ContainerFrame"..f _G[con]:EnableMouse(false) _G[con.."CloseButton"]:Hide() _G[con.."PortraitButton"]:EnableMouse(false) for i = 1, 7 do select(i, _G[con]:GetRegions()):SetAlpha(0) end for i = GetContainerNumSlots(f-1), 1, -1 do bu = _G[con.."Item"..i] bu:SetFrameStrata("HIGH") tinsert(buttons, bu) _G[con.."Item"..i.."Count"]:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") _G[con.."Item"..i.."Count"]:ClearAllPoints() _G[con.."Item"..i.."Count"]:SetPoint("TOP", bu, 0, -2) _G[con.."Item"..i.."IconTexture"]:SetTexCoord(.1,.9,.1,.9) _G[con.."Item"..i.."IconQuestTexture"]:SetTexture(C.media.questborder) _G[con.."Item"..i.."IconQuestTexture"]:SetVertexColor(1, 0, 0) _G[con.."Item"..i.."IconQuestTexture"]:SetTexCoord(0.05, .955, 0.05, .965) _G[con.."Item"..i.."IconQuestTexture"].SetTexture = F.dummy end end MoveButtons(buttons, holder, GetColumns()) firstopened = 0 end holder:Show() end local money = _G["ContainerFrame1MoneyFrame"] money:SetFrameStrata("DIALOG") money:SetParent(holder) money:ClearAllPoints() money:SetPoint("BOTTOMRIGHT", holder, "BOTTOMRIGHT", 12, 2) --[[ Bank ]] local bankholder = CreateFrame("Button", "aBagsBankHolder", UIParent) bankholder:SetFrameStrata("HIGH") bankholder:Hide() F.CreateBD(bankholder, .6) local ReanchorBankButtons = function() if(firstbankopened==1) then for f = 1, 28 do bu = _G["BankFrameItem"..f] bu:SetFrameStrata("HIGH") tinsert(bankbuttons, bu) end _G["BankFrame"]:EnableMouse(false) _G["BankCloseButton"]:Hide() for f = 1, 5 do select(f, _G["BankFrame"]:GetRegions()):SetAlpha(0) end for f = CheckSlots() + 1, CheckSlots() + CheckBankSlots(), 1 do con = "ContainerFrame"..f ban = "BankFrame" _G[con]:EnableMouse(false) _G[con.."CloseButton"]:Hide() _G[con.."PortraitButton"]:EnableMouse(false) for i = 1, 7 do select(i, _G[con]:GetRegions()):SetAlpha(0) end for i = GetContainerNumSlots(f-1), 1, -1 do bu = _G[con.."Item"..i] bu:SetFrameStrata("HIGH") tinsert(bankbuttons, bu) _G[con.."Item"..i.."Count"]:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") _G[con.."Item"..i.."Count"]:ClearAllPoints() _G[con.."Item"..i.."Count"]:SetPoint("TOP", bu, 0, -2) _G[con.."Item"..i.."IconTexture"]:SetTexCoord(.1,.9,.1,.9) _G[con.."Item"..i.."IconQuestTexture"]:SetTexture(C.media.questborder) _G[con.."Item"..i.."IconQuestTexture"]:SetVertexColor(1, 0, 0) _G[con.."Item"..i.."IconQuestTexture"]:SetTexCoord(0.05, .955, 0.05, .965) _G[con.."Item"..i.."IconQuestTexture"].SetTexture = F.dummy end for i = 1, 28 do bbu = _G[ban.."Item"..i] bbu:SetFrameStrata("HIGH") _G[ban.."Item"..i.."IconTexture"]:SetTexCoord(.1,.9,.1,.9) _G[ban.."Item"..i.."Count"]:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") _G[ban.."Item"..i.."Count"]:ClearAllPoints() _G[ban.."Item"..i.."Count"]:SetPoint("TOP", bbu, 0, -2) _G[ban.."Item"..i.."IconQuestTexture"]:SetTexture(C.media.questborder) _G[ban.."Item"..i.."IconQuestTexture"]:SetVertexColor(1, 0, 0) _G[ban.."Item"..i.."IconQuestTexture"]:SetTexCoord(0.05, .955, 0.05, .965) _G[ban.."Item"..i.."IconQuestTexture"].SetTexture = F.dummy end end MoveButtons(bankbuttons, bankholder, GetColumns() + 4) bankholder:SetPoint("BOTTOMRIGHT", "aBagsHolder", "BOTTOMLEFT", -10 , 0) firstbankopened = 0 end bankholder:Show() end local money = _G["BankFrameMoneyFrame"] money:SetFrameStrata("DIALOG") money:ClearAllPoints() money:SetPoint("BOTTOMRIGHT", bankholder, "BOTTOMRIGHT", 12, 2) --[[ Hiding misc. frames ]] _G["BankFramePurchaseInfo"]:Hide() _G["BankFramePurchaseInfo"].Show = F.dummy local BankBagButtons = { BankFrameBag1, BankFrameBag2, BankFrameBag3, BankFrameBag4, BankFrameBag5, BankFrameBag6, BankFrameBag7, } local BagButtons = { CharacterBag0Slot, CharacterBag1Slot, CharacterBag2Slot, CharacterBag3Slot, } for f = 1, 7 do _G["BankFrameBag"..f]:SetParent(bankholder) _G["BankFrameBag"..f]:ClearAllPoints() if f==1 then _G["BankFrameBag"..f]:SetPoint("BOTTOM", bankholder, "TOP", -120, 4) else _G["BankFrameBag"..f]:SetPoint("CENTER", _G["BankFrameBag"..f-1], 38, 0) end _G["BankFrameBag"..f]:SetAlpha(0) _G["BankFrameBag"..f]:HookScript("OnEnter", function(self) for _, g in pairs(BankBagButtons) do g:SetAlpha(1) end end) _G["BankFrameBag"..f]:HookScript("OnLeave", function(self) for _, g in pairs(BankBagButtons) do g:SetAlpha(0) end end) end for i = 0, 3 do _G["CharacterBag"..i.."Slot"]:SetParent(holder) _G["CharacterBag"..i.."Slot"]:ClearAllPoints() if i==0 then _G["CharacterBag"..i.."Slot"]:SetPoint("BOTTOMRIGHT", holder, "TOPRIGHT", 0, 4) else _G["CharacterBag"..i.."Slot"]:SetPoint("CENTER", _G["CharacterBag"..(i-1).."Slot"], -30, 0) end _G["CharacterBag"..i.."Slot"]:SetAlpha(0) _G["CharacterBag"..i.."Slot"]:HookScript("OnEnter", function(self) for _, g in pairs(BagButtons) do g:SetAlpha(1) end end) _G["CharacterBag"..i.."Slot"]:HookScript("OnLeave", function(self) for _, g in pairs(BagButtons) do g:SetAlpha(0) end end) end local MoneyText = { _G["ContainerFrame1MoneyFrameGoldButtonText"], _G["ContainerFrame1MoneyFrameSilverButtonText"], _G["ContainerFrame1MoneyFrameCopperButtonText"], _G["BankFrameMoneyFrameGoldButtonText"], _G["BankFrameMoneyFrameSilverButtonText"], _G["BankFrameMoneyFrameCopperButtonText"], } for _, f in pairs(MoneyText) do f:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") end --[[ Show & Hide functions etc ]] tinsert(UISpecialFrames, bankholder) tinsert(UISpecialFrames, holder) local CloseBags = function() bankholder:Hide() holder:Hide() for i = 0, 11 do CloseBag(i) end end local CloseBags2 = function() bankholder:Hide() holder:Hide() end local OpenBags = function() for i = 0, 11 do OpenBag(i) end end local ToggleBags = function() if(IsBagOpen(0)) then CloseBankFrame() CloseBags() else OpenBags() end end for i = 1, 5 do hooksecurefunc(_G["ContainerFrame"..i], "Show", ReanchorButtons) hooksecurefunc(_G["ContainerFrame"..i], "Hide", CloseBags2) end hooksecurefunc(BankFrame, "Show", function() OpenBags() ReanchorBankButtons() end) hooksecurefunc(BankFrame, "Hide", CloseBags) ToggleBackpack = ToggleBags OpenAllBags = OpenBags --OpenAllBags = ToggleBags --OpenAllBags = F.dummy OpenBackpack = OpenBags CloseAllBags = CloseBags if Aero then Aero:RegisterFrames("aBagsHolder", "aBagsBankHolder") end |
|
06-09-11, 03:54 PM | #2 | |
Hi Haleth,
I've just looked through all the events over on wowpedia, and the only suggestion I can make is to create a frame and register for the event "BAG_CLOSED", and when this event fires have the frame onevent reset the values of firstopened and firstbankopened to 1. The reason I suggest this is because this events fires when a bag is removed from its bag slot and its fired for both bags and banks slots. Quoted from Wowpedia.org:
Lordy Last edited by Lordyfrb : 06-09-11 at 03:56 PM. Reason: Added Quote for wowpedia |
||
06-09-11, 04:43 PM | #3 |
Hi there, thanks for the advice. I'll try this and update with progress.
|
|
06-10-11, 02:05 PM | #4 |
That method didn't quite work out, however using a different method I almost got it to work. New bag buttons are appropriately moved - the only problem is that after killing bu.SetPoint, I need to find a way to make that function work again, because the already existing buttons need to move to make space for the new ones. Currently, they overlap.
This is my current code: Code:
-- aBags by Alza, modified. local F, C, L = unpack(select(2, ...)) --[[ Get the number of bag and bank container slots used ]] local function CheckSlots() if GetContainerNumSlots(4) == 0 then if GetContainerNumSlots(3) == 0 then if GetContainerNumSlots(2) == 0 then if GetContainerNumSlots(1) == 0 then return 1 else return 2 end else return 3 end else return 4 end else return 5 end end local function CheckBankSlots() return GetNumBankSlots() + 1 end local function GetColumns() return CheckSlots() + 4 end -- [[ Local stuff ]] local Spacing = 4 -- local Columns = 9 local BankColumns = 13 local _G = getfenv(0) local bu, con, col, row local buttons, bankbuttons = {}, {} local firstopened, firstbankopened = 1, 1 local needsmoving = true --[[ Function to move buttons ]] local MoveButtons = function(table, frame, columns) col, row = 0, 0 if needsmoving == true then for i = 1, #table do bu = table[i] bu.SetPoint = bu:SetPoint() bu:ClearAllPoints() bu:SetNormalTexture("") bu:SetPoint("TOPLEFT", frame, "TOPLEFT", col * (37 + Spacing) + 3, -1 * row * (37 + Spacing) - 3) bu.SetPoint = F.dummy 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)) * (37 + Spacing) + 19) frame:SetWidth(columns * 37 + Spacing * (columns - 1) + 6) needsmoving = false end col, row = 0, 0 end --[[ Bags ]] local holder = CreateFrame("Button", "aBagsHolder", UIParent) holder:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -49, 49) holder:SetFrameStrata("HIGH") holder:Hide() F.CreateBD(holder, .6) local ReanchorButtons = function() for f = 1, CheckSlots() do con = "ContainerFrame"..f if not _G[con].reskinned then _G[con]:EnableMouse(false) _G[con.."CloseButton"]:Hide() _G[con.."PortraitButton"]:EnableMouse(false) for i = 1, 7 do select(i, _G[con]:GetRegions()):SetAlpha(0) end _G[con].reskinned = true end for i = GetContainerNumSlots(f-1), 1, -1 do bu = _G[con.."Item"..i] if not bu.reskinned then bu:SetFrameStrata("HIGH") tinsert(buttons, bu) _G[con.."Item"..i.."Count"]:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") _G[con.."Item"..i.."Count"]:ClearAllPoints() _G[con.."Item"..i.."Count"]:SetPoint("TOP", bu, 0, -2) _G[con.."Item"..i.."IconTexture"]:SetTexCoord(.1,.9,.1,.9) _G[con.."Item"..i.."IconQuestTexture"]:SetTexture(C.media.questborder) _G[con.."Item"..i.."IconQuestTexture"]:SetVertexColor(1, 0, 0) _G[con.."Item"..i.."IconQuestTexture"]:SetTexCoord(0.05, .955, 0.05, .965) _G[con.."Item"..i.."IconQuestTexture"].SetTexture = F.dummy bu.reskinned = true end end end MoveButtons(buttons, holder, GetColumns()) holder:Show() end local money = _G["ContainerFrame1MoneyFrame"] money:SetFrameStrata("DIALOG") money:SetParent(holder) money:ClearAllPoints() money:SetPoint("BOTTOMRIGHT", holder, "BOTTOMRIGHT", 12, 2) local reset = CreateFrame("Frame") reset:RegisterEvent("BAG_CLOSED") reset:SetScript("OnEvent", function() needsmoving = true end) --[[ Bank ]] local bankholder = CreateFrame("Button", "aBagsBankHolder", UIParent) bankholder:SetFrameStrata("HIGH") bankholder:Hide() F.CreateBD(bankholder, .6) local ReanchorBankButtons = function() if(firstbankopened==1) then for f = 1, 28 do bu = _G["BankFrameItem"..f] bu:SetFrameStrata("HIGH") tinsert(bankbuttons, bu) end _G["BankFrame"]:EnableMouse(false) _G["BankCloseButton"]:Hide() for f = 1, 5 do select(f, _G["BankFrame"]:GetRegions()):SetAlpha(0) end for f = CheckSlots() + 1, CheckSlots() + CheckBankSlots(), 1 do con = "ContainerFrame"..f ban = "BankFrame" _G[con]:EnableMouse(false) _G[con.."CloseButton"]:Hide() _G[con.."PortraitButton"]:EnableMouse(false) for i = 1, 7 do select(i, _G[con]:GetRegions()):SetAlpha(0) end for i = GetContainerNumSlots(f-1), 1, -1 do bu = _G[con.."Item"..i] bu:SetFrameStrata("HIGH") tinsert(bankbuttons, bu) _G[con.."Item"..i.."Count"]:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") _G[con.."Item"..i.."Count"]:ClearAllPoints() _G[con.."Item"..i.."Count"]:SetPoint("TOP", bu, 0, -2) _G[con.."Item"..i.."IconTexture"]:SetTexCoord(.1,.9,.1,.9) _G[con.."Item"..i.."IconQuestTexture"]:SetTexture(C.media.questborder) _G[con.."Item"..i.."IconQuestTexture"]:SetVertexColor(1, 0, 0) _G[con.."Item"..i.."IconQuestTexture"]:SetTexCoord(0.05, .955, 0.05, .965) _G[con.."Item"..i.."IconQuestTexture"].SetTexture = F.dummy end for i = 1, 28 do bbu = _G[ban.."Item"..i] bbu:SetFrameStrata("HIGH") _G[ban.."Item"..i.."IconTexture"]:SetTexCoord(.1,.9,.1,.9) _G[ban.."Item"..i.."Count"]:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") _G[ban.."Item"..i.."Count"]:ClearAllPoints() _G[ban.."Item"..i.."Count"]:SetPoint("TOP", bbu, 0, -2) _G[ban.."Item"..i.."IconQuestTexture"]:SetTexture(C.media.questborder) _G[ban.."Item"..i.."IconQuestTexture"]:SetVertexColor(1, 0, 0) _G[ban.."Item"..i.."IconQuestTexture"]:SetTexCoord(0.05, .955, 0.05, .965) _G[ban.."Item"..i.."IconQuestTexture"].SetTexture = F.dummy end end MoveButtons(bankbuttons, bankholder, GetColumns() + 4) bankholder:SetPoint("BOTTOMRIGHT", "aBagsHolder", "BOTTOMLEFT", -10 , 0) firstbankopened = 0 end bankholder:Show() end local money = _G["BankFrameMoneyFrame"] money:SetFrameStrata("DIALOG") money:ClearAllPoints() money:SetPoint("BOTTOMRIGHT", bankholder, "BOTTOMRIGHT", 12, 2) --[[ Hiding misc. frames ]] _G["BankFramePurchaseInfo"]:Hide() _G["BankFramePurchaseInfo"].Show = F.dummy local BankBagButtons = { BankFrameBag1, BankFrameBag2, BankFrameBag3, BankFrameBag4, BankFrameBag5, BankFrameBag6, BankFrameBag7, } local BagButtons = { CharacterBag0Slot, CharacterBag1Slot, CharacterBag2Slot, CharacterBag3Slot, } for f = 1, 7 do _G["BankFrameBag"..f]:SetParent(bankholder) _G["BankFrameBag"..f]:ClearAllPoints() if f==1 then _G["BankFrameBag"..f]:SetPoint("BOTTOM", bankholder, "TOP", -120, 4) else _G["BankFrameBag"..f]:SetPoint("CENTER", _G["BankFrameBag"..f-1], 38, 0) end _G["BankFrameBag"..f]:SetAlpha(0) _G["BankFrameBag"..f]:HookScript("OnEnter", function(self) for _, g in pairs(BankBagButtons) do g:SetAlpha(1) end end) _G["BankFrameBag"..f]:HookScript("OnLeave", function(self) for _, g in pairs(BankBagButtons) do g:SetAlpha(0) end end) end for i = 0, 3 do _G["CharacterBag"..i.."Slot"]:SetParent(holder) _G["CharacterBag"..i.."Slot"]:ClearAllPoints() if i==0 then _G["CharacterBag"..i.."Slot"]:SetPoint("BOTTOMRIGHT", holder, "TOPRIGHT", 0, 4) else _G["CharacterBag"..i.."Slot"]:SetPoint("CENTER", _G["CharacterBag"..(i-1).."Slot"], -30, 0) end _G["CharacterBag"..i.."Slot"]:SetAlpha(0) _G["CharacterBag"..i.."Slot"]:HookScript("OnEnter", function(self) for _, g in pairs(BagButtons) do g:SetAlpha(1) end end) _G["CharacterBag"..i.."Slot"]:HookScript("OnLeave", function(self) for _, g in pairs(BagButtons) do g:SetAlpha(0) end end) end local MoneyText = { _G["ContainerFrame1MoneyFrameGoldButtonText"], _G["ContainerFrame1MoneyFrameSilverButtonText"], _G["ContainerFrame1MoneyFrameCopperButtonText"], _G["BankFrameMoneyFrameGoldButtonText"], _G["BankFrameMoneyFrameSilverButtonText"], _G["BankFrameMoneyFrameCopperButtonText"], } for _, f in pairs(MoneyText) do f:SetFont(C.media.font, 8, "OUTLINEMONOCHROME") end --[[ Show & Hide functions etc ]] tinsert(UISpecialFrames, bankholder) tinsert(UISpecialFrames, holder) local CloseBags = function() bankholder:Hide() holder:Hide() for i = 0, 11 do CloseBag(i) end end local CloseBags2 = function() bankholder:Hide() holder:Hide() end local OpenBags = function() for i = 0, 11 do OpenBag(i) end end local ToggleBags = function() if(IsBagOpen(0)) then CloseBankFrame() CloseBags() else OpenBags() end end for i = 1, 5 do hooksecurefunc(_G["ContainerFrame"..i], "Show", ReanchorButtons) hooksecurefunc(_G["ContainerFrame"..i], "Hide", CloseBags2) end hooksecurefunc(BankFrame, "Show", function() OpenBags() ReanchorBankButtons() end) hooksecurefunc(BankFrame, "Hide", CloseBags) ToggleBackpack = ToggleBags OpenAllBags = OpenBags --OpenAllBags = ToggleBags --OpenAllBags = F.dummy OpenBackpack = OpenBags CloseAllBags = CloseBags if Aero then Aero:RegisterFrames("aBagsHolder", "aBagsBankHolder") end So, essentially, does anyone know how I can 're-activate' a function after killing it? I know you can do it for function that don't require arguments, but for SetPoint I get an error for doing so. Edit: I got everything working. The only downside is that every button has its point set again every time the bags are opened because I can't figure out how to re-enable SetPoint after killing it. Last edited by Haleth : 06-11-11 at 06:48 AM. |
|
06-13-11, 07:30 AM | #5 |
I had this thread going, posted solution works fine for me
http://www.wowinterface.com/forums/s...ad.php?t=40305
__________________
|
|
06-13-11, 10:15 AM | #6 |
Hey there, thanks for the reply. That does indeed work, but I discovered there is one flaw if I were to use my method with your suggestion; the BAG_CLOSED event only triggers when a bag is removed or upgraded, but not when a new bag is added entirely.
I guess I'll just have to wipe the button table and call SetPoint on all of them every time the bags open. It's probably still more efficient than doing it on every BAG_UPDATE - the only other option, seeing as there is no specific event fired when a new bag is added. |
|
06-13-11, 11:10 AM | #7 |
Are you planning to release your(edited) bag addon as a standalone by chance?
__________________
Aggro Color to KG Panels Borders - Nibelheim Lua Based UI Hider - Nibelheim Custom LUA PowerText - Stuf - Nibelheim, Seerah |
|
06-13-11, 11:52 AM | #8 |
aBags is still at the core, so I can't claim it as my own. I just have permission to include it in my UI.
|
|
WoWInterface » Developer Discussions » Lua/XML Help » aBags help |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Linear Mode |
Switch to Hybrid Mode |
Switch to Threaded Mode |
|
|