vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local Tablet = AceLibrary("Tablet-2.0") |
2 | local L = AceLibrary("AceLocale-2.0"):new("FuBar_ClockFu") |
||
3 | |||
4 | ClockFu = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0", "AceConsole-2.0", "AceDB-2.0", "FuBarPlugin-2.0") |
||
5 | |||
6 | ClockFu:RegisterDB("ClockFuDB") |
||
7 | ClockFu:RegisterDefaults('profile', { |
||
8 | twentyFour = false, |
||
9 | showSeconds = false, |
||
10 | localTime = false, |
||
11 | bothTimes = false, |
||
12 | bubble = false, |
||
13 | r = 1, |
||
14 | g = 1, |
||
15 | b = 1, |
||
16 | }) |
||
17 | |||
18 | ClockFu.version = "2.0." .. string.sub("$Revision: 9785 $", 12, -3) |
||
19 | ClockFu.date = string.sub("$Date: 2006-09-01 15:25:39 -1000 (Fri, 01 Sep 2006) $", 8, 17) |
||
20 | ClockFu.hasIcon = false |
||
21 | ClockFu.defaultPosition = 'RIGHT' |
||
22 | ClockFu.hideWithoutStandby = true |
||
23 | ClockFu.independantProfile = true |
||
24 | |||
25 | function ClockFu:OnInitialize() |
||
26 | if GroupCalendar_OnLoad then |
||
27 | self.db.profile.bubble = true |
||
28 | end |
||
29 | end |
||
30 | |||
31 | function ClockFu:OnEnable() |
||
32 | self.timeSinceLastUpdate = 0 |
||
33 | self.secondsDifference = 0 |
||
34 | _,self.lastMinute = GetGameTime() |
||
35 | if not self:IsShowingBubble() then |
||
36 | self.db.profile.bubble = true |
||
37 | self:ToggleShowingBubble() |
||
38 | end |
||
39 | self:ScheduleRepeatingEvent(self.Update, 1, self) |
||
40 | end |
||
41 | |||
42 | function ClockFu:OnDisable() |
||
43 | if not self:IsShowingBubble() then |
||
44 | self:ToggleShowingBubble() |
||
45 | self.db.profile.bubble = not self.db.profile.bubble |
||
46 | end |
||
47 | end |
||
48 | |||
49 | function ClockFu:GetColor() |
||
50 | return self.db.profile.r, self.db.profile.g, self.db.profile.b |
||
51 | end |
||
52 | |||
53 | function ClockFu:GetHexColor() |
||
54 | return string.format("%02x%02x%02x", self.db.profile.r * 255, self.db.profile.g * 255, self.db.profile.b * 255) |
||
55 | end |
||
56 | |||
57 | function ClockFu:SetColor(r, g, b) |
||
58 | self.db.profile.r = r |
||
59 | self.db.profile.g = g |
||
60 | self.db.profile.b = b |
||
61 | self:UpdateText() |
||
62 | end |
||
63 | |||
64 | function ClockFu:IsTwentyFour() |
||
65 | return self.db.profile.twentyFour |
||
66 | end |
||
67 | |||
68 | function ClockFu:ToggleTwentyFour() |
||
69 | self.db.profile.twentyFour = not self.db.profile.twentyFour |
||
70 | self:Update() |
||
71 | return self.db.profile.twentyFour |
||
72 | end |
||
73 | |||
74 | function ClockFu:IsShowingSeconds() |
||
75 | return self.db.profile.showSeconds |
||
76 | end |
||
77 | |||
78 | function ClockFu:ToggleShowingSeconds() |
||
79 | self.db.profile.showSeconds = not self.db.profile.showSeconds |
||
80 | self:Update() |
||
81 | return self.db.profile.showSeconds |
||
82 | end |
||
83 | |||
84 | function ClockFu:IsLocalTime() |
||
85 | return self.db.profile.localTime |
||
86 | end |
||
87 | |||
88 | function ClockFu:ToggleLocalTime() |
||
89 | self.db.profile.localTime = not self.db.profile.localTime |
||
90 | self:Update() |
||
91 | return self.db.profile.localTime |
||
92 | end |
||
93 | |||
94 | function ClockFu:IsBothTimes() |
||
95 | return self.db.profile.bothTimes |
||
96 | end |
||
97 | |||
98 | function ClockFu:ToggleBothTimes() |
||
99 | self.db.profile.bothTimes = not self.db.profile.bothTimes |
||
100 | self:Update() |
||
101 | return self.db.profile.bothTimes |
||
102 | end |
||
103 | |||
104 | function ClockFu:IsShowingBubble() |
||
105 | return self.db.profile.bubble |
||
106 | end |
||
107 | |||
108 | function ClockFu:ToggleShowingBubble() |
||
109 | self.db.profile.bubble = not self.db.profile.bubble |
||
110 | if not self.db.profile.bubble then |
||
111 | GameTimeFrame:Hide() |
||
112 | else |
||
113 | GameTimeFrame:Show() |
||
114 | end |
||
115 | return self.db.profile.bubble |
||
116 | end |
||
117 | |||
118 | function ClockFu:GetLocalOffset() |
||
119 | if self.localOffset ~= nil then |
||
120 | return self.localOffset |
||
121 | end |
||
122 | local localHour = tonumber(date("%H")) |
||
123 | local localMinute = tonumber(date("%M")) |
||
124 | local utcHour = tonumber(date("!%H")) |
||
125 | local utcMinute = tonumber(date("!%M")) |
||
126 | local loc = localHour + localMinute / 60 |
||
127 | local utc = utcHour + utcMinute / 60 |
||
128 | self.localOffset = floor((loc - utc) * 2 + 0.5) / 2 |
||
129 | if self.localOffset >= 12 then |
||
130 | self.localOffset = self.localOffset - 24 |
||
131 | end |
||
132 | return self.localOffset |
||
133 | end |
||
134 | |||
135 | function ClockFu:GetServerOffset() |
||
136 | if self.serverOffset ~= nil then |
||
137 | return self.serverOffset |
||
138 | end |
||
139 | local serverHour, serverMinute = GetGameTime() |
||
140 | local utcHour = tonumber(date("!%H")) |
||
141 | local utcMinute = tonumber(date("!%M")) |
||
142 | local ser = serverHour + serverMinute / 60 |
||
143 | local utc = utcHour + utcMinute / 60 |
||
144 | self.serverOffset = floor((ser - utc) * 2 + 0.5) / 2 |
||
145 | if self.serverOffset >= 12 then |
||
146 | self.serverOffset = self.serverOffset - 24 |
||
147 | elseif self.serverOffset < -12 then |
||
148 | self.serverOffset = self.serverOffset + 24 |
||
149 | end |
||
150 | return self.serverOffset |
||
151 | end |
||
152 | |||
153 | local optionsTable = { |
||
154 | handler = ClockFu, |
||
155 | type = 'group', |
||
156 | args = { |
||
157 | twentyFour = { |
||
158 | type = 'toggle', |
||
159 | name = L["24-hour format"], |
||
160 | desc = L["Toggle between 12-hour and 24-hour format"], |
||
161 | get = "IsTwentyFour", |
||
162 | set = "ToggleTwentyFour", |
||
163 | }, |
||
164 | seconds = { |
||
165 | type = 'toggle', |
||
166 | name = L["Show seconds"], |
||
167 | desc = L["Show seconds"], |
||
168 | get = "IsShowingSeconds", |
||
169 | set = "ToggleShowingSeconds", |
||
170 | }, |
||
171 | ["local"] = { |
||
172 | type = 'toggle', |
||
173 | name = L["Local time"], |
||
174 | desc = L["Toggle between local time and server time"], |
||
175 | get = "IsLocalTime", |
||
176 | set = "ToggleLocalTime", |
||
177 | }, |
||
178 | both = { |
||
179 | type = 'toggle', |
||
180 | name = L["Both times"], |
||
181 | desc = L["Toggle between showing two times or just one"], |
||
182 | get = "IsBothTimes", |
||
183 | set = "ToggleBothTimes", |
||
184 | }, |
||
185 | bubble = { |
||
186 | type = 'toggle', |
||
187 | name = L["Show day/night bubble"], |
||
188 | desc = L["Show the day/night bubble on the upper-right corner of the minimap"], |
||
189 | get = "IsShowingBubble", |
||
190 | set = "ToggleShowingBubble", |
||
191 | }, |
||
192 | color = { |
||
193 | type = 'color', |
||
194 | name = COLOR, |
||
195 | desc = L["Set the color of the text"], |
||
196 | get = "GetColor", |
||
197 | set = "SetColor", |
||
198 | disabled = function() |
||
199 | return not ClockFu:IsTextColored() |
||
200 | end |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | ClockFu:RegisterChatCommand(L:GetTable("AceConsole-commands"), optionsTable) |
||
205 | ClockFu.OnMenuRequest = optionsTable |
||
206 | |||
207 | function ClockFu:FormatTime(hour, minute, second, colorize) |
||
208 | if self:IsTwentyFour() then |
||
209 | if not colorize then |
||
210 | if self:IsShowingSeconds() then |
||
211 | return string.format("%d:%02d:%02d", hour, minute, second) |
||
212 | else |
||
213 | return string.format("%d:%02d", hour, minute) |
||
214 | end |
||
215 | else |
||
216 | local color = self:GetHexColor() |
||
217 | if self:IsShowingSeconds() then |
||
218 | return string.format("|cff%s%d|r:|cff%s%02d|r:|cff%s%02d|r", color, hour, color, minute, color, second) |
||
219 | else |
||
220 | return string.format("|cff%s%d|r:|cff%s%02d|r", color, hour, color, minute) |
||
221 | end |
||
222 | end |
||
223 | else |
||
224 | pm = floor(hour / 12) == 1 |
||
225 | hour = mod(hour, 12) |
||
226 | if hour == 0 then |
||
227 | hour = 12 |
||
228 | end |
||
229 | if not colorize then |
||
230 | if self:IsShowingSeconds() then |
||
231 | return string.format("%d:%02d:%02d %s", hour, minute, second, pm and " PM" or " AM") |
||
232 | else |
||
233 | return string.format("%d:%02d %s", hour, minute, pm and " PM" or " AM") |
||
234 | end |
||
235 | else |
||
236 | local color = self:GetHexColor() |
||
237 | if self:IsShowingSeconds() then |
||
238 | return string.format("|cff%s%d|r:|cff%s%02d|r:|cff%s%02d|r %s", color, hour, color, minute, color, second, pm and " PM" or " AM") |
||
239 | else |
||
240 | return string.format("|cff%s%d|r:|cff%s%02d|r %s", color, hour, color, minute, pm and " PM" or " AM") |
||
241 | end |
||
242 | end |
||
243 | end |
||
244 | end |
||
245 | |||
246 | function ClockFu:GetServerTime(colorize) |
||
247 | local hour, minute = GetGameTime() |
||
248 | if self.lastMinute ~= minute then |
||
249 | _,self.lastMinute = GetGameTime() |
||
250 | self.secondsDifference = mod(time(), 60) |
||
251 | end |
||
252 | local second = mod(time() - self.secondsDifference, 60) |
||
253 | return self:FormatTime(hour, minute, second, colorize) |
||
254 | end |
||
255 | |||
256 | function ClockFu:GetLocalTime(colorize) |
||
257 | local hour = tonumber(date("%H")) |
||
258 | local minute = tonumber(date("%M")) |
||
259 | local second = tonumber(date("%S")) |
||
260 | return self:FormatTime(hour, minute, second, colorize) |
||
261 | end |
||
262 | |||
263 | function ClockFu:GetUtcTime() |
||
264 | local hour = tonumber(date("!%H")) |
||
265 | local minute = tonumber(date("!%M")) |
||
266 | local second = tonumber(date("!%S")) |
||
267 | return self:FormatTime(hour, minute, second) |
||
268 | end |
||
269 | |||
270 | function ClockFu:OnTextUpdate() |
||
271 | local hour, minute = GetGameTime() |
||
272 | if self.lastMinute ~= minute then |
||
273 | _,self.lastMinute = GetGameTime() |
||
274 | self.secondsDifference = mod(time(), 60) |
||
275 | end |
||
276 | if self:IsBothTimes() then |
||
277 | if self:IsLocalTime() then |
||
278 | self:SetText(string.format("%s || %s", self:GetLocalTime(true), self:GetServerTime(true))) |
||
279 | else |
||
280 | self:SetText(string.format("%s || %s", self:GetServerTime(true), self:GetLocalTime(true))) |
||
281 | end |
||
282 | elseif self:IsLocalTime() then |
||
283 | self:SetText(self:GetLocalTime(true)) |
||
284 | else |
||
285 | self:SetText(self:GetServerTime(true)) |
||
286 | end |
||
287 | end |
||
288 | |||
289 | function ClockFu:OnTooltipUpdate() |
||
290 | local s = self:GetServerOffset() |
||
291 | local l = self:GetLocalOffset() |
||
292 | |||
293 | local cat = Tablet:AddCategory( |
||
294 | 'columns', 2, |
||
295 | 'child_textR', 1, |
||
296 | 'child_textG', 1, |
||
297 | 'child_textB', 0, |
||
298 | 'child_text2R', 1, |
||
299 | 'child_text2G', 1, |
||
300 | 'child_text2B', 1 |
||
301 | ) |
||
302 | cat:AddLine( |
||
303 | 'text', string.format(L["Local time"] .. " (%+03d:%02d)", l, mod(l * 60, 60)), |
||
304 | 'text2', self:GetLocalTime() |
||
305 | ) |
||
306 | cat:AddLine( |
||
307 | 'text', string.format(L["Server time"] .. " (%+03d:%02d)", s, mod(s * 60, 60)), |
||
308 | 'text2', self:GetServerTime() |
||
309 | ) |
||
310 | cat:AddLine( |
||
311 | 'text', L["UTC"], |
||
312 | 'text2', self:GetUtcTime() |
||
313 | ) |
||
314 | |||
315 | Tablet:AddCategory():AddLine( |
||
316 | 'text', date("%A, %B %d, %Y"), |
||
317 | 'textR', 1, |
||
318 | 'textG', 1, |
||
319 | 'textB', 1, |
||
320 | 'justify', "CENTER" |
||
321 | ) |
||
322 | end |