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:
This doesn't really relate to the question I guess, but the onupdate code is: Lua Code:
Thanks in advance for any possible guidance :) Aanson |
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.
|
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 = {} |
Thanks very much. The event filtering function is just what I'm after.
|
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?
|
Do what ravagernl suggested several posts up:
Code:
local lastR, lastG, lastB |
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 :) |
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.
|
Yeah, I like the idea of simply hooking ChatFrame_MessageEventHandler too. I think I may be able to accomplish everything with that one hook. I'll put something together and find out.
|
Quote:
|
Quote:
I should have said all this in my initial post, but (although I know that event filtering can be used for other things) the feature I'm adding doesn't need to filter chat messages (in-fact, it doesn't even need to know the content of the message). It's simply an alert feature for when a particular type of message is received. A sound will be played and the chat button will 'pulse' the colour of the chat message. It also auto-undocks the chat window (this is all dependent on user settings). When I say auto-undock, I'm not referring to undocking a ChatFrame from GENERAL_CHAT_DOCK. It's a feature of my chat module which essentially allows the user to show/hide all chat frames within GENERAL_CHAT_DOCK with a hotkey. In order to work properly, the function requires: 1. A guarantee that the message will actually be displayed. 2. The event (firstly so that I can get the message event category via CHAT_CATEGORY_LIST which I can then compare to user preferences and secondly, so that I can get the r, g, b values for the message). 3. The chat frame(s) on which the message will be displayed. After a good bit of experimentation, I have eventually settled on just hooking each chat frame's 'OnEvent' handler. To avoid unnecessary processing (to prevent the code from being read for config/system events), the first line of the hooked function is: Lua Code:
I've found that this works well, because due to the system already implemented in Bliz's ChatFrame.lua, each particular event will only fire for chat frames which are registered to receive them. I know that if I added a filter, I could retrieve the channel name (arg9) and work out which frames receive that channel, but I'm hoping that that won't be necessary. The obvious downside to hooking OnEvent is that my function will bypass not only the user-created filters, but also MessageEventHandler which will result in false positives. I'm going to be testing it a lot to see what kind of impact this has. Just so you know, I don't think for a second that this is the perfect way to handle what I'm attempting to achieve so any suggestions which encompass all of the function's requirements above are always welcome. |
Chat filter functions receives the [chat]frame as the first argument and also MessageEventHandler is called as a result of OnEvent, so I don't believe you gain anything by hooking OnEvent directly.
|
What if AddMessage is called like this:
Code:
:AddMessage("|cffff0000Hello.|r") |
Quote:
|
Quote:
The only relevant colour is the one which has been chosen by the user to represent the chat type being displayed. Your example would default to Channel1 which would not be monitored. |
Quote:
|
Quote:
|
Quote:
|
I'm pretty sure that I've found a good way of getting everything I need now, using Ravagernl's suggestion.
Lua Code:
That way I have a guarantee that the message will actually be displayed. It should be reliable because self.lastEvent will always be obtained immediately before AddMessage gets called. Cheers all :) |
Quote:
Anyhoo, I've sorted it now. |
All times are GMT -6. The time now is 01:22 PM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI