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:
local f = CreateFrame('GameTooltip', 'tempEnchantScanner', UIParent, 'GameTooltipTemplate')
f:SetOwner(UIParent, 'ANCHOR_NONE')
local _, playerClass = UnitClass("player")
local tempEnchants
if playerClass == "SHAMAN" then
tempEnchants = {
["Earthliving"] = GetSpellTexture(51730),
["Flametongue"] = GetSpellTexture(8024),
["Frostbrand"] = GetSpellTexture(8033),
["Rockbiter"] = GetSpellTexture(8017),
["Windfury"] = GetSpellTexture(8232),
}
elseif playerClass == "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),
}
end
local function getTempEnchantTextureOnSlotId(slotid)
local found
f:SetInventoryItem("player",slotid)
for i = 1,f:NumLines() do
local text = _G["tempEnchantScannerTextLeft"..i]:GetText()
for k,v in pairs(tempEnchants) do
if strmatch(text,k) then
found = v
end
end
end
return found
end
hooksecurefunc('TemporaryEnchantFrame_Update', function(self,...)
local mh,_,_,oh = ...
local mhtexture = getTempEnchantTextureOnSlotId(16)
local ohtexture = getTempEnchantTextureOnSlotId(17)
if mh and oh and mhtexture and ohtexture then
TempEnchant2Icon:SetTexture(mhtexture)
TempEnchant1Icon:SetTexture(ohtexture)
elseif mh and not oh and mhtexture then
TempEnchant1Icon:SetTexture(mhtexture)
elseif oh and not mh and ohtexture then
TempEnchant1Icon:SetTexture(ohtexture)
end
end)
I'm relatively new at writing AddOns, so any tips or criticism is appreciated.