Quantcast

Clean up localization, fix options, add timestamps

James Whitehead II [01-11-11 - 15:12]
Clean up localization, fix options, add timestamps
Filename
CaptainsLog.lua
diff --git a/CaptainsLog.lua b/CaptainsLog.lua
index a3cfdeb..5cd4835 100644
--- a/CaptainsLog.lua
+++ b/CaptainsLog.lua
@@ -9,6 +9,14 @@ addon.ldb = LibStub("LibDataBroker-1.1")

 local BUFFER_SIZE = 10

+local C = {
+    whisper = WHISPER,
+    party = PARTY,
+    guild = GUILD,
+    bnet = L["Battle.net"],
+    raid = RAID,
+}
+
 function addon:Initialize()
     self.db = LibStub("AceDB-3.0"):New("CaptainsLogDB", {
         char = {
@@ -17,26 +25,28 @@ function addon:Initialize()
             },
         },
         profile = {
+            timestamp = true,
+            timestamp_format = "%H:%M ",
             showinfeed = {
-                [L["Whisper"]] = true,
-                [L["Party"]] = true,
-                [L["Guild"]] = true,
-                [L["Battle.net"]] = true,
-                [L["Raid"]] = true,
+                whisper = true,
+                party = true,
+                guild = true,
+                bnet = true,
+                raid = true,
             },
             showintooltip = {
-                [L["Whisper"]] = true,
-                [L["Party"]] = true,
-                [L["Guild"]] = true,
-                [L["Battle.net"]] = true,
-                [L["Raid"]] = true,
+                whisper = true,
+                party = true,
+                guild = true,
+                bnet = true,
+                raid = true,
             },
             log = {
-                [L["Whisper"]] = false,
-                [L["Party"]] = false,
-                [L["Guild"]] = false,
-                [L["Battle.net"]] = false,
-                [L["Raid"]] = false,
+                whisper = true,
+                party = true,
+                guild = true,
+                bnet = true,
+                raid = true,
             }
         },
     })
@@ -84,16 +94,16 @@ end

 function addon:UpdateFeedText(mtype, sender)
     if addon.db.profile.showinfeed[mtype] then
-        self.feed.text = L["%s from %s"]:format(mtype, sender)
+        self.feed.text = L["%s from %s"]:format(C[mtype] or mtype, sender)
     end
 end

 local colorMap = {
-    ["Party"] = "PARTY",
-    ["Guild"] = "GUILD",
-    ["Whisper"] = "WHISPER",
-    ["Raid"] = "RAID",
-    ["Battle.net"] = "BN_WHISPER",
+    party = "PARTY",
+    guild = "GUILD",
+    whisper = "WHISPER",
+    raid = "RAID",
+    bnet = "BN_WHISPER",
 }

 function addon:GetStardate()
@@ -113,19 +123,24 @@ function addon:PopulateTooltip(tooltip)

     for idx, mtype in ipairs(sort) do
         if addon.db.profile.showintooltip[mtype] then
-            local c = ChatTypeInfo[colorMap[mtype]] or {}
+            local color = ChatTypeInfo[colorMap[mtype]] or {}

             if idx > 1 then
                 self:AddSpacerLine(tooltip, 3, 0.6, 0.6, 0.6)
             end

-            tooltip:AddLine(mtype)
+            tooltip:AddLine(C[mtype] or mtype)

             if #self.messages[mtype] > 0 then
                 for idx, msg in ipairs(self.messages[mtype]) do
+                    local timestamp = " "
+                    if addon.db.profile.timestamp then
+                        timestamp = date(addon.db.profile.timestamp_format, msg[1])
+                    end
+
                     tooltip:AddLine(
-                    string.format("[%s]: %s", msg[2], msg[3]),
-                    c.r, c.g, c.b
+                    string.format("%s[%s]: %s", timestamp, msg[2], msg[3]),
+                    color.r, color.g, color.b
                     )
                 end
             else
@@ -140,7 +155,7 @@ function addon:PopulateTooltip(tooltip)
 end

 function addon:CHAT_MSG_WHISPER(event, msg, sender, ...)
-    local mtype = L["Whisper"]
+    local mtype = "whisper"
     if not addon.db.profile.log[mtype] then return end

     local cname = GetColoredName(event, msg, sender, ...)
@@ -149,7 +164,7 @@ function addon:CHAT_MSG_WHISPER(event, msg, sender, ...)
 end

 function addon:CHAT_MSG_GUILD(event, msg, sender, ...)
-    local mtype = L["Guild"]
+    local mtype = "guild"
     if not addon.db.profile.log[mtype] then return end
     local cname = GetColoredName(event, msg, sender, ...)
     self:Log(mtype, cname, msg)
@@ -157,7 +172,7 @@ function addon:CHAT_MSG_GUILD(event, msg, sender, ...)
 end

 function addon:CHAT_MSG_PARTY(event, msg, sender, ...)
-    local mtype = L["Party"]
+    local mtype = "party"
     if not addon.db.profile.log[mtype] then return end
     local cname = GetColoredName(event, msg, sender, ...)
     self:Log(mtype, cname, msg)
@@ -165,14 +180,14 @@ function addon:CHAT_MSG_PARTY(event, msg, sender, ...)
 end

 function addon:CHAT_MSG_BN_WHISPER(event, msg, sender, ...)
-    local mtype = L["Battle.net"]
+    local mtype = "bnet"
     if not addon.db.profile.log[mtype] then return end
     self:Log(mtype, sender, msg)
     self:UpdateFeedText(mtype, sender)
 end

 function addon:CHAT_MSG_RAID(event, msg, sender, ...)
-    local mtype = L["Raid"]
+    local mtype = "raid"
     if not addon.db.profile.log[mtype] then return end
     local cname = GetColoredName(event, msg, sender, ...)
     self:Log(mtype, cname, msg)