-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCore.lua
3489 lines (3021 loc) · 116 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
--[[
Copyright (c) 2011, Jacob Hollenbeck (Grioja of <Eminent>)
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. All advertising materials mentioning features or use of this software
must display the following acknowledgement:
This product includes software developed by Jacob Hollenbeck (Grioja).
4. Neither the name of Jacob Hollenbeck nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY JACOB HOLLENBECK ''AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL JACOB HOLLENBECK BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
]]
EminentDKP = LibStub("AceAddon-3.0"):NewAddon("EminentDKP", "AceComm-3.0", "AceEvent-3.0", "AceTimer-3.0", "AceConsole-3.0", "AceHook-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("EminentDKP", false)
local libCH = LibStub:GetLibrary("LibChatHandler-1.0")
local media = LibStub("LibSharedMedia-3.0")
libCH:Embed(EminentDKP)
local libS = LibStub:GetLibrary("AceSerializer-3.0")
local libC = LibStub:GetLibrary("LibCompress")
local libCE = libC:GetAddonEncodeTable()
--local canuse = LibStub:GetLibrary("LibCanUse-1.0")
local VERSION = '2.2.5'
local newest_version = ''
local needs_update = false
local addon_versions = {}
-- All the meter windows
local windows = {}
-- Modes (see Modes.lua)
local modes = {}
local recent_achievements = {}
local recent_deaths = {}
local auction_active = false
local recent_loots = {}
local eligible_looters = {}
local events_cache = {}
local syncing = false
local openingContainer = nil
local lastContainerName = nil
local in_combat = false
--local in_guild_group = false
-- Whether or not officer functionality is allowed to run
local enabled = true
-- When logging in, officer functionality is disabled temporarily
local tempdisabled = true
-- Disable any sync functionality
local syncdisabled = false
local function convertToTimestamp(datetime)
local t, d = strsplit(' ',datetime)
local hour, min = strsplit(':',t)
local month, day, year = strsplit('/',d)
return time({day=day,month=month,year=year,hour=hour,min=min,sec=0})
end
local function GetDate(timestamp)
return date("%x",timestamp)
end
local function GetTodayDate()
return GetDate(time())
end
local function GetDaysBetween(this,that)
return math.floor((this - that) / 86400)
end
local function GetDaysSince(timestamp)
return GetDaysBetween(time(),timestamp)
end
local function IsGroupInCombat()
if GetNumRaidMembers() > 0 then
-- We are in a raid.
for i = 1, GetNumRaidMembers(), 1 do
if UnitExists("raid"..i) and UnitAffectingCombat("raid"..i) then
return true
end
end
elseif GetNumPartyMembers() > 0 then
-- In party.
for i = 1, GetNumPartyMembers(), 1 do
if UnitExists("party"..i) and UnitAffectingCombat("party"..i) then
return true
end
end
end
end
local function MergeTables(source,other,front)
for i,val in ipairs(other) do
if front then
table.insert(source,1,val)
else
table.insert(source,val)
end
end
end
local function implode(delim,list)
return table.concat(list,delim)
end
local function sendchat(msg, chan, chantype)
local prepend = "[EminentDKP] "
if chantype == "self" then
-- To self.
EminentDKP:Print(msg)
elseif chantype == "channel" then
-- To channel.
SendChatMessage(prepend .. msg, "CHANNEL", nil, chan)
elseif chantype == "preset" then
-- To a preset channel id (say, guild, etc).
SendChatMessage(prepend .. msg, string.upper(chan))
elseif chantype == "whisper" then
-- To player.
SendChatMessage(prepend .. msg, "WHISPER", nil, chan)
end
end
-- Compare two version numbers
local function CompareVersions(current,other)
local a_major, a_minor, a_bug, a_event = strsplit(".",strtrim(current),4)
local b_major, b_minor, b_bug, b_event = strsplit(".",strtrim(other),4)
local major_diff = tonumber(a_major) - tonumber(b_major)
local minor_diff = tonumber(a_minor) - tonumber(b_minor)
local bug_diff = tonumber(a_bug) - tonumber(b_bug)
local event_diff = tonumber(a_event) - tonumber(b_event)
return { major = major_diff, minor = minor_diff, bug = bug_diff, event = event_diff }
end
local function UpdateNewestVersion(newer)
local newer_version = strtrim(newer)
local compare = CompareVersions(EminentDKP:GetNewestVersion(),newer_version)
if compare.major < 0 or compare.minor < 0 then
-- There is a new major/minor addon version
needs_update = true
elseif compare.major == 0 and compare.minor == 0 then
if compare.event < 0 or compare.bug < 0 then
newest_version = newer_version
if compare.bug < 0 then
-- There is a new bug addon version
needs_update = true
end
end
end
end
local function CheckVersionCompatability(otherversion)
local compare = CompareVersions(EminentDKP:GetVersion(),otherversion)
UpdateNewestVersion(otherversion)
if compare.major < 0 or compare.minor < 0 or compare.major > 0 or compare.minor > 0 then
return false
else
return true
end
end
--[[-------------------------------------------------------------------
Meter Window Functions
---------------------------------------------------------------------]]
-- Are we in a PVP zone?
local function is_in_pvp()
return select(2,IsInInstance()) == "pvp" or select(2,IsInInstance()) == "arena"
end
-- Are we solo?
local function is_solo()
return GetNumRaidMembers() == 0 and GetNumPartyMembers() == 0
end
-- Are we in a party?
local function is_in_party()
return GetNumRaidMembers() == 0 and GetNumPartyMembers() > 0
end
local function find_mode(name)
for i, mode in ipairs(modes) do
if mode:GetName() == name then
return mode
end
end
end
-- Our window type.
local Window = {}
local mt = {__index = Window}
function Window:new()
return setmetatable({
-- Our dataset.
dataset = {},
-- Metadata about our dataset.
metadata = {},
-- Our display provider.
display = nil,
-- Our mode traversing history.
history = {},
}, mt)
end
function Window:AddOptions()
local settings = self.settings
local options = {
type = "group",
name = function() return settings.name end,
args = {
rename = {
type= "input",
name= L["Rename window"],
desc= L["Enter the name for the window."],
get= function() return settings.name end,
set= function(win, val)
if val ~= settings.name and val ~= "" and not EminentDKP:GetWindow(val) then
settings.name = val
end
end,
order= 1,
},
display = {
type= "select",
name= L["Display system"],
desc= L["Choose the system to be used for displaying data in this window."],
values= function()
local list = {}
for name, display in pairs(EminentDKP.displays) do
list[name] = display.name
end
return list
end,
get= function() return settings.display end,
set= function(win, display)
self:SetDisplay(display)
EminentDKP:ApplySettings(win[2])
end,
order= 2,
},
locked = {
type= "toggle",
name= L["Lock window"],
desc= L["Locks the bar window in place."],
get= function() return settings.barslocked end,
set= function(win)
settings.barslocked = not settings.barslocked
EminentDKP:ApplySettings(win[2])
end,
order= 3,
},
enablestatus = {
type="toggle",
name=L["Enable Status Bar"],
desc=L["Enables the the status bar under the title."],
get=function() return settings.enablestatus end,
set=function(win)
settings.enablestatus = not settings.enablestatus
EminentDKP:ApplySettings(win[2])
end,
order= 4,
},
}
}
self.display:AddDisplayOptions(self, options.args)
EminentDKP.options.args.windows.args[self.settings.name] = options
end
function Window:destroy()
self.dataset = nil
self.display:Destroy(self)
end
function Window:SetDisplay(name)
-- Don't do anything if nothing actually changed.
if name ~= self.settings.display or self.display == nil then
if self.display then
-- Destroy old display.
self.display:Destroy(self)
end
-- Set new display.
self.settings.display = name
self.display = EminentDKP.displays[self.settings.display]
-- Add options. Replaces old options.
self:AddOptions()
end
end
-- Tells window to update the display of its dataset, using its display provider.
function Window:UpdateDisplay()
-- Fetch max value if our mode has not done this itself.
if not self.metadata.maxvalue then
self.metadata.maxvalue = 0
for i, data in ipairs(self.dataset) do
if data.id and data.value > self.metadata.maxvalue then
self.metadata.maxvalue = data.value
end
end
end
-- Display it.
self.display:Update(self)
end
function Window:Show()
self.display:Show(self)
end
function Window:Hide()
self.display:Hide(self)
end
function Window:IsShown()
return self.display:IsShown(self)
end
function Window:Wipe()
-- Clear dataset.
wipe(self.dataset)
-- Clear display.
self.display:Wipe(self)
end
-- Sets up the mode view.
function Window:DisplayMode(mode)
self:Wipe()
self.selectedmode = mode
self.metadata = {}
-- Apply mode's metadata.
if mode.metadata then
for key, value in pairs(mode.metadata) do
self.metadata[key] = value
end
end
-- Save for remembrance
self.settings.mode = mode:GetName()
self.metadata.title = mode.title or mode:GetName()
EminentDKP:UpdateDisplay(self)
end
local function click_on_mode(win, id, label, button)
if button == "LeftButton" then
local mode = find_mode(id)
if mode then
win:DisplayMode(mode)
end
elseif button == "RightButton" then
win:RightClick()
end
end
-- Sets up the mode list.
function Window:DisplayModes()
self.history = {}
self:Wipe()
self.selectedmode = nil
self.metadata = {}
self.metadata.title = L["EminentDKP: Modes"]
-- Save for remembrance
self.settings.mode = nil
self.metadata.click = click_on_mode
self.metadata.maxvalue = 1
EminentDKP:UpdateDisplay(self)
end
-- Default "right-click" behaviour in case no special click function is defined:
-- 1) If there is a mode traversal history entry, go to the last mode.
-- 2) Go to modes list if we are in a mode.
function Window:RightClick(group, button)
-- If mode traversal history exists, go to last entry, else mode list.
if #(self.history) > 0 then
self:DisplayMode(tremove(self.history))
else
self:DisplayModes()
end
end
function EminentDKP:GetWindows()
return windows
end
-- Toggle visibility of all the meter displays
function EminentDKP:ToggleMeters(visible)
for i, win in ipairs(windows) do
if visible and not win:IsShown() then
win:Show()
elseif not visible and win:IsShown() then
win:Hide()
end
end
end
-- Table copy function
function EminentDKP:tcopy(to, from)
for k,v in pairs(from) do
if type(v) == "table" then
to[k] = {}
EminentDKP:tcopy(to[k], v)
else
to[k] = v
end
end
end
function EminentDKP:GetModeData()
return self:GetActivePool().modes
end
-- Create a window and its db settings
function EminentDKP:CreateWindow(name, settings)
if not settings then
settings = {}
self:tcopy(settings, EminentDKP.windowdefaults)
table.insert(self:GetSetting('windows'), settings)
end
local window = Window:new()
window.settings = settings
window.settings.name = name
if window.settings.mode then
window.selectedmode = find_mode(window.settings.mode)
end
-- Set the window's display and call it's Create function.
window:SetDisplay(window.settings.display or "meter")
window.display:Create(window)
table.insert(windows, window)
self:ApplySettings(window)
-- Display initial view depending on settings
if window.selectedmode then
window:DisplayMode(window.selectedmode)
else
window:DisplayModes()
end
end
-- Delete window from our windows table, and also from db.
function EminentDKP:DeleteWindow(name)
for i, win in ipairs(windows) do
if win.settings.name == name then
win:destroy()
wipe(table.remove(windows, i))
end
end
for i, win in ipairs(self:GetSetting('windows')) do
if win.name == name then
table.remove(self:GetSetting('windows'), i)
end
end
self.options.args.windows.args[name] = nil
end
-- Reload
function EminentDKP:ReloadWindows()
-- Delete all existing windows in case of a profile change.
for i, win in ipairs(windows) do
win:destroy()
end
wipe(windows)
-- Calculate mode data
self:UpdateModes(false)
-- Re-create windows
for i, win in ipairs(self:GetSetting('windows')) do
self:CreateWindow(win.name, win)
end
end
-- For all modes, have them re-calculate data
function EminentDKP:UpdateModes(updatedisplays)
for j, mode in ipairs(modes) do
mode:CalculateData()
end
if updatedisplays then
self:UpdateAllDisplays()
end
end
function EminentDKP:ApplySettingsAll()
for i, win in ipairs(windows) do
self:ApplySettings(win)
end
self:UpdateStatusBar()
end
function EminentDKP:ApplySettings(win)
-- Just incase we're given a window name, not a window
if type(win) == "string" then
win = self:GetWindow(win)
end
win.display:ApplySettings(win)
-- Don't show window if we are solo, option.
-- Don't show window in a PvP instance, option.
if (self:GetSetting('hidesolo') and is_solo()) or
(self:GetSetting('hidepvp') and is_in_pvp()) or
(self:GetSetting('hideparty') and is_in_party()) or
(self:GetSetting('hidecombat') and in_combat) then
win:Hide()
else
win:Show()
-- Hide specific windows if window is marked as hidden (ie, if user manually hid the window, keep hiding it).
if win.settings.hidden and win:IsShown() then
win:Hide()
end
end
self:UpdateDisplay(win)
end
-- Called before dataset is updated.
function Window:UpdateInProgress()
for i, data in ipairs(self.dataset) do
data.id = nil
end
end
-- Loop through and update each window's display
function EminentDKP:UpdateAllDisplays()
for i, win in ipairs(windows) do
self:UpdateDisplay(win)
end
end
-- Update a given window's display
function EminentDKP:UpdateDisplay(win)
if win.selectedmode then
-- Inform window that a data update will take place.
win:UpdateInProgress()
-- Let mode update data.
if win.selectedmode.PopulateData then
win.selectedmode:PopulateData(win)
else
self:Print("Mode "..win.selectedmode:GetName().." does not have a PopulateData function!")
end
else
win:Wipe()
-- View available modes.
for i, mode in ipairs(modes) do
local d = win.dataset[i] or {}
win.dataset[i] = d
d.id, d.label, d.value = mode:GetName(), mode:GetName(), 1
if mode.GetSetSummary then
d.valuetext = mode:GetSetSummary()
end
end
-- Tell window to sort by our data order.
win.metadata.ordersort = true
end
-- Let window display the data.
win:UpdateDisplay()
end
local function scan_for_columns(mode)
-- Only process if not already scanned.
if not mode.scanned then
mode.scanned = true
-- Add options for this mode if available.
if mode.metadata and mode.metadata.columns then
EminentDKP:AddColumnOptions(mode)
end
-- Scan any linked modes.
if mode.metadata then
if mode.metadata.click1 then
scan_for_columns(mode.metadata.click1)
end
if mode.metadata.click2 then
scan_for_columns(mode.metadata.click2)
end
if mode.metadata.click3 then
scan_for_columns(mode.metadata.click3)
end
end
end
end
function EminentDKP:GetWindow(name)
for i, win in ipairs(windows) do
if win.settings.name == name then
return win
end
end
return nil
end
-- Register a mode.
function EminentDKP:AddMode(mode)
table.insert(modes, mode)
-- Add column configuration if available.
if mode.metadata then
scan_for_columns(mode)
end
mode:AddAttributes()
-- Sort modes.
table.sort(modes, function(a, b) return a.sortnum < b.sortnum or (not (b.sortnum < a.sortnum) and a.name < b.name) end)
end
-- Unregister a mode.
function EminentDKP:RemoveMode(mode)
table.remove(modes, mode)
end
function EminentDKP:SetTooltipPosition(tooltip, frame)
local p = self:GetSetting('tooltippos')
if p == "default" then
tooltip:SetOwner(UIParent, "ANCHOR_NONE")
tooltip:SetPoint("BOTTOMRIGHT", "UIParent", "BOTTOMRIGHT", -40, 40)
elseif p == "topleft" then
tooltip:SetOwner(frame, "ANCHOR_NONE")
tooltip:SetPoint("TOPRIGHT", frame, "TOPLEFT")
elseif p == "topright" then
tooltip:SetOwner(frame, "ANCHOR_NONE")
tooltip:SetPoint("TOPLEFT", frame, "TOPRIGHT")
end
end
local function value_sort(a,b)
if not a or a.value == nil then
return false
elseif not b or b.value == nil then
return true
else
return a.value > b.value
end
end
-- Tooltip display. Shows subview data for a specific row.
-- Using a fake window, the subviews are asked to populate the window's dataset normally.
local ttwin = Window:new()
function EminentDKP:AddSubviewToTooltip(tooltip, win, mode, id, label)
-- Clean dataset.
wipe(ttwin.dataset)
-- Tell mode we are entering our real window.
mode:Enter(win, id, label)
-- Ask mode to populate dataset in our fake window.
mode:PopulateData(ttwin)
-- Sort dataset unless we are using ordersort.
if not mode.metadata or not mode.metadata.ordersort then
table.sort(ttwin.dataset, value_sort)
end
if mode.metadata and mode.metadata.sortfunc then
table.sort(ttwin.dataset, mode.metadata.sortfunc)
end
-- Show title and data if we have data.
if #ttwin.dataset > 0 then
tooltip:AddLine(mode.title or mode:GetName(), 1,1,1)
-- Display the top X, default 3, rows.
local nr = 0
for i, data in ipairs(ttwin.dataset) do
if data.id and nr < EminentDKP.db.profile.tooltiprows then
nr = nr + 1
local color = {r = 1, g = 1, b = 1}
if data.color then
-- Explicit color from dataset.
color = data.color
elseif data.class then
-- Class color.
local color = EminentDKP.classColors[data.class]
end
tooltip:AddDoubleLine(nr..". "..data.label, data.valuetext, color.r, color.g, color.b)
end
end
-- Add an empty line.
tooltip:AddLine(" ")
end
end
--[[-------------------------------------------------------------------
END Meter Window Functions
---------------------------------------------------------------------]]
-- Setup basic info and get database from saved variables
function EminentDKP:OnInitialize()
-- Register the SharedMedia
media:Register("font", "Adventure", [[Interface\Addons\EminentDKP\fonts\Adventure.ttf]])
media:Register("font", "ABF", [[Interface\Addons\EminentDKP\fonts\ABF.ttf]])
media:Register("font", "Vera Serif", [[Interface\Addons\EminentDKP\fonts\VeraSe.ttf]])
media:Register("font", "Diablo", [[Interface\Addons\EminentDKP\fonts\Avqest.ttf]])
media:Register("font", "Accidental Presidency", [[Interface\Addons\EminentDKP\fonts\Accidental Presidency.ttf]])
media:Register("statusbar", "Aluminium", [[Interface\Addons\EminentDKP\statusbar\Aluminium]])
media:Register("statusbar", "Armory", [[Interface\Addons\EminentDKP\statusbar\Armory]])
media:Register("statusbar", "BantoBar", [[Interface\Addons\EminentDKP\statusbar\BantoBar]])
media:Register("statusbar", "Glaze2", [[Interface\Addons\EminentDKP\statusbar\Glaze2]])
media:Register("statusbar", "Gloss", [[Interface\Addons\EminentDKP\statusbar\Gloss]])
media:Register("statusbar", "Graphite", [[Interface\Addons\EminentDKP\statusbar\Graphite]])
media:Register("statusbar", "Grid", [[Interface\Addons\EminentDKP\statusbar\Grid]])
media:Register("statusbar", "Healbot", [[Interface\Addons\EminentDKP\statusbar\Healbot]])
media:Register("statusbar", "LiteStep", [[Interface\Addons\EminentDKP\statusbar\LiteStep]])
media:Register("statusbar", "Minimalist", [[Interface\Addons\EminentDKP\statusbar\Minimalist]])
media:Register("statusbar", "Otravi", [[Interface\Addons\EminentDKP\statusbar\Otravi]])
media:Register("statusbar", "Outline", [[Interface\Addons\EminentDKP\statusbar\Outline]])
media:Register("statusbar", "Perl", [[Interface\Addons\EminentDKP\statusbar\Perl]])
media:Register("statusbar", "Smooth", [[Interface\Addons\EminentDKP\statusbar\Smooth]])
media:Register("statusbar", "Round", [[Interface\Addons\EminentDKP\statusbar\Round]])
media:Register("statusbar", "TukTex", [[Interface\Addons\EminentDKP\statusbar\normTex]])
-- DB
self.db = LibStub("AceDB-3.0"):New("EminentDKPDB", self.defaults, "Default")
LibStub("AceConfig-3.0"):RegisterOptionsTable("EminentDKP", self.options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("EminentDKP", "EminentDKP")
-- Profiles
LibStub("AceConfig-3.0"):RegisterOptionsTable("EminentDKP-Profiles", LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db))
self.profilesFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("EminentDKP-Profiles", "Profiles", "EminentDKP")
self.db.RegisterCallback(self, "OnProfileChanged", "ReloadWindows")
self.db.RegisterCallback(self, "OnProfileCopied", "ReloadWindows")
self.db.RegisterCallback(self, "OnProfileReset", "ReloadWindows")
-- Modes
for name, mode in EminentDKP:IterateModules() do
if mode.OnEnable then
mode:Enable()
end
end
self.myName = UnitName("player")
self.myGuild = GetGuildInfo("player")
self.auctionItems = {}
-- Remember sync stuff
self.syncRequests = {}
self.syncProposals = {}
self.requestedRanges = {}
self.requestCooldown = false
self.broadcastCooldown = false
self:CreateAuctionFrame()
self:ReloadWindows()
-- Since SharedMedia doesn't finish loading until after this executes, we need to re-apply
-- the settings again to ensure everything is how it should be, an unfortunate work-around...
self:ScheduleTimer("GlobalApplySettings", 2)
-- Temporarily disable officer functionality for the first 8 seconds, ensures no accidental database recreation
self:ScheduleTimer("UndoTempDisable", 8)
DEFAULT_CHAT_FRAME:AddMessage("|rYou are using |cFFEBAA32EminentDKP |cFFAAEB32v"..VERSION.."|r")
DEFAULT_CHAT_FRAME:AddMessage("|rVisit |cFFD2691Ehttp://eminent.enjin.com|r for feedback and support.")
end
-- Restore officer functionality, we should know sync status by now
function EminentDKP:UndoTempDisable()
tempdisabled = false
syncdisabled = false
self:PARTY_LOOT_METHOD_CHANGED()
end
function EminentDKP:GlobalApplySettings()
self:ApplySettingsAll()
self:ApplyAuctionFrameSettings()
self:PARTY_LOOT_METHOD_CHANGED()
self:DatabaseUpdate()
-- Broadcast version
self:SendCommMessage("EminentDKP-SV",self:GetVersion()..":Hello",'GUILD')
-- Broadcast officer version
self:BroadcastOfficerTimestamp()
end
function EminentDKP:UpdateOfficerSettings()
if self:AmOfficer() then
self:GetActivePool().officerSettingsTime = time()
self:CancelTimer(self.setOfficerBroadcastTimer, true)
self.setOfficerBroadcastTimer = self:ScheduleTimer("BroadcastOfficerTimestamp",2)
end
end
function EminentDKP:BroadcastOfficerSettings()
if self:AmOfficer() then
-- Serialize and compress the data
local data = self.db.profile.officer
local one = self:GetVersion() .. '_' .. self:GetActivePool().officerSettingsTime .. '_'.. libS:Serialize(data)
local two = libC:CompressHuffman(one)
local final = libCE:Encode(two)
self:SendCommMessage("EminentDKP-SOS",final,'OFFICER',nil,'BULK')
end
end
function EminentDKP:BroadcastOfficerTimestamp()
if self:AmOfficer() then
self:SendCommMessage("EminentDKP-SOV",self:GetVersion() .. '_' .. self:GetActivePool().officerSettingsTime,'OFFICER')
end
end
function EminentDKP:ProcessOfficerSyncVersion(prefix, message, distribution, sender)
if sender == self.myName then return end
if not self:AmOfficer() then return end
if not self:IsAnOfficer(sender) then return end
local version, timestamp = strsplit('_',message,2)
timestamp = tonumber(timestamp)
-- Ignore sync from incompatible versions
if not CheckVersionCompatability(version) then return end
if self:GetActivePool().officerSettingsTime < timestamp then
-- Our settings are older
self:BroadcastOfficerTimestamp()
elseif self:GetActivePool().officerSettingsTime > timestamp then
-- Our settings are newer
self:CancelTimer(self.officerSettingsTimer,true)
self.officerSettingsTimer = self:ScheduleTimer('BroadcastOfficerSettings',math.random(2,6))
end
end
function EminentDKP:ProcessOfficerSyncSettings(prefix, message, distribution, sender)
if sender == self.myName then return end
if not self:AmOfficer() then return end
if not self:IsAnOfficer(sender) then return end
-- Decode the compressed data
local one = libCE:Decode(message)
-- Decompress the decoded data
local two, message = libC:DecompressHuffman(one)
if not two then
self:Print("Error occured while decoding a sync event:" .. message)
return
end
local version, timestamp, data = strsplit('_',two,3)
timestamp = tonumber(timestamp)
-- Ignore sync from incompatible versions
if not CheckVersionCompatability(version) then return end
-- Deserialize the decompressed data
local success, settings = libS:Deserialize(data)
if not success then
self:Print("Error occured while deserializing a sync event.")
return
end
if self:GetActivePool().officerSettingsTime <= timestamp then
-- Our settings are older/same
self:CancelTimer(self.officerSettingsTimer,true)
-- Save these settings
self:Print(L["Syncing officer options from %s..."]:format(sender))
self:tcopy(self.db.profile.officer,settings)
self:GetActivePool().officerSettingsTime = timestamp
self:DisableCheck()
end
end
-- DATABASE UPDATES
function EminentDKP:DatabaseUpdate()
-- Clear out old set data
if self:GetActivePool().sets then
self:GetActivePool().sets = nil
end
-- Reset revision counter
if self:GetActivePool().revision ~= 0 then
self:GetActivePool().revision = 0
end
end
function EminentDKP:OnEnable()
self:RegisterEvent("PLAYER_ENTERING_WORLD") -- version broadcast
self:RegisterChatEvent("CHAT_MSG_WHISPER") -- whisper commands received
self:RegisterChatEvent("CHAT_MSG_WHISPER_INFORM") -- whispers sent
self:RegisterChatEvent("CHAT_MSG_PARTY") -- party messages
self:RegisterChatEvent("CHAT_MSG_PARTY_LEADER") -- party messages
self:RegisterChatEvent("CHAT_MSG_RAID") -- raid messages
self:RegisterChatEvent("CHAT_MSG_RAID_LEADER") -- raid messages
self:RegisterChatEvent("CHAT_MSG_RAID_WARNING") -- raid warnings
self:RegisterEvent("ACHIEVEMENT_EARNED") -- achievement tracking
self:RegisterEvent("LOOT_OPENED") -- loot listing
self:RegisterEvent("LOOT_CLOSED") -- auction cancellation
self:RegisterEvent("LOOT_SLOT_CLEARED") -- loot tracking
self:RegisterEvent("PARTY_LOOT_METHOD_CHANGED") -- masterloot change
self:RegisterEvent("RAID_ROSTER_UPDATE") -- raid member list update
self:RegisterEvent("PARTY_MEMBERS_CHANGED") -- party member list update
self:RegisterEvent("PLAYER_REGEN_DISABLED") -- addon announcements
self:RegisterEvent("PLAYER_REGEN_ENABLED") -- combat checking
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED") -- death tracking
self:RegisterEvent("UNIT_SPELLCAST_SENT") -- loot container tracking
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED") -- loot container tracking
--self:RegisterEvent("GUILD_PARTY_STATE_UPDATED") -- guild group tracking
self:RegisterChatCommand("edkp", "ProcessSlashCmd") -- admin commands
-- Addon messages
self:RegisterComm("EminentDKP-SPP", "ProcessSyncProposal")
self:RegisterComm("EminentDKP-SFF", "ProcessSyncFulfill")
self:RegisterComm("EminentDKP-SRQ", "ProcessSyncRequest")
self:RegisterComm("EminentDKP-SV", "ProcessSyncVersion")
self:RegisterComm("EminentDKP-SE", "ProcessSyncEvent")
self:RegisterComm("EminentDKP-CMD", "ProcessCommand")
self:RegisterComm("EminentDKP-INF", "ProcessInformation")
self:RegisterComm("EminentDKP-SOV", "ProcessOfficerSyncVersion")
self:RegisterComm("EminentDKP-SOS", "ProcessOfficerSyncSettings")
-- Custom event notifications
self:RawHookScript(LevelUpDisplay, "OnShow", "LevelUpDisplayShow")
self:RawHookScript(LevelUpDisplay, "OnHide", "LevelUpDisplayHide")
self:RawHookScript(RaidWarningFrame, "OnEvent", "HideRaidWarning")
self:RawHook("LevelUpDisplay_AnimStep", "LevelUpDisplayFinished", true)
if type(CUSTOM_CLASS_COLORS) == "table" then
self.classColors = CUSTOM_CLASS_COLORS
end
-- Broadcast version every 5 minutes
self:ScheduleRepeatingTimer("BroadcastVersion", 300)
end
local notify_types = { "BOUNTY_RECEIVED", "TRANSFER_RECEIVED", "AUCTION_WON",
"TRANSFER_MADE", "ADJUSTMENT_RECEIVED", "ADJUSTMENT_MADE",
"DECAY_RECEIVED" }
-- Hook the animation step function to change the font size of the flavor text
function EminentDKP:LevelUpDisplayFinished(frame)
if tContains(notify_types,frame.type) then
frame.spellFrame.flavorText:SetFontObject("GameFontNormalLarge")
end
self.hooks["LevelUpDisplay_AnimStep"](frame)
end
-- Hook the levelUpDisplay OnHide to execute any cached notifications
function EminentDKP:LevelUpDisplayHide(frame)
self:ExecuteNextNotification()
self.hooks[frame].OnHide(frame)
end
-- Overriding the default level up display to show custom messages
-- todo: add sound notification option in settings
function EminentDKP:LevelUpDisplayShow(frame)
local texcoords = {
dot = { 0.64257813, 0.68359375, 0.18750000, 0.23046875 },
goldBG = { 0.56054688, 0.99609375, 0.24218750, 0.46679688 },
gLine = { 0.00195313, 0.81835938, 0.01953125, 0.03320313 },
textTint = { 0.67, 0.93, 0.45 },
}
if tContains(notify_types,frame.type) then