View Single Post
04-24-17, 11:48 PM   #12
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 58
Originally Posted by Fizzlemizz View Post
Something like this:

Lua Code:
  1. --Beam Me Up Deja Initialization Frame
  2.    
  3. local Ecount
  4. local Rcount
  5. local Ucount
  6.  
  7. local BeamMeUpDejaInitFrame = CreateFrame("Frame", "BeamMeUpDejaInitFrame", BeamMeUpDejaDragFrame)
  8.     BeamMeUpDejaInitFrame:RegisterEvent("PLAYER_LOGIN")
  9.     BeamMeUpDejaInitFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
  10.     BeamMeUpDejaInitFrame:RegisterEvent("LOOT_OPENED")
  11.     BeamMeUpDejaInitFrame:RegisterEvent("BAG_UPDATE")
  12.    
  13.     BeamMeUpDejaInitFrame:SetScript("OnEvent", function(self, event, ...)
  14.         Ecount = 0
  15.         Rcount = 0
  16.         Ucount = 0 
  17.         for bag = 0, 4, 1 do
  18.             for slot=1, GetContainerNumSlots(bag), 1 do
  19.                 local name = GetContainerItemLink(bag,slot)
  20.                 if name and string.find(name,"Sentinax Beacon") then
  21.                 --if name and string.find(name,"Hearthstone") then
  22.                     --ddebug()
  23.                     local _, itemCount = GetContainerItemInfo(bag, slot)
  24.                     local itemName, itemLink, itemRarity,_,_,_,_,itemStackCount,_,itemTexture,_ = GetItemInfo(name)
  25.                         --print(name, itemName,itemStackCount)--Debugging
  26.                     local texture = select(10,GetItemInfo(name))
  27.                     local w = 36
  28.                     local h = 36
  29.                     local x
  30.                     local y = 0
  31.                     if itemRarity == 4 then
  32.                         --print("Ecount is "..Ecount)--Debugging
  33.                         x = (Ecount*w)*1.1
  34.                         y = h*2.1
  35.                         Ecount = Ecount+1
  36.                     end
  37.                     if itemRarity == 3 then
  38.                         --print("Rcount is "..Rcount)--Debugging
  39.                         x = (Rcount*w)*1.1
  40.                         y = h*1.1
  41.                         Rcount = Rcount+1
  42.                     end
  43.                     if itemRarity == 2 then
  44.                         --print("Ucount is "..Ucount)--Debugging
  45.                         x = (Ucount*w)*1.1
  46.                         Ucount = Ucount+1
  47.                     end
  48.                     local BMUDButton
  49.                     if not _G["BMUDButton"..name] then -- Button does not exist so create it
  50.                         BMUDButton = CreateFrame("Button", "BMUDButton"..name, UIParent, "SecureActionButtonTemplate");
  51.                         BMUDButton.Label = BMUDButton:CreateFontString("$parent_FontString","OVERLAY")
  52.                         BMUDButton:RegisterForClicks("AnyUp", "AnyDown")
  53.                         BMUDButton:SetPoint("CENTER",x,y+32)
  54.                         BMUDButton:SetSize(w,h)
  55.                         BMUDButton.Label:SetPoint("BOTTOMRIGHT", BMUDButton)
  56.                         BMUDButton.Label:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE")
  57.                         BMUDButton.Label:SetTextColor(1, 1, 1);
  58.                         BMUDButton:SetAttribute("type","item")
  59.                         BMUDButton:SetAttribute("item",itemName)
  60.                         BMUDButton:HookScript("OnEnter", function(self)
  61.                                 GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  62.                                 GameTooltip:SetHyperlink(name)
  63.                                 GameTooltip:Show()
  64.                             end)
  65.                         BMUDButton:HookScript("OnLeave", function(self) GameTooltip:Hide() end)
  66.                     else -- Button exists so reset to default state
  67.                         BMUDButton = _G["BMUDButton"..name]
  68.                         BMUDButton:SetNormalTexture(nil)
  69.                         BMUDButton:SetPushedTexture(nil)
  70.                         BMUDButton:SetHighlightTexture(nil)
  71.                         BMUDButton.Label:SetText("")
  72.  
  73.                     end
  74.                     if event == "BAG_UPDATE" then -- only set textures and text for this event
  75.                         BMUDButton.Label:SetFormattedText("%.0f", itemCount)
  76.                         BMUDButton:SetNormalTexture(itemTexture)
  77.                         BMUDButton:SetPushedTexture(itemTexture)
  78.                         BMUDButton:SetHighlightTexture(itemTexture)
  79.                         print("Bag updated:", name)
  80.                     end
  81.                 end
  82.             end
  83.         end
  84.     end)

EDIT: If the textures aren't going to change for each button then you wouldn't need to set them to nil and then re-set them, just the text value.
This also doesn't cover buttons created for beacons you no longer have. This would require either keeping a table of buttons created or checking for buttons created for beacons you don't have.
Originally Posted by Fizzlemizz View Post
Just as a note, the code will only show the number of beacons of a type in the last bag slot with that type inspected. I haven't really played 7.2 so if you can only hold one beacon in a slot or you can have more than one slot with one type of beacon, then you will only ever see one or the quantity in the last slot checked holding the item.
Making headway. The text does update.

Now to work on getting the textures to update after BAG_UPDATE like they do with a UI reload.

Thanks for the help. Any ideas on textures? Is that not possible becasue frames persist until reload? Any way to recycle the frames? Hmmm.
  Reply With Quote