04-24-17, 11:10 AM | #1 |
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) |
|
04-24-17, 12:31 PM | #2 |
I don't see where you check if a button already exists. Every OnEvent seems to trigger the creation of a new set of buttons for each specified item found.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-24-17 at 01:54 PM. |
|
04-24-17, 02:02 PM | #3 |
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:
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 Last edited by syncrow : 04-24-17 at 02:16 PM. |
|
04-24-17, 07:31 PM | #4 | |
This isn't the entire code. I am not trying to show or hide them in combat, there is an inCombat check for a button that shows or hides them all that does nothing in combat. They do indeed stack. to 20 as per itemStackCount = GetItemInfo() Thank you for taking the time. I appreciate it very much. Let me know if you have any ideas about creating them as a loop. Gah I really don;t want to make static tables for this ;/ |
||
04-24-17, 07:44 PM | #5 | |
Code:
if ((_G["BMUDButtonFS"..name])~=nil) then BMUDButton:SetNormalTexture(nil,"ARTWORK") BMUDButton:SetPushedTexture(nil,"ARTWORK") BMUDButton:SetHighlightTexture(nil,"ARTWORK") BMUDButtonFS:SetFormattedText("") end Yeah, BAG_UPDATE event fires a billion times and is more of a debugging event that i can use at a vendor to sell and rebuy my beacons to see if this works. Thanks for taking the time. Let me know if you think of anything else |
||
04-24-17, 08:42 PM | #6 | |
if BAG_UPDATE fires a billion times your code will have created a billion new buttons and fontstrings. Rather than this, you need to check if a button of the same name exists before you create a new one: Code:
local BMUDButton if not _G["BMUDButton"..name] then BMUDButton = CreateFrame("Button", "BMUDButton"..name, UIParent, "SecureActionButtonTemplate"); -- Create the extra bits here else BMUDButton = _G["BMUDButton"..name] -- reset the extra bits here end
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
||
04-24-17, 10:12 PM | #7 | ||
What do I do to reset the buttons? I have tried myriad solutions, none work.
Code:
_G["BMUDButton"..name]:SetNormalTexture(nil,"ARTWORK") _G["BMUDButton"..name]:SetPushedTexture(nil,"ARTWORK") _G["BMUDButton"..name]:SetHighlightTexture(nil,"ARTWORK") _G["BMUDButton"..name]:SetFormattedText("") |
|||
04-24-17, 10:30 PM | #8 |
Something like this:
Lua Code:
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.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-24-17 at 10:54 PM. |
|
04-24-17, 10:57 PM | #9 | |
This does exactly what I have already tried. It does not reset the text or the textures after the first creation. |
||
04-24-17, 11:13 PM | #10 |
See the last edit in the last post.
Make sure you're seeing what event last happened so you know if the button should or should not be visible. Change the bag code too: Code:
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) else print("Other Registered event", name) end
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-24-17 at 11:33 PM. |
|
04-24-17, 11:30 PM | #11 |
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.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. |
|
04-24-17, 11:48 PM | #12 | ||
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. |
|||
04-24-17, 11:51 PM | #13 |
As beacons do not stack and consume an inventory slot each, you don't have to care about stackCount at all.
So you can raise your beacon count by 1 every time that particular beacon is found. Why do you want to update the textures at all? The buttons are named by the beacons name, so they are not be recycled anyway. And a beacon's icon is static and doesn't get changed by blizzard. Last edited by syncrow : 04-25-17 at 12:01 AM. |
|
04-24-17, 11:54 PM | #14 |
That's what we're doing.
You may also be having trouble with positioning. If you /fstack over the buttons you'll probably find you have a bunch of "BMUDButton"..xxx buttons positioned over the top of each other. Edit: Thanks syncrow. You will need to keep a tally rather than just using the last itemCount value for the text. The recycle code Lua Code:
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-25-17 at 12:15 AM. |
|
04-25-17, 12:56 AM | #15 | |
I want to completely hide the button and have them collapse so that you do not have spaces where you do not have beacons. If I have two beacons I want to show them, If I then use one I want it to disappear. Then if I get a third one I want it to appear next to the one I still have, not leave a space and appear two or three icon spaces next to it, leaving empty space. |
||
04-25-17, 12:58 AM | #16 | |
-- BMUDButton points to a shiney new button or -- BMUDButton points to the previously created button I get the concept. What the hell is the syntax? What you have so far works great. But once I have a button and use it and no longer have the beacons, the button persists. No event will remove it. Any ideas? |
||
04-25-17, 01:16 AM | #17 |
This is what I pointed out previously, in edit admittedly so you may have missed it.
One idea. Keep a table of buttons as they are created (no pre-determined, fixed table needed), hide them all at the start of the event and only show the ones that actually have a count on any given pass. One idea, there may be better and it probably need refining.
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-25-17 at 01:25 AM. |
|
04-25-17, 01:39 AM | #18 | |
|
||
04-25-17, 01:41 AM | #19 |
This should handle hiding/showing (admitedly untested), collapsing/expanding would still have to be handled:
Lua Code:
There is now code that is surplus to requirements
__________________
Fizzlemizz Maintainer of Discord Unit Frames and Discord Art. Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus. Last edited by Fizzlemizz : 04-25-17 at 01:47 AM. |
|
04-25-17, 01:48 AM | #20 |
you could use "ContainerFrameItemButtonTemplate" instead of "SecureActionButtonTemplate".
pros:
cons:
Edit: I'm going to prepare some code and explanation for you later... currently at work!^^ Last edited by syncrow : 04-25-17 at 02:01 AM. |
|
WoWInterface » Developer Discussions » Lua/XML Help » Clear Button Texture and Text LUA Help |
«
Previous Thread
|
Next Thread
»
|
Thread Tools | |
Display Modes | |
|
|