-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassicEraCensus.lua
More file actions
1265 lines (964 loc) · 37.5 KB
/
ClassicEraCensus.lua
File metadata and controls
1265 lines (964 loc) · 37.5 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
local addonName, ClassicEraCensus = ...;
local json = LibStub('JsonLua-1.0');
local LibDeflate = LibStub:GetLibrary("LibDeflate")
local LibSerialize = LibStub:GetLibrary("LibSerialize")
local locale = GetLocale()
local L = ClassicEraCensus.locales[locale];
local Comms = ClassicEraCensus.Comms;
local Database = ClassicEraCensus.db;
local Census = ClassicEraCensus.Census;
local EXPANSION = GetServerExpansionLevel()
--if this goes beyond Era then this variable needs to be adjusted, either via blizz api or some config setting
local MAX_LEVEL = 60;
--main mixin
ClassicEraCensusMixin = {
helpTipsShown = false,
isCensusInProgress = false,
isCoopCensus = false,
censusGroup = {},
regions = {"EU", "NA", "KR", "TW", "Other"},
--need to update for different expansion
classesOrdered = {
alliance = {
"druid",
"hunter",
"mage",
"paladin",
"priest",
"rogue",
"warlock",
"warrior",
},
horde = {
"druid",
"hunter",
"mage",
"priest",
"rogue",
"shaman",
"warlock",
"warrior",
},
},
racesOrdered = {
alliance = {
"human",
"dwarf",
"nightelf",
"gnome",
},
horde = {
"orc",
"undead",
"troll",
"tauren",
}
}
};
--when we load get the callbacks setup, any addon navigation systems and any script hooking
function ClassicEraCensusMixin:OnLoad()
ClassicEraCensus:RegisterCallback("Database_OnInitialised", self.Database_OnInitialised, self)
ClassicEraCensus:RegisterCallback("Database_OnCensusTableChanged", self.Database_OnCensusTableChanged, self)
ClassicEraCensus:RegisterCallback("Census_OnMultiSelectChanged", self.Census_OnMultiSelectChanged, self)
ClassicEraCensus:RegisterCallback("Census_OnGuildSelectionChanged", self.Census_OnGuildSelectionChanged, self)
ClassicEraCensus:RegisterCallback("Census_OnFinished", self.Census_OnFinished, self)
ClassicEraCensus:RegisterCallback("Census_LogMessage", self.Census_LogMessage, self)
ClassicEraCensus:RegisterCallback("Database_OnConfigChanged", self.Database_OnConfigChanged, self)
ClassicEraCensus:RegisterCallback("Comms_OnMessageReceived", self.Comms_OnMessageReceived, self)
ClassicEraCensus:RegisterCallback("Census_OnCoopCensusRequestAccepted", self.Census_OnCoopCensusRequestAccepted, self)
ClassicEraCensus:RegisterCallback("Census_OnCoopCensusRecordAccepted", self.Census_OnCoopCensusRecordAccepted, self)
self:RegisterForDrag("LeftButton")
self:RegisterEvent("ADDON_LOADED")
self:RegisterEvent("PLAYER_LOGOUT")
SetPortraitToTexture(_G[self:GetName().."Portrait"], 134939)
_G[self:GetName().."TitleText"]:SetText(addonName..L.SELECT_REGION)
_G[self:GetName().."TitleText"]:SetJustifyH("LEFT")
self.numTabs = #self.tabs
self.tab1:SetText(L.DASHBOARD)
self.tab2:SetText(OPTIONS)
self.tab3:SetText(L.TABS_CENSUS_LOG)
self.tab4:SetText(L.TABS_EXPORT)
PanelTemplates_SetNumTabs(self, self.numTabs);
PanelTemplates_SetTab(self, 1);
for i = 1, self.numTabs do
self["tab"..i]:SetScript("OnClick", function()
PanelTemplates_SetTab(self, i);
self:OnTabSelected(i)
end)
end
self.help:SetScript("OnMouseDown", function()
self.helpTipsShown = not self.helpTipsShown;
for k, tip in ipairs(self.home.helptips) do
tip:SetShown(self.helpTipsShown)
end
for k, tip in ipairs(self.options.customCensus.helptips) do
tip:SetShown(self.helpTipsShown)
end
for k, tip in ipairs(self.options.helptips) do
tip:SetShown(self.helpTipsShown)
end
end)
hooksecurefunc("SetItemRef", function(link)
local linkRef, addon = strsplit("?", link)
if (linkRef == "garrmission") and (addon == addonName) then
self:ParseCensusLink(link)
end
end)
for _, hook in ipairs({"OnMouseDown", "OnMouseUp"}) do
WorldFrame:HookScript(hook, function()
if self.isCensusInProgress then
FriendsFrame:UnregisterEvent("WHO_LIST_UPDATE")
self:RegisterEvent("WHO_LIST_UPDATE")
C_FriendList.SetWhoToUi(true)
local sent = self.currentCensus:AttemptNextWhoQuery()
if sent then
self.whoCooldownStart = time()
end
end
end)
end
self.log.whoListview.header:SetText(L.LOG_ACTIONS_HEADER);
self.log.queryListview.header:SetText(L.LOG_JOBS_HEADER);
end
--addon navigation
function ClassicEraCensusMixin:OnTabSelected(tabIndex)
for k, container in ipairs(self.containers) do
container:Hide()
end
self.containers[tabIndex]:Show()
end
--need to finish the Census object so it can return census progress data to be used in here
function ClassicEraCensusMixin:OnUpdate()
if self.isCensusInProgress then
-- if self.whoCooldownStart then
-- local whoCooldown = (3 - (time() - self.whoCooldownStart)) or 3;
-- self.whoCooldown:SetValue((whoCooldown / 3) * 100)
-- end
local progress = self.currentCensus:GetProgress()
self.home.censusInfoText:SetText(string.format("Scan time: %s Recorded %d characters, processed %d of %d queries", SecondsToClock(progress.elapsed), progress.characterCount, progress.currentIndex, progress.numQueries))
end
end
--handle events
function ClassicEraCensusMixin:OnEvent(event, ...)
if event == "ADDON_LOADED" and ... == addonName then
Database:Init()
self:UnregisterEvent("ADDON_LOADED")
end
if event == "PLAYER_LOGOUT" then
Database:CleanCensusTables()
end
if event == "WHO_LIST_UPDATE" then
self:WhoList_OnUpdate()
end
end
function ClassicEraCensusMixin:Comms_OnMessageReceived(sender, data)
if data.type == "COOP_CENSUS_REQUEST" then
StaticPopup_Show("ClassicEraCensusAcceptCoopCensusRequest", nil, nil, data.payload)
end
if data.type == "COOP_CENSUS_RECORD" then
StaticPopup_Show("ClassicEraCensusAcceptCoopCensusRecord", nil, nil, data.payload)
end
end
--function used to log messages from the census
function ClassicEraCensusMixin:Census_LogMessage(type, msg)
self.log.whoListview.DataProvider:Insert({
type = type,
message = msg,
timestamp = time(),
})
self.log.whoListview.scrollBox:ScrollToEnd()
--slight hack for debugging reason
-- self.log.queryListview.DataProvider:Flush();
-- for k, v in ipairs(self.currentCensus.whoQueries) do
-- self.log.queryListview.DataProvider:Insert({
-- type = "info",
-- message = v.who,
-- })
-- end
--self.log.queryListview.scrollBox:ScrollToEnd()
end
--get data from the character string
-- function ClassicEraCensusMixin:GetCharacterInfo(character, info)
-- local t = {}
-- t.name, t.level, t.race, t.class, t.guild = strsplit(",", character)
-- t.level = tonumber(t.level)
-- if info and t[info] then
-- return t[info]
-- else
-- return t.name, t.level, t.race, t.class, t.guild;
-- end
-- end
--called after the db has initialized, load the minimap button and call any UI setup functions now the db config data is ready
function ClassicEraCensusMixin:Database_OnInitialised()
local ldb = LibStub("LibDataBroker-1.1")
local minimapDataBroker = ldb:NewDataObject(addonName, {
type = "launcher",
icon = 134939,
OnClick = function(_, button)
self:SetShown(not self:IsVisible())
end,
OnEnter = function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:AddLine(addonName)
if ClassicEraCensusUI.isCensusInProgress then
GameTooltip:AddLine("Census progress")
GameTooltip_ShowProgressBar(GameTooltip, 1, 100, ClassicEraCensusUI.currentCensus:GetProgress().percent)
end
GameTooltip:Show()
end,
OnLeave = function()
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent)
end
})
self.minimapButton = LibStub("LibDBIcon-1.0")
self.minimapButton:Register(addonName, minimapDataBroker, ClassicEraCensus_Account.config.minimapButton)
local faction = UnitFactionGroup("player")
self.faction = faction:lower()
self:LoadOptionsInterface()
self:SetupHomeTab()
self:SetupOptionsTab()
self:Database_OnCensusTableChanged()
self.realmLabel:SetText(GetNormalizedRealmName())
Comms:Init()
end
--this was in case the config list got bigger and to avoid lots of if elseif
local configCallbacks = {
region = function(ui, val)
for k, region in ipairs(ui.regions) do
if region ~= val then
ui["regionCheckbox"..region]:SetChecked(false)
end
end
end,
}
function ClassicEraCensusMixin:Database_OnConfigChanged(config, val)
if configCallbacks[config] then
configCallbacks[config](self, val)
end
end
--setup the options tab
function ClassicEraCensusMixin:SetupOptionsTab()
self.options.customCensus.coopCensusHelptip:SetText(L.CUSTOM_CENSUS_COOP_HELPTIP)
self.options.customCensus.customCensusFiltersHelptip:SetText(L.CUSTOM_CENSUS_FILTERS_HELPTIP)
self.options.customCensusIgnoredZonesHelptip:SetText(L.CUSTOM_CENSUS_IGNORED_ZONES_HELPTIP)
self.options.helpAbout.text:SetText(L.HELP_ABOUT)
local gender = UnitSex("player") == 2 and "male" or "female";
for k, race in ipairs(self.racesOrdered[self.faction]) do
self.options.customCensus["race"..k].label:SetText(string.format("%s %s", CreateAtlasMarkup(string.format("raceicon-%s-%s", race, gender), 18, 18), L[race]))
self.options.customCensus["race"..k].race = race;
if race == "nightelf" then
self.options.customCensus["race"..k].race = [[night elf]]
end
end
for k, class in ipairs(self.classesOrdered[self.faction]) do
self.options.customCensus["class"..k].label:SetText(string.format("%s %s", CreateAtlasMarkup(string.format("classicon-%s", class), 18, 18), L[class]))
self.options.customCensus["class"..k].class = class;
end
local sliders = {
["Min level"] = "minLevel",
["Max level"] = "maxLevel",
["Who interval"] = "whoCooldown",
}
for label, slider in pairs(sliders) do
self.options.customCensus[slider].label:SetText(label)
_G[self.options.customCensus[slider]:GetName().."Low"]:SetText(" ")
_G[self.options.customCensus[slider]:GetName().."High"]:SetText(" ")
_G[self.options.customCensus[slider]:GetName().."Text"]:SetText(" ")
self.options.customCensus[slider]:SetScript("OnMouseWheel", function(s, delta)
if slider == "whoCooldown" then
delta = delta/10
s:SetValue(s:GetValue() + delta)
else
s:SetValue(s:GetValue() + delta)
end
end)
self.options.customCensus[slider]:SetScript("OnValueChanged", function(s)
local x = s:GetValue() -- math.ceil(s:GetValue())
x = tonumber(string.format("%.2f", x))
s.value:SetText(x)
--special func for who cd
if slider == "whoCooldown" then
Database:SetConfig("whoCooldown", x)
if self.currentCensus then
self.currentCensus:SetWhoCooldown(x)
end
end
end)
end
local whoCD = Database:GetConfig("whoCooldown")
self.options.customCensus.whoCooldown:SetValue(whoCD)
self.options.customCensus.minLevel:SetValue(1)
self.options.customCensus.maxLevel:SetValue(60)
self.options.customCensus.getCustomFilters = function()
local races, raceFiltered = {}, false
for k, checkbox in ipairs(self.options.customCensus.raceFilters) do
if checkbox:GetChecked() then
table.insert(races, checkbox.race)
raceFiltered = true;
end
end
local classes, classFiltered = {}, false
for k, checkbox in ipairs(self.options.customCensus.classFilters) do
if checkbox:GetChecked() then
table.insert(classes, checkbox.class)
classFiltered = true;
end
end
local minL = self.options.customCensus.minLevel.value:GetText()
local maxL = self.options.customCensus.maxLevel.value:GetText()
return (raceFiltered == true and races or nil), (classFiltered == true and classes or nil), string.format("%s-%s", minL, maxL)
end
for k, zone in ipairs(ClassicEraCensus.zones[EXPANSION]) do
self.options.zoneListview.DataProvider:Insert({
zone = zone,
})
end
self.options.customCensus.startCensus:SetScript("OnClick", function()
local name, realm = UnitFullName("player");
if realm == nil or realm == "" then
realm = GetNormalizedRealmName();
end
local faction = UnitFactionGroup("player")
local region = Database:GetConfig("region")
local races, classes, levelRange = self.options.customCensus.getCustomFilters()
self.currentCensus = Census:New(name, realm, faction, region, races, classes, levelRange)
self.isCensusInProgress = true;
end)
self.options.customCensus.sendCoopCensusRequest:SetScript("OnClick", function()
local playerName = self.options.customCensus.coopCensusTeamMemberName:GetText()
if playerName == "" then
return
end
if playerName then
end
local name, realm = UnitFullName("player");
if realm == nil or realm == "" then
realm = GetNormalizedRealmName();
end
local faction = UnitFactionGroup("player")
local region = Database:GetConfig("region")
local races, classes, levelRange = self.options.customCensus.getCustomFilters()
local whoQueries, customFilters = Census:GenerateWhoQueries(faction, races, classes, levelRange)
local ignoredZones = {}
for k, zone in ipairs(ClassicEraCensus.zones[EXPANSION]) do
local ignored = Database:GetConfig(zone, "ignoredZones");
if ignored == true then
table.insert(ignoredZones, k)
end
end
local msg = {
type = "COOP_CENSUS_REQUEST",
payload = {
author = name,
realm = realm,
faction = faction,
region = region,
whoQueries = whoQueries,
customFilters = customFilters,
ignoredZones = ignoredZones,
}
}
Comms:SendCoopCensus(msg, playerName)
end)
--this is actually now in a new container/tab
self.export.exportLabel:SetText(L.EXPORT_INFO)
self.export.exportJSON.EditBox:SetMaxLetters(1000000000)
self.export.generateJSON:SetScript("OnClick", function()
--for now just grab the latest - i need to add a specific multi select listview to this tab view
local censusData;
local census = Database:GetLatestCensus()
censusData = {
census,
}
-- local serialized = LibSerialize:Serialize(census)
-- local compressed = LibDeflate:CompressDeflate(serialized)
-- local encoded = LibDeflate:EncodeForPrint(compressed)
local encoded = json.encode(censusData)
self.export.exportJSON.EditBox:SetText(encoded)
end)
end
function ClassicEraCensusMixin:SetupExportTab()
end
--setup the home tab, charts, filters etc
function ClassicEraCensusMixin:SetupHomeTab()
local sliders = {
["Min level"] = "minLevel",
["Max level"] = "maxLevel",
}
for label, slider in pairs(sliders) do
self.home.ribbon[slider].label:SetText(label)
_G[self.home.ribbon[slider]:GetName().."Low"]:SetText(" ")
_G[self.home.ribbon[slider]:GetName().."High"]:SetText(" ")
_G[self.home.ribbon[slider]:GetName().."Text"]:SetText(" ")
self.home.ribbon[slider]:SetScript("OnMouseWheel", function(s, delta)
s:SetValue(s:GetValue() + delta)
end)
self.home.ribbon[slider]:SetScript("OnValueChanged", function(s)
s.value:SetText(math.ceil(s:GetValue()))
self:CensusLevelRange_OnChanged()
end)
end
local reg = Database:GetConfig("region")
for k, region in ipairs(self.regions) do
self["regionCheckbox"..region]:SetScript("OnClick", function()
Database:SetConfig("region", region)
end)
self["regionCheckbox"..region].label:SetText(region)
if reg == region then
self["regionCheckbox"..region]:SetChecked(true)
end
end
self.home.ribbon.clearCensus:SetScript("OnClick", function()
self:ClearAllFilters()
self:ResetHomeCharts()
self.censusGroup = {}
Database:CleanCensusTables()
end)
self.home.ribbon.mergeCensus:SetScript("OnClick", function()
StaticPopup_Show("ClassicEraCensusMergeConfirm", nil, nil, self.censusGroup)
end)
self.home.ribbon.deleteCensus:SetScript("OnClick", function()
StaticPopup_Show("ClassicEraCensusDeleteConfirm", nil, nil, self.censusGroup)
end)
self.home.censusHistoryHelptip:SetText(L.HOME_CENSUS_HISTORY_HELPTIP:format(CreateAtlasMarkup("poi-workorders", 16, 16)))
self.home.classesHelptip:SetText(L.HOME_CLASSES_HELPTIP)
self.home.levelSliderHelptip:SetText(L.HOME_FILTERS_HELPTIP)
self.home.guildHelptip:SetText(L.HOME_GUILDS_HELPTIP)
self.home.races.bars = {
alliance = {},
horde = {},
}
self.home.classes.bars = {
alliance = {},
horde = {},
}
self.home.levels.bars = {}
self.home.guilds.selectedGuild = false;
local gender = UnitSex("player") == 2 and "male" or "female";
local racesParentHeight = self.home.races:GetHeight()
for _, faction in ipairs({"alliance", "horde"}) do
for k, race in ipairs(self.racesOrdered[faction]) do
local bar = CreateFrame("FRAME", nil, self.home.races, "ClassicEraCensusBarChartBarTemplate")
bar:SetWidthHeight(50, racesParentHeight)
bar:SetPoint("BOTTOMLEFT", 2 + ((k-1) * 50), 1)
bar:SetIcon(string.format("raceicon-%s-%s", race, gender))
bar:TrimIcon()
bar:SetBarColour({r = (191/255), g = (144/255), b = 0, a = 1})
bar.selected = false;
bar:SetScript("OnMouseDown", function()
bar.selected = not bar.selected
bar.barBackground:SetShown(bar.selected)
self:FilterCensus(self.censusGroup)
end)
self.home.races.bars[faction][race] = bar;
end
end
local classesParentHeight = self.home.classes:GetHeight()
for _, faction in ipairs({"alliance", "horde"}) do
for k, class in ipairs(self.classesOrdered[faction]) do
local bar = CreateFrame("FRAME", nil, self.home.classes, "ClassicEraCensusBarChartBarTemplate")
bar:SetWidthHeight(40, classesParentHeight)
bar:SetPoint("BOTTOMLEFT", 2 + ((k-1) * 40), 1)
bar:SetIcon(string.format("classicon-%s", class))
bar:SetBarColour(RAID_CLASS_COLORS[class:upper()])
bar:SetScript("OnMouseDown", function()
bar.selected = not bar.selected
bar.barBackground:SetShown(bar.selected)
self:FilterCensus(self.censusGroup)
end)
self.home.classes.bars[faction][class] = bar;
end
end
local levelParentHeight = self.home.levels:GetHeight()
local barWidth = 12
for level = 1, MAX_LEVEL do
local bar = CreateFrame("FRAME", nil, self.home.levels, "ClassicEraCensusBarChartBarTemplate")
bar:SetWidthHeight(barWidth, levelParentHeight - 5)
bar:SetNoIcon()
bar:SetPoint("BOTTOMLEFT", 2 + ((level-1) * barWidth), 1)
bar:SetBarColour({r = (191/255), g = (144/255), b = 0, a = 1})
bar:ShowValues(false)
bar:SetScript("OnMouseDown", function()
bar.selected = not bar.selected
bar.barBackground:SetShown(bar.selected)
self:FilterCensus(self.censusGroup)
end)
self.home.levels.bars[level] = bar;
end
self.startCensus:SetScript("OnClick", function()
self:Census_Start()
end)
self.home.ribbon.minLevel:SetValue(1)
self.home.ribbon.maxLevel:SetValue(60)
end
--handle the level sliders value changing
function ClassicEraCensusMixin:CensusLevelRange_OnChanged()
local levelParentWidth = self.home.levels:GetWidth() - 4
local levelParentHeight = self.home.levels:GetHeight()
local minLevel = math.ceil(self.home.ribbon.minLevel:GetValue())
local maxLevel = math.ceil(self.home.ribbon.maxLevel:GetValue())
local range = (maxLevel - minLevel ) + 1
local barWidth = (levelParentWidth / range)
for i = 1, MAX_LEVEL do
self.home.levels.bars[i]:Hide()
end
if minLevel <= maxLevel then
local j = 1
for i = minLevel, maxLevel do
self.home.levels.bars[i]:ClearAllPoints()
self.home.levels.bars[i]:SetPoint("BOTTOMLEFT", 2 + ((j-1) * (barWidth)), 1)
self.home.levels.bars[i]:SetWidthHeight(barWidth, levelParentHeight - 5)
self.home.levels.bars[i]:SetNoIcon()
self.home.levels.bars[i]:Show()
j = j + 1
end
self:FilterCensus(self.censusGroup)
end
end
--this is called when the db table 'census' changes (census added or removed)
function ClassicEraCensusMixin:Database_OnCensusTableChanged(clearCensusGroup)
self:ClearAllFilters()
self:ResetHomeCharts()
if clearCensusGroup then
self.censusGroup = {}
end
local allCensus = Database:FetchAllCensus()
self.home.censusHistory.DataProvider:Flush()
self.home.censusHistory.DataProvider:InsertTable(allCensus)
end
--filter census group for guild matches
function ClassicEraCensusMixin:Census_OnGuildSelectionChanged(guild)
if self.home.guilds.selectedGuild == guild then
self.home.guilds.selectedGuild = false
self:LoadCensusGroup()
else
self.home.guilds.selectedGuild = guild
self:FilterCensusForGuild(guild)
end
end
--handle census selection(s)
function ClassicEraCensusMixin:Census_OnMultiSelectChanged(census, listviewItem, buttonClicked)
--DevTools_Dump({listviewItem})
if #self.censusGroup == 0 then
table.insert(self.censusGroup, census)
else
local exists, key = false, nil
local realmCheck, factionCheck = true, true
for k, v in ipairs(self.censusGroup) do
--print(k, v.realm, v.timestamp)
if (v.author == census.author) and (v.timestamp == census.timestamp) then
exists = true;
key = k
end
if census.realm ~= v.realm then
realmCheck = false
end
if census.faction ~= v.faction then
factionCheck = false;
end
end
if realmCheck == false then
print("Census is from a different realm!")
listviewItem.background:Hide()
return;
end
if factionCheck == false then
print("Census is from a different faction!")
listviewItem.background:Hide()
return;
end
if census.selected == true and exists == false then
table.insert(self.censusGroup, census)
end
if (not census.selected) and key ~= nil then
table.remove(self.censusGroup, key)
end
end
self:LoadCensusGroup(self.censusGroup)
local censusGroupCharactersSeen, count = {}, 0
for _, census in ipairs(self.censusGroup) do
for k, character in ipairs(census.characters) do
--local name = self:GetCharacterInfo(character, "name")
if not censusGroupCharactersSeen[character.name]then
count = count + 1;
censusGroupCharactersSeen[character.name] = true
end
end
end
if #self.censusGroup == 0 then
self.home.censusInfoText:SetText("No census selected")
self:ClearAllFilters()
self:ResetHomeCharts()
else
self.home.censusInfoText:SetText(string.format("Selected %d, %d unique characters", #self.censusGroup, count))
end
-- if buttonClicked == "RightButton" then
-- local menu = {
-- {
-- text = DELETE,
-- isCheckable = false,
-- func = function()
-- end,
-- }
-- }
-- EasyMenu(menu, self.dropdown, "cursor", -10, -10, "MENU", 2.0)
-- end
end
--called when the popup to confirm accepting the coop census request
function ClassicEraCensusMixin:Census_OnCoopCensusRequestAccepted(request)
if self.isCensusInProgress then
return;
end
self.currentCensus = Census:NewCoopCensus(request)
self.isCensusInProgress = true;
self.isCoopCensus = true;
end
--called when the popup to accept the coop census record data
function ClassicEraCensusMixin:Census_OnCoopCensusRecordAccepted(record)
--clean up some coop stuff
if record.census.requestAuthor then
record.census.requestAuthor = nil
end
--add this census to the db and allow the user to merge the relevant census records
Database:InsertCensus(record.census)
end
--create a census object
function ClassicEraCensusMixin:Census_Start()
local name, realm = UnitFullName("player");
if realm == nil or realm == "" then
realm = GetNormalizedRealmName();
end
local faction = UnitFactionGroup("player")
local region = Database:GetConfig("region")
self.currentCensus = Census:New(name, realm, faction, region)
local whoCD = Database:GetConfig("whoCooldown")
self.currentCensus:SetWhoCooldown(whoCD)
self.isCensusInProgress = true;
end
--for now this just pauses the WorldFrame hook clicks to prevent any who queries firing off
function ClassicEraCensusMixin:Census_Pause()
self.isCensusInProgress = not self.isCensusInProgress;
end
function ClassicEraCensusMixin:Census_Stop()
end
--create a SV friendly record of the census object
function ClassicEraCensusMixin:Census_OnFinished()
if self.isCoopCensus == true then
--need to return the data now!
local census = self.currentCensus:CreateRecord()
local msg = {
type = "COOP_CENSUS_RECORD",
payload = {
census = census,
}
}
local playerNameRealm = census.requestAuthor
Comms:SendCoopCensus(msg, playerNameRealm)
else
local census = self.currentCensus:CreateRecord()
self.currentCensus = census;
Database:InsertCensus(self.currentCensus)
end
self.isCensusInProgress = false;
self.isCoopCensus = false;
end
function ClassicEraCensusMixin:ShowFactionCharts(faction)
faction = faction:lower()
for _, _faction in ipairs({"alliance", "horde"}) do
for _, chart in pairs({"races", "classes"}) do
for _, bar in pairs(self.home[chart].bars[_faction]) do
bar:Hide()
end
end
end
for _, chart in pairs({"races", "classes"}) do
for _, bar in pairs(self.home[chart].bars[faction]) do
bar:Show()
end
end
end
function ClassicEraCensusMixin:ResetHomeCharts()
for _, faction in ipairs({"alliance", "horde"}) do
for _, chart in pairs({"races", "classes"}) do
for _, bar in pairs(self.home[chart].bars[faction]) do
bar:SetBarValue(0)
end
end
end
for k, bar in ipairs(self.home.levels.bars) do
bar:SetBarValue(0)
end
self.home.guilds.DataProvider:Flush()
end
function ClassicEraCensusMixin:ClearAllFilters()
for _, faction in ipairs({"alliance", "horde"}) do
for k, bar in pairs(self.home.races.bars[faction]) do
bar.selected = false
bar.barBackground:SetShown(bar.selected)
end
for k, bar in pairs(self.home.classes.bars[faction]) do
bar.selected = false
bar.barBackground:SetShown(bar.selected)
end
end
for k, bar in pairs(self.home.levels.bars) do
bar.selected = false
bar.barBackground:SetShown(bar.selected)
end
self.home.guilds.selectedGuild = false;
end
function ClassicEraCensusMixin:FilterCensusForGuild(guild)
if #self.censusGroup == 0 then
return
end
local t = {
characters = {},
faction = self.censusGroup[1].faction,
realm = self.censusGroup[1].realm,
}
for _, census in ipairs(self.censusGroup) do
for k, character in ipairs(census.characters) do
--local _guild = self:GetCharacterInfo(character, "guild")
if character.guild == guild then
table.insert(t.characters, character)
end
end
end
self.censusGroup = {t}
self:LoadCensusGroup()
end
function ClassicEraCensusMixin:FilterCensus(censusGroup)
local levelRange = {
[1] = math.ceil(self.home.ribbon.minLevel:GetValue()),
[2] = math.ceil(self.home.ribbon.maxLevel:GetValue()),
}
local isClassFiltered, isRaceFiltered = false, false;
local guild = self.home.guilds.selectedGuild;
local races, classes, levels = {}, {}, {};
for _, faction in ipairs({"alliance", "horde"}) do
for k, bar in pairs(self.home.races.bars[faction]) do
if bar.selected then
isRaceFiltered = true;
races[k:lower()] = true
end
end
for k, bar in pairs(self.home.classes.bars[faction]) do
if bar.selected then
isClassFiltered = true;
classes[k:lower()] = true
end
end
end
if levelRange then
for level = levelRange[1], levelRange[2] do
levels[level] = true
end
end
if not censusGroup then
censusGroup = { self.currentCensus }
end
if #censusGroup == 0 then
return
end
if isRaceFiltered == false and isClassFiltered == false then
self:LoadCensusGroup(censusGroup)
return;
end
local t = {
characters = {},
faction = censusGroup[1].faction,
}
local function generateRaceFilter()
return function(character)
--local level = self:GetCharacterInfo(character, "level")
if levels[character.level] then
--local race = self:GetCharacterInfo(character, "race")
if character.race == "Night Elf" then
if races["nightelf"] then
return true
end
else
if races[character.race:lower()] then
return true