Something like this:
Lua Code:
--Beam Me Up Deja Initialization Frame
local Ecount
local Rcount
local Ucount
local BeamMeUpDejaInitFrame = CreateFrame("Frame", "BeamMeUpDejaInitFrame", BeamMeUpDejaDragFrame)
BeamMeUpDejaInitFrame:RegisterEvent("PLAYER_LOGIN")
BeamMeUpDejaInitFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
BeamMeUpDejaInitFrame:RegisterEvent("LOOT_OPENED")
BeamMeUpDejaInitFrame:RegisterEvent("BAG_UPDATE")
BeamMeUpDejaInitFrame:SetScript("OnEvent", function(self, event, ...)
Ecount = 0
Rcount = 0
Ucount = 0
for bag = 0, 4, 1 do
for slot=1, GetContainerNumSlots(bag), 1 do
local name = GetContainerItemLink(bag,slot)
if name and string.find(name,"Sentinax Beacon") then
--if name and string.find(name,"Hearthstone") then
--ddebug()
local _, itemCount = GetContainerItemInfo(bag, slot)
local itemName, itemLink, itemRarity,_,_,_,_,itemStackCount,_,itemTexture,_ = GetItemInfo(name)
--print(name, itemName,itemStackCount)--Debugging
local texture = select(10,GetItemInfo(name))
local w = 36
local h = 36
local x
local y = 0
if itemRarity == 4 then
--print("Ecount is "..Ecount)--Debugging
x = (Ecount*w)*1.1
y = h*2.1
Ecount = Ecount+1
end
if itemRarity == 3 then
--print("Rcount is "..Rcount)--Debugging
x = (Rcount*w)*1.1
y = h*1.1
Rcount = Rcount+1
end
if itemRarity == 2 then
--print("Ucount is "..Ucount)--Debugging
x = (Ucount*w)*1.1
Ucount = Ucount+1
end
local BMUDButton
if not _G["BMUDButton"..name] then -- Button does not exist so create it
BMUDButton = CreateFrame("Button", "BMUDButton"..name, UIParent, "SecureActionButtonTemplate");
BMUDButton.Label = BMUDButton:CreateFontString("$parent_FontString","OVERLAY")
BMUDButton:RegisterForClicks("AnyUp", "AnyDown")
BMUDButton:SetPoint("CENTER",x,y+32)
BMUDButton:SetSize(w,h)
BMUDButton.Label:SetPoint("BOTTOMRIGHT", BMUDButton)
BMUDButton.Label:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE")
BMUDButton.Label:SetTextColor(1, 1, 1);
BMUDButton:SetAttribute("type","item")
BMUDButton:SetAttribute("item",itemName)
BMUDButton:HookScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetHyperlink(name)
GameTooltip:Show()
end)
BMUDButton:HookScript("OnLeave", function(self) GameTooltip:Hide() end)
else -- Button exists so reset to default state
BMUDButton = _G["BMUDButton"..name]
BMUDButton:SetNormalTexture(nil)
BMUDButton:SetPushedTexture(nil)
BMUDButton:SetHighlightTexture(nil)
BMUDButton.Label:SetText("")
end
if event == "BAG_UPDATE" then -- only set textures and text for this event
BMUDButton.Label:SetFormattedText("%.0f", itemCount)
BMUDButton:SetNormalTexture(itemTexture)
BMUDButton:SetPushedTexture(itemTexture)
BMUDButton:SetHighlightTexture(itemTexture)
print("Bag updated:", name)
end
end
end
end
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.