View Single Post
06-28-21, 01:08 PM   #13
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,871
I not sure what the intended final outcome is over and above what can be achieved with the regular bags or, whether part of what you are doing is because you're figuring things out so, this is a guess at a possibilty of what you might be looking for (all your code included with bits commented out. Based on Default UI bags no bag addons).

Lua Code:
  1. -- Button
  2. --[[
  3. local BB = CreateFrame("Button","FBags_BagButton",UIParent,"SecureActionButtonTemplate")
  4. BB:SetPoint("CENTER", UIParent, "CENTER",0,500)
  5. BB:SetSize(50, 50)
  6. local ButtonTexture = BB:CreateTexture("ButtonTexture", "BACKGROUND")
  7. ButtonTexture:SetTexture("Interface\\Buttons\\Button-Backpack-Up")
  8. ButtonTexture:SetPoint("CENTER","FBags_BagButton","CENTER")
  9. ButtonTexture:SetSize(50, 50)
  10. BB:SetScript("OnClick", function(self)
  11.     FB:SetShown(not FB:IsShown())
  12.     print("Bag Clicked")
  13. end)
  14. BB:RegisterEvent("PLAYER_ENTERING_WORLD")
  15. ]]--
  16.  
  17.  
  18. FB = CreateFrame("Button","FBags",ContainerFrame1, "ActionButtonTemplate")
  19. FB:SetFrameStrata("BACKGROUND")
  20. FB:SetPoint("CENTER", UIParent, "CENTER",-400,300)
  21. FB:SetSize(50, 50)
  22. --FB:Hide() -- Parenting will do the show/hide
  23. FB:RegisterEvent("PLAYER_ENTERING_WORLD")
  24. FB:SetScript("OnEvent", function(self)
  25.     self:UnregisterEvent("PLAYER_ENTERING_WORLD")
  26.     -- Bag Layout
  27.     for bagid = 1,4 do
  28.         for bagslot = 1,GetContainerNumSlots(bagid) do
  29.         local icon, itemCount, locked,  ContItemQuality, readable, lootable, ContItemLink, isFiltered, noValue, ContItemID = GetContainerItemInfo(bagid, bagslot)
  30.         local SlotFrame = CreateFrame("Button", "Bag"..bagid.."Slot"..bagslot, FB,"SecureActionButtonTemplate, ActionButtonTemplate",100*bagid+bagslot)
  31.  
  32.         SlotFrame:SetSize(40,40)
  33.         SlotFrame:SetPoint("TOP",FB,"BOTTOM",40*bagslot,-40*bagid)
  34.  
  35.         SlotFrame:RegisterEvent("BAG_UPDATE")
  36.         SlotFrame:RegisterEvent("ITEM_LOCKED")
  37.         SlotFrame:RegisterEvent("ITEM_UNLOCKED")
  38.         SlotFrame:RegisterForClicks("AnyUp")
  39.  
  40.             -- to use items
  41.         SlotFrame:SetAttribute("type2", "item")
  42.         SlotFrame:SetAttribute("bag", bagid)
  43.         SlotFrame:SetAttribute("slot", bagslot)
  44.  
  45.  
  46.             -- adding a texture, text, cooldown
  47.         local texture = SlotFrame:CreateTexture("Bag"..bagid.."Slot"..bagslot.."Texture", "BACKGROUND")
  48.         local text = SlotFrame:CreateFontString("Bag"..bagid.."Slot"..bagslot.."Text", "OVERLAY")
  49.         text:SetFont("Fonts\\FRIZQT___CYR.TTF", 12, "OUTLINE")
  50.         text:SetPoint("BOTTOMRIGHT",SlotFrame,"BOTTOMRIGHT")
  51.         local cooldown = CreateFrame("Cooldown", "Bag"..bagid.."Slot"..bagslot.."Cooldown", SlotFrame, "CooldownFrameTemplate")
  52.         cooldown:SetAllPoints()
  53.  
  54.             -- widget scripts
  55.             -- Tooltip
  56.         SlotFrame:SetScript("OnEnter", function()
  57.             GameTooltip:SetOwner(SlotFrame, "ANCHOR_CURSOR")
  58.             GameTooltip:SetBagItem(bagid, bagslot); -- SetBagItem(bagid, bagslot)
  59.             GameTooltip:Show()
  60.         end)
  61.  
  62.         SlotFrame:SetScript("OnLeave", function()
  63.             GameTooltip:Hide()
  64.         end)
  65.  
  66.             -- Item moving
  67.         SlotFrame:SetScript("OnMouseUp", function(self, button)
  68.             local CursorItem, CursorItemID, CursorItemLink = GetCursorInfo()
  69.             local x = GetMouseFocus():GetID()
  70.             local b = (x-x%100)/100
  71.             local s = x%100
  72.             local icon1, itemCount1, locked1, quality1, readable1, lootable1, itemLink1, isFiltered1, noValue1, ContItemID1 = GetContainerItemInfo(b, s)
  73.             if not (b == 0 and s == 0) then
  74.             if button == "LeftButton" then
  75.                 if GetContainerItemInfo(b, s) and not GetCursorInfo() then
  76.                 PickupContainerItem(b, s)
  77.                 print("Picking up bag "..b.." slot "..s.." using "..button)
  78.                 elseif GetCursorInfo() and not GetContainerItemInfo(b, s) then
  79.                 PickupContainerItem(b, s)
  80.                 print("Putting down bag "..b.." slot "..s.." using "..button)
  81.                 elseif not GetCursorInfo() and not GetContainerItemInfo(b, s) then
  82.                 print("Nothing to pick up")
  83.                 elseif ContItemID1 == 82800 then
  84.                 PickupContainerItem(b, s)
  85.                 print("Putting down bag "..b.." slot "..s.." using "..button)
  86.                 elseif CursorItemID == ContItemID1 then
  87.                 ClearCursor()
  88.                 print("Same cell, putting down")
  89.                 elseif CursorItemID ~= ContItemID1 then
  90.                 PickupContainerItem(b, s)
  91.                 print("Filled cell, swapping")
  92.                 end
  93.             end
  94.             end
  95.         end)
  96.  
  97.  
  98.             -- Bag Update, cooldowns, icons
  99.         local function eventHandler(self, event, ...)
  100.             local icon, itemCount, locked, quality, readable, lootable, itemLink, isFiltered, noValue, itemID = GetContainerItemInfo(bagid, bagslot)
  101.             local startTime, duration, isEnabled = GetContainerItemCooldown(bagid, bagslot)
  102.             if event == "BAG_UPDATE" then
  103.             if GetContainerItemInfo(bagid, bagslot) then
  104.                 if duration>0 then
  105.                 cooldown:SetCooldown(startTime,duration)
  106.                 print("cooldown started in "..bagid.." "..bagslot)
  107.                 else
  108.                 cooldown:SetCooldown(0,0)
  109.                 end
  110.                 texture:SetTexture(icon)
  111.                 texture:SetPoint("CENTER","Bag"..bagid.."Slot"..bagslot,"CENTER")
  112.                 texture:SetSize(40, 40)
  113.                 if itemCount>1 then
  114.                 text:SetText(itemCount)
  115.                 else
  116.                 text:SetText(nil)
  117.                 end
  118.             else
  119.                 texture:SetTexture("Interface\\BUTTONS\\UI-Slot-Background.blp")
  120.                 texture:SetPoint("CENTER","Bag"..bagid.."Slot"..bagslot,"CENTER",11,-10)
  121.                 texture:SetSize(60, 60)
  122.                 text:SetText()
  123.                 cooldown:SetCooldown(0,0)
  124.             end
  125.             end
  126.         end
  127.         SlotFrame:SetScript("OnEvent", eventHandler);
  128.         end
  129.     end
  130. end)
  131.  
  132. -- "OpenBackpack" "CloseBackpack" "ToggleBackpack" "CloseAllBags" "OpenAllBags" "ToggleAllBags"
  133. -- hook functions
  134. --[[
  135. hooksecurefunc(  -- Parenting will do th show/hide
  136.     "CloseAllBags",function()
  137.         if FB:IsShown() then
  138.             FB:Hide()
  139.         end
  140.         print("CloseAllBags hookedfunction fired")
  141.     end
  142. )
  143.  
  144. hooksecurefunc(
  145.     "ToggleAllBags",function()
  146.         FB:SetShown(not FB:IsShown())
  147.         print("ToggleAllBags hookedfunction fired")
  148.     end
  149. )
  150. ]]--

Edit: Maybe you're looking to do somthing similar to AutoBar?
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-28-21 at 01:58 PM.
  Reply With Quote