You're code re-creates your buttons constantly, which would cause massive error junk when you loot beacons right in combat....
It would be much better to pre-create all necessary buttons and only handle the count text upon bag updates.
Here is a little example on how it would look like:
Lua Code:
local buttonSize = 36
local padding = 0;
local beacons = {
-- rares
[146923] = "", -- petrification
[147355] = "", -- bloodstrike
[146922] = "", -- fel growth
[146915] = "", -- greater Torment
[146912] = "", -- greater carnage
[146914] = "", -- greater engineering
[146910] = "", -- greater dominance
[146913] = "", -- greater warbeasts
[146911] = "", -- greater firestorm
-- uncommons
[146906] = "", -- carnage
[146907] = "", -- warbeasts
[146909] = "", -- torment
[146908] = "", -- engineering
[146903] = "", -- dominance
[146905] = "", -- firestorm
}
local function CreateButtons()
local index = 1;
for itemID in pairs(beacons) do
local itemName, itemLink = GetItemInfo(itemID)
if itemName then
local texture = select(10, GetItemInfo(itemID));
local button = CreateFrame("Button", "BMUDButton"..index, UIParent, "SecureActionButtonTemplate")
local xPos = -300 + ( (buttonSize + padding) * (index-1))
button:SetSize(buttonSize, buttonSize)
button:SetPoint("CENTER", xPos, 0)
button:RegisterForClicks("AnyUp", "AnyDown")
button:SetAttribute("type", "item")
button:SetAttribute("item", itemName)
button.fs = button:CreateFontString(nil, "OVERLAY", "GameTooltipText")
button.fs:SetPoint("BOTTOMRIGHT")
button.fs:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE")
button.fs:SetTextColor(1, 1, 1)
button:SetNormalTexture(texture)
button:SetPushedTexture(nil,"ARTWORK")
button:SetHighlightTexture(nil,"ARTWORK")
button:HookScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
GameTooltip:SetHyperlink(itemLink)
GameTooltip:Show()
end)
button:HookScript("OnLeave", GameTooltip_Hide)
-- overwrite empty string with the button as a reference here
beacons[itemID] = button;
end
index = index + 1;
end
end
local function UpdateCount()
for itemID, button in pairs(beacons) do
local itemName = GetItemInfo(itemID);
local count = 0;
for bag = 0, 4 do
for slot = 1, GetContainerNumSlots(bag) do
local item = GetContainerItemID(bag, slot);
-- found a beacon in your bag
if itemID == item then
count = count + 1
end
end
end
-- handle display
if count > 0 then
button.fs:SetText(count);
button:GetNormalTexture():SetDesaturated(false);
else
button.fs:SetText("");
button:GetNormalTexture():SetDesaturated(true);
end
end
end
local frame = CreateFrame("Frame", "BeamMeUpDejaInitFrame", BeamMeUpDejaDragFrame)
frame:RegisterEvent("PLAYER_LOGIN")
frame:SetScript("OnEvent", function(self, event, ...)
if event == "PLAYER_LOGIN" then
CreateButtons()
UpdateCount()
self:RegisterEvent("BAG_UPDATE")
end
if event == "BAG_UPDATE" then
UpdateCount()
end
end)
The buttons in this example are static and do not hide / show themselves properly, but this is further secure wrapping....
PS: beacons are not stackable, as far as i'm aware