Go to Page... |
|
Thread Tools | Display Modes |
|
03-01-14, 05:47 PM | #1 |
:SetTexture() only works for abilities on actionbar.
I've been working on an AddOn that replaces the weapon icons temporary enchant frame to the icons of the weapon enchant.
The AddOn works fine, the only issue I've run into, is that I can only use the textures if I have the icons on my actionbar. This is the code I've been working with: Lua Code:
I'm relatively new at writing AddOns, so any tips or criticism is appreciated. |
|
03-01-14, 06:49 PM | #2 |
Try:
Code:
local _, class = UnitClass("player") if class ~= "ROGUE" and class ~= "SHAMAN" then return end local addonName = ... local tooltip = CreateFrame("GameTooltip", addonName .. "TempEnchantScanner", UIParent, "GameTooltipTemplate") tooltip:Hide() local tempEnchants if class == "ROGUE" then tempEnchants = { ["Mind-Numbing Poison"] = GetSpellTexture(5761), ["Crippling Poison"] = GetSpellTexture(3408), ["Paralytic Poison"] = GetSpellTexture(108215), ["Leeching Poison"] = GetSpellTexture(108211), ["Deadly Poison"] = GetSpellTexture(2823), ["Wound Poison"] = GetSpellTexture(8679), } elseif class == "SHAMAN" then tempEnchants = { ["Earthliving"] = GetSpellTexture(51730), ["Flametongue"] = GetSpellTexture(8024), ["Frostbrand"] = GetSpellTexture(8033), ["Rockbiter"] = GetSpellTexture(8017), ["Windfury"] = GetSpellTexture(8232), } end local tooltipLine = addonName .. "TempEnchantScannerTextLeft" tooltip:SetScript("OnTooltipSetItem", function(self) for lineNum = 1, self:NumLines() do local texture = tempEnchants[_G[tooltipLine .. lineNum]:GetText():match("^(.+) %(")] if texture then self.texture = texture return end end self.texture = nil end) hooksecurefunc("TemporaryEnchantFrame_Update", function(_, mainhand, _, _, offhand) if mainhand then tooltip:SetInventoryItem("player", 16) mainhand = tooltip.texture end if offhand then tooltip:SetInventoryItem("player", 17) offhand = tooltip.texture end if mainhand then if offhand then TempEnchant2Icon:SetTexture(mainhand) TempEnchant1Icon:SetTexture(offhand) else TempEnchant1Icon:SetTexture(mainhand) end elseif offhand then TempEnchant1Icon:SetTexture(offhand) end end) |
|
03-01-14, 07:29 PM | #3 |
There is also working code to provide exactly this feature in my addon PhanxBuffs; you're welcome to use it.
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
03-01-14, 07:35 PM | #4 |
Thanks, you've cleaned up my code a whole lot. Same issue still seems to persist though.
On my Enhancement Shaman, I use a macro to buff my weapons with Windfury Weapon and Flametongue Weapon, this macro uses the Windfury Weapon icon. The Windfury Weapon icon will be displayed on the right weapon and the Offhand's icon will be blank. It does give it the right texture, which I'm testing using :GetTexture(). As soon as I place Flametongue Weapon on my actionbars everything will work perfectly. I don't really know why... Are textures created when I place them on the actionbars and emptied again when you take them off? Last edited by wiMp : 03-01-14 at 07:45 PM. |
|
03-01-14, 10:56 PM | #5 |
Try using GetSpellInfo instead of GetSpellTexture.
Also, Vrul's code could be cleaned up a bit further: Code:
hooksecurefunc("TemporaryEnchantFrame_Update", function(_, mainhand, _, _, offhand) if mainhand then tooltip:SetInventoryItem("player", 16) (offhand and TempEnchant2Icon or TempEnchant1Icon):SetTexture(tooltip.texture) end if offhand then tooltip:SetInventoryItem("player", 17) TempEnchant1Icon:SetTexture(tooltip.texture) end end)
__________________
Retired author of too many addons. Message me if you're interested in taking over one of my addons. Don’t message me about addon bugs or programming questions. |
|
03-01-14, 11:35 PM | #6 |
I leveled a shaman to 10 so I could see what you were talking about and I can't explain why that is happening but here is something that works (on a level 10 shaman at least):
Code:
local _, class = UnitClass("player") if class ~= "ROGUE" and class ~= "SHAMAN" then return end local addonName = ... local tooltip = CreateFrame("GameTooltip", addonName .. "TempEnchantScanner", UIParent, "GameTooltipTemplate") tooltip:Hide() local tempEnchants if class == "ROGUE" then tempEnchants = { ["Mind-Numbing Poison"] = GetSpellTexture(5761), ["Crippling Poison"] = GetSpellTexture(3408), ["Paralytic Poison"] = GetSpellTexture(108215), ["Leeching Poison"] = GetSpellTexture(108211), ["Deadly Poison"] = GetSpellTexture(2823), ["Wound Poison"] = GetSpellTexture(8679), } elseif class == "SHAMAN" then tempEnchants = { ["Earthliving"] = GetSpellTexture(51730), ["Flametongue"] = GetSpellTexture(8024), ["Frostbrand"] = GetSpellTexture(8033), ["Rockbiter"] = GetSpellTexture(8017), ["Windfury"] = GetSpellTexture(8232), } end local tooltipText = setmetatable({ }, { __index = function(self, index) self[index] = _G[addonName .. "TempEnchantScannerTextLeft" .. index] return self[index] end }) tooltip:SetScript("OnTooltipSetItem", function(self) for index = 1, self:NumLines() do local texture = tempEnchants[tooltipText[index]:GetText():match("^(.+) %(")] if texture then self.texture = texture return end end self.texture = nil end) local enchant = { } for index = 1, NUM_TEMP_ENCHANT_FRAMES do enchant[index] = _G["TempEnchant" .. index] enchant[index].icon = _G["TempEnchant" .. index .. "Icon"] tooltip[index] = _G[addonName .. "TempEnchantScannerTexture" .. index] end hooksecurefunc("TemporaryEnchantFrame_Update", function() for index = 1, NUM_TEMP_ENCHANT_FRAMES do if enchant[index]:IsShown() then tooltip:SetInventoryItem("player", enchant[index]:GetID()) if tooltip.texture then tooltip[index]:SetTexture(tooltip.texture) -- ugly hack fix enchant[index].icon:SetTexture(tooltip.texture) end end end end) |
|
03-02-14, 01:37 AM | #7 |
Phanx, I've tried using GetSpellInfo() instead, but also same results.
Vrul, I really appreciate you going through all this effort to help me, but it's still not perfect. Here's some screenshots: 1, 2. Both the icons work if the weapon enchant is the same, if you're using two different ones though, only the one on TempEnchant2Icon sticks. |
|
03-03-14, 11:39 AM | #8 |
I just tried this with my lvl 13 shaman (don't has windfury right now):
Lua Code:
Result: texture is 'empty' (means GetTexture() returns the correct path but the texture is not visible). So I tried Lua Code:
Shows the texture as expected. (lvl 14 shaman has Flametongue) Then I tried Lua Code:
Result: TempEnchant1Icon shows the windfury texture. Last edited by Duugu : 03-03-14 at 12:25 PM. |
|
03-03-14, 01:26 PM | #9 |
Did the texture change for Flametongue Weapon without that spell being on an action bar somewhere?
I can get the Windfury Weapon icon to show up on my level 20 rogue's Sharpening Stone temp enchant if I want, it's just the way temp enchant icons seem to need the texture to be used elsewhere that is weird. It may have something to do with the texture being changed constantly OnUpdate as well because this works too: Code:
local _, class = UnitClass("player") if class ~= "SHAMAN" then return end local addonName = ... local tooltip = CreateFrame("GameTooltip", addonName .. "TempEnchantScanner", UIParent, "GameTooltipTemplate") tooltip:Hide() local tempEnchants = { ["Earthliving"] = GetSpellTexture(51730), ["Flametongue"] = GetSpellTexture(8024), ["Frostbrand"] = GetSpellTexture(8033), ["Rockbiter"] = GetSpellTexture(8017), ["Windfury"] = GetSpellTexture(8232), } local tooltipText = setmetatable({ }, { __index = function(self, index) self[index] = _G[addonName .. "TempEnchantScannerTextLeft" .. index] return self[index] end }) tooltip:SetScript("OnTooltipSetItem", function(self) for index = 1, self:NumLines() do local texture = tempEnchants[tooltipText[index]:GetText():gsub("%s*%(.-%)%s*", "")] if texture then self.texture = texture return end end self.texture = nil end) local function StopTexture(self, texture) self.inventoryTexture = texture end local enchant, SetTexture = { }, TempEnchant1Icon.SetTexture for index = 1, NUM_TEMP_ENCHANT_FRAMES do enchant[index] = _G["TempEnchant" .. index .. "Icon"] enchant[index].inventoryID = index + 15 enchant[index].SetTexture = StopTexture end hooksecurefunc("TemporaryEnchantFrame_Update", function() for index = 1, NUM_TEMP_ENCHANT_FRAMES do local enchant = enchant[index] if enchant:IsVisible() then tooltip:SetInventoryItem("player", enchant.inventoryID) local texture = tooltip.texture or enchant.inventoryTexture if enchant.texture ~= texture then enchant.texture = texture SetTexture(enchant, texture) end end end end) |
|
03-03-14, 01:30 PM | #10 | ||
This is the frames template: Code:
<Button name="AuraButtonTemplate" virtual="true"> <Size x="30" y="30"/> <Layers> <Layer level="BACKGROUND"> <Texture name="$parentIcon" nonBlocking="true"/> <FontString name="$parentCount" inherits="NumberFontNormal" parentKey="count"> <Anchors> <Anchor point="BOTTOMRIGHT"> <Offset> <AbsDimension x="-2" y="2"/> </Offset> </Anchor> </Anchors> </FontString> <FontString name="$parentDuration" inherits="GameFontNormalSmall" hidden="true" parentKey="duration"> <Anchors> <Anchor point="TOP" relativePoint="BOTTOM" /> </Anchors> </FontString> </Layer> </Layers> <Scripts> <OnEnter> GameTooltip:SetOwner(self, "ANCHOR_BOTTOMLEFT"); GameTooltip:SetFrameLevel(self:GetFrameLevel() + 2); GameTooltip:SetUnitAura(PlayerFrame.unit, self:GetID(), self.filter); </OnEnter> <OnLeave> GameTooltip:Hide(); </OnLeave> </Scripts> </Button> Last edited by Duugu : 03-03-14 at 01:33 PM. |
|||
03-03-14, 01:32 PM | #11 |
Why don't you just create a texture on top of the button and set that?
Nonblocking means it doesn't make the game wait for the texture to load before it continues doing other things. Last edited by semlar : 03-03-14 at 01:40 PM. |
|
03-03-14, 02:49 PM | #12 | |
nonBlocking="true" is the bad guy. Setting it to nil will fix the problem. Don't know why or what exactly wents wrong ... but the texture does show up. Just add Lua Code:
[e] I think the basic problem is like this: The code sets the texture on every onupdate - again and again. And nonBlocking="true" means the interface does not wait for the loading process to be finished. Which means the texture loading starts and before even a single line of the texture is loaded into the texture frame the loading process starts again. Which leads to a "empty" texture. If the icons texture is cached then the 'loading process' is fast enough to load it within a single onupdate into the texture frame. If it is not cached (if it was not shown before ... like with the actionbar) than it is not fast enough (the icon must be loaded from disk ... which is to slow to finish within a single onupdate timeframe). At least something like that. Last edited by Duugu : 03-03-14 at 03:14 PM. |
||
03-03-14, 03:23 PM | #13 |
Looks like it's solved Great!
I've edited Vrul's code to add the nonBlocking stuff, I've also removed the 'hack' that set the texture to the tooltip, because it's no longer necessary. Lua Code:
I really appreciate everyone for helping me out! Thanks! |
|
WoWInterface » Developer Discussions » Lua/XML Help » :SetTexture() only works for abilities on actionbar. |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|