Quantcast
WoWInterface - View Single Post - Clear Button Texture and Text LUA Help
View Single Post
04-24-17, 11:10 AM   #1
Dejablue
A Wyrmkin Dreamwalker
 
Dejablue's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 55
Clear Button Texture and Text LUA Help

I am making an addon that creates buttons for the Sentinax beacons in your bags. I have it complete, except I cannot figure out how to iteratively clear and then refresh the button texture and text (for item count).

Maybe I am using the wrong template and or am missing something obvious. I always have trouble with refreshing text.

Here is code that works in game, you can copy/paste into a test addon, and it puts the buttons on your screen in the middle. Head to a vendor and sell a beacon, or go in the field and loot some. It will make new frames fine. But if the count changes it wont clear the previous text so there is, for example, a 2 on top of a 3 when you use it. The same is true for the textures.

Any help is appreciated.

Cheers!


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
					
					BMUDButton = CreateFrame("Button", "BMUDButton"..name, UIParent, "SecureActionButtonTemplate");
					_G["BMUDButton"..name] = BMUDButton

					BMUDButtonFS = BMUDButton:CreateFontString("FontString","OVERLAY","GameTooltipText")
					_G["BMUDButtonFS"..name] = BMUDButtonFS					

					if ((_G["BMUDButtonFS"..name])~=nil) then
						BMUDButton:SetNormalTexture(nil,"ARTWORK")
						BMUDButton:SetPushedTexture(nil,"ARTWORK")
						BMUDButton:SetHighlightTexture(nil,"ARTWORK")
						BMUDButtonFS:SetFormattedText("")
					end

						BMUDButton:RegisterForClicks("AnyUp", "AnyDown")
						BMUDButton:ClearAllPoints()
						BMUDButton:SetPoint("CENTER",x,y+32)
						BMUDButton:SetSize(w,h)
					
						BMUDButtonFS:SetPoint("BOTTOMRIGHT", BMUDButton)
						BMUDButtonFS:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE")
						--BMUDButtonFS:SetShadowOffset(1, -1)--Optional
						BMUDButtonFS:SetTextColor(1, 1, 1);
						--print(name, itemCount)--Debugging
						BMUDButton:SetAttribute("type","item")
						BMUDButton:SetAttribute("item",itemName)

						if event == "BAG_UPDATE" then
							BMUDButtonFS:SetFormattedText("%.0f", itemCount)
							BMUDButton:SetNormalTexture(itemTexture)
							BMUDButton:SetPushedTexture(itemTexture)
							BMUDButton:SetHighlightTexture(itemTexture)
							print("Bag updated")
						end
					BMUDButton:HookScript("OnEnter", function(self)
						GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
						GameTooltip:SetHyperlink(name)
						GameTooltip:Show()
					end)
					BMUDButton:HookScript("OnLeave", function(self) GameTooltip:Hide() end)
				end
			end 
		end
	end)
  Reply With Quote