Thread Tools Display Modes
04-20-14, 07:37 PM   #1
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
Chat Frame Window Detection [Solved]

For my addon it hooks functions for all chat frames.

My problem is when you create a new window from any source the functions arent hooked after load. So I know I need to hook them on the new frames. So I need help with the following:

1) Is there an event that fires upon creating a new chat frame that also passes the frame to hook the stuff that way?
2) How would I grab some sort of unique identifier to know that I am not setting up a second hook for the same frame. I would assume a hook set again will cause it to dup the functions tied to them.

Edit: For Future Reference I am doing the following:

<ChatFrame>.hooked = true

You can test it in wow by running:
/run ChatFrame1.hooked = true
/run print(_G["ChatFrame1"].hooked) --Will display true

Last edited by TULOA : 04-20-14 at 08:11 PM.
  Reply With Quote
04-20-14, 09:04 PM   #2
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
You should be able to just hook ChatFrame_OnLoad since it should only be called once per chat frame:
Code:
hooksecurefunc('ChatFrame_OnLoad', function(chatFrame)
    -- do stuff
end)
If you want to be extra sure not to hook the same chat frame twice:
Code:
local hooked = { }
hooksecurefunc('ChatFrame_OnLoad', function(chatFrame)
    if hooked[chatFrame] then return end
    hooked[chatFrame] = true
    -- do stuff
end)
  Reply With Quote
04-20-14, 10:32 PM   #3
TULOA
A Wyrmkin Dreamwalker
 
TULOA's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2009
Posts: 50
I hadn't thought about that but not long after I came up with a solution.

Adding a custom variable in the chat frame. The reason I chose this way is because if you delete a window and remake it its still counted 1 to NUM_CHAT_WINDOWS.

If you make a window it for example be ChatFrame2. When you delete it and make a new one it will technically be in the list still unless you hook the function if one is called on deletion. When you make another assuming it doesnt delete the addon would assume the frame is already hooked.

With my method when the frame is deleted the variable is gone as well. I was referring mainly on BNet Convos because they dont name themselves like the others. I get 's' for the name. I dont think it applies to addon created ones or others like that but I wasnt gonna take a risk and wanted a universal coding.
  Reply With Quote
04-21-14, 05:05 AM   #4
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Just process the normal chat frames normally, and hook the function that opens temporary windows. Here's what I do in my chat addon:

Code:
	for i = 1, NUM_CHAT_WINDOWS do
		self:ProcessFrame(_G["ChatFrame" .. i])
	end

	hooks.FCF_OpenTemporaryWindow = FCF_OpenTemporaryWindow
	FCF_OpenTemporaryWindow = function(...)
		local frame = hooks.FCF_OpenTemporaryWindow(...)
		self:ProcessFrame(frame)
		return frame
	end
Then my ProcessFrames function looks like this:

Code:
local frames = {}

function PhanxChat:ProcessFrame(frame)
	if frames[frame] then return end

	-- do all the stuff here

	frames[frame] = true
end
Since it stores a reference to the frame object itself, there's no need to add keys to the frame that could conceivably be removed, or match names, or anything else.
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Chat Frame Window Detection


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