WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Clear Button Texture and Text LUA Help (https://www.wowinterface.com/forums/showthread.php?t=55351)

Dejablue 04-24-17 11:10 AM

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)


Fizzlemizz 04-24-17 12:31 PM

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.

syncrow 04-24-17 02:02 PM

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:
  1. local buttonSize = 36
  2. local padding = 0;
  3. local beacons = {
  4.     -- rares
  5.     [146923] = ""-- petrification
  6.     [147355] = ""-- bloodstrike
  7.     [146922] = ""-- fel growth
  8.     [146915] = ""-- greater Torment
  9.     [146912] = ""-- greater carnage
  10.     [146914] = ""-- greater engineering
  11.     [146910] = ""-- greater dominance
  12.     [146913] = ""-- greater warbeasts
  13.     [146911] = "",  -- greater firestorm
  14.    
  15.     -- uncommons
  16.     [146906] = "",  -- carnage
  17.     [146907] = "",  -- warbeasts
  18.     [146909] = "",  -- torment
  19.     [146908] = "",  -- engineering
  20.     [146903] = "",  -- dominance
  21.     [146905] = ""-- firestorm
  22. }
  23.  
  24. local function CreateButtons()
  25.     local index = 1;
  26.    
  27.     for itemID in pairs(beacons) do
  28.         local itemName, itemLink = GetItemInfo(itemID)
  29.        
  30.         if itemName then
  31.             local texture = select(10, GetItemInfo(itemID));
  32.             local button = CreateFrame("Button", "BMUDButton"..index, UIParent, "SecureActionButtonTemplate")
  33.             local xPos = -300 + ( (buttonSize + padding) * (index-1))
  34.            
  35.             button:SetSize(buttonSize, buttonSize)
  36.             button:SetPoint("CENTER", xPos, 0)
  37.             button:RegisterForClicks("AnyUp", "AnyDown")
  38.             button:SetAttribute("type", "item")
  39.             button:SetAttribute("item", itemName)
  40.  
  41.             button.fs = button:CreateFontString(nil, "OVERLAY", "GameTooltipText")
  42.             button.fs:SetPoint("BOTTOMRIGHT")
  43.             button.fs:SetFont("Fonts\\FRIZQT__.TTF", 14, "THINOUTLINE")
  44.             button.fs:SetTextColor(1, 1, 1)
  45.  
  46.             button:SetNormalTexture(texture)
  47.             button:SetPushedTexture(nil,"ARTWORK")
  48.             button:SetHighlightTexture(nil,"ARTWORK")
  49.            
  50.             button:HookScript("OnEnter", function(self)
  51.                 GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
  52.                 GameTooltip:SetHyperlink(itemLink)
  53.                 GameTooltip:Show()
  54.             end)
  55.             button:HookScript("OnLeave", GameTooltip_Hide)
  56.            
  57.             -- overwrite empty string with the button as a reference here
  58.             beacons[itemID] = button;
  59.         end
  60.        
  61.         index = index + 1;
  62.     end    
  63. end
  64.  
  65. local function UpdateCount()
  66.     for itemID, button in pairs(beacons) do
  67.         local itemName = GetItemInfo(itemID);
  68.         local count = 0;
  69.        
  70.         for bag = 0, 4 do
  71.             for slot = 1, GetContainerNumSlots(bag) do
  72.                 local item = GetContainerItemID(bag, slot);
  73.                
  74.                 -- found a beacon in your bag
  75.                 if itemID == item then
  76.                     count = count + 1
  77.                 end
  78.             end
  79.         end
  80.        
  81.         -- handle display
  82.         if count > 0 then
  83.             button.fs:SetText(count);
  84.             button:GetNormalTexture():SetDesaturated(false);
  85.         else
  86.             button.fs:SetText("");
  87.             button:GetNormalTexture():SetDesaturated(true);
  88.         end
  89.     end
  90. end
  91.  
  92. local frame = CreateFrame("Frame", "BeamMeUpDejaInitFrame", BeamMeUpDejaDragFrame)
  93.  
  94. frame:RegisterEvent("PLAYER_LOGIN")
  95. frame:SetScript("OnEvent", function(self, event, ...)
  96.     if event == "PLAYER_LOGIN" then
  97.         CreateButtons()
  98.         UpdateCount()
  99.         self:RegisterEvent("BAG_UPDATE")
  100.     end
  101.    
  102.     if event == "BAG_UPDATE" then
  103.         UpdateCount()
  104.     end
  105. 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

Dejablue 04-24-17 07:31 PM

Quote:

Originally Posted by syncrow (Post 323038)
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:
  1. local buttonSize = 36
  2. local padding = 0;
  3. local beacons = {
  4.     -- rares
  5.     [146923] = ""-- petrification
  6.     [147355] = ""-- bloodstrike
  7.     [146922] = ""-- fel growth
  8.     [146915] = ""-- greater Torment
  9.     [146912] = ""-- greater carnage
  10.     [146914] = ""-- greater engineering
  11.     [146910] = ""-- greater dominance
  12.     [146913] = ""-- greater warbeasts
  13.     [146911] = "",  -- greater firestorm
  14.    
  15.     -- uncommons
  16.     [146906] = "",  -- carnage
  17.     [146907] = "",  -- warbeasts
  18.     [146909] = "",  -- torment
  19.     [146908] = "",  -- engineering
  20.     [146903] = "",  -- dominance
  21.     [146905] = ""-- firestorm
  22. }
  23.  
  24. .....
  25.            
  26.         ....

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

My first inclination was to create a table listing them all, but I chose to try this method as a sort of exercise as well as wanting to create them dynamically as found in the bags without knowing their specific names. This would future proof it if Blizzard decided to make a beacon of Murlocs, for example. There are also epic boss ones and epic ones that you take to each broken shore game

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 ;/

Dejablue 04-24-17 07:44 PM

Quote:

Originally Posted by Fizzlemizz (Post 323035)
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.

This is the latest attempt in the OP code:

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 :)

Fizzlemizz 04-24-17 08:42 PM

Quote:

Originally Posted by Dejablue (Post 323042)
This is the latest attempt in the OP code:

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 :)

That code doesn't actually do anything because you're checking if a Fontstring you've just created exists, and it always will because, you've just created a new one, along with a new parent button.

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


Dejablue 04-24-17 10:12 PM

Quote:

Originally Posted by Fizzlemizz (Post 323043)
That code doesn't actually do anything because you're checking if a Fontstring you've just created exists, and it always will because, you've just created a new one, along with a new parent button.

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


Wouldn't I want to check if a button exists and then clear it and if it doesn't then create it?

What do I do to reset the buttons? I have tried myriad solutions, none work.


Quote:

BMUDButton:SetNormalTexture(nil,"ARTWORK")
BMUDButton:SetPushedTexture(nil,"ARTWORK")
BMUDButton:SetHighlightTexture(nil,"ARTWORK")
BMUDButtonFS:SetFormattedText("")
or

Code:

_G["BMUDButton"..name]:SetNormalTexture(nil,"ARTWORK")
_G["BMUDButton"..name]:SetPushedTexture(nil,"ARTWORK")
_G["BMUDButton"..name]:SetHighlightTexture(nil,"ARTWORK")
_G["BMUDButton"..name]:SetFormattedText("")


Fizzlemizz 04-24-17 10:30 PM

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.

Dejablue 04-24-17 10:57 PM

Quote:

Originally Posted by Fizzlemizz (Post 323045)
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.

Have you tired this in game?

This does exactly what I have already tried. It does not reset the text or the textures after the first creation.

Fizzlemizz 04-24-17 11:13 PM

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

With this, after a /reload will not show the button because a non BAG_UPDATE event is posted last when entering the world.

Fizzlemizz 04-24-17 11:30 PM

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.

Dejablue 04-24-17 11:48 PM

Quote:

Originally Posted by Fizzlemizz (Post 323045)
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.

Quote:

Originally Posted by Fizzlemizz (Post 323048)
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.

syncrow 04-24-17 11:51 PM

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.

Fizzlemizz 04-24-17 11:54 PM

Quote:

Originally Posted by Dejablue (Post 323049)
Any way to recycle the frames? Hmmm.

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:
  1. local BMUDButton
  2. if not _G["BMUDButton"..name] then -- Button does not exist so create it
  3.     BMUDButton = CreateFrame("Button", "BMUDButton"..name, UIParent, "SecureActionButtonTemplate");
  4.     -- BMUDButton points to a shiney new button
  5. else
  6.     BMUDButton = _G["BMUDButton"..name]
  7.     -- BMUDButton points to the previously created button
  8. end

Dejablue 04-25-17 12:56 AM

Quote:

Originally Posted by syncrow (Post 323050)
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.

They do stack: http://i.imgur.com/46uZkI1.jpg

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.

Dejablue 04-25-17 12:58 AM

Quote:

Originally Posted by Fizzlemizz (Post 323051)
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:
  1. local BMUDButton
  2. if not _G["BMUDButton"..name] then -- Button does not exist so create it
  3.     BMUDButton = CreateFrame("Button", "BMUDButton"..name, UIParent, "SecureActionButtonTemplate");
  4.     -- BMUDButton points to a shiney new button
  5. else
  6.     BMUDButton = _G["BMUDButton"..name]
  7.     -- BMUDButton points to the previously created button
  8. end

I understand this. however I do not understand what you put in place of :

-- 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?

Fizzlemizz 04-25-17 01:16 AM

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.

Dejablue 04-25-17 01:39 AM

Quote:

Originally Posted by Fizzlemizz (Post 323055)
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.

Cool idea. I'll play with that and see what I come up with. Thanks :)

Fizzlemizz 04-25-17 01:41 AM

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

There is now code that is surplus to requirements ;)

syncrow 04-25-17 01:48 AM

you could use "ContainerFrameItemButtonTemplate" instead of "SecureActionButtonTemplate".

pros:
  • clickability to use items
  • non secure (prevents taint)
  • can handle show / hide / positioning even while in combat

cons:
  • you have to create a header for each button (but thats fairly easy to achieve)

Edit: I'm going to prepare some code and explanation for you later... currently at work!^^


All times are GMT -6. The time now is 08:18 PM.

vBulletin © 2020, Jelsoft Enterprises Ltd
© 2004 - 2020 MMOUI