diff --git a/README.md b/README.md index ee50776..9a43515 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,9 @@ For a detailed view of what's new and improved, check out the feature list below - **Chat History** *Save chat history of all non-combatlog windows and restore it on login.* +- **Chat Timestamps** + *Add timestamps to chat messages.* + - **Center Text Input Box** *Move the chat input box to the center of the screen.* diff --git a/ShaguTweaks-extras.toc b/ShaguTweaks-extras.toc index d957186..3ae14d2 100644 --- a/ShaguTweaks-extras.toc +++ b/ShaguTweaks-extras.toc @@ -35,6 +35,7 @@ mods\worldmap-reveal.lua mods\chat-input-center.lua mods\chat-history.lua mods\chat-text-shadow.lua +mods\chat-timestamps.lua # raid frames mods\raid.lua diff --git a/mods/chat-timestamps.lua b/mods/chat-timestamps.lua new file mode 100644 index 0000000..cf7774f --- /dev/null +++ b/mods/chat-timestamps.lua @@ -0,0 +1,43 @@ +local _G = ShaguTweaks.GetGlobalEnv() +local T = ShaguTweaks.T +local rgbhex = ShaguTweaks.rgbhex + +local module = ShaguTweaks:register({ + title = T["Chat Timestamps"], + description = T["Add timestamps to chat messages."], + expansions = { ["vanilla"] = true, ["tbc"] = false }, + category = T["Chat"], + maintainer = "@shagu (GitHub)", + enabled = false, + config = { + ["chat.timestamp.bracket"] = "[]", + ["chat.timestamp.format"] = 24, + ["chat.timestamp.color"] = { r = .8, g = .8, b = .8, a = 1}, + } +}) + +module.enable = function(self) + -- config shortcuts + local bracket = self.config["chat.timestamp.bracket"] + local clock = self.config["chat.timestamp.format"] + local rgb = self.config["chat.timestamp.color"] + + -- parse config + local left = string.sub(bracket, 1, 1) or "" + local right = string.sub(bracket, 2, 2) or "" + local format = clock == 24 and "%H:%M:%S" or "%I:%M:%S %p" + local color = rgbhex({ rgb.r, rgb.g, rgb.b, rgb.a }) + + -- add hooks to each frame + for i=1,NUM_CHAT_WINDOWS do + local original = _G["ChatFrame"..i].AddMessage + _G["ChatFrame"..i].AddMessage = function(frame, msg, a1, a2, a3, a4, a5) + -- ignore empty messages + if not msg then return end + + -- add timestamp to chat + msg = color .. left .. date(format) .. right .. "|r " .. msg + original(frame, msg, a1, a2, a3, a4, a5) + end + end +end