-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGroupCalendar.lua
More file actions
executable file
·1072 lines (834 loc) · 29.2 KB
/
GroupCalendar.lua
File metadata and controls
executable file
·1072 lines (834 loc) · 29.2 KB
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
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
----------------------------------------
-- Group Calendar 5 Copyright (c) 2018 John Stephen
-- All rights reserved, unuauthorized redistribution is prohibited
----------------------------------------
GroupCalendar_Data = nil
function GroupCalendar:Initialize()
GroupCalendar.EventLib:UnregisterEvent("PLAYER_ENTERING_WORLD", GroupCalendar.Initialize, GroupCalendar)
GroupCalendar.WoWCalendar:Init()
GroupCalendar:InitializeData()
self:InitializeRealm()
self:InitializeCharacter()
self.Alts = GroupCalendar:New(GroupCalendar._Alts)
self.WhisperLog = GroupCalendar:New(GroupCalendar._WhisperLog)
self:InitializeCalendars()
self:InitializeTradeskill()
self:InstallSlashCommand()
-- Queue a command to start loading the calendar data
self.SchedulerLib:ScheduleTask(5, function ()
local calendarDate = self.WoWCalendar:GetDate()
self.WoWCalendar:SetAbsMonth(calendarDate.month, calendarDate.year)
self.WoWCalendar:OpenCalendar()
end)
--
self.MessageFrame = GroupCalendar:New(GroupCalendar._MessageFrame)
GameTimeFrame:SetScript("OnEnter", function (...) self:GameTimeFrame_OnEnter(...) end)
GameTimeFrame:SetScript("OnUpdate", function (...) self:GameTimeFrame_OnUpdate(...) end)
self.EventLib:RegisterCustomEvent("GC5_CALENDAR_CHANGED", self.CheckForNewEvents, self)
-- Disable the built-in reminder glow/icon
GameTimeCalendarInvitesTexture:SetTexture("")
GameTimeCalendarInvitesGlow:SetTexture("")
--
self.EventLib:DispatchEvent("GC5_INIT")
self:DebugMessage("Group Calendar initialized")
end
function GroupCalendar:ShowTooltip(pOwnerFrame, pTitle, pDescription)
--[[
GameTooltip:SetOwner(pOwnerFrame, "ANCHOR_NONE")
GameTooltip:SetPoint("BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -CONTAINER_OFFSET_X - 13, CONTAINER_OFFSET_Y)
GameTooltip:SetText(pTitle, 1, 1, 1)
GameTooltip:AddLine(pDescription, NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b, 1)
GameTooltip:Show()
]]
GameTooltip_AddNewbieTip(pOwnerFrame, pTitle, 1, 1, 1, pDescription)
end
function GroupCalendar:HideTooltip()
GameTooltip:Hide()
end
function GroupCalendar:FlushEventCaches()
for _, vCalendar in pairs(self.Calendars) do
vCalendar:FlushCaches()
end
end
function GroupCalendar:GetLatestVersionInfo()
if not self.LatestVersionInfo then
self.LatestVersionInfo = GroupCalendar:New(GroupCalendar._Version, "5.0")
end
return self.LatestVersionInfo
end
function GroupCalendar:GameTimeFrame_OnEnter(pGameTimeFrame)
local vDate, vTime, vMonth, vDay, vYear = self.DateLib:GetServerDateTime()
local vEvents = self:GetDayEvents(vMonth, vDay, vYear)
local vLocalDate, vLocalTime = self.DateLib:GetLocalDateTime()
local vDateString, vTimeString
if GroupCalendar.Clock.Data.ShowLocalTime then
vDateString = GroupCalendar.DateLib:GetLongDateString(vLocalDate, true)
vTimeString = GroupCalendar.DateLib:GetShortTimeString(vLocalTime, true).." "..GroupCalendar.cServerTimeNote:format(GroupCalendar.DateLib:GetShortTimeString(vTime, true))
else
vDateString = GroupCalendar.DateLib:GetLongDateString(vDate, true)
vTimeString = GroupCalendar.DateLib:GetShortTimeString(vTime, true).." "..GroupCalendar.cLocalTimeNote:format(GroupCalendar.DateLib:GetShortTimeString(vLocalTime, true))
end
GameTooltip:SetOwner(pGameTimeFrame, "ANCHOR_BOTTOMLEFT")
GameTooltip:AddDoubleLine(
vDateString,
vTimeString,
NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b,
NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b)
GroupCalendar:AddTooltipEvents(GameTooltip, vEvents, GroupCalendar.Clock.Data.ShowLocalTime)
GameTooltip:AddLine(GroupCalendar.cMinimapButtonHint)
GameTooltip:AddLine(GroupCalendar.cMinimapButtonHint2)
GameTooltip:Show()
end
function GroupCalendar:GameTimeFrame_OnUpdate()
end
function GroupCalendar:GetDayEvents(pMonth, pDay, pYear, pRecycleTable)
local vEvents = pRecycleTable
if vEvents then
for vKey, _ in pairs(vEvents) do
vEvents[vKey] = nil
end
end
for vCalendarID, vCalendar in pairs(GroupCalendar.Calendars) do
if vCalendarID == "BLIZZARD" or vCalendarID == "PLAYER" or GroupCalendar.PlayerData.Prefs.ShowAlts then
local vCalendarDay = vCalendar:GetSchedule(pMonth, pDay, pYear)
for _, vEvent in ipairs(vCalendarDay.Events) do
if vEvent:EventIsVisible(vCalendarID == "PLAYER")
and (self.PlayerData.Prefs.ShowLockouts or vEvent.CalendarType ~= "RAID_LOCKOUT") then
if not vEvents then
vEvents = {}
end
table.insert(vEvents, vEvent)
end
end
end
end
if GroupCalendar.Clock.Data.ShowLocalTime then
local vDay2Offset
if GroupCalendar.DateLib:GetServerToLocalOffset() < 0 then
vDay2Offset = 1
else
vDay2Offset = -1
end
local vMonth2, vDay2, vYear2 = GroupCalendar.DateLib:ConvertDateToMDY(GroupCalendar.DateLib:ConvertMDYToDate(pMonth, pDay, pYear) + vDay2Offset)
for vCalendarID, vCalendar in pairs(GroupCalendar.Calendars) do
local vCalendarDay = vCalendar:GetSchedule(vMonth2, vDay2, vYear2)
for _, vEvent in ipairs(vCalendarDay.Events) do
if vEvent:EventIsVisible(vCalendarID == "PLAYER")
and (self.PlayerData.Prefs.ShowLockouts or vEvent.CalendarType ~= "RAID_LOCKOUT") then
if not vEvents then
vEvents = {}
end
table.insert(vEvents, vEvent)
end
end
end
end
if vEvents then
table.sort(vEvents, GroupCalendar.CompareEventTimes)
-- Prune out events outside the range if we're using local date/times
if GroupCalendar.Clock.Data.ShowLocalTime then
local vNumEvents = #vEvents
local vIndex = 1
while vIndex <= vNumEvents do
local vEvent = vEvents[vIndex]
local vLocalDate, vLocalTime = GroupCalendar.DateLib:GetLocalDateTimeFromServerDateTime(GroupCalendar.DateLib:ConvertMDYToDate(vEvent.Month, vEvent.Day, vEvent.Year), GroupCalendar.DateLib:ConvertHMToTime(vEvent.Hour, vEvent.Minute))
local vLocalMonth, vLocalDay, vLocalYear = GroupCalendar.DateLib:ConvertDateToMDY(vLocalDate)
if vLocalMonth ~= pMonth
or vLocalDay ~= pDay
or vLocalYear ~= pYear then
table.remove(vEvents, vIndex)
vNumEvents = vNumEvents - 1
else
vIndex = vIndex + 1
end
end
end
end
return vEvents
end
function GroupCalendar:CanCreateEventOnDate(month, day, year)
return self:IsTodayOrLater(month, day, year) and not self:IsAfterMaxCreateDate(month, day, year)
end
function GroupCalendar:IsTodayOrLater(month, day, year)
local calendarDate = self.WoWCalendar:GetDate()
if year > calendarDate.year then
return true
elseif year < calendarDate.year then
return false
elseif month > calendarDate.month then
return true
elseif month < calendarDate.month then
return false
else
return day >= calendarDate.monthDay
end
end
function GroupCalendar:IsAfterMaxCreateDate(month, day, year)
local maxCreateDate = self.WoWCalendar:GetMaxCreateDate()
if year > maxCreateDate.year then
return true
elseif year < maxCreateDate.year then
return false
elseif month > maxCreateDate.month then
return true
elseif month < maxCreateDate.month then
return false
else
return day > calendarDate.monthDay
end
end
----------------------------------------
-- Utilities
----------------------------------------
function GroupCalendar:ReverseTable(pTable)
local vTable = {}
for vKey, vValue in pairs(pTable) do
vTable[vValue] = vKey
end
return vTable
end
function GroupCalendar:SetEditBoxAutoCompleteText(editBox, text)
local editBoxText = editBox:GetText():upper()
local editBoxTextLength = editBoxText:len()
local savedCursorPos = editBox:GetCursorPosition()
editBox:SetText(text)
editBox:HighlightText(editBoxTextLength, -1)
editBox:SetCursorPosition(savedCursorPos)
end
GroupCalendar.cDeformat = {
s = "(.-)",
d = "(-?[%d]+)",
f = "(-?[%d%.e%+%-]+)",
g = "(-?[%d%.]+)",
["%"] = "%%",
}
function GroupCalendar:ConvertFormatStringToSearchPattern(pFormat)
local vFormat = pFormat:gsub(
"[%[%]%.]",
function (pChar) return "%"..pChar end)
return vFormat:gsub(
"%%[%-%d%.]-([sdgf%%])",
self.cDeformat)
end
function GroupCalendar:FormatItemList(pList)
local vNumItems = #pList
if vNumItems == 0 then
return ""
elseif vNumItems == 1 then
return string.format(self.cSingleItemFormat, pList[1])
elseif vNumItems == 2 then
return string.format(self.cTwoItemFormat, pList[1], pList[2])
else
local vStartIndex, vEndIndex, vPrefix, vRepeat, vSuffix = string.find(self.cMultiItemFormat, "(.*){{(.*)}}(.*)")
local vResult
local vParamIndex = 1
if vPrefix and string.find(vPrefix, "%%") then
vResult = string.format(vPrefix, pList[1])
vParamIndex = 2
else
vResult = vPrefix or ""
end
if vRepeat then
for vIndex = vParamIndex, vNumItems - 1 do
vResult = vResult..string.format(vRepeat, pList[vIndex])
end
end
if vSuffix then
vResult = vResult..string.format(vSuffix, pList[vNumItems])
end
return vResult
end
end
function GroupCalendar:Reset()
GroupCalendar_Data = nil
ReloadUI()
end
function GroupCalendar:ConfirmDelete(pMessage, pParam, pConfirmFunc)
if not StaticPopupDialogs.GC5_CONFIRM_DELETE then
StaticPopupDialogs.GC5_CONFIRM_DELETE =
{
preferredIndex = 3,
text = "",
button1 = DELETE,
button2 = CANCEL,
OnAccept = nil,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
end
StaticPopupDialogs.GC5_CONFIRM_DELETE.text = pMessage
StaticPopupDialogs.GC5_CONFIRM_DELETE.OnAccept = pConfirmFunc
StaticPopup_Show("GC5_CONFIRM_DELETE", pParam)
end
----------------------------------------
-- /cal
----------------------------------------
function GroupCalendar:InstallSlashCommand()
SlashCmdList.CAL = function (...) GroupCalendar:ExecuteCommand(...) end
SLASH_CAL1 = "/cal"
end
function GroupCalendar:ExecuteCommand(pCommandString, ...)
local _, _, vCommand, vParameter = string.find(pCommandString, "([^%s]+)%s*(.*)")
local vCommandFunc = self.Commands[strlower(vCommand or "help")] or self.Commands.help
vCommandFunc(self, vParameter)
end
GroupCalendar.CommandHelp =
{
GroupCalendar.cHelpHeader,
HIGHLIGHT_FONT_COLOR_CODE.."/cal help"..NORMAL_FONT_COLOR_CODE.." "..GroupCalendar.cHelpHelp,
HIGHLIGHT_FONT_COLOR_CODE.."/cal reset"..NORMAL_FONT_COLOR_CODE.." "..GroupCalendar.cHelpReset,
HIGHLIGHT_FONT_COLOR_CODE.."/cal debug switch on|off"..NORMAL_FONT_COLOR_CODE.." "..GroupCalendar.cHelpDebug,
}
----------------------------------------
GroupCalendar.Commands = {}
----------------------------------------
function GroupCalendar.Commands:help()
for _, vString in ipairs(self.CommandHelp) do
self:NoteMessage(vString)
end
end
function GroupCalendar.Commands:reset()
if not StaticPopupDialogs.GC5_CONFIRM_RESET then
StaticPopupDialogs.GC5_CONFIRM_RESET =
{
preferredIndex = 3,
text = GroupCalendar.cConfirmReset,
button1 = RESET,
button2 = CANCEL,
OnAccept = function() GroupCalendar:Reset() end,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
end
StaticPopup_Show("GC5_CONFIRM_RESET")
end
function GroupCalendar.Commands:debug(pParameter)
local _, _, vSwitch, vState = pParameter:find("([^%s]+) ?(.*)")
vSwitch = vSwitch:lower()
vState = vState:lower()
if vSwitch == "off" then
for vKey, _ in pairs(GroupCalendar.Debug) do
GroupCalendar.Debug[vKey] = nil
end
GroupCalendar:NoteMessage("All debug messages disabled")
else
GroupCalendar.Debug[vSwitch] = vState == "on" or vState == "true"
GroupCalendar:NoteMessage("Debug flag %s is now set to %s", vSwitch, tostring(GroupCalendar.Debug[vSwitch]))
end
end
----------------------------------------
GroupCalendar._MinimapReminder = {}
----------------------------------------
function GroupCalendar._MinimapReminder:New()
return CreateFrame("Frame", nil, GameTimeFrame)
end
function GroupCalendar._MinimapReminder:Construct()
self:SetAllPoints()
self:SetFrameLevel(GameTimeFrame:GetFrameLevel() + 2)
self.Enabled = false
self.OnDuration = 0.4
self.OffDuration = 0.2
self.FadeDuration = 0.5
self.FlashDuration = 60 * 60
self.ShowingIcon = false
self.Icon = nil
--[[
self.Texture = self:CreateTexture(nil, "BACKGROUND")
self.Texture:SetWidth(32)
self.Texture:SetHeight(32)
self.Texture:SetPoint("TOPLEFT", self, "TOPLEFT", 8, -8)
self.Texture:SetTexture("")
]]
self.OverlayTexture = self:CreateTexture(nil, "BORDER")
self.OverlayTexture:SetAllPoints(true)
self.OverlayTexture:SetTexture(GroupCalendar.AddonPath.."Textures\\CalendarButton-ReminderFrame")
self.OverlayTexture:SetTexCoord(0, 0.78125, 0, 0.78125)
self.HighlightTexture = self:CreateTexture("GC5MinimapHighlight", "OVERLAY")
self.HighlightTexture:SetBlendMode("ADD")
self.HighlightTexture:SetAllPoints(true)
self.HighlightTexture:SetTexture(GroupCalendar.AddonPath.."Textures\\CalendarButton-Hilight")
self.HighlightTexture:SetTexCoord(0, 0.78125, 0, 0.78125)
self.HighlightTexture:Hide()
end
function GroupCalendar._MinimapReminder:ShowIcon(pIcon, pTexCoords)
--GroupCalendar.Clock.Frame:SetBackground(pIcon, pTexCoords)
end
function GroupCalendar._MinimapReminder:HideIcon()
--GroupCalendar.Clock.Frame:SetBackground(nil)
end
function GroupCalendar._MinimapReminder:StartFlashing(pIcon, pTexCoords)
if pIcon then
self:ShowIcon(pIcon, pTexCoords)
end
if not self.Enabled then
self.Enabled = true
self:UpdateIcon()
end
end
function GroupCalendar._MinimapReminder:StopFlashing()
self.Enabled = false
self:UpdateIcon()
end
function GroupCalendar._MinimapReminder:Stop()
self:StopFlashing()
self:HideIcon()
end
function GroupCalendar._MinimapReminder:UpdateIcon()
local vShowNotifyIcon = false
if self.FlashAnimation then
self.FlashAnimation:Stop()
self.HighlightTexture:Hide()
end
if self.Enabled then
if not self.FlashAnimation then
self.FlashAnimation = self.HighlightTexture:CreateAnimationGroup()
local fadeIn = self.FlashAnimation:CreateAnimation("Alpha")
fadeIn:SetDuration(self.FadeDuration)
fadeIn:SetFromAlpha(0)
fadeIn:SetToAlpha(1)
fadeIn:SetOrder(1)
fadeIn:SetEndDelay(self.OnDuration)
local fadeOut = self.FlashAnimation:CreateAnimation("Alpha")
fadeOut:SetDuration(self.FadeDuration)
fadeOut:SetFromAlpha(1)
fadeOut:SetToAlpha(0)
fadeOut:SetOrder(2)
fadeOut:SetEndDelay(self.OffDuration)
self.FlashAnimation:SetLooping("REPEAT")
end
self.HighlightTexture:SetAlpha(0)
self.HighlightTexture:Show()
self.HighlightTexture:SetVertexColor(1, 0.6, 0.2)
self.FlashAnimation:Play()
vShowNotifyIcon = true
else
self.HighlightTexture:Hide()
end
if vShowNotifyIcon then
self:Show()
else
self:Hide()
end
end
function GroupCalendar:StartFlashingReminder()
if not self.MinimapReminder then
self.MinimapReminder = GroupCalendar:New(GroupCalendar._MinimapReminder)
end
self.MinimapReminder:StartFlashing()
end
function GroupCalendar:StopFlashingReminder()
if self.MinimapReminder then
self.MinimapReminder:Stop()
end
end
function GroupCalendar:ShowReminderIcon(pIcon, pTexCoords)
if not self.MinimapReminder then
self.MinimapReminder = GroupCalendar:New(GroupCalendar._MinimapReminder)
end
self.MinimapReminder:ShowIcon(pIcon, pTexCoords)
end
function GroupCalendar:HideReminderIcon()
if self.MinimapReminder then
self.MinimapReminder:HideIcon()
end
end
function GroupCalendar:CheckForNewEvents()
GroupCalendar.SchedulerLib:RescheduleTask(1, self.CheckForNewEventsNow, self)
end
function GroupCalendar:CheckForNewEventsNow()
local vCalendar = GroupCalendar.Calendars.PLAYER
for vDate, vSchedule in pairs(vCalendar.Schedules) do
for _, vEvent in pairs(vSchedule.Events) do
if vEvent.Unseen then
GroupCalendar:StartFlashingReminder()
return
end
end
end
GroupCalendar:StopFlashingReminder()
end
function GroupCalendar:MarkAllEventsAsSeen()
local vCalendar = GroupCalendar.Calendars.PLAYER
for vDate, vSchedule in pairs(vCalendar.Schedules) do
for _, vEvent in pairs(vSchedule.Events) do
vEvent.Unseen = nil
end
end
GroupCalendar:StopFlashingReminder()
end
----------------------------------------
GroupCalendar._MessageFrame = {}
----------------------------------------
function GroupCalendar._MessageFrame:New()
return CreateFrame("MessageFrame", nil, UIParent)
end
function GroupCalendar._MessageFrame:Construct()
self:SetFading(true)
self:SetFadeDuration(3)
self:SetTimeVisible(10)
self:SetInsertMode("BOTTOM")
self:SetFrameStrata("HIGH")
self:SetWidth(768)
self:SetHeight(100)
self:SetPoint("TOP", UIParent, "TOP", 0, -122)
self:SetFontObject(PVPInfoTextFont)
self:SetJustifyH("CENTER")
end
----------------------------------------
GroupCalendar._Version = {}
----------------------------------------
GroupCalendar._Version.cBuildLevelByCode =
{
d = 4,
a = 3,
b = 2,
f = 1,
}
GroupCalendar._Version.cBuildCodeByLevel = GroupCalendar:ReverseTable(GroupCalendar._Version.cBuildLevelByCode)
function GroupCalendar._Version:Construct(pString)
if pString then
self:FromString(pString)
end
end
function GroupCalendar._Version:FromString(pString)
local _, _, vMajor, vMinor, vBugFix, vBuildLevelCode, vBuildNumber = string.find(pString, "[vV]?(%d+)%.(%d+)%.?(%d*)(%w?)(%d*)")
local vBuildLevel
vMajor = tonumber(vMajor)
if not vMajor then
vMajor = 0
end
vMinor = tonumber(vMinor)
if not vMinor then
vMinor = 0
end
vBugFix = tonumber(vBugFix)
if not vBugFix then
vBugFix = 0
end
if vBuildLevelCode == "" then
vBuildLevel = 0
else
vBuildLevel = self.cBuildLevelByCode[vBuildLevelCode]
if not vBuildLevel then
vBuildLevel = 5
end
end
vBuildNumber = tonumber(vBuildNumber)
if not vBuildNumber then
vBuildNumber = 0
end
self.Major = vMajor
self.Minor = vMinor
self.BugFix = vBugFix
self.BuildLevel = vBuildLevel
self.BuildNumber = vBuildNumber
end
function GroupCalendar._Version:LessThan(pVersion)
if self.Major ~= pVersion.Major then
return self.Major < pVersion.Major
end
if self.Minor ~= pVersion.Minor then
return self.Minor < pVersion.Minor
end
if self.BugFix ~= pVersion.BugFix then
return self.BugFix < pVersion.BugFix
end
if self.BuildLevel ~= pVersion.BuildLevel then
return self.BuildLevel > pVersion.BuildLevel
end
if self.BuildNumber ~= pVersion.BuildNumber then
return self.BuildNumber < pVersion.BuildNumber
end
return false
end
function GroupCalendar._Version:ToString()
local vString = string.format("%d.%d", self.Major, self.Minor)
if self.BugFix > 0 then
vString = vString.."."..self.BugFix
end
if self.BuildLevel > 0 then
vString = string.format("%s%s%d", vString, GroupCalendar._Version.cBuildCodeByLevel[self.BuildLevel] or "?", self.BuildNumber)
end
return vString
end
----------------------------------------
-- Calendars
----------------------------------------
function GroupCalendar:InitializeCalendars()
self.Calendars = {}
self.Calendars.BLIZZARD = GroupCalendar:New(GroupCalendar._Calendar, GroupCalendar.cBlizzardOwner, "BLIZZARD", nil, false)
for vRealmName, vRealmData in pairs(self.Data.Realms) do
for vCharacterGUID, vCharacterData in pairs(vRealmData.Characters) do
local vCalendarID, vReadOnly
if vCharacterData == self.PlayerData then
vCalendarID = "PLAYER"
vReadOnly = false
else
vCalendarID = vCharacterData.GUID
vReadOnly = true
end
self.Calendars[vCalendarID] = GroupCalendar:New(GroupCalendar._Calendar, vCharacterData.Name, vCalendarID, vCharacterData.Events, vReadOnly)
end
end
end
----------------------------------------
-- Roles
----------------------------------------
function GroupCalendar:GetPlayerDefaultRoleCode(pPlayerName, pClassID)
if not self.RealmData.DefaultRoles
or not self.RealmData.DefaultRoles[pPlayerName] then
if not pClassID or pClassID == "" then
return "?"
end
if not self.ClassInfoByClassID[pClassID] then
error(string.format("Unknown class ID %s", tostring(pClassID)))
end
return self.ClassInfoByClassID[pClassID].DefaultRole
end
return self.RealmData.DefaultRoles[pPlayerName]
end
function GroupCalendar:SetPlayerDefaultRoleCode(pPlayerName, pRoleCode)
if not self.RealmData.DefaultRoles then
self.RealmData.DefaultRoles = {}
end
self.RealmData.DefaultRoles[pPlayerName] = pRoleCode
end
----------------------------------------
-- Event templates
----------------------------------------
function GroupCalendar:AutoCompleteEventTitle(pEditBox)
local editBoxText = pEditBox:GetText()
local upperEditBoxText = editBoxText:upper()
local upperEditBoxTextLen = upperEditBoxText:len()
local template = self:FindEventTemplateByPartialTitle(editBoxText)
if template then
GroupCalendar:SetEditBoxAutoCompleteText(pEditBox, template.Title)
return nil, nil, template
end
for eventType = CALENDAR_EVENTTYPE_RAID, CALENDAR_EVENTTYPE_OTHER do
local eventTypeTextures = GroupCalendar:GetEventTypeTextures(eventType)
for textureIndex, textureInfo in ipairs(eventTypeTextures) do
local name = textureInfo.title
if name:upper():sub(1, upperEditBoxTextLen) == upperEditBoxText then
GroupCalendar:SetEditBoxAutoCompleteText(pEditBox, name)
return eventType, textureIndex
end
end
end
end
function GroupCalendar:FindEventTemplateByTitle(pTitle)
local vUpperTitle = pTitle:upper()
for vIndex, vTemplate in ipairs(self.PlayerData.EventTemplates) do
local vTemplateTitle = self.WoWCalendar:GetDisplayTitle(vTemplate.CalendarType, vTemplate.SequenceType, vTemplate.Title or "")
local vTemplateUpperTitle = vTemplateTitle:upper()
if vTemplateUpperTitle == vUpperTitle then
return vTemplate, vIndex
end
end
end
function GroupCalendar:FindEventTemplateByPartialTitle(pTitle)
if not self.PlayerData.EventTemplates then
return
end
local vUpperTitle = pTitle:upper()
local vUpperTitleLen = vUpperTitle:len()
for vIndex, vTemplate in ipairs(self.PlayerData.EventTemplates) do
local vTemplateTitle = self.WoWCalendar:GetDisplayTitle(vTemplate.CalendarType, vTemplate.SequenceType, vTemplate.Title or "")
local vTemplateUpperTitle = vTemplateTitle:upper()
if vTemplateUpperTitle:sub(1, vUpperTitleLen) == vUpperTitle then
return vTemplate, vIndex
end
end
end
function GroupCalendar:FindEventTemplateByEvent(pEvent)
if not self.PlayerData.EventTemplates then
return
end
for vIndex, vTemplate in ipairs(self.PlayerData.EventTemplates) do
if pEvent.CalendarType == vTemplate.CalendarType
and pEvent.EventType == vTemplate.EventType
and pEvent.TitleTag == vTemplate.TitleTag
and pEvent.TextureIndex == vTemplate.TextureIndex then
if not vTemplate.Title then
vTemplate.Title = "" -- Fix missing Title field
end
return vTemplate, vIndex
end
end
end
GroupCalendar.EventTemplateFields =
{
Hour = true,
Minute = true,
Second = true,
Limits = true,
CalendarType = true,
Description = true,
DescriptionTag = true,
Title = true,
TitleTag = true,
TextureIndex = true,
TextureID = true,
EventType = true,
MinLevel = true,
MaxLevel = true,
Attendance = true,
}
function GroupCalendar:SaveEventTemplate(pEvent)
-- Remove any existing template
if self.PlayerData.EventTemplates then
local _, vIndex = self:FindEventTemplateByEvent(pEvent)
if vIndex then
table.remove(self.PlayerData.EventTemplates, vIndex)
end
else
self.PlayerData.EventTemplates = {}
end
-- Make a deep duplicate of the event
local vTemplate = {}
for vField, _ in pairs(GroupCalendar.EventTemplateFields) do
if type(pEvent[vField]) == "table" then
vTemplate[vField] = GroupCalendar:DuplicateTable(pEvent[vField], true)
else
vTemplate[vField] = pEvent[vField]
end
end
-- Change all attendance to "invited" in the template
if vTemplate.Attendance then
for _, vInfo in pairs(vTemplate.Attendance) do
vInfo.InviteStatus = self.CALENDAR_INVITESTATUS_INVITED
end
end
-- Eliminate fields we want ignored
vTemplate.Year = nil
vTemplate.Month = nil
vTemplate.Day = nil
vTemplate.CacheUpdateDate = nil
vTemplate.CacheUpdateTime = nil
vTemplate.Group = nil
-- Ensure required fields are present
if not vTemplate.Title then
vTemplate.Title = ""
end
-- Save the template at the front of the list to give it
-- higher priority next time around
table.insert(self.PlayerData.EventTemplates, 1, vTemplate)
end
----------------------------------------
-- Database repairs/upgrades
----------------------------------------
function GroupCalendar:InitializeData()
-- Purge the data if the user is downgrading from a newer build
if GroupCalendar_Data then
local vThisVersion = GroupCalendar:New(GroupCalendar._Version, GroupCalendar.cVersionString)
local vLastVersion = GroupCalendar:New(GroupCalendar._Version, GroupCalendar_Data.LastVersion)
if not GroupCalendar_Data.LastVersion
or vThisVersion:LessThan(vLastVersion) then -- Downgrading, purge the old data
GroupCalendar_Data = nil
end
end
-- Initialize the data
if not GroupCalendar_Data
or not GroupCalendar_Data.LastVersion then
GroupCalendar_Data =
{
Realms = {},
Prefs = {},
Debug = {},
LastVersion = GroupCalendar.cVersionString,
}
end
-- Perform repairs and upgrades
-- Done
self.Debug = GroupCalendar_Data.Debug
self.Data = GroupCalendar_Data
GroupCalendar_Data.LastVersion = GroupCalendar.cVersionString
end
----------------------------------------
-- Running event
----------------------------------------
function GroupCalendar:GetEventElapsedSeconds(pEvent)
local vEvent = pEvent.OriginalEvent or pEvent
local vElapsed = vEvent.ElapsedSeconds or 0
if self.RunningEvent == pEvent then
local vDate, vTime60 = GroupCalendar.DateLib:GetServerDateTime60()
vElapsed = vElapsed + (vDate * GroupCalendar.DateLib.cSecondsPerDay + vTime60)
- (vEvent.StartDate * GroupCalendar.DateLib.cSecondsPerDay + vEvent.StartTime60)
end
return vElapsed
end
function GroupCalendar:StartEvent(pEvent, pNotificationFunc)
if self.RunningEvent then
self:StopEvent(self.RunningEvent)
end
self.RunningEvent = pEvent
local vEvent = self.RunningEvent.OriginalEvent or self.RunningEvent
if not vEvent.StartDate then
vEvent.StartDate, vEvent.StartTime60 = GroupCalendar.DateLib:GetServerDateTime60()
end
GroupCalendar.EventLib:RegisterCustomEvent("MC2RAIDLIB_RAID_CHANGED", self.EventRaidChanged, self)
GroupCalendar.EventLib:DispatchEvent("GC5_EVENT_START", self.RunningEvent)
self:EventRaidChanged()
self.RaidInvites = GroupCalendar:New(GroupCalendar._RaidInvites)
self.RaidInvites:BeginInvites(pEvent.Title, true, pNotificationFunc)
end
function GroupCalendar:StopEvent()
if not self.RunningEvent then
return
end
self.RaidInvites:EndInvites()