Hey all,
This help request is in reference to my addon
XanMapIcons.
I've been trying to figure this bug out for a few days now for one of my addons. Normally I like to figure things out for myself as I learn this way from trial and error. However, I will admit this bug has me completely stumped. It was working fine before cataclysm but now it's just something I can't pinpoint what is causing the problem. I've search all through Blizzards API and can't seem to figure out what the problem is.
Here is what is happening:
- The player POI texture gets distorted, solid texture. Sometimes this happens and sometimes it doesn't.
- For some reason the texture keeps blinking. Almost like somewhere somehow blizzard is modifying the TexCoords.
- I've tried forcing the TexCoords but they get reset somehow.
- I've tried clearing the texture and setting my own texture. GetTexture will always return the texture I loaded. So it's not being overridden anywhere.
- I've tried setting the VertexColor in different formats, nothing seems to work.
- Party icons will just keep blinking on and off with the texture. The solid texture sometimes displays.
If you put the following code under f:UpdateIcon(icon, unit, frm) at the very bottom the texture mysteriously appears correctly even though the textcoords were already set and are virtually the same. Though this causes the blinking problem.
Code:
icon:SetTexCoord( 0, 1, 0, 1 )
I really am at a loss here. Maybe someone can see something that I'm missing. It's probably something really really stupid. Though I can't seem to see it.
Note: Ive tried several other solutions that I can't even recall anymore. I've been at this for some time already.
It BLINKS between these two images constantly.
here is a picture of sometimes the distorted picture on the left occurs
Code:
--This mod is heavily inspired by the Group Icons found in the Mapster Mod.
--I wanted the functionality of the group icons without having to have Mapster installed.
--Full credit where due to Hendrik "Nevcairiel" Leppkes for his addon Mapster.
local _G = _G
local RAID_CLASS_COLORS = RAID_CLASS_COLORS
local UnitClass = UnitClass
local GetRaidRosterInfo = GetRaidRosterInfo
local UnitAffectingCombat = UnitAffectingCombat
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local f = CreateFrame("frame","XanMapIcons",UIParent)
f:SetScript("OnEvent", function(self, event, ...) if self[event] then return self[event](self, event, ...) end end)
local WORLD_MAP = 0
local BATTLEFIELD_MAP = 1
local SIZE_WORLDMAP = 24
local SIZE_BATTLEMAP = 16
local BATTLEFIXED = false
----------------------
-- Enable --
----------------------
function f:PLAYER_LOGIN()
if IsAddOnLoaded("Blizzard_BattlefieldMinimap") and not BATTLEFIXED then
f:FixMapUnits(BATTLEFIELD_MAP, true, SIZE_BATTLEMAP)
BATTLEFIXED = true
end
f:FixMapUnits(WORLD_MAP, true, SIZE_WORLDMAP)
--replace the worldmapunit function
WorldMapUnit_Update = f.WorldMapUnit_Update;
self:UnregisterEvent("PLAYER_LOGIN")
self.PLAYER_LOGIN = nil
local ver = GetAddOnMetadata("XanMapIcons","Version") or '1.0'
DEFAULT_CHAT_FRAME:AddMessage(string.format("|cFF99CC33%s|r [v|cFFDF2B2B%s|r] Loaded", "XanMapIcons", ver or "1.0"))
end
------------------------------
-- Handlers --
------------------------------
function f:ADDON_LOADED(event, addon)
if addon == "Blizzard_BattlefieldMinimap" and not BATTLEFIXED then
self:UnregisterEvent("ADDON_LOADED")
f:FixMapUnits(BATTLEFIELD_MAP, true, SIZE_BATTLEMAP)
BATTLEFIXED = true
end
end
function f:WorldMapUnit_Update()
local unit = self.unit or self.name
local icon = self.icon
if unit and icon then
f:UpdateIcon(icon, unit, self)
end
end
------------------------------
-- Icon Functions --
------------------------------
function f:SetIcon(unit, switch, state, size, isNormal)
local frm = _G[unit]
local icon = frm.icon
if state then
frm:SetWidth(size)
frm:SetHeight(size)
icon:SetWidth(size)
icon:SetHeight(size)
frm.elapsed = 0.5
frm:SetScript('OnUpdate', function(self, elapsed)
self.elapsed = self.elapsed - elapsed
if self.elapsed <= 0 then
self.elapsed = 0.5
XanMapIcons:UpdateIcon(self.icon, self.unit, self)
end
end)
frm:SetScript("OnEvent", nil)
if isNormal then
icon:SetTexture("Interface\\AddOns\\XanMapIcons\\Icons\\Normal")
end
else
if switch == WORLD_MAP then
frm:SetWidth(16)
frm:SetHeight(16)
icon:SetWidth(16)
icon:SetHeight(16)
else
frm:SetWidth(12)
frm:SetHeight(12)
icon:SetWidth(12)
icon:SetHeight(12)
end
frm.elapsed = nil
frm:SetScript("OnUpdate", nil)
frm:SetScript("OnEvent", WorldMapUnit_OnEvent)
icon:SetVertexColor(1, 1, 1)
icon:SetTexCoord( 0, 1, 0, 1 )
icon:SetTexture("Interface\\WorldMap\\WorldMapPartyIcon")
end
end
function f:FixMapUnits(switch, state, size)
if switch == WORLD_MAP then
for i = 1, 4 do
f:SetIcon(string.format("WorldMapParty%d", i), switch, state, size, true)
end
for i = 1,40 do
f:SetIcon(string.format("WorldMapRaid%d", i), switch, state, size)
end
elseif switch == BATTLEFIELD_MAP then
if BattlefieldMinimap then
for i = 1, 4 do
f:SetIcon(string.format("BattlefieldMinimapParty%d", i), switch, state, size, true)
end
for i = 1, 40 do
f:SetIcon(string.format("BattlefieldMinimapRaid%d", i), switch, state, size)
end
end
end
end
function f:UpdateIcon(icon, unit, frm)
if not (icon and unit) then return end
local _, fileName = UnitClass(unit)
if not fileName then return end
if string.find(unit, "raid", 1, true) then
local _, _, subgroup = GetRaidRosterInfo(string.sub(unit, 5))
if not subgroup then return end
icon:SetTexture(string.format("Interface\\AddOns\\XanMapIcons\\Icons\\Group%d", subgroup))
end
--set colors, flash if in combat
local t = RAID_CLASS_COLORS[fileName]
if (GetTime() % 1 < 0.5) then
if UnitAffectingCombat(unit) then
icon:SetVertexColor(0.8, 0, 0) --red flash, unit in combat
elseif UnitIsDeadOrGhost(unit) then
icon:SetVertexColor(0.2, 0.2, 0.2) --grey for dead units
elseif PlayerIsPVPInactive(unit) then
icon:SetVertexColor(0.5, 0.2, 0.8) --purple for inactives
end
elseif t then
icon:SetVertexColor(t.r, t.g, t.b) --class color
else
icon:SetVertexColor(0.8, 0.8, 0.8) --grey for default
end
end
------------------------
-- LOADER --
------------------------
if IsLoggedIn() then
f:PLAYER_LOGIN()
else
f:RegisterEvent("PLAYER_LOGIN")
f:RegisterEvent("ADDON_LOADED")
end