Reply
 
Thread Tools Display Modes
Old 11-06-05, 03:13 PM   #1
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
Hooking a hooked function (tooltips specifically)

I've seen a few posts on hooking and such and they have all worked just fine. Unfortunately, I haven't seen any covering or how to deal with functions that are already hooked by another mod. What I'm trying to do is hook the UnitFrame_OnEnter function, so that I can let my mod have some TipBuddy support. The mod I'm working on is a unit frame mod so I need to have a custom UnitFrame_OnEnter for each frame (such as target, party1, party2, etc) unless there is a simple way of sending the UnitFrame_OnEnter function a specific this.unit value, in which case, screw the hooking. My most recent attempt looks like this.

Code:
local Original_UnitFrame_OnEnter = nil;

function Perl_Target_Tooltip_Hook()
	Original_UnitFrame_OnEnter = UnitFrame_OnEnter;
	UnitFrame_OnEnter = Perl_Target_Replacement_UnitFrame_OnEnter;
end

function Perl_Target_Tooltip_Unhook()
	UnitFrame_OnEnter = Original_UnitFrame_OnEnter;
end

function Perl_Target_Replacement_UnitFrame_OnEnter()	-- Taken from 1.8 UnitFrame_OnEnter()
	this.unit = "target";  --this is the whole reason i'm doing the hook, this one variable
	if ( SpellIsTargeting() ) then
		if ( SpellCanTargetUnit(this.unit) ) then
			SetCursor("CAST_CURSOR");
		else
			SetCursor("CAST_ERROR_CURSOR");
		end
	end

	GameTooltip_SetDefaultAnchor(GameTooltip, this);
	-- If showing newbie tips then only show the explanation
	if ( SHOW_NEWBIE_TIPS == "1" and this:GetName() ~= "PartyMemberFrame1" and this:GetName() ~= "PartyMemberFrame2" and this:GetName() ~= "PartyMemberFrame3" and this:GetName() ~= "PartyMemberFrame4") then
		if ( this:GetName() == "PlayerFrame" ) then
			GameTooltip_AddNewbieTip(PARTY_OPTIONS_LABEL, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_PARTYOPTIONS);
			return;
		elseif ( UnitPlayerControlled("target") and not UnitIsUnit("target", "player") and not UnitIsUnit("target", "pet") ) then
			GameTooltip_AddNewbieTip(PLAYER_OPTIONS_LABEL, 1.0, 1.0, 1.0, NEWBIE_TOOLTIP_PLAYEROPTIONS);
			return;
		end
	end
	
	if ( GameTooltip:SetUnit(this.unit) ) then
		this.updateTooltip = TOOLTIP_UPDATE_TIME;
	else
		this.updateTooltip = nil;
	end

	this.r, this.g, this.b = GameTooltip_UnitColor(this.unit);
	--GameTooltip:SetBackdropColor(this.r, this.g, this.b);
	GameTooltipTextLeft1:SetTextColor(this.r, this.g, this.b);
end
Then I just call UnitFrame_OnEnter(); in the OnEnter section in the XML and the hook works fine, but when I do this I end up breaking TipBuddy's hook it appears. Any ideas on how to do this correctly would be greatly appreciated.
Global is offline   Reply With Quote
Old 11-06-05, 04:25 PM   #2
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 770
You will have to call

Original_UnitFrame_OnEnter()

in your replacement to get it to work.

other options would be to chance tipbuddy's TOC file to make your's a dependency, which would be all in all a fairly bad idea if you plan to distrubite this.

Only thing else that comes to mind is to add support for TipBuddy, where if its present that you hook its funciton instead of the default one. IE's TipBuddy's Original UnitFrame OnEnter.
__________________
WowAce.com & CurseForge.com Adminstrator
Developer of Ace3, OneBag3, and many other addons and libraries
Project lead and Mac developer for the Curse Client

Anyone that needs what they want
And doesn't want what they need
I want nothing to do with
Kaelten is offline   Reply With Quote
Old 11-06-05, 04:46 PM   #3
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
See, the thing is, I don't want to call the original ever because i need to set this:

this.unit = "target";

If i could somehow set this.unit in the unitframe_onenter i'd be gold. Without setting that value I just get the unit is not set error. I know it's possible since other unit frames like discord can do it, but it's hard to dig through all the more complicated code to find the few lines that do it.
Global is offline   Reply With Quote
Old 11-06-05, 04:49 PM   #4
Kaelten
Jack's raging bile duct
 
Kaelten's Avatar
Featured
Join Date: May 2005
Posts: 770
well you could actually hook the script using Set/GetScript()

problem is tha tunless you call the parent hook, you're going to have the incompatibiliity problem, or your going to have to have special code for eveything else.
__________________
WowAce.com & CurseForge.com Adminstrator
Developer of Ace3, OneBag3, and many other addons and libraries
Project lead and Mac developer for the Curse Client

Anyone that needs what they want
And doesn't want what they need
I want nothing to do with
Kaelten is offline   Reply With Quote
Old 11-06-05, 05:05 PM   #5
Global
A Flamescale Wyrmkin
 
Global's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2005
Posts: 95
I'm not familiar with Set/GetScript() so I'll have to take a look at it and get back to you.
Global is offline   Reply With Quote
Reply

Go BackWoWInterface » Developer Discussions » Lua/XML Help » Hooking a hooked function (tooltips specifically)

Thread Tools
Display Modes

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