-
Notifications
You must be signed in to change notification settings - Fork 0
/
zCountdownTimer.lua
528 lines (429 loc) · 16.7 KB
/
zCountdownTimer.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
--------------------------------------------------------------------------------
-- Author: Dustin Z. dzCountdownTimer.lua
-- Name: dzCountdownTimer
-- Abstract:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--------------------------------------------------------------------------------
local dzCountdownTimer = LibStub("AceAddon-3.0"):NewAddon("dzCountdownTimer", "AceEvent-3.0", "AceConsole-3.0", "AceTimer-3.0")
-- Defines the name of our mod
local mod = dzCountdownTimer
local strTimeEntered, frmCDT, fsTimerDisplay, ebTimeEntered, btnSet, btnStart, btnStop, Timer
local DEBUG = 1
-- -- Create the global table if it does not exist yet
CONFIGMODE_CALLBACKS = CONFIGMODE_CALLBACKS or {}
-- -- Declare our handler
CONFIGMODE_CALLBACKS["dzCountdownTimer"] = function(action)
if action == "ON" then
dzCountdownTimer.configMode = true
-- mod:UnlockFrames()
elseif action == "OFF" then
dzCountdownTimer.configMode = false
-- mod:LockFrames()
end
end
local alert_options = {
type = "group",
desc = "Alerts",
args = {
AudibleAlert = {
name = "Audible Alert",
type = "toggle",
desc = "Play audible alert when countdown is finished?",
get = function() return db.AudibleAlert end,
set = function(i, switch)
db.AudibleAlert = switch
end
},
AlertSound = {
name = "Alert Sound",
type = "select",
dialogControl = "LSM30_Sound",
desc = "Set Audio Alert Sound.",
values = AceGUIWidgetLSMlists.sound,
get = function() return db.AlertSound end,
set = function(self, key)
db.AlertSound = key
end
},
VisualAlert = {
name = "Visual Alert",
type = "toggle",
desc = "Display visual alert when countdown is finished?",
get = function() return db.VisualAlert end,
set = function(i, switch)
db.VisualAlert = switch
end
},
AudioChannel = {
name = "Audio Channel",
type = "select",
desc = "Channel to play sounds",
get = function(info) return db.AudioChannel end,
set = function(info,v)
db.AudioChannel = v
end,
values = {
["Ambience"] = "Ambience",
["SFX"] = "Effects",
["Music"] = "Music",
["Master"] = "Master",
}
}
}
}
local ui_options = {
type = "group",
desc = "UI Options",
args = {
Visible = {
name = "Window Visibility",
type = "toggle",
desc = "Toggle Display of the Countdown Timers Window.",
get = function() return db.Visible end,
set = function(i, switch)
mod:SetVisibility(switch)
end
},
}
}
--------------------------------------------------------------------------------
-- Name: defaults
-- Abstract: A table which holds our preference variables
--------------------------------------------------------------------------------
local defaults = {
profile = {
AlertSound = "Interface\\AddOns\\ClearerCast\\Clearcasting_Impact_Chest.ogg",
AudibleAlert = true,
AudioChannel = "Master",
VisualAlert = true,
Visible = true,
width = 275,
height = 200,
pos = { },
}
}
local function ProfileSetup()
local profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(dzCountdownTimer.db)
return profiles
end
--------------------------------------------------------------------------------
-- Name: dzCDT:OnInitialize()
-- Abstract: Our would be constructor, isn't it cute?
--------------------------------------------------------------------------------
function dzCountdownTimer:OnInitialize()
-- self.abacus = LibStub("LibAbacus-3.0")
self.ACR = LibStub("AceConfigRegistry-3.0")
self.ACD = LibStub("AceConfigDialog-3.0")
--# Initialize DB
self.db = LibStub("AceDB-3.0"):New("dzCountdownTimerDB", defaults)
db = self.db.profile
--# Register our options
self.ACR:RegisterOptionsTable("dzCountdownTimer", ProfileSetup)
self.ACR:RegisterOptionsTable("dzCountdownTimer Alerts",alert_options)
self.ACR:RegisterOptionsTable("dzCountdownTimer UI Options",ui_options)
self.ACD:AddToBlizOptions("dzCountdownTimer")
self.ACD:AddToBlizOptions("dzCountdownTimer Alerts", "Alerts", "dzCountdownTimer")
self.ACD:AddToBlizOptions("dzCountdownTimer UI Options", "UI Options", "dzCountdownTimer")
self.configMode = false
SlashCmdList["dzCDT"] = function() end
SLASH_dzCDT1 = "/dzCountdownTimer"
SLASH_dzCDT2 = "/dzCDT"
mod:dzAddMessage("Loaded!")
end
--------------------------------------------------------------------------------
-- Name: dzCDT:OnEnable()
-- Abstract: Our would be constructor, isn't it cute?
--------------------------------------------------------------------------------
function dzCountdownTimer:OnEnable()
for varname, val in pairs(alert_options.args) do
if db[varname] then alert_options.args[varname].set(true, db[varname]) end
end
-- for varname, val in pairs(ui_options.args) do
-- if db[varname] then ui_options.args[varname].set(true, db[varname]) end
-- end
-- create our interface frame
mod:CreateInterface()
-- send msg on enable
mod:dzAddMessage("Enabled!")
end
--------------------------------------------------------------------------------
-- Name: dzCDT:OnDisable()
-- Abstract: Our would be de-constructor, isn't it cute?
--------------------------------------------------------------------------------
function dzCountdownTimer:OnDisable()
-- -- Unhook, Unregister Events, Hide frames that you created.
-- -- You would probably only use an OnDisable if you want to
-- -- build a "standby" mode, or be able to toggle modules on/off.
-- send messag eon disable
mod:dzAddMessage("Disabled!")
end
--------------------------------------------------------------------------------
-- Name: dzCDT:dzAddMessage(msg, r, g, b)
-- Abstract:
--------------------------------------------------------------------------------
function dzCountdownTimer:dzAddMessage(msg, r, g, b)
-- strMod = format("|cff0062ffdz|r|cff0deb11CountdownTimers|r")
strMod = format("|cff696969dz|r|cff008B8BCountdownTimers|r")
DEFAULT_CHAT_FRAME:AddMessage("" .. strMod .. ": " .. tostring(msg), r, g, b)
end
--------------------------------------------------------------------------------
-- Name: dzCDT:CreateInterface()
-- Abstract: Creates our interface for dzCDT, whee!
--------------------------------------------------------------------------------
function dzCountdownTimer:CreateInterfacepkb()
local AceGUI = LibStub("AceGUI-3.0")
frmCDT = AceGUI:Create("Frame")
frmCDT:SetTitle("dzCDT")
frmCDT:SetWidth(275)
frmCDT:SetHeight(200)
-- frmCDT:SetUserPlaced(1)
frmCDT:SetStatusText("")
frmCDT:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
frmCDT:SetLayout("Flow")
lblTimerDisplay = AceGUI:Create("Label")
lblTimerDisplay:SetFont("Interface\\Addons\\dzCDT\\Fonts\\Calibri.ttf", 18)
lblTimerDisplay:SetText("00:00:00")
frmCDT:AddChild(lblTimerDisplay)
txtTimeEntered = AceGUI:Create("EditBox")
txtTimeEntered:SetLabel("Enter countdown time (hh:mm:ss):")
txtTimeEntered:SetMaxLetters(8)
-- txtTimeEntered:SetWidth(37)
txtTimeEntered:SetFocus()
txtTimeEntered:SetText("00:00:00")
txtTimeEntered:SetCallback("OnEnterPressed", function(widget, event, text) mod:SetTime(text) end)
frmCDT:AddChild(txtTimeEntered)
-- btnSet = AceGUI:Create("Button")
-- btnSet:SetText("Set")
-- btnSet:SetWidth(75)
-- btnSet:SetCallback("OnClick", function(widget, event, text) mod:SetTime(txtTimeEntered:GetText()))
-- frmCDT:AddChild(btnSet)
btnStart = AceGUI:Create("Button")
btnStart:SetText("Start")
btnStart:SetWidth(75)
btnStart:SetCallback("OnClick", function(widget, event, text) mod:StartTimer() end)
frmCDT:AddChild(btnStart)
btnStop = AceGUI:Create("Button")
btnStop:SetText("Stop")
btnStop:SetWidth(75)
frmCDT:AddChild(btnStop)
end
--------------------------------------------------------------------------------
-- Name: dzCDT:CreateInterface()
-- Abstract: Creates our interface for dzCDT, whee!
--------------------------------------------------------------------------------
function dzCountdownTimer:CreateInterface()
local AceGUI = LibStub("AceGUI-3.0")
width = db.width
height = db.height
frmCDT = CreateFrame("Frame","frmCDT",UIParent)
local f = frmCDT
f:SetPoint("CENTER",0,0)
f:SetWidth(275)
f:SetHeight(200)
f:SetMinResize(120, 80)
f:SetMovable(true)
f:SetResizable(true)
f:SetUserPlaced(1)
-- f:RegisterForClicks("LeftButtonUp", "RightButtonUp")
f:EnableMouse(enable)
f:RegisterForDrag("LeftButton")
f:SetClampedToScreen(true)
f:SetClampRectInsets(10, -10, -10, 10)
f:SetBackdropBorderColor(1,1,1,1)
txFCDT = f:CreateTexture("Interface\\DialogFrame\\UI-DialogBox-Background", "BACKGROUND")
ftx = txFCDT
-- ftx = f:CreateTexture()
ftx:SetAllPoints(f)
ftx:SetTexture(0,0,0,.5)
ftrFCDT = f:CreateTitleRegion()
local ftr = ftrFCDT
ftr:SetPoint("CENTER", f, "TOP")
ftr:SetHeight(20)
ftr:SetWidth(f:GetRight() - f:GetLeft() - 10)
fsTimerDisplay = f:CreateFontString("fsTimerDisplay", nil)
local fstd = fsTimerDisplay
fstd:SetPoint('CENTER', f, 'TOP', 0, -20)
fstd:SetJustifyV('MIDDLE')
fstd:SetJustifyH('CENTER')
fstd:SetHeight(20)
fstd:SetWidth(f:GetRight() - f:GetLeft() - 10)
fstd:SetFont("Interface\\Addons\\dzCountdownTimer\\Fonts\\Calibri.ttf", 24)
fstd:SetText("00:00:00")
btnClose = CreateFrame("Button", "btnClose", f, "UIPanelCloseButton")
local fbcls = btnClose
-- fbcls:SetWidth(75)
fbcls:SetText("Start")
fbcls:SetPoint("TOPRIGHT", f, "TOPRIGHT", 2, 0)
fbcls:SetScript("OnClick", function() f:Hide() end)
ebTimeEntered = CreateFrame("EditBox", "ebTimeEntered", f, "InputBoxTemplate")
local febte = ebTimeEntered
febte:SetHeight(20)
febte:SetWidth(75)
febte:SetMaxLetters(8)
-- febte:SetFocus()
febte:SetFont("Interface\\Addons\\dzCountdownTimer\\Fonts\\Calibri.ttf", 18)
febte:AddHistoryLine("00:00:00")
febte:SetText("00:00:00")
febte:HighlightText()
febte:SetPoint("CENTER", f, "TOP", 0, -90)
febte:SetScript("OnEnterPressed", function(widget, event, text) mod:SetTime(text) end)
btnSet = CreateFrame("Button", "btnSet", f, "UIPanelButtonTemplate")
local fbset = btnSet
fbset:SetHeight(20)
fbset:SetWidth(60)
fbset:SetText("Set")
fbset:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 5, 5)
fbset:SetScript("OnClick", function() mod:SetTime() end)
btnStart = CreateFrame("Button", "btnStart", f, "UIPanelButtonTemplate")
local fbsrt = btnStart
fbsrt:SetHeight(20)
fbsrt:SetWidth(60)
fbsrt:SetText("Start")
fbsrt:SetPoint("LEFT", fbset, "RIGHT", 5, 0)
fbsrt:SetScript("OnClick", function() mod:StartTimer() end)
btnStop = CreateFrame("Button", "btnStop", f, "UIPanelButtonTemplate")
local fbstp = btnStop
fbstp:SetHeight(20)
fbstp:SetWidth(60)
fbstp:SetText("Stop")
fbstp:SetPoint("LEFT", btnStart, "RIGHT", 5, 0)
fbstp:SetScript("OnClick", function() mod:StopTimer() end)
btnResize = CreateFrame("Button", "btnResize", f, "UIPanelButtonGrayTemplate")
local fbr = btnResize
-- fbr:SetWidth(8)
-- fbr:SetHeight(8)
fbr:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -4, 4)
fbr:SetScript("OnMouseDown", ResizeStart)
fbr:SetScript("OnMouseUp", ResizeEnd)
fbr:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
fbr:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
fbr:SetWidth(14)
fbr:SetHeight(14)
end
--------------------------------------------------------------------------------
-- Name: dzCDT:SetTime(time)
-- Abstract: Set's the time for the countdown timer
--------------------------------------------------------------------------------
function dzCountdownTimer:SetTime(time)
strTimeEntered = 0
strTimeEntered = time
strTimeEntered = ebTimeEntered:GetText()
fsTimerDisplay:SetText(strTimeEntered)
if (DEBUG) then
mod:dzAddMessage("CDT Time: " .. strTimeEntered)
end
end
--------------------------------------------------------------------------------
-- Name: dzCDT:SetTime(time)
-- Abstract: Set's the time for the countdown timer
--------------------------------------------------------------------------------
function dzCountdownTimer:ParseTime()
intHours = 0
intMinutes = 0
intSeconds = 0
intTotal = 0
intHours = strTimeEntered:sub(1, 2)
intMinutes = strTimeEntered:sub(4, 5)
intSeconds = strTimeEntered:sub(7, 8)
intTotal = ( ( (intHours * 60) * 60) + ( intMinutes * 60) + intSeconds )
if (DEBUG) then
mod:dzAddMessage(intHours .. " hours " .. intMinutes .. " minutes " .. intSeconds .. " seconds = " .. intTotal .. " seconds!")
end
return intTotal
end
--------------------------------------------------------------------------------
-- Name: dzCDT:StartTimer()
-- Abstract: Start the countdown timer
--------------------------------------------------------------------------------
function dzCountdownTimer:StartTimer()
intTime = 0
intTime = mod:ParseTime()
Timer = self:ScheduleTimer("TimerComplete", intTime)
if (DEBUG) then
mod:dzAddMessage(Timer .. " was set for " .. intTime)
end
end
--------------------------------------------------------------------------------
-- Name: dzCDT:StopTimer()
-- Abstract: Set's the time for the countdown timer
--------------------------------------------------------------------------------
function dzCountdownTimer:StopTimer()
self:CancelTimer(Timer)
if (DEBUG) then
mod:dzAddMessage(Timer .. " was cancelled!")
end
end
--------------------------------------------------------------------------------
-- Name: dzCDT:TimerComplete()
-- Abstract: What we do when the timer finishes
--------------------------------------------------------------------------------
function dzCountdownTimer:TimerComplete()
if db.AudibleAlert == true then
local sound = _G[db.AlertSound]
local audiochannel = _G[db.AudioChannel]
PlaySoundFile(sound, audiochannel)
end
if (DEBUG) then
mod:dzAddMessage("WERK WERK, TIMER COMPLETE!@#")
end
end
--------------------------------------------------------------------------------
-- Name: dzCDT:TimeRemaining()
-- Abstract: Return's the amount of time left in the timer
--------------------------------------------------------------------------------
function dzCountdownTimer:TimeRemaining()
intTimeLeft = 0
intTimeLeft = self:TimeLeft(self.Timer)
return intTimeLeft
end
--------------------------------------------------------------------------------
-- Name: dzCDT:SetVisibility()
-- Abstract: Set the Visibility of dzCDT Window
--------------------------------------------------------------------------------
function dzCountdownTimer:SetVisibility(blnVisible)
db.Visible = blnVisible
if (db.Visible == true) then
if not frmCDT:IsHidden() then
frmCDT:Show()
mod:dzAddMessage("Show teh framez0r!@#")
end
elseif (db.Visible == false) then
if frmCDT:IsHidden() then
frmCDT:Hide()
mod:dzAddMessage("Hide teh framez0r!@#")
end
else
mod:dzAddMessage("Some Kind Of Error!@#")
end
end
--------------------------------------------------------------------------------
-- Name: dzCDT:ToggleVisibility()
-- Abstract: Toggle Visibility of dzCDT Window
--------------------------------------------------------------------------------
function dzCountdownTimer:ToggleVisibility()
if (db.Visible == true) then
db.Visible = false
frmCDT:Hide()
lblTimerDisplay:Hide()
txtTimeEntered:Hide()
btnSet:Hide()
btnStart:Hide()
btnStop:Hide()
mod:dzAddMessage("Hide teh framez0r!@#")
elseif (db.Visible == false) then
db.Visible = true
frmCDT:Show()
lblTimerDisplay:Show()
txtTimeEntered:Show()
btnSet:Show()
btnStart:Show()
btnStop:Show()
mod:dzAddMessage("Show teh framez0r!@#")
else
end
end
--------------------------------------------------------------------------------
-- Event Handlers
--------------------------------------------------------------------------------