Thread Tools Display Modes
12-25-13, 10:13 PM   #1
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Chat message colours

Hey all, Happy Christmas!

Just a quick question...

Does anyone know of a simple way to obtain the colour of the most recently shown text in the ChatFrames?

I have a function in my addon which makes a frame 'pulse' when a new message is received, kinda like:

Lua Code:
  1. ChatButton.Pulse = function(self)
  2.   self.fadeStep = ( (self.pulseIntensity * 2) / (self.pulseDuration * GetFramerate()) );
  3.   self.isFading = nil;
  4.   self.pulseTexture:SetTexture(1, 1, 1); -- [color="Red"]to match chatType colour[/color]
  5.   return ( self.pulseIsEnabled and (not self.alpha) ) and self:SetScript("OnUpdate", self.OnUpdate);
  6. end

This doesn't really relate to the question I guess, but the onupdate code is:

Lua Code:
  1. ChatButton.OnUpdate = function(self)
  2.   self.alpha = self.isFading and ( (self.alpha or 0) - self.fadeStep ) or ( (self.alpha or 0) + self.fadeStep );
  3.   if ( (self.alpha >= 0) and (self.alpha <= self.pulseIntensity) ) then
  4.     return self.pulseTexture:SetAlpha(self.alpha);
  5.   elseif self.isFading then
  6.     self.alpha, self.fadeStep, self.isFading = nil, nil, nil;
  7.     return self:SetScript("OnUpdate", nil);
  8.   end
  9.   self.alpha, self.isFading = self.pulseIntensity, true;
  10. end

Thanks in advance for any possible guidance

Aanson
__________________
__________________
  Reply With Quote
12-26-13, 03:59 AM   #2
ravagernl
Proceritate Corporis
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 1,176
It depends on what messages you want to listen to. If you don't care about what is added, just do a hook on ChatFrame:AddMessage.
  Reply With Quote
12-26-13, 04:41 AM   #3
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you need to know the actual message type (rather than just what color the message was printed in) you will need to either (a) use chat filters or (b) hook ChatFrame_MessageEventHandler. Both suffer from the same problem, in that both will get you every single chat message, whether or not it's set to show in a specific frame, or any frame, so you'll have to figure that out yourself.

Code:
local eventToCategory = {}

local function SaveLastMessageType(frame, event, ...)
	local category = eventToCategory[event]
	-- This maps eg. "CHAT_MSG_PARTY_LEADER" to "PARTY"
	-- which you can look up in ChatTypeInfo etc.
	
	-- Insert code here to figure out whether this frame
	-- should display this category, and return out if not.
	
	frame.lastMessageType = category
	-- Now you can reference this value in your other scripts.
end

for category, events in pairs(CHAT_CATEGORY_LIST) do
	for i = 1, #events do
		local event = "CHAT_MSG_" .. events[i]
		eventToCategory[event] = category
		ChatFrame_RegisterMessageEventFilter(event, SaveLastMessageType)
	end
end
__________________
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
12-30-13, 08:46 AM   #4
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Thanks very much. The event filtering function is just what I'm after.
__________________
__________________
  Reply With Quote
02-06-14, 07:36 PM   #5
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
Out of interest, see if I was just looking for the colour used for the last message, is there a simple way of going about that?
__________________
__________________
  Reply With Quote
02-07-14, 04:13 AM   #6
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Do what ravagernl suggested several posts up:

Code:
local lastR, lastG, lastB
hooksecurefunc(ChatFrame1, "AddMessage", function(self, message, r, g, b, ...)
     lastR, lastG, lastB = r or 1, g or 1, b or 1
end)
__________________
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-08-14, 01:12 PM   #7
Aanson
A Flamescale Wyrmkin
Join Date: Aug 2009
Posts: 124
That's great to know, thanks.

I need to know the message type (ChatTypeInfo) and the Chat Frame it was posted to.

I can hook the AddMessage function of each ChatFrame to establish the latter.

Cheers
__________________
__________________

Last edited by Aanson : 02-08-14 at 01:13 PM. Reason: Typo
  Reply With Quote
02-08-14, 09:54 PM   #8
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
If you need that, just use a filter function, as in the code I'd posted previously; you can get the color from ChatTypeInfo, as detailed in the comments in that code. You do not need to hook multiple functions and deal with tracking messages between them.
__________________
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 » 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