Thread Tools Display Modes
12-04-10, 09:19 AM   #1
Xruptor
A Flamescale Wyrmkin
 
Xruptor's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 137
Cannot get Texture on Map to load properly

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
__________________
Click HERE for the ultimate idiot test.

if (sizeof(sadness) > sizeof(happiness)) { initDepression(); }

Last edited by Xruptor : 12-04-10 at 09:37 AM.
  Reply With Quote
12-04-10, 04:16 PM   #2
Xruptor
A Flamescale Wyrmkin
 
Xruptor's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 137
Anyone? No one has any ideas?
__________________
Click HERE for the ultimate idiot test.

if (sizeof(sadness) > sizeof(happiness)) { initDepression(); }
  Reply With Quote
12-04-10, 05:06 PM   #3
Sniffles
A Black Drake
 
Sniffles's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2010
Posts: 86
Maybe you should use hooksecurefunc.
  Reply With Quote
12-04-10, 09:16 PM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I don't know all the details, but the group icons module in Mapster (which is what your code is based on) was removed because it conflicted with the changes Blizzard made in Patch 4.0.1 and no longer added much/any functionality.

On a side note, I'm not sure how much of your code is from Mapster, but if it's more "based on" than "inspired by", you should probably make sure you have permission from Nevcairiel before releasing it. He likely won't mind, but the copyright notice at the top of the GroupIcons.lua file in Mapster is pretty clear that it's not open source.
  Reply With Quote
12-05-10, 07:26 AM   #5
Xruptor
A Flamescale Wyrmkin
 
Xruptor's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2005
Posts: 137
Originally Posted by Phanx View Post
I don't know all the details, but the group icons module in Mapster (which is what your code is based on) was removed because it conflicted with the changes Blizzard made in Patch 4.0.1 and no longer added much/any functionality.

On a side note, I'm not sure how much of your code is from Mapster, but if it's more "based on" than "inspired by", you should probably make sure you have permission from Nevcairiel before releasing it. He likely won't mind, but the copyright notice at the top of the GroupIcons.lua file in Mapster is pretty clear that it's not open source.
Thanks Phanx for your respose. Suffice to say it didn't really help me much as I was trying to implement a feature that was removed. Still it was kind of you to take your time to reply . I've have already sent a message to Nevcairiel per your advice.

This still brings up the issue that I'm trying to get resolved. If a solution is found I could possibly rewrite it. There has to be a solution to the issue rather then just ignoring it the problem. Which is why I requested help here in the first place. Thanks to all those that have replied so far.


@Zerpy: I already tried using hooksecurefunc it didn't really help as well as the same issue was occuring. It seems to be another function that is causing the issue. I believe it's WorldMapUnit_Update. But I'm not entirely sure. Still trying to figure a solution out.
__________________
Click HERE for the ultimate idiot test.

if (sizeof(sadness) > sizeof(happiness)) { initDepression(); }

Last edited by Xruptor : 12-05-10 at 07:44 AM. Reason: de evil grammer natzi
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Cannot get Texture on Map to load properly


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off