vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | idChat2_Timestamps = idChat2:NewModule('timestamps') |
2 | |||
3 | function idChat2_Timestamps:OnInitialize() |
||
4 | self.db = idChat2:AcquireDBNamespace('Timestamps') |
||
5 | |||
6 | idChat2:RegisterDefaults('Timestamps', 'profile', { |
||
7 | on = true, |
||
8 | ChatFrame1 = true, |
||
9 | ChatFrame2 = true, |
||
10 | ChatFrame3 = true, |
||
11 | ChatFrame4 = true, |
||
12 | ChatFrame5 = true, |
||
13 | ChatFrame6 = true, |
||
14 | ChatFrame7 = true, |
||
15 | Format = '%X', |
||
16 | Color = { |
||
17 | r = 1, |
||
18 | g = 1, |
||
19 | b = 1, |
||
20 | On = true |
||
21 | } |
||
22 | }) |
||
23 | |||
24 | idChat2.Options.args.timestamps = { |
||
25 | name = 'Timestamps', |
||
26 | desc = 'Timestamps', |
||
27 | type = 'group', |
||
28 | args = { |
||
29 | toggle = { |
||
30 | name = 'Toggle', |
||
31 | desc = 'Toggle the module on and off', |
||
32 | type = 'toggle', |
||
33 | get = function() return self.db.profile.on end, |
||
34 | set = function(v) |
||
35 | if v then |
||
36 | self:OnEnable() |
||
37 | else |
||
38 | self:OnDisable() |
||
39 | end |
||
40 | self.db.profile.on = v |
||
41 | end |
||
42 | }, |
||
43 | format = { |
||
44 | name = 'Format', |
||
45 | desc = 'The format to print the timestamps in. This is strftime format.', |
||
46 | type = 'text', |
||
47 | usage = '<string>', |
||
48 | get = function() return self.db.profile.Format end, |
||
49 | set = function(v) self.db.profile.Format = v end |
||
50 | }, |
||
51 | color = { |
||
52 | name = 'Color', |
||
53 | type = 'group', |
||
54 | desc = 'Settings for the color of the timestamp.', |
||
55 | args = { |
||
56 | color = { |
||
57 | name = 'Color', |
||
58 | type = 'color', |
||
59 | desc = "Change the color of the timestamp.", |
||
60 | get = function() return self.db.profile.Color.r, self.db.profile.Color.g, self.db.profile.Color.b end, |
||
61 | set = function(r, g, b, a) self.db.profile.Color.r, self.db.profile.Color.g, self.db.profile.Color.b = r, g, b end, |
||
62 | }, |
||
63 | toggle = { |
||
64 | name = 'Toggle', |
||
65 | desc = 'Toggle the timestamp color on and off.', |
||
66 | type = 'toggle', |
||
67 | get = function() return self.db.profile.Color.On end, |
||
68 | set = function(v) self.db.profile.Color.On = v end |
||
69 | } |
||
70 | } |
||
71 | }, |
||
72 | chatframe1 = { |
||
73 | name = 'Chatframe1 Toggle', |
||
74 | desc = 'Toggle the timestamp for chatframe1 on and off', |
||
75 | type = 'toggle', |
||
76 | get = function() return self:GetChatFrameStatus(1) end, |
||
77 | set = function(v) self:SetChatFrameStatus(1, v) end |
||
78 | }, |
||
79 | chatframe2 = { |
||
80 | name = 'Chatframe2 Toggle', |
||
81 | desc = 'Toggle the timestamp for chatframe2 on and off', |
||
82 | type = 'toggle', |
||
83 | get = function() return self:GetChatFrameStatus(2) end, |
||
84 | set = function(v) self:SetChatFrameStatus(2, v) end |
||
85 | }, |
||
86 | chatframe3 = { |
||
87 | name = 'Chatframe3 Toggle', |
||
88 | desc = 'Toggle the timestamp for chatframe3 on and off', |
||
89 | type = 'toggle', |
||
90 | get = function() return self:GetChatFrameStatus(3) end, |
||
91 | set = function(v) self:SetChatFrameStatus(3, v) end |
||
92 | }, |
||
93 | chatframe4 = { |
||
94 | name = 'Chatframe4 Toggle', |
||
95 | desc = 'Toggle the timestamp for chatframe4 on and off', |
||
96 | type = 'toggle', |
||
97 | get = function() return self:GetChatFrameStatus(4) end, |
||
98 | set = function(v) self:SetChatFrameStatus(4, v) end |
||
99 | }, |
||
100 | chatframe5 = { |
||
101 | name = 'Chatframe5 Toggle', |
||
102 | desc = 'Toggle the timestamp for chatframe5 on and off', |
||
103 | type = 'toggle', |
||
104 | get = function() return self:GetChatFrameStatus(5) end, |
||
105 | set = function(v) self:SetChatFrameStatus(5, v) end |
||
106 | }, |
||
107 | chatframe6 = { |
||
108 | name = 'Chatframe6 Toggle', |
||
109 | desc = 'Toggle the timestamp for chatframe6 on and off', |
||
110 | type = 'toggle', |
||
111 | get = function() return self:GetChatFrameStatus(6) end, |
||
112 | set = function(v) self:SetChatFrameStatus(6, v) end |
||
113 | }, |
||
114 | chatframe7 = { |
||
115 | name = 'Chatframe7 Toggle', |
||
116 | desc = 'Toggle the timestamp for chatframe7 on and off', |
||
117 | type = 'toggle', |
||
118 | get = function() return self:GetChatFrameStatus(7) end, |
||
119 | set = function(v) self:SetChatFrameStatus(7, v) end |
||
120 | } |
||
121 | } |
||
122 | } |
||
123 | end |
||
124 | |||
125 | function idChat2_Timestamps:OnEnable() |
||
126 | for i=1,7 do |
||
127 | self:Hook(getglobal('ChatFrame'..i), 'AddMessage') |
||
128 | end |
||
129 | end |
||
130 | |||
131 | function idChat2_Timestamps:OnDisable() |
||
132 | for i=1,7 do |
||
133 | self:Unhook(getglobal('ChatFrame'..i), 'AddMessage') |
||
134 | end |
||
135 | end |
||
136 | |||
137 | function idChat2_Timestamps:GetChatFrameStatus(id) |
||
138 | return self.db.profile['ChatFrame'..id] |
||
139 | end |
||
140 | |||
141 | function idChat2_Timestamps:SetChatFrameStatus(id, bool) |
||
142 | self.db.profile['ChatFrame'..id] = bool |
||
143 | if bool then |
||
144 | self:Hook(getglobal('ChatFrame'..id), 'AddMessage') |
||
145 | else |
||
146 | self:Unhook(getglobal('ChatFrame'..id), 'AddMessage') |
||
147 | end |
||
148 | end |
||
149 | |||
150 | function idChat2_Timestamps:AddMessage(frame, text, red, green, blue, id) |
||
151 | if self.db.profile[frame:GetName()] then |
||
152 | if self.db.profile.Color.On then |
||
153 | local color = string.format("%02x%02x%02x", self.db.profile.Color.r*255, self.db.profile.Color.g*255, self.db.profile.Color.b*255) |
||
154 | text = string.format('|cff'..color..'%s|r %s', date(self.db.profile.Format), text) |
||
155 | else |
||
156 | text = string.format('%s %s', date(self.db.profile.Format), text) |
||
157 | end |
||
158 | end |
||
159 | |||
160 | self.hooks[frame].AddMessage.orig(frame, text, red, green, blue, id) |
||
161 | end |
||
162 |