-
Notifications
You must be signed in to change notification settings - Fork 3
/
CensusPlus.lua
3235 lines (2840 loc) · 101 KB
/
CensusPlus.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
--[[
CensusPlus for World of Warcraft(tm).
Copyright 2005 - 2006 Cooper Sellers and WarcraftRealms.com
Updated by Lexie for Turtle WoW - 2021
License:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program(see GLP.txt); if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
]]
local blclass = AceLibrary("Babble-Class-2.2")
------------------------------------------------------------------------------------
--
-- CensusPlus Turtle
-- A WoW UI customization by Cooper Sellers
-- Updated for Turtle WoW by Lexie
--
--
------------------------------------------------------------------------------------
----------------------------------------------------------------------------------
--
-- EURO vs US localization problem workaround for common server names
--
---------------------------------------------------------------------------------
local g_InterfaceVersion = 11200;
g_CensusPlusLocale = "N/A"; -- Must read either US or EU
g_CensusPlusTZOffset = -999;
local g_LocaleSet = false;
local g_TZWarningSent = false;
----------------------------------------------------------------------------------
--
-- Constants
--
---------------------------------------------------------------------------------
local CensusPlus_VERSION = "1.0.4"; -- version
local CensusPlus_MAXBARHEIGHT = 128; -- Length of blue bars
local CensusPlus_NUMGUILDBUTTONS = 19; -- How many guild buttons are on the UI?
local MAX_CHARACTER_LEVEL = 60; -- Maximum level a PC can attain
local MAX_WHO_RESULTS = 49; -- Maximum number of who results the server will return
CensusPlus_GUILDBUTTONSIZEY = 16;
local CensusPlus_UPDATEDELAY = 30; -- Delay time between /who messages
local CP_MAX_TIMES = 50;
local g_ServerPrefix = ""; -- US VERSION!!
--local g_ServerPrefix = "EU-"; -- EU VERSION!!
----------------------------------------------------------------------------------
--
-- Print a string to the chat frame
-- msg - message to print
--
---------------------------------------------------------------------------------
function CensusPlus_Msg(msg)
ChatFrame1:AddMessage("Census+ Turtle: "..msg, 1.0, 1.0, 0.5);
end
function CensusPlus_WhoMsg(msg)
ChatFrame1:AddMessage("Census+ Turtle Who: "..msg, 0.8, 0.8, 0.1);
end
local function CensusPlus_Msg2( msg )
ChatFrame2:AddMessage("Census+ Turtle: "..msg, 0.5, 1.0, 1.0);
end
----------------------------------------------------------------------------------
--
-- Global scope variables
--
---------------------------------------------------------------------------------
CensusPlus_Database = {}; -- Database of all CensusPlus results
CensusPlus_BGInfo = {}; -- Battleground info
CensusPlus_PerCharInfo = {}; -- Per character settings
----------------------------------------------------------------------------------
--
-- File scope variables
--
---------------------------------------------------------------------------------
local g_CensusPlusInitialized; -- Is CensusPlus initialized?
local g_JobQueue = {}; -- The queue of pending jobs
local g_CurrentJob = {}; -- Current job being executed
g_IsCensusPlusInProgress = false; -- Is a CensusPlus in progress?
g_CensusPlusPaused = false; -- Is CensusPlus in progress paused?
g_CensusPlusManuallyPaused = false; -- Is CensusPlus in progress manually paused?
local g_WhoAutoClose = 0; -- AutoClose who window?
local g_NumNewCharacters = 0; -- How many new characters found this CensusPlus
local g_NumUpdatedCharacters = 0; -- How many characters were updated during this CensusPlus
local g_MobXPByLevel = {}; -- XP earned for killing
local g_CharacterXPByLevel = {}; -- XP required to advance through the given level
local g_TotalCharacterXPPerLevel = {}; -- Total XP required to attain the given level
CensusPlus_Guilds = {}; -- All known guild
local g_TotalCharacterXP = 0; -- Total character XP for currently selected search
local g_TotalCount = 0; -- Total number of characters which meet search criteria
local g_RaceCount = {}; -- Totals for each race given search criteria
local g_ClassCount = {}; -- Totals for each class given search criteria
local g_LevelCount = {}; -- Totals for each level given search criteria
local g_TempCount = {};
local g_TempZoneCount = {};
g_GuildSelected = 0; -- Search criteria: Currently selected guild, 0 indicates none
g_RaceSelected = 0; -- Search criteria: Currently selected race, 0 indicates none
g_ClassSelected = 0; -- Search criteria: Currently selected class, 0 indicates none
g_LevelSelected = 0;
local g_LastOnUpdateTime = 0; -- Last time OnUpdate was called
local g_WaitingForWhoUpdate = false; -- Are we waiting for a who update event?
local g_WhoAttempts = 0; -- Counter for detecting stuck who results
local g_MiniOnStart = 1; -- Flag to have the mini-censusP displayed on startup
local g_CompleteCensusStarted = false; -- Flag for counter
local g_TakeHour = 0; -- Our timing hour
local g_TimeDatabase = {}; -- Time database
local g_ResetHour = true; -- Rest hour
local g_VariablesLoaded = false; -- flag to tell us if vars are loaded
local g_FirstRun = true;
local g_LastCensusRun = time() - 1500; -- timer used if auto census is turned on
local g_Pre_FriendsFrameOnHideOverride = nil; -- override for friend's frame to stop the close window sound
local g_Pre_FriendsFrameOnShowOverride = nil; -- override for friend's frame to stop the close window sound
local g_Pre_WhoList_UpdateOverride = nil; -- override for friend's frame to stop the close window sound
local g_Pre_WhoHandler = nil; -- override for submiting a who
local g_Pre_FriendsFrame_Update = nil;
local CP_updatingGuild = nil;
g_CensusPlusLastTarget = nil;
g_CensusPlusLastTargetName = nil;
local g_CurrentlyInBG = false;
local g_InternalSearchName = nil;
local g_InternalSearchLevel = nil;
local g_InternalSearchCount = 0;
CensusPlus_EnableProfiling = false;
local g_CensusPlus_StartTime = 0;
local g_CensusWhoOverrideMsg = nil;
local g_WaitingForOverrideUpdate = false;
-- Battleground info
CENSUSPLUS_CURRENT_BATTLEFIELD_QUEUES = {};
local g_AccumulatedPruneData = {};
g_RaceClassList = { }; -- Used to pick the right icon
g_RaceClassList[CENSUSPlus_DRUID] = 10;
g_RaceClassList[CENSUSPlus_HUNTER] = 11;
g_RaceClassList[CENSUSPlus_MAGE] = 12;
g_RaceClassList[CENSUSPlus_PRIEST] = 13;
g_RaceClassList[CENSUSPlus_ROGUE] = 14;
g_RaceClassList[CENSUSPlus_WARLOCK] = 15;
g_RaceClassList[CENSUSPlus_WARRIOR] = 16;
g_RaceClassList[CENSUSPlus_SHAMAN] = 17;
g_RaceClassList[CENSUSPlus_PALADIN] = 18;
g_RaceClassList[CENSUSPlus_DWARF] = 20;
g_RaceClassList[CENSUSPlus_GNOME] = 21;
g_RaceClassList[CENSUSPlus_HUMAN] = 22;
g_RaceClassList[CENSUSPlus_NIGHTELF] = 23;
g_RaceClassList[CENSUSPlus_ORC] = 24;
g_RaceClassList[CENSUSPlus_TAUREN] = 25;
g_RaceClassList[CENSUSPlus_TROLL] = 26;
g_RaceClassList[CENSUSPlus_UNDEAD] = 27;
g_RaceClassList[CENSUSPlus_HIGHELF] = 28;
g_RaceClassList[CENSUSPlus_GOBLIN] = 29;
g_TimeDatabase[CENSUSPlus_DRUID] = 0;
g_TimeDatabase[CENSUSPlus_HUNTER] = 0;
g_TimeDatabase[CENSUSPlus_MAGE] = 0;
g_TimeDatabase[CENSUSPlus_PRIEST] = 0;
g_TimeDatabase[CENSUSPlus_ROGUE] = 0;
g_TimeDatabase[CENSUSPlus_WARLOCK] = 0;
g_TimeDatabase[CENSUSPlus_WARRIOR] = 0;
g_TimeDatabase[CENSUSPlus_SHAMAN] = 0;
g_TimeDatabase[CENSUSPlus_PALADIN] = 0;
g_TimeDatabase[CENSUSPlus_WarsongGulch] = 0;
g_TimeDatabase[CENSUSPlus_AlteracValley] = 0;
g_TimeDatabase[CENSUSPlus_ArathiBasin] = 0;
-- These two DO NOT need to be localized
local CENSUSPlus_TURTLE = "TURTLE";
local g_FactionCheck = {};
g_FactionCheck[CENSUSPlus_ORC] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_TAUREN] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_TROLL] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_UNDEAD] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_GOBLIN] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_DWARF] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_GNOME] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_HUMAN] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_NIGHTELF] = CENSUSPlus_TURTLE;
g_FactionCheck[CENSUSPlus_HIGHELF] = CENSUSPlus_TURTLE;
----------------------------------------------------------------------------------
--
-- Set up confirmation boxes
--
---------------------------------------------------------------------------------
StaticPopupDialogs["CP_PURGE_CONFIRM"] = {
text = CENSUSPlus_PURGE_LOCAL_CONFIRM,
button1 = CENSUSPlus_YES,
button2 = CENSUSPlus_NO,
OnAccept = function()
CensusPlus_DoPurge();
end,
sound = "levelup2",
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1
};
----------------------------------------------------------------------------------
--
-- Set up Continue after override box
--
---------------------------------------------------------------------------------
StaticPopupDialogs["CP_CONTINUE_CENSUS"] = {
text = CENSUSPlus_OVERRIDE_COMPLET_PAUSED,
button1 = CENSUSPlus_CONTINUE,
OnAccept = function()
g_CensusPlusManuallyPaused = false;
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlus\\SkinTurtle\\CensusButton-Running")
CensusPlusTakeButton:SetText( CENSUSPlus_PAUSE );
end,
sound = "levelup2",
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
showAlert = 1
};
----------------------------------------------------------------------------------
--
-- Chat msg hook
--
---------------------------------------------------------------------------------
local function CP_HookAddMessage(frame)
local AddMessage = frame.AddMessage;
-- Create a closure to cleanly hook the AddMessage routine.
frame.AddMessage = function (this, msg, r, g, b, id)
if( g_IsCensusPlusInProgress ) then
local s, e;
local results = { };
local whoMsg = false;
s, e, results[0], results[1], results[2], results[3], results[4] = string.find(msg, CENSUS_LEVEL_NO_GUILD);
if( results[0] ~= nil ) then
whoMsg = true;
end
local s, e;
local results = { };
s, e, results[0], results[1], results[2], results[3], results[4] = string.find(msg, CENSUS_LEVEL_W_GUILD);
if( results[0] ~= nil ) then
whoMsg = true;
end
local s, e;
local results = { };
s, e, results[0], results[1], results[2], results[3], results[4] = string.find(msg, CENSUS_MULT_PLAYERS);
if( results[0] ~= nil ) then
whoMsg = true;
end
local s, e;
local results = { };
s, e, results[0], results[1], results[2], results[3], results[4] = string.find(msg, CENSUS_SING_PLAYER);
if( results[0] ~= nil ) then
whoMsg = true;
end
if( whoMsg ) then
--
-- Also bail out of an override if in place
--
if( g_CensusWhoOverrideMsg ~= nil and g_WaitingForOverrideUpdate == true ) then
--
-- Allow the who to act normally
--
g_CensusWhoOverrideMsg = nil;
g_WaitingForOverrideUpdate = false;
CensusPlus_Msg( CENSUSPlus_OVERRIDE_COMPLETE );
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusButton-Running")
return AddMessage(this, msg, r, g, b, id)
elseif( CensusPlus_PerCharInfo["Verbose"] ~= true and
not g_CensusPlusPaused and
not g_CensusPlusManuallyPaused ) then
return;
end
end
return AddMessage(this, msg, r, g, b, id)
else
return AddMessage(this, msg, r, g, b, id)
end
end
end
-----------------------------------------------------------------------------------
--
-- Insert a job at the end of the job queue
--
-----------------------------------------------------------------------------------
local function InsertJobIntoQueue(job)
table.insert(g_JobQueue, job);
end
-----------------------------------------------------------------------------------
--
-- Initialize the tables of constants for XP calculations
--
-----------------------------------------------------------------------------------
local function InitConstantTables()
--
-- XP earned for killing
--
for i = 1, MAX_CHARACTER_LEVEL, 1 do
g_MobXPByLevel[i] = (i * 5) + 45;
end
--
-- XP required to advance through the given level
--
for i = 1, MAX_CHARACTER_LEVEL, 1 do
g_CharacterXPByLevel[i] = ((8 * i * g_MobXPByLevel[i]) / 100) * 100;
end
--
-- Total XP required to attain the given level
--
local totalCharacterXP = 0;
for i = 1, MAX_CHARACTER_LEVEL, 1 do
g_TotalCharacterXPPerLevel[i] = totalCharacterXP;
totalCharacterXP = totalCharacterXP + g_CharacterXPByLevel[i];
end
end
-----------------------------------------------------------------------------------
--
-- Return a table of races for the input faction
--
-----------------------------------------------------------------------------------
function CensusPlus_GetFactionRaces(faction)
local ret = {};
ret = {CENSUSPlus_ORC, CENSUSPlus_TAUREN, CENSUSPlus_TROLL, CENSUSPlus_UNDEAD, CENSUSPlus_GOBLIN, CENSUSPlus_DWARF, CENSUSPlus_GNOME, CENSUSPlus_HUMAN, CENSUSPlus_NIGHTELF, CENSUSPlus_HIGHELF};
return ret;
end
-----------------------------------------------------------------------------------
--
-- Return a table of classes for the input faction
--
-----------------------------------------------------------------------------------
function CensusPlus_GetFactionClasses(faction)
local ret = {};
ret = {CENSUSPlus_DRUID, CENSUSPlus_HUNTER, CENSUSPlus_MAGE, CENSUSPlus_PRIEST, CENSUSPlus_ROGUE, CENSUSPlus_WARLOCK, CENSUSPlus_WARRIOR, CENSUSPlus_SHAMAN, CENSUSPlus_PALADIN};
return ret;
end
-----------------------------------------------------------------------------------
--
-- Return a table of classes for the input race
--
-----------------------------------------------------------------------------------
local function GetRaceClasses(race)
local ret = {};
if (race == CENSUSPlus_ORC) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_SHAMAN, CENSUSPlus_WARLOCK, CENSUSPlus_MAGE};
elseif (race == CENSUSPlus_TAUREN) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_SHAMAN, CENSUSPlus_DRUID};
elseif (race == CENSUSPlus_TROLL) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_SHAMAN, CENSUSPlus_WARLOCK, CENSUSPlus_MAGE};
elseif (race == CENSUSPlus_UNDEAD) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_MAGE, CENSUSPlus_WARLOCK, CENSUSPlus_HUNTER};
elseif (race == CENSUSPlus_DWARF) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_PALADIN, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_MAGE};
elseif (race == CENSUSPlus_GNOME) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_ROGUE, CENSUSPlus_MAGE, CENSUSPlus_WARLOCK, CENSUSPlus_HUNTER};
elseif (race == CENSUSPlus_HUMAN) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_PALADIN, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_MAGE, CENSUSPlus_WARLOCK};
elseif (race == CENSUSPlus_NIGHTELF) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_DRUID};
elseif (race == CENSUSPlus_HIGHELF) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_PRIEST, CENSUSPlus_MAGE, CENSUSPlus_PALADIN};
elseif (race == CENSUSPlus_GOBLIN) then
ret = {CENSUSPlus_WARRIOR, CENSUSPlus_HUNTER, CENSUSPlus_ROGUE, CENSUSPlus_MAGE, CENSUSPlus_WARLOCK};
end
return ret;
end
-----------------------------------------------------------------------------------
--
-- Return common letters found in zone names
--
-----------------------------------------------------------------------------------
local function GetZoneLetters()
return {"t", "d", "g", "f", "h", "b", "x", "gulch", "valley", "basin" };
end
-----------------------------------------------------------------------------------
--
-- Return common letters found in names, may override this for other languages
-- Worst case scenario is to do it for every letter in the alphabet
--
-----------------------------------------------------------------------------------
local function GetNameLetters()
return { "a", "b", "c", "d", "e", "f", "g", "i", "o", "p", "r", "s", "t", "u", "y" };
end
---------------------------------------------------------------------------------
--
-- Register with Cosmos UI
--
---------------------------------------------------------------------------------
local function CensusPlus_RegisterCosmos()
--
-- If Cosmos is installed, add a button to the Cosmos page to activate CensusPlus
--
if ( EarthFeature_AddButton ) then
EarthFeature_AddButton(
{
id = "CensusPlus";
name = CENSUSPlus_BUTTON_TEXT;
subtext = CENSUSPlus_BUTTON_SUBTEXT;
tooltip = CENSUSPlus_BUTTON_TIP;
icon = "Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusPlus_Icon";
callback = CensusPlus_Toggle;
}
);
elseif ( Cosmos_RegisterButton ) then
Cosmos_RegisterButton(CENSUSPlus_BUTTON_TEXT, CENSUSPlus_BUTTON_SUBTEXT, CENSUSPlus_BUTTON_TIP, "Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusPlus_Icon", CensusPlus_Toggle);
end
end
----------------------------------------------------------------------------------
--
-- Called when the main window is shown
--
---------------------------------------------------------------------------------
function CensusPlus_OnShow()
-- Initialize if this is the first OnShow event
if (g_CensusPlusInitialized == false) then
g_CensusPlusInitialized = true;
end
CensusPlus_UpdateView();
end
----------------------------------------------------------------------------------
--
-- Toggle hidden status
--
---------------------------------------------------------------------------------
function CensusPlus_Toggle()
if ( CensusPlus:IsVisible() ) then
CensusPlus:Hide();
else
CensusPlus:Show();
end
end
----------------------------------------------------------------------------------
--
-- Toggle options pane
--
---------------------------------------------------------------------------------
function CensusPlus_ToggleOptions()
if ( CP_OptionsWindow:IsVisible() ) then
CP_OptionsWindow:Hide();
else
CP_OptionsWindow:Show();
end
end
-----------------------------------------------------------------------------------
--
-- Called once on load
--
-----------------------------------------------------------------------------------
function CensusPlus_OnLoad()
--
-- Update the version number
--
CensusPlusText:SetText("Census+ Turtle v"..CensusPlus_VERSION .. " " .. g_CensusPlusLocale );
CensusPlusText2:SetText( CENSUSPlus_UPLOAD );
--
-- Init constant tables
--
InitConstantTables();
--
-- Register with Cosmos, if it is installed
--
CensusPlus_RegisterCosmos();
--
-- Register for events
--
this:RegisterEvent("VARIABLES_LOADED");
this:RegisterEvent("WHO_LIST_UPDATE");
-- this:RegisterEvent("GUILD_ROSTER_SHOW");
-- this:RegisterEvent("GUILD_ROSTER_UPDATE");
-- this:RegisterEvent("TRAINER_SHOW");
-- this:RegisterEvent("TRAINER_CLOSED");
-- this:RegisterEvent("MERCHANT_SHOW");
-- this:RegisterEvent("MERCHANT_CLOSED");
-- this:RegisterEvent("GUILD_REGISTRAR_SHOW");
-- this:RegisterEvent("GUILD_REGISTRAR_CLOSED");
-- this:RegisterEvent("TRADE_SHOW");
-- this:RegisterEvent("TRADE_CLOSED");
-- this:RegisterEvent("AUCTION_HOUSE_SHOW");
-- this:RegisterEvent("AUCTION_HOUSE_CLOSED");
-- this:RegisterEvent("BANKFRAME_OPENED");
-- this:RegisterEvent("BANKFRAME_CLOSED");
-- this:RegisterEvent("QUEST_GREETING");
-- this:RegisterEvent("QUEST_DETAIL");
-- this:RegisterEvent("QUEST_PROGRESS");
-- this:RegisterEvent("QUEST_COMPLETE");
-- this:RegisterEvent("QUEST_FINISHED");
-- this:RegisterEvent("QUEST_ITEM_UPDATE");
-- this:RegisterEvent("QUEST_ACCEPT_CONFIRM");
-- this:RegisterEvent("QUEST_LOG_UPDATE");
this:RegisterEvent("UNIT_FOCUS");
this:RegisterEvent("PLAYER_TARGET_CHANGED" );
this:RegisterEvent("UPDATE_MOUSEOVER_UNIT");
this:RegisterEvent("PLAYER_PVP_KILLS_CHANGED");
this:RegisterEvent("INSPECT_HONOR_UPDATE");
this:RegisterEvent("CHAT_MSG_SYSTEM");
this:RegisterEvent("CHAT_MSG_COMBAT_SELF_HITS");
this:RegisterEvent("CHAT_MSG_COMBAT_HOSTILEPLAYER_HITS");
this:RegisterEvent("ZONE_CHANGED_NEW_AREA");
this:RegisterEvent("UPDATE_BATTLEFIELD_STATUS");
--
-- Register a slash command
--
SLASH_CensusPlusCMD1 = "/CensusPlus";
SLASH_CensusPlusCMD2 = "/Census+";
SLASH_CensusPlusCMD3 = "/Census";
SlashCmdList["CensusPlusCMD"] = CensusPlus_Command;
SLASH_CensusPlusVerbose1 = "/censusverbose";
SlashCmdList["CensusPlusVerbose"] = CensusPlus_Verbose;
--
-- Set the auto close to true
--
CensusPlus_AutoCloseWho( 1 );
--AutoClose:SetChecked( 1 );
g_Pre_FriendsFrameOnHideOverride = FriendsFrame_OnHide;
FriendsFrame_OnHide = CensusPlus_FriendsFrame_OnHide;
g_Pre_FriendsFrameOnShowOverride = FriendsFrame_OnShow;
FriendsFrame_OnShow = CensusPlus_FriendsFrame_OnShow;
g_Pre_WhoList_UpdateOverride = WhoList_Update;
WhoList_Update = CensusPlus_WhoList_Update;
g_Pre_FriendsFrame_Update = FriendsFrame_Update;
FriendsFrame_Update = CensusPlus_FriendsFrame_Update;
g_Pre_WhoHandler = SlashCmdList["WHO"];
SlashCmdList["WHO"] = CensusPlus_WhoHandler;
CensusPlus_CheckForBattleground();
-- Hook the default chat frame's AddMessage method.
CP_HookAddMessage(ChatFrame1);
end
-----------------------------------------------------------------------------------
--
-- Load Handler for options box
--
-----------------------------------------------------------------------------------
function CP_OptionsOnShow()
CP_OptionAutoClose:SetChecked(g_WhoAutoClose);
CP_OptionAutoStartButton:SetChecked(g_MiniOnStart);
CP_OptionVerboseButton:SetChecked(CensusPlus_PerCharInfo["Verbose"]);
CP_OptionAutoCensusButton:SetChecked( CensusPlus_Database["Info"]["AutoCensus"] );
CP_OptionProcessCharProfileButton:SetChecked( CensusPlus_DoThisCharacter );
end
-----------------------------------------------------------------------------------
--
-- CensusPlus Friends Frame override to stop the window close sound
--
-----------------------------------------------------------------------------------
function CensusPlus_FriendsFrame_OnHide()
g_Pre_FriendsFrameOnHideOverride();
end
-----------------------------------------------------------------------------------
--
-- CensusPlus Friends Frame override to stop the window close sound
--
-----------------------------------------------------------------------------------
function CensusPlus_FriendsFrame_OnShow()
g_Pre_FriendsFrameOnShowOverride();
end
function CensusPlus_WhoList_Update()
if( g_IsCensusPlusInProgress == true and g_WhoAutoClose ) then
local numWhos, totalCount = GetNumWhoResults();
local name, guild, level, race, class, zone, group;
local button;
local columnTable;
local whoOffset = FauxScrollFrame_GetOffset(WhoListScrollFrame);
local whoIndex;
local showScrollBar = nil;
if ( numWhos > WHOS_TO_DISPLAY ) then
showScrollBar = 1;
end
local displayedText = "";
if ( totalCount > MAX_WHOS_FROM_SERVER ) then
displayedText = format(WHO_FRAME_SHOWN_TEMPLATE, MAX_WHOS_FROM_SERVER);
end
WhoFrameTotals:SetText(format(GetText("WHO_FRAME_TOTAL_TEMPLATE", nil, totalCount), totalCount).." "..displayedText);
for i=1, WHOS_TO_DISPLAY, 1 do
whoIndex = whoOffset + i;
button = getglobal("WhoFrameButton"..i);
button.whoIndex = whoIndex;
name, guild, level, race, class, zone, group = GetWhoInfo(whoIndex);
columnTable = { zone, guild, race };
getglobal("WhoFrameButton"..i.."Name"):SetText(name);
getglobal("WhoFrameButton"..i.."Level"):SetText(level);
getglobal("WhoFrameButton"..i.."Class"):SetText(class);
local variableText = getglobal("WhoFrameButton"..i.."Variable");
variableText:SetText(columnTable[UIDropDownMenu_GetSelectedID(WhoFrameDropDown)]);
if ( not group ) then
group = "";
end
--getglobal("WhoFrameButton"..i.."Group"):SetText(getglobal(strupper(group)));
-- If need scrollbar resize columns
if ( showScrollBar ) then
variableText:SetWidth(95);
else
variableText:SetWidth(110);
end
-- Highlight the correct who
if ( WhoFrame.selectedWho == whoIndex ) then
button:LockHighlight();
else
button:UnlockHighlight();
end
if ( whoIndex > numWhos ) then
button:Hide();
else
button:Show();
end
end
if ( not WhoFrame.selectedWho ) then
WhoFrameGroupInviteButton:Disable();
WhoFrameAddFriendButton:Disable();
else
WhoFrameGroupInviteButton:Enable();
WhoFrameAddFriendButton:Enable();
WhoFrame.selectedName = GetWhoInfo(WhoFrame.selectedWho);
end
-- If need scrollbar resize columns
if ( showScrollBar ) then
WhoFrameColumn_SetWidth(105, WhoFrameColumnHeader2);
UIDropDownMenu_SetWidth(80, WhoFrameDropDown);
else
WhoFrameColumn_SetWidth(120, WhoFrameColumnHeader2);
UIDropDownMenu_SetWidth(95, WhoFrameDropDown);
end
-- ScrollFrame update
FauxScrollFrame_Update(WhoListScrollFrame, numWhos, WHOS_TO_DISPLAY, FRIENDS_FRAME_WHO_HEIGHT );
else
g_Pre_WhoList_UpdateOverride();
end
end
function CensusPlus_FriendsFrame_Update()
if ( FriendsFrame.selectedTab == 3 and g_IsCensusPlusInProgress == true and g_WhoAutoClose ) then
FriendsFrameTopLeft:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopLeft");
FriendsFrameTopRight:SetTexture("Interface\\ClassTrainerFrame\\UI-ClassTrainer-TopRight");
FriendsFrameBottomLeft:SetTexture("Interface\\FriendsFrame\\GuildFrame-BotLeft");
FriendsFrameBottomRight:SetTexture("Interface\\FriendsFrame\\GuildFrame-BotRight");
local guildName;
guildName = GetGuildInfo("player");
FriendsFrameTitleText:SetText(guildName);
FriendsFrame_ShowSubFrame("GuildFrame");
else
g_Pre_FriendsFrame_Update();
end
end
-----------------------------------------------------------------------------------
--
-- CensusPlus Who Handler
--
-----------------------------------------------------------------------------------
function CensusPlus_WhoHandler( msg )
if( g_IsCensusPlusInProgress == true ) then
if ( msg == "" ) then
msg = WhoFrame_GetDefaultWhoCommand();
ShowWhoPanel();
elseif ( msg == "cheat" ) then
-- Remove the "cheat" part later!
ShowWhoPanel();
end
--
-- Queue up the command to run next
--
g_CensusWhoOverrideMsg = msg;
CensusPlus_Msg( CENSUSPlus_OVERRIDE );
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusButton-Paused")
-- SendWho(msg);
else
g_Pre_WhoHandler(msg);
end
end
-----------------------------------------------------------------------------------
--
-- CensusPlus command
--
-----------------------------------------------------------------------------------
function CensusPlus_Command( param )
local i,j, command, value = string.find(param, "^([^ ]+) (.+)$");
-- local firsti, lasti, command, value = string.find (param, "(%w+) (%w+) (%w+)") ;
-- if( string.lower(param) == "locale" ) then
-- CP_EU_US_Version:Show();
-- else
if( string.lower(param) == "options" ) then
CP_OptionsWindow:Show();
-- elseif( string.lower(param) == "tz" ) then
-- CensusPlus_DetermineServerDate();
elseif( command ~= nil and string.lower(command) == "prune" ) then
if( value ~= nil ) then
CensusPlus_PruneData( value, nil );
else
CensusPlus_PruneData( 30, nil );
end
elseif( command ~= nil and string.lower(command) == "timer" ) then
if( value ~= nil ) then
CensusPlus_Database["Info"]["AutoCensusTimer"] = value * 60;
CensusPlus_Msg( "Set autocensus timer to " .. value .. " minutes" );
else
CensusPlus_Database["Info"]["AutoCensusTimer"] = 1800;
CensusPlus_Msg( "Set autocensus timer to 30 minutes" );
end
elseif( string.lower(param) == "serverprune" ) then
CensusPlus_PruneData( 0, 1 );
elseif( string.lower(param) == "bufftest" ) then
showAllUnitBuffs("player");
elseif( string.lower(param) == "verbose" ) then
CensusPlus_Verbose();
elseif( string.lower(param) == "take" ) then
CensusPlus_Take_OnClick();
elseif( string.lower(param) == "stop" ) then
CensusPlus_StopCensus();
elseif( command ~= nil and string.lower(command) == "who" ) then
local m,n, check, level = string.find(value, "(%w+) (%w+)");
if( check ~= nil ) then
CensusPlus_InternalWho( string.lower(check), level );
else
CensusPlus_InternalWho( string.lower(value), nil );
end
elseif( command ~= nil and string.lower(command) == "test" ) then
if( value ~= nil ) then
CensusPlus_Test( value );
else
CensusPlus_Test( 1 );
end
else
CensusPlus_DisplayUsage();
end
end
-----------------------------------------------------------------------------------
--
-- CensusPlus Display Usage
--
-----------------------------------------------------------------------------------
function CensusPlus_DisplayUsage()
local text;
CensusPlus:Show();
CensusPlus_Msg("Usage:\n /CensusPlus \n");
CensusPlus_Msg(" /censusPlus verbose Toggle verbose mode off/on\n");
-- CensusPlus_Msg(" /CensusPlus locale Bring up the locale selection dialog - (WARNING -- CHANGING YOUR LOCALE WILL PURGE YOUR DATABASE)\n");
CensusPlus_Msg(" /CensusPlus options Bring up the Option window\n");
CensusPlus_Msg(" /CensusPlus take Start a Census snapshot\n");
CensusPlus_Msg(" /CensusPlus stop Stop a Census snapshot\n");
CensusPlus_Msg(" /CensusPlus prune X Prune the database by removing characters not seen in X days\n");
CensusPlus_Msg(" /CensusPlus serverprune Prune the database by removing all data from servers other than the one you are currently on.\n");
CensusPlus_Msg(" /CensusPlus who XXX Will display info that matches names or guilds.\n");
CensusPlus_Msg(" /CensusPlus who unguilded ## Will list unguilded characters of that level.\n");
CensusPlus_Msg(" /CensusPlus timer X ## Will set the autocensus timer (in minutes).\n");
end
-----------------------------------------------------------------------------------
--
-- CensusPlus_InternalWho - will go through our local database and see if we have
-- any info on this person
--
-----------------------------------------------------------------------------------
function CensusPlus_InternalWho( search, level )
if( g_CensusPlusLocale == "N/A" ) then
return;
end
g_InternalSearchName = search;
g_InternalSearchLevel = level;
g_InternalSearchCount = 0;
local realmName = g_CensusPlusLocale .. GetCVar("realmName");
local factionName = "TURTLE";
CensusPlus_ForAllCharacters( realmName, factionName, nil, nil, nil, nil, CensusPlus_InternalWhoResult)
CensusPlus_WhoMsg( "Found " .. g_InternalSearchCount .. " players." );
end
function CensusPlus_InternalWhoResult(name, level, guild, race, class, lastSeen )
lowerName = string.lower( name );
level = string.lower( level );
lowerGuild = string.lower( CensusPlus_SafeCheck( guild ) );
if( g_InternalSearchName == "unguilded" ) then
if( guild == "" ) then
local doit = 1;
if( g_InternalSearchLevel ~= nil ) then
if( g_InternalSearchLevel ~= level ) then
doit = 0;
end
end
if( doit == 1 ) then
local out = name .. " : Level " .. level .. " " .. race .. " " .. " " .. class;
out = out .. " Last Seen: " .. lastSeen;
CensusPlus_WhoMsg( out );
g_InternalSearchCount = g_InternalSearchCount + 1;
end
end
elseif( string.find( lowerName, g_InternalSearchName ) or string.find( lowerGuild, g_InternalSearchName ) ) then
-- found someone!
local out = name .. " : Level " .. level .. " " .. race .. " " .. " " .. class;
if( guild ~= "" ) then
out = out .. " <" .. guild .. ">";
end
out = out .. " Last Seen: " .. lastSeen;
CensusPlus_WhoMsg( out );
g_InternalSearchCount = g_InternalSearchCount + 1;
end
end
-----------------------------------------------------------------------------------
--
-- CensusPlus Verbose option
--
-----------------------------------------------------------------------------------
function CensusPlus_Verbose()
if( CensusPlus_PerCharInfo["Verbose"] == true ) then
CensusPlus_Msg( "Verbose Mode : OFF" );
CensusPlus_PerCharInfo["Verbose"] = false;
else
CensusPlus_Msg( "Verbose Mode : ON" );
CensusPlus_PerCharInfo["Verbose"] = true;
end
end
-----------------------------------------------------------------------------------
--
-- CensusPlus Auto Census set flag
--
-----------------------------------------------------------------------------------
function CensusPlus_SetAutoCensus( flag )
if( flag == 1 ) then
CensusPlus_Database["Info"]["AutoCensus"] = true;
else
CensusPlus_Database["Info"]["AutoCensus"] = false;
end
end
-----------------------------------------------------------------------------------
--
-- Minimize the window
--
-----------------------------------------------------------------------------------
function CensusPlus_OnClickMinimize()
if( CensusPlus:IsVisible() ) then
-- MiniCensusPlus:Show();
CensusPlus:Hide();
end
end
-----------------------------------------------------------------------------------
--
-- Minimize the window
--
-----------------------------------------------------------------------------------
function CensusPlus_OnClickMaximize()
if( MiniCensusPlus:IsVisible() ) then
MiniCensusPlus:Hide();
CensusPlus:Show();
end
end
-----------------------------------------------------------------------------------
--
-- Take or pause a census depending on current status
--
-----------------------------------------------------------------------------------
function CensusPlus_Take_OnClick()
if (g_IsCensusPlusInProgress) then
CensusPlus_TogglePause();
else
CensusPlus_StartCensus();
end
end
-----------------------------------------------------------------------------------
--
-- Display a tooltip for the take button
--
-----------------------------------------------------------------------------------
function CensusPlus_Take_OnEnter()
if (g_IsCensusPlusInProgress) then
if (g_CensusPlusManuallyPaused) then
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
GameTooltip:SetText(CENSUSPlus_UNPAUSECENSUS, 1.0, 1.0, 1.0);
GameTooltip:Show();
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusButton-Paused")
else
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
GameTooltip:SetText(CENSUSPlus_PAUSECENSUS, 1.0, 1.0, 1.0);
GameTooltip:Show();
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusButton-Running")
end
else
GameTooltip:SetOwner(this, "ANCHOR_RIGHT");
GameTooltip:SetText(CENSUSPlus_TAKECENSUS, 1.0, 1.0, 1.0);
GameTooltip:Show();
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusButton-Up")
end
end
-----------------------------------------------------------------------------------
--
-- Pause the current census
--
-----------------------------------------------------------------------------------
function CensusPlus_TogglePause()
if (g_IsCensusPlusInProgress == true) then
if( g_CensusPlusManuallyPaused == true ) then
CensusPlusTakeButton:SetText( CENSUSPlus_PAUSE );
g_CensusPlusManuallyPaused = false;
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusButton-Running")
else
CensusPlusTakeButton:SetText( CENSUSPlus_UNPAUSE );
g_CensusPlusManuallyPaused = true;
CensusButton:SetNormalTexture("Interface\\AddOns\\CensusPlusTurtle\\Skin\\CensusButton-Paused")
end
end
end