-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathZoomBasedEditor.lua
More file actions
1673 lines (1400 loc) · 57.7 KB
/
ZoomBasedEditor.lua
File metadata and controls
1673 lines (1400 loc) · 57.7 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 = ...
local L = LibStub("AceLocale-3.0"):GetLocale("DynamicCam")
local GetCameraZoom = _G.GetCameraZoom
-------------------------------------------------------------------------------
-- ZOOM-BASED CURVE EDITOR (ButtonFrameTemplate)
--
-- Complete curve editor for zoom-based settings, built on ButtonFrameTemplate.
-- Users define control points on a graph where:
-- Y-axis = Camera zoom level (0 at top, max zoom at bottom)
-- X-axis = Setting value (min to max of the setting)
-- The system interpolates between points to get the value at any zoom level.
-------------------------------------------------------------------------------
------------
-- LOCALS --
------------
-- Colors (addon-wide, also used by the mini preview in Widgets.lua)
DynamicCam.GRAPH_COLORS = {
curveLine = {0.8, 0.0, 0.0, 1.0},
pointNormal = {0.8, 0.0, 0.0, 1.0},
pointHighlight = {1.0, 1.0, 1.0, 1.0},
gridLabel = {0.7, 0.7, 0.7},
gridMajor = {0.4, 0.4, 0.5, 0.6},
gridMinor = {0.3, 0.3, 0.4, 0.3},
gridBackground = {0.0, 0.0, 0.25, 1},
}
local COLORS = DynamicCam.GRAPH_COLORS
-- Point display
local POINT_RADIUS = 8
-- Zoom constraints
local MIN_ZOOM_SPACING = 0.1
local EDGE_LABEL_THRESHOLD = 0.5
local VALUE_EDGE_THRESHOLD_PCT = 0.08
local ZOOM_INDICATOR_FRAME_LEVEL_OFFSET = 100
-- Frame dimensions
local EDITOR_WIDTH = 300
local EDITOR_HEIGHT = 450
-- Graph layout (padding inside the Inset)
local GRAPH_PADDING_TOP = 15
local GRAPH_PADDING_BOTTOM = 40
local GRAPH_PADDING_LEFT = 45
local GRAPH_PADDING_RIGHT = 15
-- Label spacing
local Y_AXIS_LABEL_OFFSET = -7
local X_AXIS_LABEL_OFFSET = -7
-- Snap threshold
local SNAP_THRESHOLD_DIVISOR = 100
---------------------
-- UTILITY FUNCTIONS
---------------------
local function Round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
local function CalculateNiceGridStep(minValue, maxValue, targetDivisions)
local range = maxValue - minValue
if range <= 0 then return 1, 0.5 end
local roughStep = range / targetDivisions
local magnitude = 10 ^ math.floor(math.log10(roughStep))
local normalized = roughStep / magnitude
local niceStep
if normalized <= 1.5 then
niceStep = 1
elseif normalized <= 3 then
niceStep = 2
elseif normalized <= 7 then
niceStep = 5
else
niceStep = 10
end
local majorStep = niceStep * magnitude
local minorStep
if niceStep == 1 or niceStep == 5 then
minorStep = majorStep / 5
else
minorStep = majorStep / 4
end
return majorStep, minorStep
end
local function GenerateGridPositions(minValue, maxValue, step)
local positions = {}
local start = math.ceil(minValue / step) * step
for pos = start, maxValue, step do
pos = Round(pos, 6)
if pos >= minValue and pos <= maxValue then
table.insert(positions, pos)
end
end
return positions
end
local function FindClosestValidZoom(desiredZoom, otherZooms, maxZoom)
local minValid = MIN_ZOOM_SPACING
local maxValid = maxZoom - MIN_ZOOM_SPACING
desiredZoom = math.max(minValid, math.min(maxValid, desiredZoom))
local function isValid(z)
if z < minValid - 0.001 or z > maxValid + 0.001 then return false end
for _, other in ipairs(otherZooms) do
if math.abs(z - other) < MIN_ZOOM_SPACING - 0.001 then return false end
end
return true
end
if isValid(desiredZoom) then
return desiredZoom
end
local candidates = {minValid, maxValid}
for _, z in ipairs(otherZooms) do
table.insert(candidates, z - MIN_ZOOM_SPACING)
table.insert(candidates, z + MIN_ZOOM_SPACING)
end
local best = nil
local bestDist = 999
for _, candidate in ipairs(candidates) do
if isValid(candidate) then
local dist = math.abs(candidate - desiredZoom)
if dist < bestDist then
bestDist = dist
best = candidate
end
end
end
return best or desiredZoom
end
local function SnapToGrid(value, minValue, maxValue, majorStep)
local range = maxValue - minValue
local snapThreshold = range / SNAP_THRESHOLD_DIVISOR
local gridPositions = GenerateGridPositions(minValue, maxValue, majorStep)
table.insert(gridPositions, minValue)
table.insert(gridPositions, maxValue)
for _, gridValue in ipairs(gridPositions) do
if math.abs(value - gridValue) <= snapThreshold then
return gridValue
end
end
return value
end
-------------------------------------------------------------------------------
-- MULTI-EDITOR STATE MANAGEMENT
-------------------------------------------------------------------------------
local curveEditorFramePool = {}
local openEditors = {}
local editorStrataCounter = 0
-- Shared clipboard: stores normalized points (values in 0-1 range) so curves
-- can be pasted across settings with different value ranges.
local clipboard = nil
local function GetConfigId(situationId, cvarName)
return (situationId or "standard") .. "_" .. cvarName
end
-------------------------------------------------------------------------------
-- POOL FUNCTIONS
-------------------------------------------------------------------------------
-- Point pool
local function CreatePointFrame(parent, editorFrame)
local point = CreateFrame("Button", nil, parent)
point:SetSize(POINT_RADIUS * 2, POINT_RADIUS * 2)
point:EnableMouse(true)
point:RegisterForClicks("LeftButtonUp", "RightButtonUp")
point.editorFrame = editorFrame
point.texture = point:CreateTexture(nil, "OVERLAY")
point.texture:SetAllPoints()
point.texture:SetTexture("Interface\\COMMON\\Indicator-Red")
point.texture:SetVertexColor(unpack(COLORS.pointNormal))
return point
end
local function GetPointFromPool(editorFrame, parent)
for _, point in ipairs(editorFrame.pointFramePool) do
if not point:IsShown() then
point:SetParent(parent)
point.isDragging = false
point.editorFrame = editorFrame
point:Show()
return point
end
end
local newPoint = CreatePointFrame(parent, editorFrame)
newPoint.isDragging = false
table.insert(editorFrame.pointFramePool, newPoint)
return newPoint
end
local function ReleaseAllPoints(editorFrame)
for _, point in ipairs(editorFrame.activePointFrames) do
point:Hide()
end
editorFrame.activePointFrames = {}
end
-- Grid line pool
local function GetGridLineFromPool(editorFrame, parent)
for _, line in ipairs(editorFrame.gridLinePool) do
if not line:IsShown() then
line:Show()
return line
end
end
-- ARTWORK layer so curve lines on OVERLAY always render on top
local newLine = parent:CreateLine(nil, "ARTWORK")
table.insert(editorFrame.gridLinePool, newLine)
return newLine
end
local function ReleaseAllGridLines(editorFrame)
for _, line in ipairs(editorFrame.activeGridLines) do
line:Hide()
end
editorFrame.activeGridLines = {}
end
-- Grid label pool
local function GetGridLabelFromPool(editorFrame)
for _, label in ipairs(editorFrame.gridLabelPool) do
if not label:IsShown() then
label:Show()
return label
end
end
local newLabel = editorFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
table.insert(editorFrame.gridLabelPool, newLabel)
return newLabel
end
local function ReleaseAllGridLabels(editorFrame)
for _, label in ipairs(editorFrame.activeGridLabelsZoom) do
label:Hide()
end
for _, label in ipairs(editorFrame.activeGridLabelsValue) do
label:Hide()
end
editorFrame.activeGridLabelsZoom = {}
editorFrame.activeGridLabelsValue = {}
end
-- Curve line pool
local function GetCurveLineFromPool(editorFrame, parent)
for _, line in ipairs(editorFrame.curveLinePool) do
if not line:IsShown() then
line:Show()
return line
end
end
local newLine = parent:CreateLine(nil, "OVERLAY")
table.insert(editorFrame.curveLinePool, newLine)
return newLine
end
local function ReleaseAllCurveLines(editorFrame)
for _, line in ipairs(editorFrame.activeCurveLines) do
line:Hide()
end
editorFrame.activeCurveLines = {}
end
-------------------------------------------------------------------------------
-- UI HELPERS
-------------------------------------------------------------------------------
local function HighlightPoint(point)
point.texture:SetVertexColor(unpack(COLORS.pointHighlight))
end
local function UnhighlightPoint(point)
point.texture:SetVertexColor(unpack(COLORS.pointNormal))
end
local function ShowPointTooltip(point, zoom, value)
GameTooltip:SetOwner(point, "ANCHOR_RIGHT")
GameTooltip:SetText(string.format("Zoom: %.1f\nValue: %.2f", zoom or 0, value or 0))
GameTooltip:Show()
end
local function IsAnyPointDragging(editorFrame)
if not editorFrame or not editorFrame.activePointFrames then return false end
for _, p in ipairs(editorFrame.activePointFrames) do
if p.isDragging then return true end
end
return false
end
local function SortPointsByZoom(points)
table.sort(points, function(a, b) return a.zoom < b.zoom end)
end
-------------------------------------------------------------------------------
-- GRAPH COORDINATE CONVERSION
-------------------------------------------------------------------------------
-- Convert data values to graph coordinates (Y inverted: zoom 0 at top)
local function DataToGraph(zoom, value, minValue, maxValue, maxZoom, gw, gh)
local graphX = ((value - minValue) / (maxValue - minValue)) * gw
local graphY = (1 - zoom / maxZoom) * gh
return graphX, graphY
end
-- Convert graph coordinates to data values
local function GraphToData(graphX, graphY, minValue, maxValue, maxZoom, gw, gh)
local zoom = (1 - graphY / gh) * maxZoom
local value = minValue + (graphX / gw) * (maxValue - minValue)
return zoom, value
end
local function CollectOtherZooms(points, excludeIndex)
local otherZooms = {}
for i, pointData in ipairs(points) do
if i ~= excludeIndex then
table.insert(otherZooms, pointData.zoom)
end
end
return otherZooms
end
local function CollectOtherZoomsFromFrames(pointFrames, excludePoint)
local otherZooms = {}
for _, otherPoint in ipairs(pointFrames) do
if otherPoint ~= excludePoint then
table.insert(otherZooms, otherPoint.zoom)
end
end
return otherZooms
end
local function GetSituationStatus(info)
local cvarName = info.cvarName
local situationId = info.situationId
local currentSitId = DynamicCam.currentSituationID
local sc = DynamicCam.situationColors
if situationId then
local sitData = DynamicCam.db.profile.situations[situationId]
local sitName = sitData and sitData.name or situationId
local labelText = L["Situation Settings"] .. ": " .. sitName
if not (sitData and sitData.enabled) then
return sc.disabled .. labelText .. sc.colorEnd, false,
sc.disabled .. L["Situation disabled."] .. sc.colorEnd
end
if sitData.errorEncountered then
return sc.error .. labelText .. sc.colorEnd, false,
sc.error .. L["Situation has a script error."] .. sc.colorEnd
end
if not DynamicCam.conditionExecutionCache[situationId] then
return sc.inactive .. labelText .. sc.colorEnd, false,
sc.inactive .. L["Situation enabled but condition not fulfilled."] .. sc.colorEnd
end
if currentSitId and currentSitId ~= situationId then
local activeSit = DynamicCam.db.profile.situations[currentSitId]
local activeSitName = activeSit and activeSit.name or currentSitId
local coloredName = sc.active .. "\"" .. activeSitName .. "\"" .. sc.colorEnd
return sc.overridden .. labelText .. sc.colorEnd, false,
sc.overridden .. L["Currently overridden by the active situation %s."]:format(coloredName) .. sc.colorEnd
end
return sc.active .. labelText .. sc.colorEnd, true, nil
else
local labelText = L["Standard Settings"]
if currentSitId then
local activeSit = DynamicCam.db.profile.situations[currentSitId]
if activeSit and activeSit.situationSettings then
local ss = activeSit.situationSettings
if (ss.cvars and ss.cvars[cvarName] ~= nil) or
(ss.cvarsZoomBased and ss.cvarsZoomBased[cvarName] ~= nil) then
local sitName = activeSit.name or currentSitId
local coloredName = sc.active .. "\"" .. sitName .. "\"" .. sc.colorEnd
return sc.overridden .. labelText .. sc.colorEnd, false,
sc.overridden .. L["Currently overridden by the active situation %s."]:format(coloredName) .. sc.colorEnd
end
end
end
return labelText, true, nil
end
end
-- Forward declaration (defined further below).
local UpdateCurveEditor
-- Re-anchors the instructions text below whichever line-3 widget is visible, then
-- measures the rendered heights and repositions the Inset accordingly.
local function UpdateTopRegionLayout(f)
f.instructions:ClearAllPoints()
if f.currentZoomLabelText:IsShown() then
f.instructions:SetPoint("TOPLEFT", f.currentZoomLabelText, "BOTTOMLEFT", 0, -4)
else
f.instructions:SetPoint("TOPLEFT", f.statusExplanation, "BOTTOMLEFT", 0, -4)
end
f.instructions:SetPoint("RIGHT", f, "RIGHT", -10, 0)
-- Defer measurement by one frame so WoW layout has fully settled.
C_Timer.After(0, function()
if not f or not f:IsShown() then return end
local frameTop = f:GetTop()
local instrBottom = f.instructions:GetBottom()
if not frameTop or not instrBottom then return end
local topRegionHeight = math.ceil(frameTop - instrBottom) + 4
if topRegionHeight ~= f.lastTopRegionHeight then
f.lastTopRegionHeight = topRegionHeight
f.Inset:ClearAllPoints()
f.Inset:SetPoint("TOPLEFT", f, "TOPLEFT", 10, -topRegionHeight)
f.Inset:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -6, 26)
UpdateCurveEditor(f)
end
end)
end
local function UpdateStatusDisplay(editorFrame, statusLabel, isActive, explanationText)
editorFrame.isActive = isActive
editorFrame.situationLabel:SetText(statusLabel)
if isActive then
editorFrame.currentZoomLabelText:Show()
editorFrame.currentValueIndicator:Show()
editorFrame.currentValueValue:Show()
editorFrame.statusExplanation:Hide()
else
editorFrame.currentZoomLabelText:Hide()
editorFrame.currentValueIndicator:Hide()
editorFrame.currentValueValue:Hide()
if explanationText then
editorFrame.statusExplanation:SetText(explanationText)
editorFrame.statusExplanation:Show()
end
if editorFrame.graphFrame and editorFrame.graphFrame.zoomIndicator then
editorFrame.graphFrame.zoomIndicator:Hide()
end
end
UpdateTopRegionLayout(editorFrame)
end
-------------------------------------------------------------------------------
-- BUTTON STATE HELPERS
-------------------------------------------------------------------------------
local function DeepCopyPoints(points)
local copy = {}
for i, point in ipairs(points) do
copy[i] = {zoom = point.zoom, value = point.value}
end
return copy
end
local function HasUnsavedChanges(editorFrame)
if not editorFrame.savedPoints or not editorFrame.cvarInfo then return false end
local currentPoints = DynamicCam:GetZoomBasedPoints(editorFrame.cvarInfo.situationId, editorFrame.cvarInfo.cvarName)
if not currentPoints then return false end
if #currentPoints ~= #editorFrame.savedPoints then return true end
local sortedCurrent = DeepCopyPoints(currentPoints)
local sortedSaved = DeepCopyPoints(editorFrame.savedPoints)
SortPointsByZoom(sortedCurrent)
SortPointsByZoom(sortedSaved)
for i = 1, #sortedCurrent do
if sortedCurrent[i].zoom ~= sortedSaved[i].zoom or sortedCurrent[i].value ~= sortedSaved[i].value then
return true
end
end
return false
end
-- Visually grey out / restore a UIPanelButtonTemplate button to emulate disabled.
-- (WoW does not fire OnEnter on truly-disabled buttons, so we fake it.)
local function SetButtonActive(button, active)
button.dcActive = active
if active then
if button.Left then button.Left:SetDesaturated(false) end
if button.Right then button.Right:SetDesaturated(false) end
if button.Middle then button.Middle:SetDesaturated(false) end
if button:GetHighlightTexture() then
button:GetHighlightTexture():SetAlpha(1)
end
button:GetFontString():SetTextColor(NORMAL_FONT_COLOR:GetRGB())
else
if button.Left then button.Left:SetDesaturated(true) end
if button.Right then button.Right:SetDesaturated(true) end
if button.Middle then button.Middle:SetDesaturated(true) end
if button:GetHighlightTexture() then
button:GetHighlightTexture():SetAlpha(0)
end
button:GetFontString():SetTextColor(DISABLED_FONT_COLOR:GetRGB())
end
end
local function UpdateButtonStates(editorFrame)
if not editorFrame.saveButton then return end
local hasChanges = HasUnsavedChanges(editorFrame)
SetButtonActive(editorFrame.saveButton, hasChanges)
SetButtonActive(editorFrame.revertButton, hasChanges)
SetButtonActive(editorFrame.pasteButton, clipboard ~= nil)
end
-- Refresh paste-button state on every open editor (called after copy).
local function UpdateAllPasteButtons()
for _, frame in pairs(openEditors) do
if frame:IsShown() and frame.pasteButton then
SetButtonActive(frame.pasteButton, clipboard ~= nil)
end
end
end
-------------------------------------------------------------------------------
-- UPDATE CURVE EDITOR
-------------------------------------------------------------------------------
UpdateCurveEditor = function(editorFrame)
if not editorFrame or not editorFrame:IsShown() or not editorFrame.cvarInfo then
return
end
local info = editorFrame.cvarInfo
local graphFrame = editorFrame.graphFrame
local gw = graphFrame:GetWidth()
local gh = graphFrame:GetHeight()
if gw <= 0 or gh <= 0 then return end
local maxZoom = DynamicCam.cameraDistanceMaxZoomFactor_max
-- Update status display
local statusLabel, isActive, explanationText = GetSituationStatus(info)
UpdateStatusDisplay(editorFrame, statusLabel, isActive, explanationText)
editorFrame.lastStatusKey = statusLabel .. (explanationText or "")
-- Clear existing grid lines and labels (return to pools)
ReleaseAllGridLines(editorFrame)
ReleaseAllGridLabels(editorFrame)
-- Draw grid line helper (uses pool)
local function DrawGridLine(x1, y1, x2, y2, isMajor)
local line = GetGridLineFromPool(editorFrame, graphFrame)
line:SetThickness(1.5)
if isMajor then
line:SetColorTexture(unpack(COLORS.gridMajor))
else
line:SetColorTexture(unpack(COLORS.gridMinor))
end
line:SetStartPoint("BOTTOMLEFT", graphFrame, x1, y1)
line:SetEndPoint("BOTTOMLEFT", graphFrame, x2, y2)
table.insert(editorFrame.activeGridLines, line)
end
-- Calculate grid steps
local zoomMajorStep, zoomMinorStep = CalculateNiceGridStep(0, maxZoom, 5)
local valueMajorStep, valueMinorStep = CalculateNiceGridStep(info.minValue, info.maxValue, 5)
editorFrame.cvarInfo.valueMajorStep = valueMajorStep
-- Horizontal grid lines (zoom levels)
DrawGridLine(0, gh, gw, gh, true) -- Top border (zoom=0)
DrawGridLine(0, 0, gw, 0, true) -- Bottom border (zoom=max)
local zoomMinorPositions = GenerateGridPositions(0, maxZoom, zoomMinorStep)
for _, zoom in ipairs(zoomMinorPositions) do
local _, y = DataToGraph(zoom, 0, info.minValue, info.maxValue, maxZoom, gw, gh)
DrawGridLine(0, y, gw, y, false)
end
local zoomMajorPositions = GenerateGridPositions(0, maxZoom, zoomMajorStep)
for _, zoom in ipairs(zoomMajorPositions) do
local _, y = DataToGraph(zoom, 0, info.minValue, info.maxValue, maxZoom, gw, gh)
DrawGridLine(0, y, gw, y, true)
if zoom > EDGE_LABEL_THRESHOLD and zoom < maxZoom - EDGE_LABEL_THRESHOLD then
local label = GetGridLabelFromPool(editorFrame)
label:ClearAllPoints()
label:SetPoint("RIGHT", graphFrame, "BOTTOMLEFT", Y_AXIS_LABEL_OFFSET, y)
label:SetText(tostring(Round(zoom, 1)))
label:SetTextColor(unpack(COLORS.gridLabel))
table.insert(editorFrame.activeGridLabelsZoom, label)
end
end
-- Edge zoom labels (zoom=0 at top, zoom=max at bottom)
local zoomMinLabel = GetGridLabelFromPool(editorFrame)
zoomMinLabel:ClearAllPoints()
zoomMinLabel:SetPoint("RIGHT", graphFrame, "TOPLEFT", Y_AXIS_LABEL_OFFSET, 0)
zoomMinLabel:SetText("0")
zoomMinLabel:SetTextColor(unpack(COLORS.gridLabel))
table.insert(editorFrame.activeGridLabelsZoom, zoomMinLabel)
local zoomMaxLabel = GetGridLabelFromPool(editorFrame)
zoomMaxLabel:ClearAllPoints()
zoomMaxLabel:SetPoint("RIGHT", graphFrame, "BOTTOMLEFT", Y_AXIS_LABEL_OFFSET, 0)
zoomMaxLabel:SetText(tostring(maxZoom))
zoomMaxLabel:SetTextColor(unpack(COLORS.gridLabel))
table.insert(editorFrame.activeGridLabelsZoom, zoomMaxLabel)
-- Vertical grid lines (values)
DrawGridLine(0, 0, 0, gh, true) -- Left border (minValue)
DrawGridLine(gw, 0, gw, gh, true) -- Right border (maxValue)
local valueMinorPositions = GenerateGridPositions(info.minValue, info.maxValue, valueMinorStep)
for _, value in ipairs(valueMinorPositions) do
local x, _ = DataToGraph(0, value, info.minValue, info.maxValue, maxZoom, gw, gh)
DrawGridLine(x, 0, x, gh, false)
end
local valueMajorPositions = GenerateGridPositions(info.minValue, info.maxValue, valueMajorStep)
local valueRange = info.maxValue - info.minValue
for _, value in ipairs(valueMajorPositions) do
local x, _ = DataToGraph(0, value, info.minValue, info.maxValue, maxZoom, gw, gh)
DrawGridLine(x, 0, x, gh, true)
local distFromMin = math.abs(value - info.minValue)
local distFromMax = math.abs(value - info.maxValue)
local edgeThreshold = valueRange * VALUE_EDGE_THRESHOLD_PCT
if distFromMin > edgeThreshold and distFromMax > edgeThreshold then
local label = GetGridLabelFromPool(editorFrame)
label:ClearAllPoints()
label:SetPoint("TOP", graphFrame, "BOTTOMLEFT", x, X_AXIS_LABEL_OFFSET)
local displayValue
if math.abs(value) >= 100 then
displayValue = tostring(Round(value, 0))
elseif math.abs(value) >= 10 then
displayValue = tostring(Round(value, 1))
else
displayValue = tostring(Round(value, 2))
end
label:SetText(displayValue)
label:SetTextColor(unpack(COLORS.gridLabel))
table.insert(editorFrame.activeGridLabelsValue, label)
end
end
-- Edge value labels (minValue at left, maxValue at right)
local valueMinLabel = GetGridLabelFromPool(editorFrame)
valueMinLabel:ClearAllPoints()
valueMinLabel:SetPoint("TOP", graphFrame, "BOTTOMLEFT", 0, X_AXIS_LABEL_OFFSET)
valueMinLabel:SetText(tostring(info.minValue))
valueMinLabel:SetTextColor(unpack(COLORS.gridLabel))
table.insert(editorFrame.activeGridLabelsValue, valueMinLabel)
local valueMaxLabel = GetGridLabelFromPool(editorFrame)
valueMaxLabel:ClearAllPoints()
valueMaxLabel:SetPoint("TOP", graphFrame, "BOTTOMRIGHT", 0, X_AXIS_LABEL_OFFSET)
valueMaxLabel:SetText(tostring(info.maxValue))
valueMaxLabel:SetTextColor(unpack(COLORS.gridLabel))
table.insert(editorFrame.activeGridLabelsValue, valueMaxLabel)
-- Clear existing points and curve lines
ReleaseAllPoints(editorFrame)
ReleaseAllCurveLines(editorFrame)
-- Get points
local points = DynamicCam:GetZoomBasedPoints(info.situationId, info.cvarName)
if not points or #points < 2 then return end
-- Draw curve (lines connecting points)
SortPointsByZoom(points)
for i = 1, #points - 1 do
local x1, y1 = DataToGraph(points[i].zoom, points[i].value, info.minValue, info.maxValue, maxZoom, gw, gh)
local x2, y2 = DataToGraph(points[i + 1].zoom, points[i + 1].value, info.minValue, info.maxValue, maxZoom, gw, gh)
local line = GetCurveLineFromPool(editorFrame, graphFrame)
line:SetThickness(2)
line:SetColorTexture(unpack(COLORS.curveLine))
line:SetStartPoint("BOTTOMLEFT", graphFrame, x1, y1)
line:SetEndPoint("BOTTOMLEFT", graphFrame, x2, y2)
table.insert(editorFrame.activeCurveLines, line)
end
-- Draw points
for i, pointData in ipairs(points) do
local point = GetPointFromPool(editorFrame, graphFrame)
local x, y = DataToGraph(pointData.zoom, pointData.value, info.minValue, info.maxValue, maxZoom, gw, gh)
point:ClearAllPoints()
point:SetPoint("CENTER", graphFrame, "BOTTOMLEFT", x, y)
point.zoom = pointData.zoom
point.value = pointData.value
point.pointIndex = i
local isEndpoint = (i == 1 or i == #points)
point.isEndpoint = isEndpoint
UnhighlightPoint(point)
-- Hover handlers
point:SetScript("OnEnter", function(self)
if IsAnyPointDragging(self.editorFrame) then return end
HighlightPoint(self)
ShowPointTooltip(self, self.zoom, self.value)
end)
point:SetScript("OnLeave", function(self)
if IsAnyPointDragging(self.editorFrame) then return end
UnhighlightPoint(self)
GameTooltip:Hide()
end)
-- Right-click to delete (except endpoints)
point:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonUp")
point:SetScript("OnClick", function(self, button)
if button == "RightButton" and not self.isEndpoint then
table.remove(points, self.pointIndex)
DynamicCam:SetZoomBasedPoints(info.situationId, info.cvarName, points)
UpdateCurveEditor(editorFrame)
end
end)
-- Drag handlers
point:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self.isDragging = true
HighlightPoint(self)
ShowPointTooltip(self, self.zoom, self.value)
end
end)
point:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" and self.isDragging then
self.isDragging = false
UnhighlightPoint(self)
GameTooltip:Hide()
local graphLeft = graphFrame:GetLeft()
local graphBottom = graphFrame:GetBottom()
if not graphLeft or not graphBottom then return end
local pointX = self:GetLeft() + POINT_RADIUS
local pointY = self:GetBottom() + POINT_RADIUS
local relX = pointX - graphLeft
local relY = pointY - graphBottom
relX = math.max(0, math.min(relX, gw))
relY = math.max(0, math.min(relY, gh))
local newZoom, newValue = GraphToData(relX, relY, info.minValue, info.maxValue, maxZoom, gw, gh)
if info.valueMajorStep then
newValue = SnapToGrid(newValue, info.minValue, info.maxValue, info.valueMajorStep)
end
if self.isEndpoint then
if self.pointIndex == 1 then
newZoom = 0
else
newZoom = maxZoom
end
else
local otherZooms = CollectOtherZooms(points, self.pointIndex)
newZoom = FindClosestValidZoom(newZoom, otherZooms, maxZoom)
end
points[self.pointIndex].zoom = Round(newZoom, 1)
points[self.pointIndex].value = Round(newValue, 2)
DynamicCam:SetZoomBasedPoints(info.situationId, info.cvarName, points)
UpdateCurveEditor(editorFrame)
end
end)
table.insert(editorFrame.activePointFrames, point)
end
-- Zoom indicator (only shown when active)
if graphFrame.zoomIndicator then
graphFrame.zoomIndicator:Hide()
end
if editorFrame.isActive then
local currentZoom = GetCameraZoom()
local currentValue = DynamicCam:GetInterpolatedValue(info.situationId, info.cvarName, currentZoom)
if not currentValue then
currentValue = tonumber(GetCVar(info.cvarName)) or 0
end
local indicatorX, indicatorY = DataToGraph(currentZoom, currentValue, info.minValue, info.maxValue, maxZoom, gw, gh)
if not graphFrame.zoomIndicator then
graphFrame.zoomIndicator = CreateFrame("Frame", nil, graphFrame)
graphFrame.zoomIndicator:SetSize(POINT_RADIUS * 2 + 2, POINT_RADIUS * 2 + 2)
graphFrame.zoomIndicator:SetFrameLevel(graphFrame:GetFrameLevel() + ZOOM_INDICATOR_FRAME_LEVEL_OFFSET)
graphFrame.zoomIndicator.texture = graphFrame.zoomIndicator:CreateTexture(nil, "OVERLAY")
graphFrame.zoomIndicator.texture:SetAllPoints()
graphFrame.zoomIndicator.texture:SetTexture("Interface\\COMMON\\Indicator-Green")
end
graphFrame.zoomIndicator:ClearAllPoints()
graphFrame.zoomIndicator:SetPoint("CENTER", graphFrame, "BOTTOMLEFT", indicatorX, indicatorY)
graphFrame.zoomIndicator:Show()
editorFrame.currentValueValue:SetText(string.format("%.1f / %.2f", currentZoom, currentValue))
end
UpdateButtonStates(editorFrame)
end
-------------------------------------------------------------------------------
-- FRAME CREATION
-------------------------------------------------------------------------------
local function CreateZoomBasedEditorFrame()
editorStrataCounter = editorStrataCounter + 1
local frameName = "DynamicCamZoomEditor" .. editorStrataCounter
local f = CreateFrame("Frame", frameName, UIParent, "ButtonFrameTemplate")
ButtonFrameTemplate_HidePortrait(f)
f:SetSize(EDITOR_WIDTH, EDITOR_HEIGHT)
-- Offset each editor so they don't overlap exactly
local offsetX = 100 + ((editorStrataCounter - 1) % 5) * 40
local offsetY = -80 - ((editorStrataCounter - 1) % 5) * 40
f:SetPoint("TOPLEFT", UIParent, "TOPLEFT", offsetX, offsetY)
f:SetFrameStrata("HIGH")
f:SetToplevel(true)
f:SetMovable(true)
f:EnableMouse(true)
f:SetClampedToScreen(true)
-- Drag to move + raise (OnMouseDown fires immediately, no threshold)
f:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self:Raise()
self:StartMoving()
end
end)
f:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
end
end)
-- ESC closing is handled by our CloseSpecialWindows wrapper in
-- DetachFrame.lua (calling EscAllCurveEditors). We intentionally
-- do NOT register in UISpecialFrames because ShowUIPanel calls
-- CloseSpecialWindows which would close editors when the game
-- settings panel opens.
-- Initialize per-frame pools
f.pointFramePool = {}
f.activePointFrames = {}
f.gridLinePool = {}
f.activeGridLines = {}
f.gridLabelPool = {}
f.activeGridLabelsZoom = {}
f.activeGridLabelsValue = {}
f.curveLinePool = {}
f.activeCurveLines = {}
-- Per-frame state
f.cvarInfo = nil
f.ownerWidget = nil
-- Title
f.TitleContainer.TitleText:SetText(L["DynamicCam: Zoom-Based Setting"])
-- Override the default OnClick which calls HideUIPanel() (a secure function
-- that is blocked during combat). We only need a plain Hide() here.
f.CloseButton:SetScript("OnClick", function(self)
self:GetParent():Hide()
end)
-- Close button tooltip
f.CloseButton:HookScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT")
GameTooltip:SetText(L["Close"], 1, 0.82, 0, 1, true)
GameTooltip:AddLine(L["<close_tooltip>"], 1, 1, 1, 1, true)
GameTooltip:Show()
end)
f.CloseButton:HookScript("OnLeave", function(self)
GameTooltip:Hide()
end)
-- Info labels (in top region above Inset)
-- Line 1: CVAR name (bounded before the close button; clips if too long)
f.settingLabel = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.settingLabel:SetPoint("TOPLEFT", f.TopTileStreaks, "TOPLEFT", 6, -6)
f.settingLabel:SetPoint("RIGHT", f, "RIGHT", -32, 0)
f.settingLabel:SetJustifyH("LEFT")
-- Invisible mouse-capture frame so the (potentially clipped) label shows a tooltip
f.settingLabelHover = CreateFrame("Frame", nil, f)
f.settingLabelHover:SetPoint("TOPLEFT", f.settingLabel, "TOPLEFT", 0, 4)
f.settingLabelHover:SetPoint("BOTTOMRIGHT", f.settingLabel, "BOTTOMRIGHT", 0, -4)
f.settingLabelHover:EnableMouse(true)
f.settingLabelHover:Hide() -- shown only when text is truncated
f.settingLabelHover:SetScript("OnEnter", function(self)
if not f.cvarInfo then return end
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:SetText(L["CVAR: "] .. f.cvarInfo.cvarName, 1, 0.82, 0)
GameTooltip:Show()
end)
f.settingLabelHover:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
-- Line 2: Situation/Standard label (colored by status)
f.situationLabel = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.situationLabel:SetPoint("TOPLEFT", f.settingLabel, "BOTTOMLEFT", 0, -4)
f.situationLabel:SetPoint("TOPRIGHT", f.TopTileStreaks, "TOPRIGHT", -10, 0)
f.situationLabel:SetJustifyH("LEFT")
-- Line 3a: Current Zoom/Value (shown when active)
f.currentZoomLabelText = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.currentZoomLabelText:SetPoint("TOPLEFT", f.situationLabel, "BOTTOMLEFT", 0, -4)
f.currentZoomLabelText:SetText(L["Current Zoom/Value:"])
f.currentValueIndicator = CreateFrame("Frame", nil, f)
f.currentValueIndicator:SetSize(POINT_RADIUS * 2, POINT_RADIUS * 2)
f.currentValueIndicator:SetPoint("LEFT", f.currentZoomLabelText, "RIGHT", 5, 0)
f.currentValueIndicator.texture = f.currentValueIndicator:CreateTexture(nil, "OVERLAY")
f.currentValueIndicator.texture:SetAllPoints()
f.currentValueIndicator.texture:SetTexture("Interface\\COMMON\\Indicator-Green")
f.currentValueValue = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.currentValueValue:SetPoint("LEFT", f.currentValueIndicator, "RIGHT", 1, 1)
f.currentValueValue:SetText("--- / ---")
-- Line 3b: Status explanation (shown when inactive, replaces zoom/value line)
f.statusExplanation = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
f.statusExplanation:SetPoint("TOPLEFT", f.situationLabel, "BOTTOMLEFT", 0, -4)
f.statusExplanation:SetPoint("TOPRIGHT", f.TopTileStreaks, "TOPRIGHT", -10, 0)
f.statusExplanation:SetJustifyH("LEFT")
f.statusExplanation:SetWordWrap(true)
f.statusExplanation:Hide()
f.instructions = f:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
-- Instructions text (anchor is managed dynamically by UpdateTopRegionLayout)
f.instructions:SetJustifyH("LEFT")
f.instructions:SetWordWrap(true)
f.instructions:SetTextColor(unpack(COLORS.gridLabel))
f.instructions:SetText(L["Left-click: add/drag point\nRight-click: remove point"])
-- Inset height is managed dynamically by UpdateTopRegionLayout.
-- Graph frame inside the Inset
f.graphFrame = CreateFrame("Frame", nil, f.Inset)
f.graphFrame:SetPoint("TOPLEFT", f.Inset, "TOPLEFT", GRAPH_PADDING_LEFT, -GRAPH_PADDING_TOP)
f.graphFrame:SetPoint("BOTTOMRIGHT", f.Inset, "BOTTOMRIGHT", -GRAPH_PADDING_RIGHT, GRAPH_PADDING_BOTTOM)
-- Solid background for the grid.
f.graphFrame.bg = f.graphFrame:CreateTexture(nil, "BACKGROUND")
f.graphFrame.bg:SetAllPoints()
f.graphFrame.bg:SetColorTexture(unpack(COLORS.gridBackground))
-- Y-axis title (vertical)
f.yAxisTitle = f:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
f.yAxisTitle:SetPoint("RIGHT", f.graphFrame, "LEFT", Y_AXIS_LABEL_OFFSET - 14, 0)
f.yAxisTitle:SetText(L["Z\no\no\nm"])
f.yAxisTitle:SetJustifyH("CENTER")
-- X-axis title