forked from tullamods/Dominos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dominos.lua
644 lines (513 loc) · 13.3 KB
/
Dominos.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
--[[
Dominos.lua
Driver for Dominos Frames
--]]
local AddonName, AddonTable = ...
local Addon = LibStub('AceAddon-3.0'):NewAddon(AddonTable, AddonName, 'AceEvent-3.0', 'AceConsole-3.0')
local L = LibStub('AceLocale-3.0'):GetLocale(AddonName)
local CURRENT_VERSION = GetAddOnMetadata(AddonName, 'Version')
local CONFIG_ADDON_NAME = AddonName .. '_Config'
--[[ Startup ]]--
function Addon:OnInitialize()
--register database events
self.db = LibStub('AceDB-3.0'):New(AddonName .. 'DB', self:GetDefaults(), UnitClass('player'))
self.db.RegisterCallback(self, 'OnNewProfile')
self.db.RegisterCallback(self, 'OnProfileChanged')
self.db.RegisterCallback(self, 'OnProfileCopied')
self.db.RegisterCallback(self, 'OnProfileReset')
self.db.RegisterCallback(self, 'OnProfileDeleted')
--version update
if _G[AddonName .. 'Version'] then
if _G[AddonName .. 'Version'] ~= CURRENT_VERSION then
self:UpdateSettings(_G[AddonName .. 'Version']:match('(%w+)%.(%w+)%.(%w+)'))
self:UpdateVersion()
end
--new user
else
_G[AddonName .. 'Version'] = CURRENT_VERSION
end
--create a loader for the options menu
local f = CreateFrame('Frame', nil, _G['InterfaceOptionsFrame'])
f:SetScript('OnShow', function(self)
self:SetScript('OnShow', nil)
LoadAddOn(CONFIG_ADDON_NAME)
end)
--keybound support
local kb = LibStub('LibKeyBound-1.0')
kb.RegisterCallback(self, 'LIBKEYBOUND_ENABLED')
kb.RegisterCallback(self, 'LIBKEYBOUND_DISABLED')
end
function Addon:OnEnable()
self:UpdateUseOverrideUI()
self:Load()
self.MultiActionBarGridFixer:SetShowGrid(self:ShowGrid())
end
--[[ Version Updating ]]--
function Addon:GetDefaults()
return {
profile = {
possessBar = 1,
sticky = true,
linkedOpacity = false,
showMacroText = true,
showBindingText = true,
showTooltips = true,
showTooltipsCombat = true,
useOverrideUI = true,
minimap = {
hide = false,
},
ab = {
count = 10,
showgrid = true,
},
frames = {}
}
}
end
function Addon:UpdateSettings(major, minor, bugfix)
--inject new roll bar defaults
if major == '5' and minor == '0' and bugfix < '14' then
for profile, sets in pairs(self.db.sv.profiles) do
if sets.frames then
local rollBarFrameSets = sets.frames['roll']
if rollBarFrameSets then
rollBarFrameSets.showInPetBattleUI = true
rollBarFrameSets.showInOverrideUI = true
end
end
end
end
end
function Addon:UpdateVersion()
_G[AddonName .. 'Version'] = CURRENT_VERSION
self:Printf(L.Updated, _G[AddonName .. 'Version'])
end
function Addon:PrintVersion()
self:Print(_G[AddonName .. 'Version'])
end
--Load is called when the addon is first enabled, and also whenever a profile is loaded
function Addon:Load()
local module_load = function(module)
if module.Load then
module:Load()
end
end
for i, module in self:IterateModules() do
local success, msg = pcall(module_load, module)
if not success then
self:Printf('Failed to load %s\n%s', module:GetName(), msg)
end
end
self.Frame:ForAll('Reanchor')
end
--unload is called when we're switching profiles
function Addon:Unload()
local module_unload = function(module)
if module.Unload then
module:Unload()
end
end
--unload any module stuff
for i, module in self:IterateModules() do
local success, msg = pcall(module_unload, module)
if not success then
self:Printf('Failed to unload %s\n%s', module:GetName(), msg)
end
end
end
--[[
Configuration
--]]
function Addon:SetUseOverrideUI(enable)
self.db.profile.useOverrideUI = enable and true or false
self:UpdateUseOverrideUI()
end
function Addon:UsingOverrideUI()
return self.db.profile.useOverrideUI
end
function Addon:UpdateUseOverrideUI()
local usingOverrideUI = self:UsingOverrideUI()
self.OverrideController:SetAttribute('state-useoverrideui', usingOverrideUI)
local oab = _G['OverrideActionBar']
oab:ClearAllPoints()
if usingOverrideUI then
oab:SetPoint('BOTTOM')
else
oab:SetPoint('LEFT', oab:GetParent(), 'RIGHT', 100, 0)
end
end
--[[ Keybound Events ]]--
function Addon:LIBKEYBOUND_ENABLED()
for _,frame in self.Frame:GetAll() do
if frame.KEYBOUND_ENABLED then
frame:KEYBOUND_ENABLED()
end
end
end
function Addon:LIBKEYBOUND_DISABLED()
for _,frame in self.Frame:GetAll() do
if frame.KEYBOUND_DISABLED then
frame:KEYBOUND_DISABLED()
end
end
end
--[[ Profile Functions ]]--
function Addon:SaveProfile(name)
local toCopy = self.db:GetCurrentProfile()
if name and name ~= toCopy then
self:Unload()
self.db:SetProfile(name)
self.db:CopyProfile(toCopy)
self.isNewProfile = nil
self:Load()
end
end
function Addon:SetProfile(name)
local profile = self:MatchProfile(name)
if profile and profile ~= self.db:GetCurrentProfile() then
self:Unload()
self.db:SetProfile(profile)
self.isNewProfile = nil
self:Load()
else
self:Print(format(L.InvalidProfile, name or 'null'))
end
end
function Addon:DeleteProfile(name)
local profile = self:MatchProfile(name)
if profile and profile ~= self.db:GetCurrentProfile() then
self.db:DeleteProfile(profile)
else
self:Print(L.CantDeleteCurrentProfile)
end
end
function Addon:CopyProfile(name)
if name and name ~= self.db:GetCurrentProfile() then
self:Unload()
self.db:CopyProfile(name)
self.isNewProfile = nil
self:Load()
end
end
function Addon:ResetProfile()
self:Unload()
self.db:ResetProfile()
self.isNewProfile = true
self:Load()
end
function Addon:ListProfiles()
self:Print(L.AvailableProfiles)
local current = self.db:GetCurrentProfile()
for _,k in ipairs(self.db:GetProfiles()) do
if k == current then
print(' - ' .. k, 1, 1, 0)
else
print(' - ' .. k)
end
end
end
function Addon:MatchProfile(name)
local name = name:lower()
local nameRealm = name .. ' - ' .. GetRealmName():lower()
local match
for i, k in ipairs(self.db:GetProfiles()) do
local key = k:lower()
if key == name then
return k
elseif key == nameRealm then
match = k
end
end
return match
end
--[[ Profile Events ]]--
function Addon:OnNewProfile(msg, db, name)
self.isNewProfile = true
self:Print(format(L.ProfileCreated, name))
end
function Addon:OnProfileDeleted(msg, db, name)
self:Print(format(L.ProfileDeleted, name))
end
function Addon:OnProfileChanged(msg, db, name)
self:Print(format(L.ProfileLoaded, name))
end
function Addon:OnProfileCopied(msg, db, name)
self:Print(format(L.ProfileCopied, name))
end
function Addon:OnProfileReset(msg, db)
self:Print(format(L.ProfileReset, db:GetCurrentProfile()))
end
--[[ Settings...Setting ]]--
function Addon:SetFrameSets(id, sets)
local id = tonumber(id) or id
self.db.profile.frames[id] = sets
return self.db.profile.frames[id]
end
function Addon:GetFrameSets(id)
return self.db.profile.frames[tonumber(id) or id]
end
--[[ Options Menu Display ]]--
function Addon:GetOptions()
local options = self.Options
if (not options) and LoadAddOn(CONFIG_ADDON_NAME) then
options = self.Options
end
return options
end
function Addon:ShowOptions()
if InCombatLockdown() then return end
local options = self:GetOptions()
if options then
options:ShowAddonPanel()
return true
end
return false
end
function Addon:NewMenu()
local options = self:GetOptions()
if options then
return options.Menu:New()
end
return nil
end
function Addon:IsConfigAddonEnabled()
return GetAddOnEnableState(UnitName('player'), CONFIG_ADDON_NAME) >= 1
end
--[[ Configuration Functions ]]--
--moving
Addon.locked = true
function Addon:SetLock(enable)
if InCombatLockdown() and (not enable) then
return
end
self.locked = enable or false
if self:Locked() then
self:GetModule('ConfigOverlay'):Hide()
else
LibStub('LibKeyBound-1.0'):Deactivate()
self:GetModule('ConfigOverlay'):Show()
end
end
function Addon:Locked()
return self.locked
end
function Addon:ToggleLockedFrames()
self:SetLock(not self:Locked())
end
function Addon:ToggleBindingMode()
self:SetLock(true)
LibStub('LibKeyBound-1.0'):Toggle()
end
function Addon:IsBindingModeEnabled()
return LibStub('LibKeyBound-1.0'):IsShown()
end
--scale
function Addon:ScaleFrames(...)
local numArgs = select('#', ...)
local scale = tonumber(select(numArgs, ...))
if scale and scale > 0 and scale <= 10 then
for i = 1, numArgs - 1 do
self.Frame:ForFrame(select(i, ...), 'SetFrameScale', scale)
end
end
end
--opacity
function Addon:SetOpacityForFrames(...)
local numArgs = select('#', ...)
local alpha = tonumber(select(numArgs, ...))
if alpha and alpha >= 0 and alpha <= 1 then
for i = 1, numArgs - 1 do
self.Frame:ForFrame(select(i, ...), 'SetFrameAlpha', alpha)
end
end
end
--faded opacity
function Addon:SetFadeForFrames(...)
local numArgs = select('#', ...)
local alpha = tonumber(select(numArgs, ...))
if alpha and alpha >= 0 and alpha <= 1 then
for i = 1, numArgs - 1 do
self.Frame:ForFrame(select(i, ...), 'SetFadeMultiplier', alpha)
end
end
end
--columns
function Addon:SetColumnsForFrames(...)
local numArgs = select('#', ...)
local cols = tonumber(select(numArgs, ...))
if cols then
for i = 1, numArgs - 1 do
self.Frame:ForFrame(select(i, ...), 'SetColumns', cols)
end
end
end
--spacing
function Addon:SetSpacingForFrame(...)
local numArgs = select('#', ...)
local spacing = tonumber(select(numArgs, ...))
if spacing then
for i = 1, numArgs - 1 do
self.Frame:ForFrame(select(i, ...), 'SetSpacing', spacing)
end
end
end
--padding
function Addon:SetPaddingForFrames(...)
local numArgs = select('#', ...)
local pW, pH = select(numArgs - 1, ...)
if tonumber(pW) and tonumber(pH) then
for i = 1, numArgs - 2 do
self.Frame:ForFrame(select(i, ...), 'SetPadding', tonumber(pW), tonumber(pH))
end
end
end
--visibility
function Addon:ShowFrames(...)
for i = 1, select('#', ...) do
self.Frame:ForFrame(select(i, ...), 'ShowFrame')
end
end
function Addon:HideFrames(...)
for i = 1, select('#', ...) do
self.Frame:ForFrame(select(i, ...), 'HideFrame')
end
end
function Addon:ToggleFrames(...)
for i = 1, select('#', ...) do
self.Frame:ForFrame(select(i, ...), 'ToggleFrame')
end
end
--clickthrough
function Addon:SetClickThroughForFrames(...)
local numArgs = select('#', ...)
local enable = select(numArgs - 1, ...)
for i = 1, numArgs - 2 do
self.Frame:ForFrame(select(i, ...), 'SetClickThrough', tonumber(enable) == 1)
end
end
--empty button display
function Addon:ToggleGrid()
self:SetShowGrid(not self:ShowGrid())
end
function Addon:SetShowGrid(enable)
self.db.profile.showgrid = enable or false
self.ActionBar:ForAll('UpdateGrid')
self.MultiActionBarGridFixer:SetShowGrid(enable)
end
function Addon:ShowGrid()
return self.db.profile.showgrid
end
--right click selfcast
function Addon:SetRightClickUnit(unit)
self.db.profile.ab.rightClickUnit = unit
self.ActionBar:ForAll('UpdateRightClickUnit')
end
function Addon:GetRightClickUnit()
return self.db.profile.ab.rightClickUnit
end
--binding text
function Addon:SetShowBindingText(enable)
self.db.profile.showBindingText = enable or false
for _,f in self.Frame:GetAll() do
if f.buttons then
for _,b in pairs(f.buttons) do
if b.UpdateHotkey then
b:UpdateHotkey()
end
end
end
end
end
function Addon:ShowBindingText()
return self.db.profile.showBindingText
end
--macro text
function Addon:SetShowMacroText(enable)
self.db.profile.showMacroText = enable or false
for _,f in self.Frame:GetAll() do
if f.buttons then
for _,b in pairs(f.buttons) do
if b.UpdateMacro then
b:UpdateMacro()
end
end
end
end
end
function Addon:ShowMacroText()
return self.db.profile.showMacroText
end
--possess bar settings
function Addon:SetOverrideBar(id)
local prevBar = self:GetOverrideBar()
self.db.profile.possessBar = id
local newBar = self:GetOverrideBar()
prevBar:UpdateOverrideBar()
newBar:UpdateOverrideBar()
end
function Addon:GetOverrideBar()
return self.Frame:Get(self.db.profile.possessBar)
end
--action bar numbers
function Addon:SetNumBars(count)
count = max(min(count, 120), 1) --sometimes, I do entertaininig things
if count ~= self:NumBars() then
self.ActionBar:ForAll('Delete')
self.db.profile.ab.count = count
for i = 1, self:NumBars() do
self.ActionBar:New(i)
end
end
end
function Addon:SetNumButtons(count)
self:SetNumBars(120 / count)
end
function Addon:NumBars()
return self.db.profile.ab.count
end
--tooltips
function Addon:ShowTooltips()
return self.db.profile.showTooltips
end
function Addon:SetShowTooltips(enable)
self.db.profile.showTooltips = enable or false
self:GetModule('Tooltips'):SetShowTooltips(enable)
end
function Addon:SetShowCombatTooltips(enable)
self.db.profile.showTooltipsCombat = enable or false
self:GetModule('Tooltips'):SetShowTooltipsInCombat(enable)
end
function Addon:ShowCombatTooltips()
return self.db.profile.showTooltipsCombat
end
--minimap button
function Addon:SetShowMinimap(enable)
self.db.profile.minimap.hide = not enable
self:GetModule('Launcher'):Update()
end
function Addon:ShowingMinimap()
return not self.db.profile.minimap.hide
end
--sticky bars
function Addon:SetSticky(enable)
self.db.profile.sticky = enable or false
if not enable then
self.Frame:ForAll('Stick')
self.Frame:ForAll('Reposition')
end
end
function Addon:Sticky()
return self.db.profile.sticky
end
--linked opacity
function Addon:SetLinkedOpacity(enable)
self.db.profile.linkedOpacity = enable or false
self.Frame:ForAll('UpdateWatched')
self.Frame:ForAll('UpdateAlpha')
end
function Addon:IsLinkedOpacityEnabled()
return self.db.profile.linkedOpacity
end
--[[ exports ]]--
_G[AddonName] = Addon