View Single Post
12-23-16, 05:04 AM   #9
Aftermathhqt
A Molten Giant
 
Aftermathhqt's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 784
Originally Posted by tonyis3l33t View Post
https://github.com/tekkub/wow-ui-sou...ainerFrame.xml
https://github.com/tekkub/wow-ui-sou...ainerFrame.lua

As d87 pointed out, these ARE exactly where you should start STUDYING. This is how Blizzard themselves make the bags. ALL the functions in the lua will be needed to simply maintain the existing features. The .xml will also be needed unless you plan to convert it all manually into .lua code.
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:
  1. local function CheckSlots()
  2.     local numBags = 1
  3.     for i = 1, NUM_BAG_FRAMES do
  4.         local bagName = "ContainerFrame"..i+1
  5.         if _G[bagName]:IsShown() and not _G[bagName.."BackgroundTop"]:GetTexture():find("Bank") then
  6.             numBags = numBags + 1
  7.         end
  8.     end
  9.     return numBags
  10. end
  11.  
  12. local Spacing = 4
  13. local bu, con, bag, col, row
  14. local buttons, bankbuttons = {}, {}
  15.  
  16. local MoveButtons = function(table, frame, extraHeight)
  17.     local columns = ceil(sqrt(#table))
  18.     local iconSize = 32
  19.  
  20.     col, row = 0, 0
  21.     for i = 1, #table do
  22.         bu = table[i]
  23.         bu:ClearAllPoints()
  24.         bu:SetPoint("TOPLEFT", frame, "TOPLEFT", col * (iconSize + Spacing) + 3, -1 * row * (iconSize + Spacing) - 3)
  25.         if(col > (columns - 2)) then
  26.             col = 0
  27.             row = row + 1
  28.         else
  29.             col = col + 1
  30.         end
  31.     end
  32.  
  33.     frame:SetHeight((row + (col==0 and 0 or 1)) * (iconSize + Spacing) + 19 + (extraHeight or 0))
  34.     frame:SetWidth(columns * iconSize + Spacing * (columns - 1) + 6)
  35.     col, row = 0, 0
  36. end
  37.  
  38. local BagHolder = CreateFrame("Button", "BagsHolder", UIParent)
  39. BagHolder:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", -30, 30)
  40. BagHolder:SetFrameStrata("HIGH")
  41. BagHolder:Hide()
  42.  
  43. local ReanchorButtons = function()
  44.     table.wipe(buttons)
  45.     for f = 1, CheckSlots() do
  46.         con = "ContainerFrame"..f
  47.        
  48.         for i = GetContainerNumSlots(_G[con]:GetID()), 1, -1 do
  49.             bu = _G[con.."Item"..i]
  50.             tinsert(buttons, bu)
  51.         end
  52.     end
  53.  
  54.     MoveButtons(buttons, BagHolder)
  55.  
  56.     BagHolder:Show()
  57. end
  58.  
  59. local CloseBags = function()
  60.     BagHolder:Hide()
  61.     for i = 0, 11 do
  62.         CloseBag(i)
  63.     end
  64. end
  65.  
  66. local CloseBags2 = function()
  67.     BagHolder:Hide()
  68. end
  69.  
  70. local OpenBags = function()
  71.     for i = 0, 4 do
  72.         OpenBag(i)
  73.     end
  74. end
  75.  
  76. local ToggleBags = function()
  77.     if(IsBagOpen(0)) then
  78.         CloseBags()
  79.     else
  80.         OpenBags()
  81.     end
  82. end
  83.  
  84. for i = 1, 5 do
  85.     local bag = _G["ContainerFrame"..i]
  86.     hooksecurefunc(bag, "Show", ReanchorButtons)
  87.     hooksecurefunc(bag, "Hide", CloseBags2)
  88. end
  89.  
  90. ToggleBackpack = ToggleBags
  91. ToggleBag = ToggleBags
  92. OpenAllBags = OpenBags
  93. OpenBackpack = OpenBags
  94. CloseAllBags = CloseBags
  Reply With Quote