-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcore.lua
66 lines (55 loc) · 1.98 KB
/
core.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local name, addon = ...
LibStub('AceAddon-3.0'):NewAddon(addon, name, 'AceTimer-3.0', 'LibPubSub-1.0')
-- Localise global variables
local _G = _G
local date, floor, GetGameTime = _G.date, _G.floor, _G.GetGameTime
local IsAltKeyDown, IsAddOnLoaded = _G.IsAltKeyDown, _G.IsAddOnLoaded
local ToggleCalendar, Stopwatch_Toggle = _G.ToggleCalendar, _G.Stopwatch_Toggle
local GroupCalendar = _G.GroupCalendar
function addon:OnInitialize()
self.L = LibStub('AceLocale-3.0'):GetLocale(name)
end
function addon:OnEnable()
self.timer = self:ScheduleRepeatingTimer('UpdateTime', 1)
self:Subscribe('MOUSE_CLICK', 'OnClick')
self:Subscribe('UPDATE_OPTIONS', 'OnUpdateOptions')
end
function addon:OnDisable()
self:CancelTimer(self.timer)
self:Unsubscribe('MOUSE_CLICK', 'OnClick')
self:Unsubscribe('UPDATE_OPTIONS', 'OnUpdateOptions')
end
function addon:OnClick(frame, button)
if IsAltKeyDown() then
self:GetModule('Options').Open()
elseif button == 'RightButton' then
Stopwatch_Toggle()
elseif IsAddOnLoaded('GroupCalendar5') then
if GroupCalendar.UI.Window:IsShown() then
GroupCalendar.UI.Window:Hide()
else
GroupCalendar.UI.Window:Show()
end
elseif ToggleCalendar then
ToggleCalendar()
end
end
function addon:OnUpdateOptions(group)
if group == nil or group == 'clock' then
self:UpdateTime()
end
end
function addon:UpdateTime()
local seconds = date('%S')
local realmHours, realmMinutes = GetGameTime()
local localTime = {hours=date('%H'), minutes=date('%M'), seconds=seconds}
local realmTime = {hours=realmHours, minutes=realmMinutes, seconds=seconds}
local universalTime = {hours=date('!%H'), minutes=date('!%M'), seconds=seconds}
localTime.am = (floor(localTime.hours / 12) == 0)
realmTime.am = (floor(realmTime.hours / 12) == 0)
universalTime.am = (floor(universalTime.hours / 12) == 0)
localTime.pm = (localTime.am == false)
realmTime.pm = (realmTime.am == false)
universalTime.pm = (universalTime.am == false)
self:Publish('UPDATE_TIME', localTime, realmTime, universalTime)
end