--[[ $Id: Core.lua 4 2008-08-23 16:03:27Z DarkImakuni-16655 $ ]]-- |
|
uClock = AceLibrary("AceAddon-2.0"):new("AceDB-2.0", "AceEvent-2.0", "FuBarPlugin-2.0") |
uClock.date = ("$Date: 2008-08-23 17:03:27 +0100 (Sat, 23 Aug 2008) $"):match("%d%d%d%d%-%d%d%-%d%d") |
uClock.blizzardTooltip = true |
uClock.cannotHideText = true |
|
uClock:RegisterDB("uClockDB") |
uClock:RegisterDefaults('profile', { twentyFour = true, showSeconds = false }) |
|
|
function uClock:OnEnable() |
self:ScheduleRepeatingEvent(self.UpdateDisplay, 1, self) |
|
LibStub("AceConfigRegistry-3.0"):RegisterOptionsTable("uClock", { |
name = "FuBar uClock", |
desc = "Minimalistic date/time display", |
get = function(k) return self.db.profile[k.arg] end, |
set = function(k, v) self.db.profile[k.arg] = v end, |
type = "group", |
args = { |
twentyFour = { |
name = "24 Hour Mode", |
type = "toggle", arg = "twentyFour", order = 1, |
}, |
showSeconds = { |
name = "Show Seconds", |
type = "toggle", arg = "showSeconds", order = 2, |
}, |
}, |
}) |
|
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("uClock", "FuBar uClock") |
end |
|
function uClock:OnTextUpdate() |
self:SetText(date("%H:%M:%S")) |
self:SetText(self:GetTimeString(date("%H"), date("%M"))) |
end |
|
function uClock:OnTooltipUpdate() |
GameTooltip:SetText(date("%A, %B %d, %Y")) |
local hour, minute = GetGameTime() |
|
GameTooltip:AddDoubleLine("Server Time", self:GetTimeString(hour, minute)) |
GameTooltip:AddDoubleLine("Today's Date", date("%A, %B %d, %Y")) |
end |
|
function uClock:OnClick() |
ToggleTimeManager() |
function uClock:OnClick(button) |
if button == "LeftButton" then |
if IsShiftKeyDown() then ToggleCalendar() |
else ToggleTimeManager() end |
elseif button == "RightButton" then |
InterfaceOptionsFrame_OpenToCategory("FuBar uClock") |
end |
end |
|
|
function uClock:GetTimeString(hour, minute) |
local time, pm |
|
if not self.db.profile.twentyFour then |
pm = floor(hour / 12) == 1 |
hour = mod(hour, 12) |
|
if hour == 0 then hour = 12 end |
end |
|
time = ("%d:%02d"):format(hour, minute) |
|
if self.db.profile.showSeconds then |
time = time..date(":%S") |
end |
|
if not self.db.profile.twentyFour then |
time = time..(pm and " PM" or " AM") |
end |
|
return time |
end |