-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathCore.lua
More file actions
1512 lines (1140 loc) · 48.1 KB
/
Core.lua
File metadata and controls
1512 lines (1140 loc) · 48.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local folderName, Addon = ...
---------------
-- LIBRARIES --
---------------
local LibCamera = LibStub("LibCamera-1.0")
local LibEasing = LibStub("LibEasing-1.0")
local LibHideUI = LibStub("LibHideUI-1.0")
local L = LibStub("AceLocale-3.0"):GetLocale("DynamicCam")
-------------
-- GLOBALS --
-------------
DynamicCam = LibStub("AceAddon-3.0"):NewAddon(folderName, "AceConsole-3.0", "AceEvent-3.0", "AceTimer-3.0")
-- Needed by CameraOverShoulderFix to know if a zoom easing is in progress.
DynamicCam.LibCamera = LibCamera
DynamicCam.currentSituationID = nil
-- For other Addons (like Narcissus) to temporarily disable
-- "Adjust Shoulder offset according to zoom level" without
-- having to change the user's permanent DynamicCam profile.
-- This flag is checked by CvarUpdateFunction to prevent it from
-- applying zoom-based shoulder offset adjustments.
DynamicCam.shoulderOffsetZoomTmpDisable = false
function DynamicCam:BlockShoulderOffsetZoom()
self.shoulderOffsetZoomTmpDisable = true
end
function DynamicCam:AllowShoulderOffsetZoom()
self.shoulderOffsetZoomTmpDisable = false
end
-- This flag indicates when shoulder offset is being eased (during situation transitions).
-- This info is needed by CameraOverShoulderFix, such that it does not interfere.
DynamicCam.easeShoulderOffsetInProgress = false
-- Stores the "desired" shoulder offset value (as configured by the user/situation).
-- The actual test_cameraOverShoulder CVar may differ from this value because
-- CameraOverShoulderFix multiplies it by currentModelFactor to compensate for player model.
-- So: GetCVar("test_cameraOverShoulder") = currentShoulderOffset * cosFix.currentModelFactor
--
-- This must be stored because:
-- 1) During easing animations, it's continuously updated by LibEasing
-- 2) Zoom functions need to know the current value during easing
-- 3) CameraOverShoulderFix needs to know the sign (positive/negative) when mounted
DynamicCam.currentShoulderOffset = 0
DynamicCam.conditionExecutionCache = {}
-- When the users sets ActionCam features that are prevented by Motion Sickness settings,
-- we temporarily disable these Motion Sicknes settings. But we restore them when no
-- affected ActionCam features are used any more.
DynamicCam.userCameraKeepCharacterCentered = DynamicCam.userCameraKeepCharacterCentered or GetCVar("CameraKeepCharacterCentered")
DynamicCam.userCameraReduceUnexpectedMovement = DynamicCam.userCameraReduceUnexpectedMovement or GetCVar("CameraReduceUnexpectedMovement")
-- When SetView() happens, the zoom level of the new view is
-- returned instantaneously by GetCameraZoom().
-- If "Adjust Shoulder offset according to zoom level" is activated,
-- this may lead to a shoulder offset skip. Thus we have to make
-- a virtual zoom ease for the duration of the view change on this variable (see SituationManager.lua):
DynamicCam.virtualCameraZoom = nil
-- To evaluate situations one frame after an event is triggered (see EventHandler()).
DynamicCam.evaluateSituationsNextFrame = false
-- We use this to suppress situation entering easing at login!
DynamicCam.enteredSituationAtLogin = false
------------
-- LOCALS --
------------
local function Round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
-- Forward declaration.
local UpdateCurrentShoulderOffset
-- Use this variable to get the duration of the last frame.
-- This is more accurate than the game framerate, which is the average over several recent frames.
-- (Needed in SituationManager.lua and MouseZoom.lua.)
DynamicCam.secondsPerFrame = 1.0 / GetFramerate()
-- Always evaluate to be on the safe side.
-- Because some situations (like taking off on a mount) cannot be associated with an event.
local alwaysEvaluateDelay = 1
local alwaysEvaluateTimer = alwaysEvaluateDelay
local function ConstantlyRunningFrameFunction(_, elapsed)
-- Also using this frame's OnUpdate to log secondsPerFrame.
DynamicCam.secondsPerFrame = elapsed
alwaysEvaluateTimer = alwaysEvaluateTimer - elapsed
-- Using this frame to evaluate situations one frame after an event
-- is triggered (see EventHandler()). This way we are never too early.
if DynamicCam.evaluateSituationsNextFrame or alwaysEvaluateTimer < 0 then
DynamicCam.evaluateSituationsNextFrame = false
alwaysEvaluateTimer = alwaysEvaluateDelay
DynamicCam:EvaluateSituations()
end
end
local constantlyRunningFrame = CreateFrame("Frame")
function DynamicCam:DC_SetCVar(cvar, setting)
-- Special handling for shoulder offset
if cvar == "test_cameraOverShoulder" then
UpdateCurrentShoulderOffset(setting)
-- If zoom-based curves are enabled, CvarUpdateFunction will handle application
if self:IsCvarZoomBased(self.currentSituationID, "test_cameraOverShoulder") then
return
end
-- If zooming or easing, don't apply now
if LibCamera:IsZooming() or DynamicCam.easeShoulderOffsetInProgress then
return
end
-- Apply with CameraOverShoulderFix compensation
setting = DynamicCam.ApplyCameraOverShoulderFixCompensation(DynamicCam.currentShoulderOffset)
end
-- Apply the cvar if it's not already set to the new value
if GetCVar(cvar) ~= tostring(setting) then
SetCVar(cvar, setting)
end
end
----------------------
-- SHOULDER OFFSET --
----------------------
-- Applies CameraOverShoulderFix compensation to a shoulder offset value.
-- Takes the "desired" value and returns what should actually be set in the CVar.
-- Returns: shoulderOffset * cosFix.currentModelFactor (or unchanged if cosFix not present)
-- Made global so ZoomBasedSettings.lua can use it too.
function DynamicCam.ApplyCameraOverShoulderFixCompensation(shoulderOffset)
local cosFix = _G.cosFix
if cosFix then
if not cosFix.currentModelFactor then
cosFix.currentModelFactor = cosFix:CorrectShoulderOffset()
end
return Round(shoulderOffset * cosFix.currentModelFactor, 10)
end
return shoulderOffset
end
-- Updates the stored "desired" shoulder offset value.
-- Handles CameraOverShoulderFix sign-change detection when mounted.
-- Note: This updates currentShoulderOffset (desired value), NOT the CVar directly.
-- The CVar is set separately using ApplyCameraOverShoulderFixCompensation().
function DynamicCam.UpdateCurrentShoulderOffset(offset)
-- If offset changes sign while mounted, CameraOverShoulderFix needs to update currentModelFactor!
local cosFix = _G.cosFix
if cosFix and IsMounted() then
if (DynamicCam.currentShoulderOffset < 0 and offset >= 0)
or (DynamicCam.currentShoulderOffset >= 0 and offset < 0) then
cosFix.currentModelFactor = cosFix:CorrectShoulderOffset()
end
end
DynamicCam.currentShoulderOffset = offset
end
-- Local alias for backward compatibility within this file
UpdateCurrentShoulderOffset = DynamicCam.UpdateCurrentShoulderOffset
-------------
-- FADE UI --
-------------
-- We Show() this frame, whenever we are hiding the UI.
-- Inserting it into UISpecialFrames leads to the frame being hidden when
-- the user presses ESCAPE. So we can use the frame's OnHide script to
-- bring the UI back.
local fadeUIEscapeHandlerFrame = CreateFrame("Frame", "DynamicCamfadeUIEscapeHandlerFrame")
tinsert(UISpecialFrames, fadeUIEscapeHandlerFrame:GetName())
fadeUIEscapeHandlerFrame:SetScript("OnHide", function(self)
-- print("Hiding FadeUIEscapeHandler")
if not DynamicCam.db.profile.situations[DynamicCam.currentSituationID].hideUI.emergencyShowEscEnabled then return end
-- We do not even have to Show() UIParent here, because whenever
-- UIParent is hidden the first press of ESCAPE will bring
-- UIParent back. Only a second ESCAPE press would then hide
-- all shown UISpecialFrames. That's why we are always hiding
-- fadeUIEscapeHandlerFrame after UIParent's OnHide handler.
-- (see below).
-- Use this as default.
local fadeInTime = 0.5
-- Check if we are currently in a situation with fadeInTime.
local curSituation = DynamicCam.db.profile.situations[DynamicCam.currentSituationID]
if curSituation and curSituation.hideUI.enabled then
fadeInTime = curSituation.transitionTime.timeToExit
end
DynamicCam:FadeInUI(fadeInTime)
end)
-- For debugging.
-- fadeUIEscapeHandlerFrame:SetScript("OnShow", function() print("Showing FadeUIEscapeHandler") end)
-- Whenever UIParent is hidden, the first ESCAPE press brings UIParent back.
-- A second ESCAPE press would be needed to hide UISpecialFrames.
-- So we already hide fadeUIEscapeHandlerFrame with the first ESCAPE press.
UIParent:HookScript("OnShow", function()
if fadeUIEscapeHandlerFrame:IsShown() then
fadeUIEscapeHandlerFrame:Hide()
end
end)
-- To hide fadeUIEscapeHandlerFrame without triggering its OnHide script.
local function UIEscapeHandlerDisable()
if fadeUIEscapeHandlerFrame:IsShown() then
local onHide = fadeUIEscapeHandlerFrame:GetScript("OnHide")
fadeUIEscapeHandlerFrame:SetScript("OnHide", nil)
fadeUIEscapeHandlerFrame:Hide()
fadeUIEscapeHandlerFrame:SetScript("OnHide", onHide)
end
end
-- When the UI is loaded fadeUIEscapeHandlerFrame is shown, so we hide it.
UIEscapeHandlerDisable()
-- To prevent unintended showing of UIParent, we set this flag whenever we have hidden it.
local uiParentHidden = false
local enterCombatFrame = CreateFrame("Frame")
enterCombatFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
enterCombatFrame:SetScript("OnEvent", function()
-- print("enterCombatFrame")
-- If entering combat while UIParent is hidden,
-- we have to show it here again, because it is not allowed during combat.
-- To avoid that the UI is also faded in again, we have to
-- temporarily disable our UIEscapeHandler while showing UIParent.
if not UIParent:IsShown() then
local fadeUIEscapeHandlerShown = fadeUIEscapeHandlerFrame:IsShown()
if fadeUIEscapeHandlerShown then UIEscapeHandlerDisable() end
uiParentHidden = false
UIParent:Show()
if fadeUIEscapeHandlerShown then fadeUIEscapeHandlerFrame:Show() end
end
-- If entering combat while frames are faded to 0 *and hidden*,
-- we have to show the hidden frames again, because Show() is
-- not allowed for protected frames during combat.
if ludius_UiHideModule.uiHiddenTime ~= 0 then
Addon.ShowUI(0, true)
end
end)
-- If the user leaves combat while still in a situation with hidden UI,
-- we hide it again everything again.
local leaveCombatFrame = CreateFrame("Frame")
leaveCombatFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
leaveCombatFrame:SetScript("OnEvent", function()
-- print("leaveCombatFrame")
-- But not, if the user has pressed ESC in between.
if fadeUIEscapeHandlerFrame:IsShown() then
-- Check if we are currently in a situation with hideUI settings.
local curSituation = DynamicCam.db.profile.situations[DynamicCam.currentSituationID]
if curSituation and curSituation.hideUI.enabled then
DynamicCam:FadeOutUI(0, curSituation.hideUI)
end
end
end)
-- To prevent UIParent from being shown when a situation change coincides with a cinematic start.
-- CINEMATIC_START and CINEMATIC_STOP are just for in-game cinematics.
-- For pre-rendered cinematics, there is unfortunately no stop event.
-- CinematicFrame:IsShown() also does not work for pre-rendered cinematics.
-- So we go with just taking the elapsed time since the last PLAY_MOVIE.
local ingameCinematicRunning = false
local lastPlayMovie = GetTime()
local cinematicTrackingFrame = CreateFrame("Frame")
cinematicTrackingFrame:RegisterEvent("CINEMATIC_START")
cinematicTrackingFrame:RegisterEvent("CINEMATIC_STOP")
cinematicTrackingFrame:RegisterEvent("PLAY_MOVIE")
cinematicTrackingFrame:SetScript("OnEvent", function(_, event)
if event == "CINEMATIC_START" then
ingameCinematicRunning = true
elseif event == "CINEMATIC_STOP" then
ingameCinematicRunning = false
else
lastPlayMovie = GetTime()
end
end)
-- To prevent other addons (Immersion, I'm looking in your direction) from
-- fading-in UIParent while DynamicCam has hidden it.
hooksecurefunc(UIParent, "SetAlpha", function(self, alpha)
-- print("UIParent SetAlpha", alpha, UIParent.ludius_intendedUIParentAlpha)
if UIParent.ludius_intendedUIParentAlpha ~= nil and UIParent.ludius_intendedUIParentAlpha ~= alpha then
-- print("no")
UIParent:SetAlpha(UIParent.ludius_intendedUIParentAlpha)
-- else
-- print("ok")
end
end)
-- WoW's UIFrameFade(), UIFrameFadeOut() and UIFrameFadeIn() cause errors in combat lockdown when used with UIParent.
-- Hence, we need our own function.
local easeUIParentAlphaHandle
local function EaseUIParentAlpha(endValue, duration, callback)
if easeUIParentAlphaHandle then
LibEasing:StopEasing(easeUIParentAlphaHandle)
easeUIParentAlphaHandle = nil
end
if UIParent:GetAlpha() ~= endValue then
easeUIParentAlphaHandle = LibEasing:Ease(
function(alpha)
if alpha == 1 then
UIParent.ludius_intendedUIParentAlpha = nil
else
UIParent.ludius_intendedUIParentAlpha = alpha
end
UIParent:SetAlpha(alpha)
end,
UIParent:GetAlpha(),
endValue,
duration,
LibEasing.Linear,
callback
)
else
if callback then callback() end
end
end
function DynamicCam:FadeOutUI(fadeOutTime, settings)
-- print("FadeOutUI", fadeOutTime, GetTime())
-- If we are starting to fade-out while a fade-in was still in progress,
-- we are not updating ludius_alphaBeforeFadeOut.
-- Because ludius_alphaBeforeFadeOut is only set to nil after a fade-in is complete.
if UIParent.ludius_alphaBeforeFadeOut == nil then
-- If fading of another source (e.g. Immersion) is in progress.
if fadeOutTime > 0 and UIParent.fadeInfo and UIParent.fadeInfo.fadeTimer ~= nil and UIParent.fadeInfo.timeToFade ~= nil and tonumber(UIParent.fadeInfo.fadeTimer) < tonumber(UIParent.fadeInfo.timeToFade) then
-- When fading out we take the maximum alpha of the other fade as our alpha before fade out.
UIParent.ludius_alphaBeforeFadeOut = math.max(UIParent.fadeInfo.startAlpha, UIParent.fadeInfo.endAlpha)
-- Stop the other fade progress.
-- (We do not want to use the UIFrameFade(), UIFrameFadeOut() and UIFrameFadeIn()
-- which we have seen to cause errors in combat lockdown when used with UIParent.)
UIParent.fadeInfo.startAlpha = UIParent:GetAlpha()
UIParent.fadeInfo.endAlpha = UIParent:GetAlpha()
UIParent.fadeInfo.timeToFade = -1
else
UIParent.ludius_alphaBeforeFadeOut = UIParent:GetAlpha()
end
-- print("Remembering", UIParent.ludius_alphaBeforeFadeOut)
end
EaseUIParentAlpha(settings.hideEntireUI and 0 or settings.fadeOpacity, fadeOutTime)
if settings.hideEntireUI then
-- The frame rate indicator is the only frame that is independent of UIParent.
-- So we can keep or hide it even when UIParent is hidden.
Addon.HideUI(fadeOutTime, {hideFrameRate = not settings.keepFrameRate, UIParentAlpha = 0})
if self.hideEntireUITimer then LibStub("AceTimer-3.0"):CancelTimer(self.hideEntireUITimer) end
self.hideEntireUITimer = LibStub("AceTimer-3.0"):ScheduleTimer(
function()
if not InCombatLockdown() then
UIParent:Hide()
uiParentHidden = true
end
end,
fadeOutTime
)
else
local config = {
UIParentAlpha = settings.fadeOpacity,
hideFrameRate = not settings.keepFrameRate,
keepAlertFrames = settings.keepAlertFrames,
keepTooltip = settings.keepTooltip,
keepMinimap = settings.keepMinimap,
keepChatFrame = settings.keepChatFrame,
keepPartyRaidFrame = settings.keepPartyRaidFrame,
keepTrackingBar = settings.keepTrackingBar,
-- This only has an effect when keepTrackingBar is true.
-- (For now we are not allowing DynamicCam users to partially fade out single frames.
-- That's just for "Immersion ExtraFade".)
trackingBarAlpha = 1,
keepEncounterBar = settings.keepEncounterBar,
keepCustomFrames = settings.keepCustomFrames,
customFramesToKeep = settings.customFramesToKeep,
}
-- Use the UiHideModule to keep configured frames and properly hide the others.
Addon.HideUI(fadeOutTime, config)
end
if settings.emergencyShowEscEnabled then
fadeUIEscapeHandlerFrame:Show()
end
end
function DynamicCam:FadeInUI(fadeInTime)
-- print("FadeInUI", fadeInTime, GetTime())
if self.hideEntireUITimer then LibStub("AceTimer-3.0"):CancelTimer(self.hideEntireUITimer) end
-- Actually allow the last PLAY_MOVIE to be at most 2 seconds ago. You never know...
if not UIParent:IsShown() and uiParentHidden and not ingameCinematicRunning and lastPlayMovie + 2 < GetTime() then
uiParentHidden = false
UIParent:Show()
end
-- If fading of another source (e.g. Immersion) is in progress, stop it.
if fadeInTime > 0 and UIParent.fadeInfo and UIParent.fadeInfo.fadeTimer ~= nil and UIParent.fadeInfo.timeToFade ~= nil and tonumber(UIParent.fadeInfo.fadeTimer) < tonumber(UIParent.fadeInfo.timeToFade) then
UIParent.fadeInfo.startAlpha = UIParent:GetAlpha()
UIParent.fadeInfo.endAlpha = UIParent:GetAlpha()
UIParent.fadeInfo.timeToFade = -1
end
if UIParent.ludius_alphaBeforeFadeOut then
UIEscapeHandlerDisable()
local function FadeInCallback()
-- print("Fade in finished")
UIParent.ludius_alphaBeforeFadeOut = nil
UIParent.ludius_intendedUIParentAlpha = nil
end
-- print("UIParent.ludius_alphaBeforeFadeOut", UIParent.ludius_alphaBeforeFadeOut)
EaseUIParentAlpha(UIParent.ludius_alphaBeforeFadeOut, fadeInTime, FadeInCallback)
Addon.ShowUI(fadeInTime, false)
end
end
----------
-- CORE --
----------
local started = false
function DynamicCam:OnInitialize()
-- setup db
self:InitDatabase()
self:RefreshConfig()
-- setup chat commands
self:RegisterChatCommand("dynamiccam", "OpenMenu")
self:RegisterChatCommand("dc", "OpenMenu")
self:RegisterChatCommand("saveview", "SaveViewSlash")
self:RegisterChatCommand("sv", "SaveViewSlash")
self:RegisterChatCommand("setView", "SetViewSlash")
self:RegisterChatCommand("zoominfo", "ZoomInfoSlash")
self:RegisterChatCommand("zi", "ZoomInfoSlash")
self:RegisterChatCommand("zoom", "ZoomSlash")
self:RegisterChatCommand("pitch", "PitchSlash")
self:RegisterChatCommand("yaw", "YawSlash")
self:RegisterChatCommand("hideUI", "HideUISlash")
self:RegisterChatCommand("showUI", "ShowUISlash")
-- Disable the ActionCam warning message.
UIParent:UnregisterEvent("EXPERIMENTAL_CVAR_CONFIRMATION_NEEDED")
end
function DynamicCam:OnEnable()
self:Startup()
end
function DynamicCam:OnDisable()
self:Shutdown()
end
function DynamicCam:Startup()
-- If there is a bug in the options, don't start.
if not DynamicCam.GetSettingsValue then
return self:Shutdown()
end
if started then return end
self.enteredSituationAtLogin = false
-- initial evaluate needs to be delayed because the camera doesn't like changing cvars on startup
self:ScheduleTimer("ApplySettings", 0.1)
self:ScheduleTimer("EvaluateSituations", 0.2)
self:ScheduleTimer("RegisterEvents", 0.3)
-- turn on reactive zoom if it's enabled
if self:GetSettingsValue(self.currentSituationID, "reactiveZoomEnabled") then
self:ReactiveZoomOn()
else
-- Must call this to prehook NonReactiveZoomIn/Out.
self:ReactiveZoomOff()
end
if tonumber(GetCVar("CameraKeepCharacterCentered")) == 1 then
if tonumber(GetCVar("test_cameraOverShoulder")) ~= 0 then
print("|cFFFF0000" .. L["While you are using horizontal camera offset, DynamicCam prevents CameraKeepCharacterCentered!"] .. "|r")
SetCVar("CameraKeepCharacterCentered", false, "DynamicCam")
elseif tonumber(GetCVar("test_cameraDynamicPitch")) == 1 then
print("|cFFFF0000" .. L["While you are using vertical camera pitch, DynamicCam prevents CameraKeepCharacterCentered!"] .. "|r")
SetCVar("CameraKeepCharacterCentered", false, "DynamicCam")
end
end
-- As off 11.0.2 this is also needed for shoulder offset to take effect.
if tonumber(GetCVar("CameraReduceUnexpectedMovement")) == 1 then
if tonumber(GetCVar("test_cameraOverShoulder")) ~= 0 then
print("|cFFFF0000" .. L["While you are using horizontal camera offset, DynamicCam prevents CameraReduceUnexpectedMovement!"] .. "|r")
SetCVar("CameraReduceUnexpectedMovement", false, "DynamicCam")
end
end
-- https://github.com/Mpstark/DynamicCam/issues/40
local validValuesCameraView = {[1] = true, [2] = true, [3] = true, [4] = true, [5] = true,}
if not validValuesCameraView[tonumber(GetCVar("cameraView"))] then
-- print("cameraView =", GetCVar("cameraView"), "prevented by DynamicCam!")
SetCVar("cameraView", GetCVarDefault("cameraView"))
end
self:SettingsPanelSetIgnoreParentAlpha(DynamicCam.db.profile.settingsPanelIgnoreParentAlpha)
hooksecurefunc(
LibStub("AceGUI-3.0"),
"Create",
function(_, widgetType)
if widgetType == "Dropdown-Pullout" then
DynamicCam:SettingsPanelSetIgnoreParentAlpha(DynamicCam.db.profile.settingsPanelIgnoreParentAlpha)
end
end
)
-- A frame to determine the current player model.
if DynamicCam.db.profile.reactiveZoomEnhancedMinZoom then
DynamicCam.modelFrame = CreateFrame("PlayerModel")
end
constantlyRunningFrame:SetScript("OnUpdate", ConstantlyRunningFrameFunction)
started = true
-- -- For coding
-- C_Timer.After(0, function()
-- self:OpenMenu()
-- LibStub("AceConfigDialog-3.0"):SelectGroup("DynamicCam", "standardSettingsTab")
-- -- LibStub("AceConfigDialog-3.0"):SelectGroup("DynamicCam", "situationSettingsTab", "situationSettings")
-- -- LibStub("AceConfigDialog-3.0"):SelectGroup("DynamicCam", "situationSettingsTab", "export")
-- end)
-- C_Timer.After(3, function()
-- if BugSack then
-- BugSack:OpenSack()
-- BugSackFrame:SetIgnoreParentAlpha(true)
-- BugSackFrame:Hide()
-- end
-- end)
end
function DynamicCam:Shutdown()
if not started then return end
-- exit the current situation if in one
if self.currentSituationID then
self:ChangeSituation(self.currentSituationID, nil)
end
self.events = {}
self:UnregisterAllEvents()
self:UnregisterAllMessages()
self:ApplySettings()
self:ReactiveZoomOff()
constantlyRunningFrame:SetScript("OnUpdate", nil)
started = false
end
-- function DynamicCam:DebugPrint(...)
-- if self.db.profile.debugMode then
-- self:Print(...)
-- end
-- end
-------------
-- UTILITY --
-------------
function DynamicCam:ApplySettings()
local curSituation = self.db.profile.situations[self.currentSituationID]
-- Set the cvars (standard or situation).
for cvar, value in pairs(self.db.profile.standardSettings.cvars) do
if curSituation and curSituation.situationSettings.cvars[cvar] then
value = curSituation.situationSettings.cvars[cvar]
end
-- Skip cvars that are zoom-based, currently being eased, or controlled
-- by a toggle group transition - CvarUpdateFunction handles them.
if not (self:IsCvarZoomBased(self.currentSituationID, cvar) or self:IsCvarBeingEased(cvar) or self:IsCvarToggleControlled(cvar)) then
self:DC_SetCVar(cvar, value)
end
end
-- Set reactive zoom.
if self:GetSettingsValue(self.currentSituationID, "reactiveZoomEnabled") then
self:ReactiveZoomOn()
else
self:ReactiveZoomOff()
end
if not LibCamera:IsZooming() then
-- This is necessary to see effects of changing the maximum camera distance, without having to manually zoom.
self:ZoomSlash(GetCameraZoom() .. " " .. 0)
end
-- print("Finished ApplySettings", newSituationID, GetTime())
end
--------------
-- DATABASE --
--------------
function DynamicCam:InitDatabase()
self.db = LibStub("AceDB-3.0"):New("DynamicCamDB", self.defaults, true)
self.db.RegisterCallback(self, "OnProfileChanged", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileCopied", "RefreshConfig")
self.db.RegisterCallback(self, "OnProfileReset", "RefreshConfig")
self.db.RegisterCallback(self, "OnDatabaseShutdown", "Shutdown")
if DynamicCamDB.profiles then
-- reset db if we've got a really old version
for profileName, profile in pairs(DynamicCamDB.profiles) do
if profile.defaultCvars and profile.defaultCvars["cameraovershoulder"] then
self:Print("Detected very old profile versions, resetting DB, sorry about that!")
self.db:ResetDB()
end
end
local profilesModernized = false
-- modernize each profile
for profileName, profile in pairs(DynamicCamDB.profiles) do
local modernized = self:ModernizeProfile(profile)
profilesModernized = profilesModernized or modernized
end
-- Setting the profile cleans up the storage.
-- I.e. defaults are not explicitly stored.
if profilesModernized then
local currentProfile = self.db:GetCurrentProfile()
for profileName, profile in pairs(DynamicCamDB.profiles) do
self.db:SetProfile(profileName)
end
self.db:SetProfile(currentProfile)
end
end
end
-- This function checks if a value exists in the values table.
-- We have to make the check like this, because values[key] may be false or 0, which are valid values and should not be overridden by the default.
local function ValueOrDefault(values, defaults, key)
if values and values[key] ~= nil then
return values[key]
else
return defaults[key]
end
end
-- 1 : some early DC version
-- 2 : DC pre-2.0
-- 3 : DC post-2.0
-- 4 : New mounted situation IDs.
-- 5 : Migrated shoulderOffsetZoom to cvarsZoomBased (stored in standardSettings/situationSettings).
-- Generalized transition times (migrate from zoom/rotation/UI fade times to transitionTime.timeToEnter/Exit).
function DynamicCam:ModernizeProfile(p)
-- If there is no version number, it is most probably a newly created one!
if not p.version then
p.version = 5
return false
end
if p.version == 1 then
if p.defaultCvars and p.defaultCvars["test_cameraLockedTargetFocusing"] ~= nil then
p.defaultCvars["test_cameraLockedTargetFocusing"] = nil
end
-- modernize each situation
if p.situations then
for k, v in pairs(p.situations) do
self:ModernizeSituation(v, k, p.version)
end
end
p.version = 2
end
-- Upgrade to DynamicCam 2.0
if p.version == 2 then
-- Not changing:
-- p.zoomRestoreSetting
-- These existed before. But as the user is currently not supposed to change the values, we do not set them (i.e. they assume the default).
-- p.standardSettings.easingZoom
-- p.standardSettings.easingYaw
-- p.standardSettings.easingPitch
-- p.standardSettings.reactiveZoomEasingFunc
-- Newly introduced setting also assumes default.
-- p.settingsPanelIgnoreParentAlpha
p.standardSettings = {cvars = {},}
p.standardSettings.reactiveZoomEnabled = ValueOrDefault(p.reactiveZoom, DynamicCam.v2Defaults.reactiveZoom, "enabled")
p.standardSettings.reactiveZoomAddIncrementsAlways = ValueOrDefault(p.reactiveZoom, DynamicCam.v2Defaults.reactiveZoom, "addIncrementsAlways")
p.standardSettings.reactiveZoomAddIncrements = ValueOrDefault(p.reactiveZoom, DynamicCam.v2Defaults.reactiveZoom, "addIncrements")
p.standardSettings.reactiveZoomIncAddDifference = ValueOrDefault(p.reactiveZoom, DynamicCam.v2Defaults.reactiveZoom, "incAddDifference")
p.standardSettings.reactiveZoomMaxZoomTime = ValueOrDefault(p.reactiveZoom, DynamicCam.v2Defaults.reactiveZoom, "maxZoomTime")
p.standardSettings.shoulderOffsetZoomEnabled = ValueOrDefault(p.shoulderOffsetZoom, DynamicCam.v2Defaults.shoulderOffsetZoom, "enabled")
p.standardSettings.shoulderOffsetZoomLowerBound = ValueOrDefault(p.shoulderOffsetZoom, DynamicCam.v2Defaults.shoulderOffsetZoom, "lowerBound")
p.standardSettings.shoulderOffsetZoomUpperBound = ValueOrDefault(p.shoulderOffsetZoom, DynamicCam.v2Defaults.shoulderOffsetZoom, "upperBound")
for cvarName, _ in pairs(p.defaultCvars) do
p.standardSettings.cvars[cvarName] = ValueOrDefault(p.defaultCvars, DynamicCam.v2Defaults.defaultCvars, cvarName)
end
-- If we did not import anything...
if next(p.standardSettings.cvars) == nil then p.standardSettings.cvars = nil end
if next(p.standardSettings) == nil then p.standardSettings = nil end
-- Deep compare of two tables in Lua is not trivial.
-- So we just delete all old settings manually here.
p.enabled = nil
p.advanced = nil
p.debugMode = nil
p.actionCam = nil
p.easingZoom = nil
p.easingYaw = nil
p.easingPitch = nil
p.reactiveZoom = nil
p.shoulderOffsetZoom = nil
p.defaultCvars = nil
-- modernize each situation
if p.situations then
for k, v in pairs(p.situations) do
self:ModernizeSituation(v, k, p.version)
-- It may happen that a situation becomes empty
-- because old values are the same as new defaults.
-- (Particularly "enabled")
if next(v) == nil then p.situations[k] = nil end
end
end
p.version = 3
end
-- Rearrange situation IDs.
if p.version == 3 then
if p.situations then
local function SwapSituationIDs(src, dst, situations)
if situations[src] then
assert(not situations[dst])
situations[dst] = situations[src]
situations[src] = nil
end
end
SwapSituationIDs("102", "170", p.situations) -- Vehicle
SwapSituationIDs("101", "160", p.situations) -- Taxi
SwapSituationIDs("103", "115", p.situations) -- Druid Travel Form
SwapSituationIDs("100.5", "105", p.situations) -- mounted (only airborne)
SwapSituationIDs("126", "106", p.situations) -- mounted (only airborne + Skyriding)
SwapSituationIDs("125", "107", p.situations) -- mounted (only Skyriding)
end
p.version = 4
end
-- Migrate legacy shoulderOffsetZoom to new zoom-based settings system.
if p.version == 4 then
local maxZoom = self.cameraDistanceMaxZoomFactor_max or 39
-- Get effective profile-wide values (stored values or defaults)
-- These were global settings that applied to ALL shoulder offsets (standard + all situations)
local enabled = ValueOrDefault(p.standardSettings, DynamicCam.v4ShoulderOffsetZoomDefaults, "shoulderOffsetZoomEnabled")
local lowerBound = ValueOrDefault(p.standardSettings, DynamicCam.v4ShoulderOffsetZoomDefaults, "shoulderOffsetZoomLowerBound")
local upperBound = ValueOrDefault(p.standardSettings, DynamicCam.v4ShoulderOffsetZoomDefaults, "shoulderOffsetZoomUpperBound")
-- Helper function to create zoom-based curve for a settings table
local function CreateZoomBasedCurve(settings, shoulderOffset)
if shoulderOffset ~= 0 then
-- Initialize cvarsZoomBased if needed
if not settings.cvarsZoomBased then
settings.cvarsZoomBased = {}
end
-- Create the zoom-based setting with migrated points:
-- (0, 0) -> (lowerBound, 0) -> (upperBound, fullValue) -> (maxZoom, fullValue)
settings.cvarsZoomBased["test_cameraOverShoulder"] = {
enabled = true,
points = {
{zoom = 0, value = 0},
{zoom = lowerBound, value = 0},
{zoom = upperBound, value = shoulderOffset},
{zoom = maxZoom, value = shoulderOffset},
}
}
end
end
-- Migrate standard settings if shoulder offset exists there
if enabled and p.standardSettings then
local shoulderOffset = p.standardSettings.cvars and p.standardSettings.cvars.test_cameraOverShoulder or 0
if shoulderOffset ~= 0 then
CreateZoomBasedCurve(p.standardSettings, shoulderOffset)
end
end
-- Migrate each situation's settings if shoulder offset exists there
if enabled and p.situations then
for situationID, situation in pairs(p.situations) do
if situation.situationSettings and situation.situationSettings.cvars then
local shoulderOffset = situation.situationSettings.cvars.test_cameraOverShoulder
if shoulderOffset and shoulderOffset ~= 0 then
CreateZoomBasedCurve(situation.situationSettings, shoulderOffset)
end
end
end
end
-- Always remove the old profile-wide settings (they will be ignored anyway, but clean up)
if p.standardSettings then
p.standardSettings.shoulderOffsetZoomEnabled = nil
p.standardSettings.shoulderOffsetZoomLowerBound = nil
p.standardSettings.shoulderOffsetZoomUpperBound = nil
end
-- Modernize each situation (transition time migration)
if p.situations then
for k, v in pairs(p.situations) do
self:ModernizeSituation(v, k, p.version)
end
end
p.version = 5
return true
end
return false
end
function DynamicCam:ModernizeSituation(s, situationID, version)
if version == 1 then
-- clear unused nameplates db stuff
if s.extras then
s.extras["nameplates"] = nil
s.extras["friendlyNameplates"] = nil
s.extras["enemyNameplates"] = nil
end
-- update targetlock features
if s.targetLock then
if s.targetLock.enabled then
if not s.cameraCVars then