Thread Tools Display Modes
02-14-14, 08:34 PM   #1
pelf
Sentient Plasmoid
 
pelf's Avatar
Premium Member
Join Date: May 2008
Posts: 133
Alright, I see the reason for both, now. I just got thrown off by the talk about "the color used by the last message" instead of just looking up the color once you have the chat type.

Incidentally, what is the chat type of a message that gets added like this?
Code:
DEFAULT_CHAT_FRAME:AddMessage("Hello, world.")
Does is it end up as "SAY", even though it isn't?

@Phanx
After ChatTypeGroup is defined, a reverse lookup table is created called ChatTypeGroupInverted. Couldn't that be used instead of the one you created in your code? The output is the key into ChatTypeInfo, so I assume it could be.
  Reply With Quote
02-14-14, 09:04 PM   #2
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Originally Posted by pelf View Post
Alright, I see the reason for both, now. I just got thrown off by the talk about "the color used by the last message" instead of just looking up the color once you have the chat type.

Incidentally, what is the chat type of a message that gets added like this?
Code:
DEFAULT_CHAT_FRAME:AddMessage("Hello, world.")
Does is it end up as "SAY", even though it isn't?

@Phanx
After ChatTypeGroup is defined, a reverse lookup table is created called ChatTypeGroupInverted. Couldn't that be used instead of the one you created in your code? The output is the key into ChatTypeInfo, so I assume it could be.
I'm not sure what it would default to actually.

I'd just assumed that Phanx had written it that way to avoid global table lookups all the time.
__________________
__________________
  Reply With Quote
02-15-14, 08:00 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by pelf View Post
Incidentally, what is the chat type of a message that gets added like this?
Code:
DEFAULT_CHAT_FRAME:AddMessage("Hello, world.")
It doesn't have a type. Adding a message directly does not trigger any event handlers.

Originally Posted by pelf View Post
After ChatTypeGroup is defined, a reverse lookup table is created called ChatTypeGroupInverted. Couldn't that be used instead of the one you created in your code? The output is the key into ChatTypeInfo, so I assume it could be.
Ah, I missed that. Yes, that will work.

Also, I've realized that using only a filter could "alert" on messages that aren't actually added to the frame (due to being removed by another filter). If you want to account for that possibility, you could use an AddMessage hook in conjunction with a filter, but you'd want to be a little smarter about it than just assuming the last event seen by the filter was related to the current message.

Code:
local lastGroup = {}

local ChatTypeGroupInverted = ChatTypeGroupInverted
ChatFrame_AddMessageEventFilter(function(frame, event, ...)
     lastGroup[frame] = ChatTypeGroupInverted[event]
end)

local function AddMessage(frame, message, r, g, b)
     local group = lastGroup[frame]
     lastGroup[frame] = nil
     if not group or not MONITORED_EVENTS[group] or not frame.isDocked then return end

     local color = ChatTypeInfo[group]
     if r == color.r and g == color.g and b == color.b then
          -- check group against your settings and flash if desired
     end
end

for i = 1, 10 do
     local frame = _G["ChatFrame"..i]
     hooksecurefunc(frame, "AddMessage", AddMessage)
end
Still not foolproof, but better than no checking at all. Also note that your MONITORED_EVENTS table would need to be changed to hold chat groups (eg. the keys in ChatTypeInfo) rather than all the individual events... if you actually want to let users pick and choose individual events instead of whole groups, just set event as the value in the filter, and do the ChatTypeGroupInverted lookup to find the group (to find the color) in the AddMessage hook after the return check.
__________________
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
02-17-14, 04:28 PM   #4
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Originally Posted by Phanx View Post
Also, I've realized that using only a filter could "alert" on messages that aren't actually added to the frame (due to being removed by another filter). If you want to account for that possibility, you could use an AddMessage hook in conjunction with a filter, but you'd want to be a little smarter about it than just assuming the last event seen by the filter was related to the current message.
Yeah, that was my concern when I initially dealt with it via filters. My other concern was that filters are checked quite early on in CF_MEH and the message could potentially (albeit a slim chance) get filtered out later on during the function.

Thanks for that example code and for the advice Phanx. I'll get stuck into it now.
__________________
__________________
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Chat message colours


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