-
Notifications
You must be signed in to change notification settings - Fork 1
/
Core.lua
2160 lines (1807 loc) · 65 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
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
local ADDON_NAME = "GuildsOfWoW";
local FRAME_NAME = ADDON_NAME .. "MainFrame";
local GOW = LibStub("AceAddon-3.0"):NewAddon(ADDON_NAME);
GuildsOfWow = GOW;
GOW.consts = {
INVITE_INTERVAL = 2,
ENABLE_DEBUGGING = false,
GUILD_EVENT = 1,
PLAYER_EVENT = 2
};
GOW.defaults = {
profile = {
version = 1,
minimap = { hide = false },
warnNewEvents = true
}
}
local getGowGameVersionId = function()
-- if (GOW.consts.ENABLE_DEBUGGING) then
-- print("WOW_PROJECT_ID: " .. WOW_PROJECT_ID);
-- end
if (WOW_PROJECT_ID == WOW_PROJECT_MAINLINE) then
return 1;
elseif (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC) then
return 2;
elseif (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC) then
return 3;
end
return nil;
end
function GetCurrentRegionByGameVersion()
local regionId = GetCurrentRegion();
if (getGowGameVersionId() == 3) then
return tonumber("4" .. tostring(regionId));
elseif (getGowGameVersionId() == 2) then
return tonumber("8" .. tostring(regionId));
end
return regionId;
end
function GetCurrentCharacterUniqueKey()
local name, characterRealm = UnitName("player");
if (characterRealm == nil) then
characterRealm = GetNormalizedRealmName();
end
return name .. "-" .. characterRealm;
end
local openRaidLib = nil;
if (getGowGameVersionId() == 1) then
openRaidLib = LibStub:GetLibrary("LibOpenRaid-1.0");
end
local ns = select(2, ...);
local Core = {};
local f = CreateFrame("Frame");
f:RegisterEvent("PLAYER_ENTERING_WORLD");
f:RegisterEvent("FIRST_FRAME_RENDERED");
f:RegisterEvent("GUILD_ROSTER_UPDATE");
f:RegisterEvent("FRIENDLIST_UPDATE");
f:RegisterEvent("CALENDAR_UPDATE_GUILD_EVENTS");
f:RegisterEvent("CALENDAR_UPDATE_EVENT_LIST");
f:RegisterEvent("CALENDAR_NEW_EVENT");
f:RegisterEvent("CALENDAR_UPDATE_EVENT");
f:RegisterEvent("CALENDAR_UPDATE_INVITE_LIST");
f:RegisterEvent("CALENDAR_OPEN_EVENT");
f:RegisterEvent("CALENDAR_CLOSE_EVENT");
f:RegisterEvent("CALENDAR_ACTION_PENDING");
local isInitialLogin = false;
local isPropogatingUpdate = false;
local containerFrame = nil;
local containerTabs = nil;
local containerScrollFrame = nil;
local currentOpenDialog = nil;
local workQueue = nil;
local persistentWorkQueue = nil;
local processedEvents = nil;
local isEventProcessCompleted = false;
local isNewEventBeingCreated = false;
local isProcessedEventsPrinted = false;
local isCalendarOpened = false;
local isCalendarOpenEventBound = false;
local selectedTab = "events";
local tabs = {
{ value = "events", text = "Upcoming Events" },
{ value = "teams", text = "Teams" },
{ value = "recruitmentApps", text = "Recruitment Applications" },
};
local LibQTip = LibStub('LibQTip-1.0');
function GOW:OnInitialize()
self.GUI = LibStub("AceGUI-3.0");
self.DB = LibStub("AceDB-3.0"):New("GoWDB", GOW.defaults, "Default");
self.LDB = LibStub("LibDataBroker-1.1");
self.LDBIcon = LibStub("LibDBIcon-1.0");
self.CONSOLE = LibStub("AceConsole-3.0");
self.SCROLLINGTABLE = LibStub("ScrollingTable");
self.timers = {};
LibStub("AceTimer-3.0"):Embed(self.timers);
self.events = {};
LibStub("AceEvent-3.0"):Embed(self.events);
workQueue = self.WorkQueue.new();
persistentWorkQueue = self.WorkQueue.new();
processedEvents = GOW.List.new();
local consoleCommandFunc = function(msg, editbox)
if (msg == "minimap") then
Core:ToggleMinimap();
else
Core:ToggleWindow();
end
end
self.CONSOLE:RegisterChatCommand("gow", consoleCommandFunc);
local dataobj = self.LDB:NewDataObject("gowicon", {
type = "data source",
label = "Guilds of WoW",
text = "Guilds of WoW",
icon = "Interface\\Addons\\GuildsOfWoW\\icons\\VAS_GuildFactionChange.tga",
OnTooltipShow = function(tooltip)
tooltip:SetText("Guilds of WoW");
tooltip:Show();
end,
OnClick = GuildsOfWow_OnAddonButtonClick
});
self.LDBIcon:Register("gowicon", dataobj, self.DB.profile.minimap);
string.lpad = function(str, len, char)
if char == nil then char = ' ' end
return string.rep(char, len - #str) .. str;
end
string.splitByDelimeter = function(str, delimiter)
local result = {};
for match in (str .. delimiter):gmatch("(.-)" .. delimiter) do
table.insert(result, match);
end
return result;
end
containerFrame = GOW.GUI:Create("Frame");
containerFrame:SetLayout("Fill");
containerFrame:SetHeight(550);
containerFrame.frame:SetFrameStrata("MEDIUM");
containerFrame:SetTitle("Guilds of WoW");
containerFrame:SetStatusText("Type /gow for quick access");
containerFrame:SetCallback("OnClose", function(widget)
containerFrame:Hide();
if (currentOpenDialog) then
StaticPopup_Hide(currentOpenDialog);
currentOpenDialog = nil;
end
end);
containerFrame:Hide();
_G[FRAME_NAME] = containerFrame.frame;
tinsert(UISpecialFrames, FRAME_NAME);
containerTabs = GOW.GUI:Create("TabGroup");
containerTabs:SetTabs(tabs);
containerTabs:SelectTab(selectedTab);
containerTabs:SetCallback("OnGroupSelected", function(frame, event, value) Core:ToggleTabs(value) end);
containerFrame:AddChild(containerTabs);
containerScrollFrame = GOW.GUI:Create("ScrollFrame");
containerScrollFrame:SetLayout("Flow");
containerScrollFrame:SetFullWidth(true);
containerScrollFrame:SetFullHeight(true);
containerTabs:AddChild(containerScrollFrame);
if (ns.UPCOMING_EVENTS == nil or ns.TEAMS == nil or ns.RECRUITMENT_APPLICATIONS == nil) then
Core:PrintErrorMessage("Data is not fetched! Please make sure your sync app is installed and working properly.");
end
StaticPopupDialogs["NEW_EVENT_FOUND"] = {
text = "There are events not registered on calendar.\r\n\r\nDo you wish to view Guilds of WoW upcoming events?",
button1 = YES,
button2 = NO,
button3 = "Don't ask again",
OnAccept = function(self, data)
containerFrame:Show();
containerTabs:SelectTab("events");
Core:DialogClosed();
end,
OnCancel = function()
Core:DialogClosed();
end,
OnAlt = function()
GOW.DB.profile.warnNewEvents = false;
Core:DialogClosed();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["CONFIRM_EVENT_CREATION"] = {
text = "Are you sure you want to create this event on in-game calendar?",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self, event)
Core:ConfirmEventCreation(event);
end,
OnCancel = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["CONFIRM_GUILD_EVENT_CREATION"] = {
text =
"Are you sure you want to create this guild event on in-game calendar?\r\n\r\n(Note: Guild events RSVP integration only works single direction which is from WoW to GoW.)",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self, event)
Core:ConfirmEventCreation(event);
end,
OnCancel = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["CONFIRM_INVITE_TO_GUILD"] = {
text = "Are you sure you want to invite %s to your guild?",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self, data)
C_GuildInfo.Invite(data);
Core:PrintSuccessMessage("Invitation sent to " .. data);
Core:DialogClosed();
end,
OnCancel = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["CONFIRM_ADD_FRIEND"] = {
text = ADD_CHARACTER_FRIEND,
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self, data)
C_FriendList.AddFriend(data, "Guilds of WoW recruitment");
Core:DialogClosed();
end,
OnCancel = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["WHISPER_PLAYER"] = {
text = "Type your message",
button1 = "Send",
button2 = CANCEL,
OnAccept = function(self, data)
local text = self.editBox:GetText();
if (text ~= nil and text ~= "") then
SendChatMessage(text, "WHISPER", nil, data);
Core:DialogClosed();
end
end,
OnCancel = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
EditBoxOnEscapePressed = StaticPopup_StandardEditBoxOnEscapePressed,
timeout = 100,
enterClicksFirstButton = 1,
whileDead = 1,
hideOnEscape = 1,
hasEditBox = 1,
exclusive = 1,
preferredIndex = 3
};
StaticPopupDialogs["COPY_TEXT"] = {
text = "Select & copy following text",
button1 = DONE,
OnShow = function(self, data)
self.editBox:SetText(data);
self.editBox:HighlightText();
self.editBox:SetFocus();
end,
OnAccept = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
EditBoxOnEscapePressed = StaticPopup_StandardEditBoxOnEscapePressed,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
hasEditBox = 1,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["CONFIRM_INVITE_TO_PARTY"] = {
text = "Are you sure you want to invite %s member(s) to your party?",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self, data)
Core:InviteAllToParty(data);
Core:DialogClosed();
end,
OnCancel = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["CONFIRM_INVITE_TEAM_TO_PARTY"] = {
text = "Are you sure you want to invite %s member(s) to your party?",
button1 = ACCEPT,
button2 = CANCEL,
OnAccept = function(self, data)
Core:InviteAllTeamMembersToParty(data);
Core:DialogClosed();
end,
OnCancel = function()
Core:DialogClosed();
end,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["INVITE_TO_PARTY_NOONE_FOUND"] = {
text = "No member from this event is available to invite.",
button1 = OKAY,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
enterClicksFirstButton = 1,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["INVITE_TO_PARTY_INVALID_CALENDAR"] = {
text =
"Only 'Player Event' attendances can be invited via addon. For 'Guild Events' you can create the event and use that event's 'Invite Members' functionality.",
button1 = OKAY,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
enterClicksFirstButton = 1,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
StaticPopupDialogs["INVITE_TO_PARTY_USE_CALENDAR"] = {
text = "This event is also created on calendar. Please use calendar event's 'Invite Members' button.",
button1 = OKAY,
OnHide = function()
Core:DialogClosed();
end,
timeout = 0,
enterClicksFirstButton = 1,
whileDead = true,
hideOnEscape = true,
exclusive = 1,
preferredIndex = 1
};
end
f:SetScript("OnEvent", function(self, event, arg1, arg2)
Core:Debug(event);
if event == "PLAYER_ENTERING_WORLD" then
isInitialLogin = arg1;
Core:Debug(tostring(arg1));
Core:Debug(tostring(arg2));
elseif event == "FIRST_FRAME_RENDERED" then
isCalendarOpened = true;
if (isInitialLogin) then
persistentWorkQueue:addTask(function()
Core:InitializeEventInvites();
end, nil, 5);
else
Core:InitializeEventInvites();
end
if (openRaidLib) then
openRaidLib.RequestKeystoneDataFromGuild();
end
elseif event == "GUILD_ROSTER_UPDATE" then
Core:SetRosterInfo();
elseif event == "CALENDAR_ACTION_PENDING" then
if (tostring(arg1) == "false") then
Core:Debug("CALENDAR_ACTION_PENDING: " .. tostring(arg1));
Core:RefreshUpcomingEventsList();
end
elseif event == "CALENDAR_UPDATE_EVENT_LIST" then
--f:UnregisterEvent("CALENDAR_UPDATE_EVENT_LIST");
if (CalendarFrame and not isCalendarOpenEventBound) then
isCalendarOpenEventBound = true;
hooksecurefunc(CalendarFrame, "Show", function()
if (isEventProcessCompleted and not isNewEventBeingCreated) then
Core:Debug("Clearing tasks: CALENDAR_UPDATE_EVENT_LIST");
workQueue:clearTasks();
end
containerFrame:Hide();
end);
if (containerFrame:IsShown()) then
containerFrame:Hide();
end
end
--Core:InitializeEventInvites();
--Core:RefreshUpcomingEventsList();
elseif event == "CALENDAR_NEW_EVENT" or event == "CALENDAR_UPDATE_EVENT" or event == "CALENDAR_UPDATE_GUILD_EVENTS" then
if (CalendarFrame and CalendarFrame:IsShown()) then
Core:Debug("Calendar frame is open.");
return;
end
if (event == "CALENDAR_UPDATE_GUILD_EVENTS") then
--f:UnregisterEvent("CALENDAR_UPDATE_GUILD_EVENTS");
Core:InitializeEventInvites();
end
Core:RefreshUpcomingEventsList();
elseif event == "CALENDAR_OPEN_EVENT" then
if (CalendarFrame and CalendarFrame:IsShown()) then
Core:Debug("Calendar frame is open.");
return;
end
if (C_Calendar.IsEventOpen()) then
local eventInfo = C_Calendar.GetEventInfo();
if (eventInfo and eventInfo.title and string.len(eventInfo.title) > 0) then
Core:Debug("CALENDAR_OPEN_EVENT: Opened: " ..
eventInfo.title .. ". Calendar Type: " .. eventInfo.calendarType);
Core:ClearEventInvites(false);
isNewEventBeingCreated = false;
if (eventInfo.calendarType == "GUILD_EVENT" or eventInfo.calendarType == "PLAYER") then
local upcomingEvent = Core:FindUpcomingEventFromName(eventInfo.title);
if (upcomingEvent) then
if (eventInfo.isLocked) then
if (not upcomingEvent.isLocked) then
C_Calendar.EventClearLocked();
end
else
if (upcomingEvent.isLocked) then
C_Calendar.EventSetLocked();
end
end
if (eventInfo.calendarType == "PLAYER") then
--processedEvents:remove(upcomingEvent.titleWithKey)
Core:CreateEventInvites(upcomingEvent, not isEventProcessCompleted);
else
Core:SetAttendance(upcomingEvent, not isEventProcessCompleted);
end
else
Core:Debug("Event couldn't be found!");
end
else
Core:Debug("Not suitable calendar type!");
end
else
Core:Debug("Event info is null!");
end
else
Core:Debug("Event is not open!");
workQueue:addTask(function()
Core:Debug("Checking attendances");
Core:CheckEventInvites();
end, nil, 10);
end
elseif event == "CALENDAR_CLOSE_EVENT" then
if (isNewEventBeingCreated) then
isNewEventBeingCreated = false;
if (CalendarFrame and CalendarFrame:IsShown()) then
isEventProcessCompleted = false;
end
end
if (not isEventProcessCompleted) then
Core:ClearEventInvites(true);
end
elseif event == "CALENDAR_UPDATE_INVITE_LIST" then
if (not isEventProcessCompleted and CalendarFrame and CalendarFrame:IsShown()) then
Core:Debug("Calendar frame is open.");
return;
end
if (C_Calendar.IsEventOpen()) then
local eventInfo = C_Calendar.GetEventInfo();
if (processedEvents:contains(eventInfo.title)) then
if (eventInfo.title == "") then
Core:ClearEventInvites(false);
else
local upcomingEvent = Core:FindUpcomingEventFromName(eventInfo.title);
if (upcomingEvent) then
--processedEvents:remove(eventInfo.title);
Core:SetAttendance(upcomingEvent, false);
end
end
elseif (workQueue:isEmpty()) then
Core:Debug("Continuing event attendance and moderation!");
local upcomingEvent = Core:FindUpcomingEventFromName(eventInfo.title);
if (upcomingEvent) then
Core:SetAttendance(upcomingEvent, false);
end
end
end
elseif event == "FRIENDLIST_UPDATE" then
Core:CreateRecruitmentApplications();
end
end)
function Core:ToggleTabs(tabKey)
selectedTab = tabKey;
Core:RefreshApplication();
end
function Core:RefreshApplication()
isPropogatingUpdate = true;
if (selectedTab == "events") then
Core:CreateUpcomingEvents();
elseif (selectedTab == "teams") then
Core:CreateTeams();
elseif (selectedTab == "recruitmentApps") then
Core:CreateRecruitmentApplications();
end
end
function Core:ToggleWindow()
if (containerFrame:IsShown()) then
containerFrame:Hide();
else
if (CalendarFrame) then
HideUIPanel(CalendarFrame);
end
StaticPopup_Hide("NEW_EVENT_FOUND");
Core:RefreshApplication();
containerFrame:Show();
end
end
function Core:RefreshUpcomingEventsList()
Core:Debug("RefreshUpcomingEventsList: containerFrame:IsShown(): " .. tostring(containerFrame:IsShown()) .. ". isPropogatingUpdate: " .. tostring(isPropogatingUpdate) .. ". selectedTab: " .. selectedTab .. ". isEventProcessCompleted: " .. tostring(isEventProcessCompleted) .. ". isNewEventBeingCreated: " .. tostring(isNewEventBeingCreated));
if (containerFrame:IsShown() and isPropogatingUpdate == false and selectedTab == "events" and isEventProcessCompleted and not isNewEventBeingCreated) then
Core:Debug("Adding to work queue: CreateUpcomingEvents");
persistentWorkQueue:addTask(function()
isPropogatingUpdate = true;
Core:CreateUpcomingEvents();
end, nil, 2);
end
end
function Core:CreateUpcomingEvents()
if (selectedTab ~= "events") then
Core:Debug("Selected tab is not events.");
return;
end
containerScrollFrame:ReleaseChildren();
if (ns.UPCOMING_EVENTS == nil) then
Core:AppendMessage(
"Upcoming events data is not found! Please make sure your sync app is installed and working properly!", true);
else
local isInGuild = IsInGuild();
if (not isInGuild) then
Core:AppendMessage("This character is not in a guild! You must be a guild member to use this feature.", false);
return;
end
local guildName, _, _, realmName = GetGuildInfo("player");
if (not guildName) then
Core:AppendMessage("This character is not in a guild! You must be a guild member to use this feature.", false);
return;
end
if (ns.UPCOMING_EVENTS.totalEvents > 0) then
if (not isEventProcessCompleted or isNewEventBeingCreated or C_Calendar.IsActionPending()) then
Core:AppendMessage("Addon is busy right now! Please wait for a while...");
isPropogatingUpdate = false;
return;
end
end
Core:Debug("Core:CreateUpcomingEvents");
if (not realmName) then
realmName = GetNormalizedRealmName();
end
local regionId = GetCurrentRegionByGameVersion();
local hasAnyData = false;
if (ns.UPCOMING_EVENTS.totalEvents > 0) then
Core:ResetCalendar();
for i = 1, ns.UPCOMING_EVENTS.totalEvents do
local upcomingEvent = ns.UPCOMING_EVENTS.events[i];
if (guildName == upcomingEvent.guild and realmName == upcomingEvent.guildRealmNormalized and regionId == upcomingEvent.guildRegionId) then
if (Core:AppendCalendarList(upcomingEvent)) then
hasAnyData = true;
end
end
end
end
if (not hasAnyData) then
Core:AppendMessage(
"This guild either doesn't have any upcoming events that you are a member of, or you are not an event manager!\r\n\r\nGuild: " ..
guildName .. " / " .. realmName, true);
end
end
isPropogatingUpdate = false;
end
function Core:CreateTeams()
if (selectedTab ~= "teams") then
return;
end
if (ns.TEAMS == nil) then
containerScrollFrame:ReleaseChildren();
Core:AppendMessage("Team data is not found! Please make sure your sync app is installed and working properly!",
true);
else
local isInGuild = IsInGuild();
if (isInGuild == false) then
Core:AppendMessage("This character is not in a guild! You must be a guild member to use this feature.", false);
return;
end
local guildName, _, _, realmName = GetGuildInfo("player");
if (guildName == nil) then
Core:AppendMessage("This character is not in a guild! You must be a guild member to use this feature.", false);
return;
end
containerScrollFrame:ReleaseChildren();
if (realmName == nil) then
realmName = GetNormalizedRealmName();
end
local regionId = GetCurrentRegionByGameVersion();
local hasAnyData = false;
if (isInGuild and ns.TEAMS.totalTeams > 0) then
for i = 1, ns.TEAMS.totalTeams do
local team = ns.TEAMS.teams[i];
if (guildName == team.guild and realmName == team.guildRealmNormalized and regionId == team.guildRegionId) then
hasAnyData = true;
Core:AppendTeam(team);
end
end
--containerScrollFrame:DoLayout();
end
if (not hasAnyData) then
Core:AppendMessage(
"This guild doesn't have any team or you are not a roster manager!\r\n\r\nGuild: " ..
guildName .. " / " .. realmName, true);
end
end
isPropogatingUpdate = false;
end
function Core:CreateRecruitmentApplications()
if (selectedTab ~= "recruitmentApps") then
return;
end
if (ns.RECRUITMENT_APPLICATIONS == nil) then
containerScrollFrame:ReleaseChildren();
Core:AppendMessage(
"Recruitment applications data is not found! Please make sure your sync app is installed and working properly!",
true);
else
local isInGuild = IsInGuild();
if (isInGuild == false) then
Core:AppendMessage("This character is not in a guild! You must be a guild member to use this feature.", false);
return;
end
local guildName, _, _, realmName = GetGuildInfo("player");
if (guildName == nil) then
Core:AppendMessage("This character is not in a guild! You must be a guild member to use this feature.", false);
return;
end
containerScrollFrame:ReleaseChildren();
if (realmName == nil) then
realmName = GetNormalizedRealmName();
end
local regionId = GetCurrentRegionByGameVersion();
local hasAnyData = false;
if (isInGuild and ns.RECRUITMENT_APPLICATIONS.totalApplications > 0) then
for i = 1, ns.RECRUITMENT_APPLICATIONS.totalApplications do
local recruitmentApplication = ns.RECRUITMENT_APPLICATIONS.recruitmentApplications[i]
if (guildName == recruitmentApplication.guild and realmName == recruitmentApplication.guildRealmNormalized and regionId == recruitmentApplication.guildRegionId) then
hasAnyData = true;
Core:AppendRecruitmentList(recruitmentApplication);
end
end
--containerScrollFrame:DoLayout()
end
if (not hasAnyData) then
Core:AppendMessage(
"This guild doesn't have any guild recruitment application or you are not a recruitment manager!\r\n\r\nGuild: " ..
guildName .. " / " .. realmName, true);
end
end
isPropogatingUpdate = false;
end
function Core:ResetCalendar()
local monthInfo = C_Calendar.GetMonthInfo();
local calendarMonth = monthInfo.month;
local calendarYear = monthInfo.year;
local serverTime = C_DateAndTime.GetServerTimeLocal();
local serverMonth = tonumber(date("%m", serverTime));
local serverYear = tonumber(date("%Y", serverTime));
if (calendarMonth ~= serverMonth or calendarYear ~= serverYear) then
Core:Debug("Resetting calendar to current date. Current: " .. calendarMonth .. "/" .. calendarYear .. " - Server: " .. serverMonth .. "/" .. serverYear);
C_Calendar.SetAbsMonth(serverMonth, serverYear);
end
end
function Core:searchForEvent(event)
local serverTime = C_DateAndTime.GetServerTimeLocal();
if (CalendarFrame and CalendarFrame:IsShown()) then
return -2;
end
if (event.eventDate < serverTime) then
return 0;
end
--C_Calendar.SetAbsMonth(event.month, event.year);
--local month, year = C_Calendar.GetMonthInfo();
local offsetMonths = tonumber(date("%m", event.eventDate)) - tonumber(date("%m", serverTime))
local numDayEvents = C_Calendar.GetNumDayEvents(offsetMonths, event.day);
--Core:Debug("Searching: " .. event.titleWithKey .. ". Found: " .. numDayEvents .. " : " .. event.day .. "/" .. event.month .. "/" .. event.year);
if (numDayEvents > 0) then
for i = 1, numDayEvents do
local dayEvent = C_Calendar.GetDayEvent(offsetMonths, event.day, i);
if (dayEvent.calendarType == "GUILD_EVENT" or dayEvent.calendarType == "PLAYER") then
--Core:Debug("dayEvent: " .. dayEvent.title .. " - " .. dayEvent.calendarType);
if (string.match(dayEvent.title, "*" .. event.eventKey)) then
return i, offsetMonths, dayEvent;
end
end
end
end
return -1
end
function Core:AppendMessage(message, appendReloadUIButton)
local fontPath = STANDARD_TEXT_FONT;
local fontSize = 13;
local itemGroup = GOW.GUI:Create("SimpleGroup");
--itemGroup:SetLayout("Line");
itemGroup:SetFullWidth(true);
itemGroup:SetFullHeight(true);
local blankMargin = GOW.GUI:Create("SimpleGroup");
blankMargin:SetLayout("Line");
blankMargin:SetFullWidth(true);
blankMargin:SetHeight(10);
itemGroup:AddChild(blankMargin);
local messageLabel = GOW.GUI:Create("Label");
messageLabel:SetText(message);
messageLabel:SetFullWidth(true);
messageLabel:SetFont(fontPath, fontSize, "");
itemGroup:AddChild(messageLabel);
if (appendReloadUIButton) then
local blankMargin2 = GOW.GUI:Create("SimpleGroup");
blankMargin2:SetLayout("Line");
blankMargin2:SetFullWidth(true);
blankMargin2:SetHeight(10);
itemGroup:AddChild(blankMargin2);
local reloadUIButton = GOW.GUI:Create("Button");
reloadUIButton:SetText("Reload UI");
reloadUIButton:SetCallback("OnClick", function()
ReloadUI();
end);
itemGroup:AddChild(reloadUIButton);
end
containerScrollFrame:AddChild(itemGroup);
end
function Core:AppendCalendarList(event)
if not Core:IsInvitedToEvent(event) then
return false;
end
local itemGroup = GOW.GUI:Create("InlineGroup");
itemGroup:SetTitle(event.title);
itemGroup:SetFullWidth(true);
if (event.description ~= nil and event.description ~= "") then
local descriptionLabel = GOW.GUI:Create("SFX-Info");
descriptionLabel:SetLabel("Description");
descriptionLabel:SetText(event.description);
descriptionLabel:SetDisabled(false);
descriptionLabel:SetCallback("OnEnter", function(self)
local tooltip = LibQTip:Acquire("EventMessageTooltip", 1, "LEFT");
GOW.tooltip = tooltip;
tooltip:AddHeader('|cffffcc00Event Description');
local line = tooltip:AddLine();
tooltip:SetCell(line, 1, event.description, "LEFT", 1, nil, 0, 0, 300, 50);
tooltip:SmartAnchorTo(self.frame);
tooltip:Show();
end);
descriptionLabel:SetCallback("OnLeave", function()
LibQTip:Release(GOW.tooltip);
GOW.tooltip = nil;
end);
itemGroup:AddChild(descriptionLabel);
end
local dateLabel = GOW.GUI:Create("SFX-Info");
dateLabel:SetLabel("Date");
dateLabel:SetText(event.dateText .. ", " .. event.hourText);
dateLabel:SetDisabled(false);
dateLabel:SetCallback("OnEnter", function(self)
local tooltip = LibQTip:Acquire("EventDateTooltip", 1, "LEFT");
GOW.tooltip = tooltip;
tooltip:AddHeader('|cffffcc00All dates are realm time.');
tooltip:SmartAnchorTo(self.frame);
tooltip:Show();
end);
dateLabel:SetCallback("OnLeave", function()
LibQTip:Release(GOW.tooltip);
GOW.tooltip = nil;
end);
itemGroup:AddChild(dateLabel);
local eventDurationLabel = GOW.GUI:Create("SFX-Info");
eventDurationLabel:SetLabel("Duration");
eventDurationLabel:SetText(event.durationText);
itemGroup:AddChild(eventDurationLabel);
if (event.team ~= "") then
local teamLabel = GOW.GUI:Create("SFX-Info");
teamLabel:SetLabel("Team");
teamLabel:SetText(event.team);
itemGroup:AddChild(teamLabel);
elseif (event.calendarType == GOW.consts.PLAYER_EVENT) then
local levelText = event.minLevel;
if event.minLevel ~= event.maxLevel then
levelText = levelText .. " -> " .. event.maxLevel;
end
local eventLevelLabel = GOW.GUI:Create("SFX-Info");
eventLevelLabel:SetLabel("Level");
eventLevelLabel:SetText(levelText);
itemGroup:AddChild(eventLevelLabel);
if (event.minItemLevel > 0) then
local eventMinItemLevelLabel = GOW.GUI:Create("SFX-Info");
eventMinItemLevelLabel:SetLabel("Item Level");
eventMinItemLevelLabel:SetText(event.minItemLevel .. "+");
itemGroup:AddChild(eventMinItemLevelLabel);
end
end
local isEventMember = event.isEventMember;
local canAddEvent = event.isEventManager;
local eventInvitingMembersLabel = GOW.GUI:Create("SFX-Info");
eventInvitingMembersLabel:SetLabel("Inviting");
local invitineDetailsText = "";
if (event.calendarType == GOW.consts.GUILD_EVENT) then
invitineDetailsText = "All guildies";
else
if (event.totalMembers > 1) then
invitineDetailsText = event.totalMembers .. " members";
else
invitineDetailsText = event.totalMembers .. " member";
end
end