View Single Post
04-24-14, 11:36 AM   #3
Digital_Utopia
A Flamescale Wyrmkin
 
Digital_Utopia's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2012
Posts: 110
Originally Posted by semlar View Post
I would strongly recommend against overwriting the ZoomOut function because that is going to taint the world map.

You're also changing the behavior of ZoomOut to the point where it won't function correctly.

If ZoomOut is called from a map other than the current one, you're setting it to the current map then calling ZoomOut, so it will only ever switch to the map above the current one, and you aren't returning anything (it's supposed to return whether it can zoom out or not).
I honestly would prefer if it didn't seem that I had to do this, and if someone has a better way, I'm certainly all ears; but every time ZONE_CHANGED_NEW_AREA fires, this addon checks whether or not the player is in a MicroDungeon, and if so - calls ZoomOut. Which, in turn, fires off another ZCNA event.

This means, that for every ZCNA event, while inside a microdungeon, the first call to GetCurrentMapAreaID will deliver the correct mapID, while subsequent ones will all return the zoomed out mapID.

My first attempt was to use hooksecurefunc on ZoomOut, which would at least let me know when ZoomOut was called; but since it's a post-hook, the ZCNA event would already fire, and calling SetMapToCurrentZone would result in a tug of war of sorts with this other addon.

Basically, on the hook function, I'd call SetMapToCurrentZone, which would fire the ZCNA event, which the other addon would respond to, by calling ZoomOut, which would get hooked, and the entire process repeats indefinitely.

By pre-hooking/overriding, I can get the information I should be able to get, allow the other addons to do their own thing, and ignore the results of their actions.

But thanks for pointing out the issues with the above. Neither WoWpedia or wowprogramming.com mentioned a return value for ZoomOut; but that was easy enough to address. The second issue, regarding the altering of the map where the ZoomOut would be called on, was also an oversight. While I'd hope that other addons aren't going to strong-arm a map change, I understand that it's fairly common to traverse the map while it's hidden, to get one-time information - something I don't want to interfere with.

So, the result is as such:

Code:
local zo=_G.ZoomOut;
function ZoomOut()
	if(not WorldMapFrame:IsVisible())then
		local z =GetCurrentMapAreaID()
		SetMapToCurrentZone()
		local z2 = GetCurrentMapAreaID();
		local dl,x1,y1,x2,y2=GetCurrentMapDungeonLevel();
		map:updateInfo(GetCurrentMapAreaID(),dl)
		local mn, tw, th, imd, mdn = GetMapInfo()
		indoors=imd;
		zoomChanged=true;
		if(z~=z2)then
			SetMapByID(z);
		end
	end
	return zo();
end
__________________
  Reply With Quote