forked from funkydude/SexyMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Buttons.lua
679 lines (616 loc) · 22 KB
/
Buttons.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
local _, sm = ...
sm.buttons = {}
local mod = sm.buttons
local L = sm.L
local ldbi = LibStub("LibDBIcon-1.0")
local moving, ButtonFadeOut
local animFrames = {}
local blizzButtons = {
GameTimeFrame = L["Calendar"],
MiniMapTracking = L["Tracking Button"],
SexyMapZoneTextButton = L["Zone Text"],
MinimapZoomIn = L["Zoom In Button"],
MinimapZoomOut = L["Zoom Out Button"],
MiniMapWorldMapButton = L["Map Button"],
TimeManagerClockButton = L["Clock"],
}
local dynamicButtons = {
GuildInstanceDifficulty = L["Guild Dungeon Difficulty Indicator (When Available)"],
MiniMapChallengeMode = L["Challenge Mode Button (When Available)"],
MiniMapInstanceDifficulty = L["Dungeon Difficulty Indicator (When Available)"],
MiniMapMailFrame = L["New Mail Indicator (When Available)"],
QueueStatusMinimapButton = L["Queue Status (PvP/LFG) Button (When Available)"],
GarrisonLandingPageMinimapButton = L["Garrison Button (When Available)"],
}
local namesCompatForDF = ExpansionLandingPageMinimapButton and {
[ExpansionLandingPageMinimapButton] = "GarrisonLandingPageMinimapButton",
[Minimap.ZoomIn] = "MinimapZoomIn",
[Minimap.ZoomOut] = "MinimapZoomOut",
[MinimapCluster.Tracking] = "MiniMapTracking",
[MinimapCluster.InstanceDifficulty] = "MiniMapInstanceDifficulty",
[MinimapCluster.MailFrame] = "MiniMapMailFrame",
[GameTimeFrame] = "GameTimeFrame", -- Just here to change parent to Minimap in :NewFrame
[MinimapCluster.Tracking.Button] = "none", -- Prevent error when being passed to :NewFrame
} or {}
local options = {
type = "group",
name = L["Buttons"],
childGroups = "tab",
args = {
custom = {
type = "group",
name = L["Addon Buttons"],
disabled = function()
return not mod.db.controlVisibility
end,
args = {},
order = 3,
},
dynamic = {
type = "group",
name = L["Dynamic Buttons"],
disabled = function()
return not mod.db.controlVisibility
end,
args = {},
order = 2,
},
stock = {
type = "group",
disabled = function()
return not mod.db.controlVisibility
end,
name = L["Standard Buttons"],
args = {},
order = 1,
},
enableDragging = {
type = "toggle",
name = L["Let SexyMap handle button dragging"],
desc = L["Allow SexyMap to assume drag ownership for buttons attached to the minimap. Turn this off if you have another mod that you want to use to position your minimap buttons."],
width = 2,
order = 101,
get = function()
return mod.db.allowDragging
end,
set = function(info, v)
mod.db.allowDragging = v
if v then mod:UpdateDraggables() end
end
},
lockDragging = {
type = "toggle",
name = L["Lock Button Dragging"],
order = 102,
disabled = function()
return not mod.db.allowDragging
end,
get = function()
return mod.db.lockDragging
end,
set = function(info, v)
mod.db.lockDragging = v
end
},
dragRadius = {
type = "range",
name = L["Drag Radius"],
min = -30,
max = 100,
step = 1,
bigStep = 1,
order = 103,
disabled = function()
return not mod.db.allowDragging
end,
get = function()
return mod.db.radius
end,
set = function(info, v)
mod.db.radius = v
mod:UpdateDraggables()
end
},
visSpacer = {
order = 104,
type = "header",
name = L["Visibility"],
},
controlVisibility = {
type = "toggle",
name = L["Let SexyMap control button visibility"],
desc = L["Turn this off if you want another mod to handle which buttons are visible on the minimap."],
width = "full",
order = 105,
get = function()
return mod.db.controlVisibility
end,
set = function(info, v)
mod.db.controlVisibility = v
for i = 1, #animFrames do
local f = animFrames[i]
if not v then
mod:ChangeFrameVisibility(f, "always")
else
local name = namesCompatForDF[f] or f:GetName()
mod:ChangeFrameVisibility(f, mod.db.visibilitySettings[name] or "hover")
end
end
end
},
}
}
do
local hideValues = {
["always"] = L["Always"],
["never"] = L["Never"],
["hover"] = L["On Hover"],
}
local function hideGet(info, v)
return (mod.db.visibilitySettings[info[#info]] or "hover") == v
end
local function hideSet(info, value)
local name = info[#info]
mod.db.visibilitySettings[name] = value
for k,v in next, namesCompatForDF do
if v == name then
mod:ChangeFrameVisibility(k, value)
return
end
end
mod:ChangeFrameVisibility(_G[name], value)
end
function mod:AddButtonOptions(name)
local p
if blizzButtons[name] then
p = options.args.stock.args -- Blizz icon = stock section
elseif dynamicButtons[name] then
p = options.args.dynamic.args -- Blizz dynamic (off by default) icon = dynamic section
else
p = options.args.custom.args -- Addon icon = custom section
end
p[name] = {
type = "multiselect",
name = L["Show %s:"]:format(blizzButtons[name] or dynamicButtons[name] or name:gsub("LibDBIcon10_", "")),
values = hideValues,
get = hideGet,
set = hideSet,
}
end
end
function mod:OnInitialize(profile)
if type(profile.buttons) ~= "table" then
profile.buttons = {
radius = 10,
dragPositions = {},
visibilitySettings = {
MinimapZoomIn = "never",
MinimapZoomOut = "never",
MiniMapWorldMapButton = "never",
SexyMapZoneTextButton = "always",
TimeManagerClockButton = "always",
MiniMapMailFrame = "always",
QueueStatusMinimapButton = "always",
GarrisonLandingPageMinimapButton = "always",
},
allowDragging = true,
lockDragging = false,
controlVisibility = true
}
end
self.db = profile.buttons
-- XXX temp 9.0.1
if not profile.buttons.visibilitySettings.SexyMapZoneTextButton then
profile.buttons.visibilitySettings.SexyMapZoneTextButton = "always"
profile.buttons.visibilitySettings.MinimapZoneTextButton = nil
end
end
function mod:OnEnable()
-- Customize the world map: Defaults!
-- Interface\\minimap\\UI-Minimap-WorldMapSquare
-- MiniMapWorldMapButton:GetRegions():SetTexCoord(0,0,0,0.5,1,0,1,0.5) -- Normal
-- MiniMapWorldMapButton:GetRegions():SetTexCoord(0,0.5,0,1,1,0.5,1,1) -- Pushed
if MiniMapWorldMapButton then
local overlay = MiniMapWorldMapButton:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53,53)
overlay:SetTexture(136430) -- 136430 = Interface\\Minimap\\MiniMap-TrackingBorder
overlay:SetPoint("TOPLEFT")
local background = MiniMapWorldMapButton:CreateTexture(nil, "BACKGROUND")
background:SetSize(25,25)
background:SetTexture(136467) -- 136467 = Interface\\Minimap\\UI-Minimap-Background
background:SetPoint("TOPLEFT", MiniMapWorldMapButton, "TOPLEFT", 4, -2)
local icon, pushedIcon, highlight = MiniMapWorldMapButton:GetRegions()
icon:SetTexCoord(0.32,0,0.32,0.5,1,0,1,0.5)
icon:ClearAllPoints()
icon:SetPoint("BOTTOMRIGHT", MiniMapWorldMapButton, "BOTTOMRIGHT", -4, 2)
icon:SetSize(20,30)
pushedIcon:SetTexCoord(0.32,0.5,0.32,1,1,0.5,1,1)
pushedIcon:ClearAllPoints()
pushedIcon:SetPoint("BOTTOMRIGHT", MiniMapWorldMapButton, "BOTTOMRIGHT", -4, 2)
pushedIcon:SetSize(20,30)
MiniMapWorldMapButton:SetHighlightTexture(136477) -- 136477 = Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight
highlight:ClearAllPoints()
highlight:SetPoint("TOPLEFT", MiniMapWorldMapButton, "TOPLEFT", 2, -2)
else
-- Mail Button
local overlay = MinimapCluster.MailFrame:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53,53)
overlay:SetTexture(136430) -- 136430 = Interface\\Minimap\\MiniMap-TrackingBorder
overlay:SetPoint("CENTER", MiniMapMailIcon, "CENTER", 10, -10)
local background = MinimapCluster.MailFrame:CreateTexture(nil, "BACKGROUND")
background:SetSize(25,25)
background:SetTexture(136467) -- 136467 = Interface\\Minimap\\UI-Minimap-Background
background:SetPoint("CENTER", MiniMapMailIcon, "CENTER")
-- Tracking Button
overlay = MinimapCluster.Tracking:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53,53)
overlay:SetTexture(136430) -- 136430 = Interface\\Minimap\\MiniMap-TrackingBorder
overlay:SetPoint("CENTER", MinimapCluster.Tracking.Button, "CENTER", 10, -10)
background = MinimapCluster.Tracking:CreateTexture(nil, "BACKGROUND")
background:SetSize(25,25)
background:SetTexture(136467) -- 136467 = Interface\\Minimap\\UI-Minimap-Background
background:SetPoint("CENTER", MinimapCluster.Tracking.Button, "CENTER")
-- Calendar Button
overlay = GameTimeFrame:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53,53)
overlay:SetTexture(136430) -- 136430 = Interface\\Minimap\\MiniMap-TrackingBorder
overlay:SetPoint("CENTER", GameTimeFrame, "CENTER", 10, -10)
background = GameTimeFrame:CreateTexture(nil, "BACKGROUND")
background:SetSize(25,25)
background:SetTexture(136467) -- 136467 = Interface\\Minimap\\UI-Minimap-Background
background:SetPoint("CENTER", GameTimeFrame, "CENTER")
-- Zoom in Button
overlay = Minimap.ZoomIn:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53,53)
overlay:SetTexture(136430) -- 136430 = Interface\\Minimap\\MiniMap-TrackingBorder
overlay:SetPoint("CENTER", Minimap.ZoomIn, "CENTER", 10, -10)
background = Minimap.ZoomIn:CreateTexture(nil, "BACKGROUND")
background:SetSize(25,25)
background:SetTexture(136467) -- 136467 = Interface\\Minimap\\UI-Minimap-Background
background:SetPoint("CENTER", Minimap.ZoomIn, "CENTER")
-- Zoom out Button
overlay = Minimap.ZoomOut:CreateTexture(nil, "OVERLAY")
overlay:SetSize(53,53)
overlay:SetTexture(136430) -- 136430 = Interface\\Minimap\\MiniMap-TrackingBorder
overlay:SetPoint("CENTER", Minimap.ZoomOut, "CENTER", 10, -10)
background = Minimap.ZoomOut:CreateTexture(nil, "BACKGROUND")
background:SetSize(25,25)
background:SetTexture(136467) -- 136467 = Interface\\Minimap\\UI-Minimap-Background
background:SetPoint("CENTER", Minimap.ZoomOut, "CENTER")
end
if GarrisonLandingPageMinimapButton then
GarrisonLandingPageMinimapButton:SetSize(36, 36) -- Shrink the missions button
-- Stop Blizz changing the icon size || GarrisonLandingPageMinimapButton_UpdateIcon() >> SetLandingPageIconFromAtlases() >> self:SetSize()
hooksecurefunc(GarrisonLandingPageMinimapButton, "SetSize", function()
sm.core.button.SetSize(GarrisonLandingPageMinimapButton, 36, 36)
end)
-- Stop Blizz moving the icon || GarrisonLandingPageMinimapButton_UpdateIcon() >> ApplyGarrisonTypeAnchor() >> anchor:SetPoint()
hooksecurefunc("GarrisonLandingPageMinimapButton_UpdateIcon", function()
mod:UpdateDraggables(GarrisonLandingPageMinimapButton)
end)
else
sm.core.button.SetParent(ExpansionLandingPageMinimapButton, Minimap)
sm.core.button.SetSize(ExpansionLandingPageMinimapButton, 36, 36) -- Shrink the missions button
-- Stop Blizz changing the icon size || Minimap.lua ExpansionLandingPageMinimapButtonMixin:UpdateIcon() >> SetLandingPageIconFromAtlases() >> self:SetSize()
hooksecurefunc(ExpansionLandingPageMinimapButton, "SetSize", function()
sm.core.button.SetSize(ExpansionLandingPageMinimapButton, 36, 36)
end)
-- Stop Blizz moving the icon || Minimap.lua ExpansionLandingPageMinimapButtonMixin:UpdateIcon()>> self:UpdateIconForGarrison() >> ApplyGarrisonTypeAnchor() >> anchor:SetPoint()
hooksecurefunc(ExpansionLandingPageMinimapButton, "UpdateIconForGarrison", function()
mod:UpdateDraggables(ExpansionLandingPageMinimapButton)
end)
end
sm.core:RegisterModuleOptions("Buttons", options, L["Buttons"])
C_Timer.After(1, mod.StartFrameGrab)
end
--------------------------------------------------------------------------------
-- Fading
--
local OnFinished, KillAnimation
do
local fadeStop = false -- Use a variable to prevent fadeout/in when moving the mouse around minimap/icons
local restoreGarrisonButtonAnimation = false
local restoreLFGButtonAnimation = false
OnFinished = function(anim)
-- Work around issues with buttons that have a pulse/fade ring animation.
if restoreGarrisonButtonAnimation and anim:GetParent():GetName() == "GarrisonLandingPageMinimapButton" then
anim:GetParent().MinimapLoopPulseAnim:Play()
restoreGarrisonButtonAnimation = false
end
if restoreLFGButtonAnimation and anim:GetParent():GetName() == "QueueStatusMinimapButton" then
anim:GetParent().EyeHighlightAnim:Play()
restoreLFGButtonAnimation = false
end
end
KillAnimation = function(n, f)
-- Work around issues with buttons that have a pulse/fade ring animation.
if n == "GarrisonLandingPageMinimapButton" and (f.MinimapLoopPulseAnim:IsPlaying() or restoreGarrisonButtonAnimation) then
restoreGarrisonButtonAnimation = true
f.MinimapLoopPulseAnim:Stop()
return f.MinimapLoopPulseAnim
end
if n == "QueueStatusMinimapButton" and (f.EyeHighlightAnim:IsPlaying() or restoreLFGButtonAnimation) then
restoreLFGButtonAnimation = true
f.EyeHighlightAnim:Stop()
return f.EyeHighlightAnim
end
end
local OnEnter = function()
if not mod.db.controlVisibility or fadeStop or moving then return end
for i = 1, #animFrames do
local f = animFrames[i]
local n = namesCompatForDF[f] or f:GetName()
if not mod.db.visibilitySettings[n] or mod.db.visibilitySettings[n] == "hover" then
f.sexyMapFadeOut:Stop()
local anim = KillAnimation(n, f)
f:SetAlpha(1)
if anim then
OnFinished(anim)
end
end
end
end
local OnLeave = function()
if not mod.db.controlVisibility or moving then return end
local focus = GetMouseFocus() -- Minimap or Minimap icons including nil checks to compensate for other addons
if focus and not focus:IsForbidden() and ((focus:GetName() == "Minimap") or (focus:GetParent() and focus:GetParent():GetName() and focus:GetParent():GetName():find("Mini[Mm]ap"))) then
fadeStop = true
return
end
fadeStop = false
for i = 1, #animFrames do
local f = animFrames[i]
local n = namesCompatForDF[f] or f:GetName()
if not mod.db.visibilitySettings[n] or mod.db.visibilitySettings[n] == "hover" then
if n ~= "GameTimeFrame" or (n == "GameTimeFrame" and C_Calendar.GetNumPendingInvites() < 1) then
f.sexyMapFadeOut:Play()
KillAnimation(n, f)
end
end
end
end
local hideFrame = CreateFrame("Frame") -- Dummy frame we use for hiding buttons to prevent other addons re-showing them
hideFrame:Hide()
function mod:NewFrame(f)
local n = namesCompatForDF[f] or f:GetName()
-- Only add Blizz buttons & LibDBIcon buttons
if blizzButtons[n] or dynamicButtons[n] or n:find("LibDBIcon") then
-- Create the animation
f.sexyMapFadeOut = f:CreateAnimationGroup()
local smAlphaAnimOut = f.sexyMapFadeOut:CreateAnimation("Alpha")
smAlphaAnimOut:SetOrder(1)
smAlphaAnimOut:SetDuration(0.2)
smAlphaAnimOut:SetFromAlpha(1)
smAlphaAnimOut:SetToAlpha(0)
smAlphaAnimOut:SetStartDelay(1)
f.sexyMapFadeOut:SetToFinalAlpha(true)
-- Work around issues with buttons that have a pulse/fade ring animation.
if n == "GarrisonLandingPageMinimapButton" or n == "QueueStatusMinimapButton" then
f.sexyMapFadeOut:SetScript("OnFinished", OnFinished)
end
-- These frames are parented to MinimapCluster, if the map scale is changed they won't drag properly, so we parent to Minimap
if n == "MiniMapInstanceDifficulty" or n == "GuildInstanceDifficulty" or n == "MiniMapChallengeMode" then
f:ClearAllPoints()
f:SetParent(Minimap)
f:SetPoint("CENTER", Minimap, "CENTER", -60, 55)
elseif namesCompatForDF[f] then
f:SetParent(Minimap)
end
animFrames[#animFrames+1] = f
-- Configure fading
if n == "TimeManagerClockButton" then -- This is disgusting but have to work around other addons messing with it
hooksecurefunc(f, "SetParent", function(self)
local vis = mod.db.visibilitySettings[n] or "hover"
if vis == "always" then
sm.core.button.SetParent(self, Minimap)
self:SetAlpha(1)
elseif vis == "never" then
sm.core.button.SetParent(self, hideFrame)
else
sm.core.button.SetParent(self, Minimap)
self:SetAlpha(0)
end
end)
f:SetParent(Minimap) -- Run the hook
elseif mod.db.controlVisibility then
self:ChangeFrameVisibility(f, mod.db.visibilitySettings[n] or "hover")
end
-- Don't add config or moving capability to the Zone Text and Clock buttons, handled in their own modules
if n ~= "SexyMapZoneTextButton" and n ~= "TimeManagerClockButton" then
self:AddButtonOptions(n)
-- Configure dragging
if n == "MiniMapTracking" then
if MiniMapTrackingButton then
self:MakeMovable(MiniMapTrackingButton, f)
else
self:MakeMovable(MinimapCluster.Tracking.Button, f)
end
else
self:MakeMovable(f)
end
end
end
f:HookScript("OnEnter", OnEnter)
f:HookScript("OnLeave", OnLeave)
end
local frameParents = {} -- Store the original button parents for restoration
function mod:ChangeFrameVisibility(frame, vis)
if vis == "always" then
if frameParents[frame] then
frame:SetParent(frameParents[frame])
frameParents[frame] = nil
end
if frame.MinimapLoopPulseAnim or frame.EyeHighlightAnim then
KillAnimation(frame:GetName(), frame)
frame:SetAlpha(1)
OnFinished(frame.MinimapLoopPulseAnim or frame.EyeHighlightAnim)
else
frame:SetAlpha(1)
end
elseif vis == "never" then
if not frameParents[frame] then
frameParents[frame] = frame:GetParent()
end
frame:SetParent(hideFrame)
else
if frameParents[frame] then
frame:SetParent(frameParents[frame])
frameParents[frame] = nil
end
if frame.MinimapLoopPulseAnim or frame.EyeHighlightAnim then
KillAnimation(frame:GetName(), frame)
frame:SetAlpha(0)
OnFinished(frame.MinimapLoopPulseAnim or frame.EyeHighlightAnim)
else
frame:SetAlpha(0)
end
end
end
ButtonFadeOut = OnLeave
end
--------------------------------------------------------------------------------
-- Dragging
--
local dragFrame = CreateFrame("Frame")
do
local getCurrentAngle = function(parent, bx, by)
local mx, my = parent:GetCenter()
if not mx or not my or not bx or not by then return 0 end
local h, w = (by - my), (bx - mx)
if w == 0 then w = 0.001 end -- Prevent /0
local angle = atan(h / w)
if w < 0 then
angle = angle + 180
end
return angle
end
local setPosition = function(frame, angle)
local radius = (Minimap:GetWidth() / 2) + mod.db.radius
local bx, by = sm.shapes:GetPosition(angle, radius)
frame:ClearAllPoints()
frame:SetPoint("CENTER", Minimap, "CENTER", bx, by)
end
local updatePosition = function()
local x, y = GetCursorPosition()
x, y = x / Minimap:GetEffectiveScale(), y / Minimap:GetEffectiveScale()
local angle = getCurrentAngle(Minimap, x, y)
local name = namesCompatForDF[moving] or moving:GetName()
mod.db.dragPositions[name] = angle
setPosition(moving, angle)
end
local OnDragStart = function(frame)
if mod.db.lockDragging or not mod.db.allowDragging then return end
moving = frame
fadeStop = true
for i = 1, #animFrames do
local f = animFrames[i]
local n = namesCompatForDF[f] or f:GetName()
if not mod.db.visibilitySettings[n] or mod.db.visibilitySettings[n] == "hover" then
f.sexyMapFadeOut:Stop()
local anim = KillAnimation(n, f)
f:SetAlpha(1)
if anim then
OnFinished(anim)
end
end
end
dragFrame:SetScript("OnUpdate", updatePosition)
end
local OnDragStop = function()
dragFrame:SetScript("OnUpdate", nil)
moving = nil
fadeStop = false
ButtonFadeOut() -- Call the fade out function
end
function mod:MakeMovable(frame, altFrame)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
if altFrame then
frame:SetScript("OnDragStart", function()
if mod.db.lockDragging or not mod.db.allowDragging then return end
moving = altFrame
dragFrame:SetScript("OnUpdate", updatePosition)
end)
else
frame:SetScript("OnDragStart", OnDragStart)
end
frame:SetScript("OnDragStop", OnDragStop)
self:UpdateDraggables(altFrame or frame)
end
function mod:UpdateDraggables(frame)
if not mod.db.allowDragging then return end
if frame then
local x, y = frame:GetCenter()
local name = namesCompatForDF[frame] or frame:GetName()
local angle = mod.db.dragPositions[name] or getCurrentAngle(frame:GetParent(), x, y)
if angle then
setPosition(frame, angle)
end
else
for i = 1, #animFrames do
local f = animFrames[i]
local n = namesCompatForDF[f] or f:GetName()
-- Don't move the Clock or Zone Text when changing shape/preset
if n ~= "SexyMapZoneTextButton" and n ~= "TimeManagerClockButton" then
local x, y = f:GetCenter()
local angle = mod.db.dragPositions[n] or getCurrentAngle(f:GetParent(), x, y)
if angle then
setPosition(f, angle)
end
end
end
end
end
end
--------------------------------------------------------------------------------
-- Button grab
--
do
local tbl = {
Minimap, MiniMapTrackingButton, MiniMapTracking, TimeManagerClockButton, GameTimeFrame,
MinimapZoomIn, MinimapZoomOut, MiniMapWorldMapButton, GuildInstanceDifficulty, MiniMapChallengeMode, MiniMapInstanceDifficulty,
MiniMapMailFrame, QueueStatusMinimapButton, GarrisonLandingPageMinimapButton
}
local tblDF = {
Minimap, MinimapCluster.Tracking, MinimapCluster.Tracking.Button, TimeManagerClockButton, GameTimeFrame,
Minimap.ZoomIn, Minimap.ZoomOut, MinimapCluster.InstanceDifficulty,
MinimapCluster.MailFrame, ExpansionLandingPageMinimapButton
}
function mod:AddButton(_, button)
self:NewFrame(button)
end
local function CheckCalendar()
if not mod.db.controlVisibility then return end
local vis = mod.db.visibilitySettings.GameTimeFrame
if not vis or vis == "hover" then
if C_Calendar.GetNumPendingInvites() < 1 then
mod:ChangeFrameVisibility(GameTimeFrame, "hover")
else
mod:ChangeFrameVisibility(GameTimeFrame, "always")
end
end
end
function mod:StartFrameGrab()
if MiniMapMailFrame then
for i = 1, #tbl do
mod:NewFrame(tbl[i])
end
else
for i = 1, #tblDF do
mod:NewFrame(tblDF[i])
end
end
local ldbiTbl = ldbi:GetButtonList()
for i = 1, #ldbiTbl do
mod:NewFrame(ldbi:GetMinimapButton(ldbiTbl[i]))
end
ldbi.RegisterCallback(mod, "LibDBIcon_IconCreated", "AddButton")
-- If calendar is set to "hover" and we have pending invites, force show it
local frame = CreateFrame("Frame")
frame:SetScript("OnEvent", CheckCalendar)
frame:RegisterEvent("CALENDAR_UPDATE_PENDING_INVITES")
frame:RegisterEvent("CALENDAR_ACTION_PENDING")
CheckCalendar()
mod.StartFrameGrab = nil
end
end