-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathZoomBasedSettings.lua
More file actions
2030 lines (1653 loc) · 71.3 KB
/
ZoomBasedSettings.lua
File metadata and controls
2030 lines (1653 loc) · 71.3 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 LibEasing = LibStub("LibEasing-1.0")
local GetCameraZoom = _G.GetCameraZoom
-------------------------------------------------------------------------------
-- ZOOM-BASED SETTINGS
--
-- This module allows settings to be controlled by a curve based on zoom level.
-- Instead of a single value, users define points on a 2D 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
local COLORS = {
pointNormal = {0.3, 0.7, 1.0, 1.0},
pointHighlight = {0.5, 0.9, 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},
curveLine = {0.3, 0.7, 1.0, 1.0},
}
-- Zoom constraints
local MIN_ZOOM_SPACING = 0.1
local EDGE_LABEL_THRESHOLD = 0.5
local VALUE_EDGE_THRESHOLD_PCT = 0.08
local NEW_POINT_MATCH_TOLERANCE = 0.15
local ZOOM_INDICATOR_FRAME_LEVEL_OFFSET = 100
local function Round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return math.floor(num * mult + 0.5) / mult
end
-- Calculate a "nice" step size for grid lines
-- Returns major step and minor step
local function CalculateNiceGridStep(minValue, maxValue, targetDivisions)
local range = maxValue - minValue
if range <= 0 then return 1, 0.5 end
local roughStep = range / targetDivisions
-- Find the magnitude (power of 10)
local magnitude = 10 ^ math.floor(math.log10(roughStep))
-- Normalize to 1-10 range
local normalized = roughStep / magnitude
-- Round to nearest "nice" number: 1, 2, 2.5, 5, or 10
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
-- Minor step is typically 1/5 or 1/4 of major, depending on major step
local minorStep
if niceStep == 1 or niceStep == 5 then
minorStep = majorStep / 5
else
minorStep = majorStep / 4
end
return majorStep, minorStep
end
-- Generate grid line positions
local function GenerateGridPositions(minValue, maxValue, step)
local positions = {}
-- Start from the first multiple of step >= minValue
local start = math.ceil(minValue / step) * step
for pos = start, maxValue, step do
-- Avoid floating point issues by rounding
pos = Round(pos, 6)
if pos >= minValue and pos <= maxValue then
table.insert(positions, pos)
end
end
return positions
end
-- Find the closest valid zoom position that maintains MIN_ZOOM_SPACING distance from all other points
local function FindClosestValidZoom(desiredZoom, otherZooms, maxZoom)
local minValid = MIN_ZOOM_SPACING
local maxValid = maxZoom - MIN_ZOOM_SPACING
-- Clamp desired to valid range first
desiredZoom = math.max(minValid, math.min(maxValid, desiredZoom))
-- Check if a position is valid (at least MIN_ZOOM_SPACING from all other points)
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 desired position is already valid, use it
if isValid(desiredZoom) then
return desiredZoom
end
-- Generate candidate positions: edges of valid range + positions just outside each existing point
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
-- Find the valid candidate closest to desired position
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 -- Fallback if no valid position found
end
-------------------------------------------------------------------------------
-- MULTI-EDITOR STATE MANAGEMENT
-------------------------------------------------------------------------------
-- Pool of curve editor frames for reuse
local curveEditorFramePool = {}
-- Currently open editors keyed by configId (situationId + cvarName)
local openEditors = {}
-- Counter for strata management - newer editors appear on top
local editorStrataCounter = 0
local BASE_FRAME_LEVEL = 100
-- Generate a unique config ID for a cvar
local function GetConfigId(situationId, cvarName)
return (situationId or "standard") .. "_" .. cvarName
end
-- Frame dimensions
local EDITOR_WIDTH = 350
local EDITOR_HEIGHT = 450
local GRAPH_PADDING_LEFT = 50
local GRAPH_PADDING_RIGHT = 20
local GRAPH_WIDTH = EDITOR_WIDTH - GRAPH_PADDING_LEFT - GRAPH_PADDING_RIGHT
local GRAPH_HEIGHT = 280
-- Point display
local POINT_RADIUS = 8
-- Label spacing
local Y_AXIS_LABEL_OFFSET = -7 -- Gap between graph and y-axis labels
local X_AXIS_LABEL_OFFSET = -7 -- Gap between graph and x-axis labels
-- Snap threshold (1/20 of the value range)
local SNAP_THRESHOLD_DIVISOR = 100
-- Snap a value to grid lines if close enough
local function SnapToGrid(value, minValue, maxValue, majorStep)
local range = maxValue - minValue
local snapThreshold = range / SNAP_THRESHOLD_DIVISOR
-- Generate grid positions
local gridPositions = GenerateGridPositions(minValue, maxValue, majorStep)
-- Also include min and max as snap targets
table.insert(gridPositions, minValue)
table.insert(gridPositions, maxValue)
-- Find closest grid position
for _, gridValue in ipairs(gridPositions) do
if math.abs(value - gridValue) <= snapThreshold then
return gridValue
end
end
return value -- No snap, return original value
end
-------------------------------------------------------------------------------
-- DATA STRUCTURE FOR ZOOM-BASED SETTINGS
-------------------------------------------------------------------------------
--[[
The zoom-based settings are stored within standardSettings or situationSettings,
parallel to the existing 'cvars' table. The new table is called 'cvarsZoomBased'.
Structure:
DynamicCamDB.profiles[profileName].standardSettings.cvarsZoomBased = {
["cvarName"] = {
enabled = true/false,
points = {
-- Array of {zoom, value} pairs, sorted by zoom
-- There's always a point at zoom=0 and zoom=maxZoom
{zoom = 0, value = 0.5},
{zoom = 10, value = 1.0},
{zoom = 39, value = 1.5},
}
}
}
For situation-specific settings:
DynamicCamDB.profiles[profileName].situations[situationID].situationSettings.cvarsZoomBased = {
["cvarName"] = { enabled = ..., points = {...} }
}
Note: minValue and maxValue are NOT stored in SavedVariables.
They are passed in when opening the curve editor (from the slider definition).
When cvarsZoomBased[cvarName] is nil, the curve editor initializes the points
using the current value from the non-zoom-based slider.
--]]
-- Get the zoom-based cvar data for a specific cvar
-- Returns nil if zoom-based is not enabled for this cvar
function DynamicCam:GetZoomBasedCvar(situationId, cvarName)
local settings = self:GetSettingsTable(situationId)
if settings and settings.cvarsZoomBased and
settings.cvarsZoomBased[cvarName] and
settings.cvarsZoomBased[cvarName].enabled then
return settings.cvarsZoomBased[cvarName]
end
return nil
end
-- Check if a cvar is zoom-based
function DynamicCam:IsCvarZoomBased(situationId, cvarName)
local setting = self:GetZoomBasedCvar(situationId, cvarName)
return setting ~= nil and setting.enabled
end
-- Set whether a cvar should be zoom-based
-- currentValue is the current slider value, used for initializing default points
function DynamicCam:SetCvarZoomBased(situationId, cvarName, enabled, currentValue)
local settings = self:GetSettingsTable(situationId)
if not settings then return end
-- Initialize cvarsZoomBased if needed
if not settings.cvarsZoomBased then
settings.cvarsZoomBased = {}
end
if not settings.cvarsZoomBased[cvarName] then
-- Initialize with default points using current slider value
-- This creates a flat line at the current value
settings.cvarsZoomBased[cvarName] = {
enabled = enabled,
points = {
{zoom = 0, value = currentValue},
{zoom = self.cameraDistanceMaxZoomFactor_max, value = currentValue},
}
}
else
settings.cvarsZoomBased[cvarName].enabled = enabled
end
-- Trigger an immediate update if this is for the active situation
local isActiveSituation = (situationId == nil and self.currentSituationID == nil)
or (situationId == self.currentSituationID)
if isActiveSituation then
-- Reset the cache so ZoomBasedUpdateFunction will recalculate all zoom-based cvars on next frame
self:ResetZoomBasedSettingsCache()
-- If we're disabling zoom-based mode, apply the current slider value immediately
if not enabled then
self:ApplySettings()
end
end
-- Notify the UI to refresh so that the slider's disabled state updates
LibStub("AceConfigRegistry-3.0"):NotifyChange("DynamicCam")
end
-- Get the points for a zoom-based cvar
function DynamicCam:GetZoomBasedPoints(situationId, cvarName)
local setting = self:GetZoomBasedCvar(situationId, cvarName)
if setting then
return setting.points
end
return nil
end
-- Set the points for a zoom-based cvar
function DynamicCam:SetZoomBasedPoints(situationId, cvarName, points)
local settings = self:GetSettingsTable(situationId)
if not settings then return end
if settings.cvarsZoomBased and settings.cvarsZoomBased[cvarName] then
-- Sort points by zoom level
table.sort(points, function(a, b) return a.zoom < b.zoom end)
settings.cvarsZoomBased[cvarName].points = points
end
end
-------------------------------------------------------------------------------
-- INTERPOLATION
-------------------------------------------------------------------------------
-- Cache for last used segment index per cvar (optimization to avoid searching all points every frame)
local lastSegmentIndices = {}
-- Calculate the setting value for a given zoom level using linear interpolation
function DynamicCam:GetInterpolatedValue(situationId, cvarName, zoomLevel)
local setting = self:GetZoomBasedCvar(situationId, cvarName)
if not setting or not setting.points or #setting.points < 2 then
-- Fallback to regular setting
return self:GetSettingsValue(situationId, "cvars", cvarName)
end
local points = setting.points
-- Clamp zoom level to valid range
zoomLevel = math.max(0, math.min(zoomLevel, self.cameraDistanceMaxZoomFactor_max))
-- Find the two points to interpolate between
local lowerPoint = points[1]
local upperPoint = points[#points]
-- Get or create cache table for this situation
local sitKey = situationId or "standard"
if not lastSegmentIndices[sitKey] then
lastSegmentIndices[sitKey] = {}
end
-- Optimization: Try the last successful segment first (works well for incremental zoom changes or when zoom has not changed at all)
local segmentIndex = nil
local lastSegmentIndex = lastSegmentIndices[sitKey][cvarName]
if lastSegmentIndex and lastSegmentIndex <= #points - 1 then
if points[lastSegmentIndex].zoom <= zoomLevel and points[lastSegmentIndex + 1].zoom >= zoomLevel then
segmentIndex = lastSegmentIndex
end
end
-- If cached segment didn't work, search through all segments
if not segmentIndex then
for i = 1, #points - 1 do
if points[i].zoom <= zoomLevel and points[i + 1].zoom >= zoomLevel then
segmentIndex = i
break
end
end
end
-- Use the found segment (or fallback to endpoints)
if segmentIndex then
lowerPoint = points[segmentIndex]
upperPoint = points[segmentIndex + 1]
lastSegmentIndices[sitKey][cvarName] = segmentIndex -- Cache for next call
end
-- Linear interpolation
if upperPoint.zoom == lowerPoint.zoom then
return lowerPoint.value
end
local t = (zoomLevel - lowerPoint.zoom) / (upperPoint.zoom - lowerPoint.zoom)
return lowerPoint.value + t * (upperPoint.value - lowerPoint.value)
end
-------------------------------------------------------------------------------
-- CURVE EDITOR UI
-------------------------------------------------------------------------------
local function DrawLine(parent, startX, startY, endX, endY, thickness, r, g, b, a)
local line = parent:CreateLine()
line:SetThickness(thickness)
line:SetColorTexture(r, g, b, a)
line:SetStartPoint("BOTTOMLEFT", parent, startX, startY)
line:SetEndPoint("BOTTOMLEFT", parent, endX, endY)
return line
end
-- Helper functions for point highlighting and tooltips
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
-- Helper to check if any point is being dragged in a specific editor
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 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 -- Store reference to owning editor
-- Circle texture
point.texture = point:CreateTexture(nil, "OVERLAY")
point.texture:SetAllPoints()
point.texture:SetTexture("Interface\\COMMON\\Indicator-Gray")
point.texture:SetVertexColor(unpack(COLORS.pointNormal))
-- Highlight on mouseover (but not while any point is being dragged)
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)
return point
end
local function GetPointFromPool(editorFrame, parent)
for i, 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
local function SortPointsByZoom(points)
table.sort(points, function(a, b) return a.zoom < b.zoom end)
end
-- Convert graph coordinates to data values (Y is inverted: 0 at top)
local function GraphToData(graphX, graphY, minValue, maxValue, maxZoom)
local zoom = (1 - graphY / GRAPH_HEIGHT) * maxZoom
local value = minValue + (graphX / GRAPH_WIDTH) * (maxValue - minValue)
return zoom, value
end
-- Helper to collect other point zooms for constraint checking
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
-- Grid line pool functions
local function GetGridLineFromPool(editorFrame, parent)
for _, line in ipairs(editorFrame.gridLinePool) do
if not line:IsShown() then
line:Show()
return line
end
end
local newLine = parent:CreateLine()
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 functions
local function GetGridLabelFromPool(editorFrame, parent)
for _, label in ipairs(editorFrame.gridLabelPool) do
if not label:IsShown() then
label:Show()
return label
end
end
local newLabel = parent: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 functions
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()
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
-- Convert data values to graph coordinates (Y is inverted: 0 at top)
local function DataToGraph(zoom, value, minValue, maxValue, maxZoom)
local graphX = ((value - minValue) / (maxValue - minValue)) * GRAPH_WIDTH
local graphY = (1 - zoom / maxZoom) * GRAPH_HEIGHT
return graphX, graphY
end
local function UpdateCurveEditor(editorFrame)
if not editorFrame or not editorFrame:IsShown() or not editorFrame.cvarInfo then
return
end
local info = editorFrame.cvarInfo
local graphFrame = editorFrame.graphFrame
-- 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)
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)
return line
end
-- Calculate grid steps for zoom axis (Y)
local zoomMajorStep, zoomMinorStep = CalculateNiceGridStep(0, DynamicCam.cameraDistanceMaxZoomFactor_max, 5)
-- Calculate grid steps for value axis (X)
local valueMajorStep, valueMinorStep = CalculateNiceGridStep(info.minValue, info.maxValue, 5)
-- Store major step for snapping during dragging
editorFrame.cvarInfo.valueMajorStep = valueMajorStep
-- Draw horizontal grid lines (zoom levels)
-- Border lines first (top and bottom edges)
DrawGridLine(0, GRAPH_HEIGHT, GRAPH_WIDTH, GRAPH_HEIGHT, true) -- Top border (zoom=0)
DrawGridLine(0, 0, GRAPH_WIDTH, 0, true) -- Bottom border (zoom=max)
-- Minor lines
local zoomMinorPositions = GenerateGridPositions(0, DynamicCam.cameraDistanceMaxZoomFactor_max, zoomMinorStep)
for _, zoom in ipairs(zoomMinorPositions) do
local _, y = DataToGraph(zoom, 0, info.minValue, info.maxValue, DynamicCam.cameraDistanceMaxZoomFactor_max)
DrawGridLine(0, y, GRAPH_WIDTH, y, false)
end
-- Major horizontal lines with labels
local zoomMajorPositions = GenerateGridPositions(0, DynamicCam.cameraDistanceMaxZoomFactor_max, zoomMajorStep)
for _, zoom in ipairs(zoomMajorPositions) do
local _, y = DataToGraph(zoom, 0, info.minValue, info.maxValue, DynamicCam.cameraDistanceMaxZoomFactor_max)
DrawGridLine(0, y, GRAPH_WIDTH, y, true)
-- Add label for this zoom level (skip if too close to edge labels)
if zoom > EDGE_LABEL_THRESHOLD and zoom < DynamicCam.cameraDistanceMaxZoomFactor_max - EDGE_LABEL_THRESHOLD then
local label = GetGridLabelFromPool(editorFrame, 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
-- Draw vertical grid lines (values)
-- Border lines first (left and right edges)
DrawGridLine(0, 0, 0, GRAPH_HEIGHT, true) -- Left border (minValue)
DrawGridLine(GRAPH_WIDTH, 0, GRAPH_WIDTH, GRAPH_HEIGHT, true) -- Right border (maxValue)
-- Minor lines
local valueMinorPositions = GenerateGridPositions(info.minValue, info.maxValue, valueMinorStep)
for _, value in ipairs(valueMinorPositions) do
local x, _ = DataToGraph(0, value, info.minValue, info.maxValue, DynamicCam.cameraDistanceMaxZoomFactor_max)
DrawGridLine(x, 0, x, GRAPH_HEIGHT, false)
end
-- Major vertical lines with labels
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, DynamicCam.cameraDistanceMaxZoomFactor_max)
DrawGridLine(x, 0, x, GRAPH_HEIGHT, true)
-- Add label for this value (skip if too close to edge labels)
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, editorFrame)
label:ClearAllPoints()
label:SetPoint("TOP", graphFrame, "BOTTOMLEFT", x, X_AXIS_LABEL_OFFSET)
-- Format based on magnitude
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
-- Clear existing elements
ReleaseAllPoints(editorFrame)
-- Clear existing curve lines (return to pool)
ReleaseAllCurveLines(editorFrame)
-- Get points
local points = DynamicCam:GetZoomBasedPoints(info.situationId, info.cvarName)
if not points or #points < 2 then return end
-- Draw the 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, DynamicCam.cameraDistanceMaxZoomFactor_max)
local x2, y2 = DataToGraph(points[i + 1].zoom, points[i + 1].value, info.minValue, info.maxValue, DynamicCam.cameraDistanceMaxZoomFactor_max)
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 the 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, DynamicCam.cameraDistanceMaxZoomFactor_max)
point:ClearAllPoints()
point:SetPoint("CENTER", graphFrame, "BOTTOMLEFT", x, y)
point.zoom = pointData.zoom
point.value = pointData.value
point.pointIndex = i
-- Mark endpoints (cannot have their zoom changed)
local isEndpoint = (i == 1 or i == #points)
point.isEndpoint = isEndpoint
UnhighlightPoint(point) -- Reset to normal color
-- Right-click to delete (except endpoints)
point:SetScript("OnClick", function(self, button)
if button == "RightButton" and not self.isEndpoint then
-- Remove this point
table.remove(points, self.pointIndex)
DynamicCam:SetZoomBasedPoints(info.situationId, info.cvarName, points)
UpdateCurveEditor(editorFrame)
end
end)
-- Make points draggable with immediate response
point:RegisterForClicks("LeftButtonDown", "LeftButtonUp", "RightButtonUp")
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()
-- Calculate final position
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
-- Clamp to graph bounds
relX = math.max(0, math.min(relX, GRAPH_WIDTH))
relY = math.max(0, math.min(relY, GRAPH_HEIGHT))
local newZoom, newValue = GraphToData(relX, relY, info.minValue, info.maxValue, DynamicCam.cameraDistanceMaxZoomFactor_max)
-- Snap value to grid if close enough
if info.valueMajorStep then
newValue = SnapToGrid(newValue, info.minValue, info.maxValue, info.valueMajorStep)
end
-- Endpoints can only move horizontally (value changes, zoom stays fixed)
if self.isEndpoint then
if self.pointIndex == 1 then
newZoom = 0
else
newZoom = DynamicCam.cameraDistanceMaxZoomFactor_max
end
else
-- For non-endpoints, find the closest valid zoom position
local otherZooms = CollectOtherZooms(points, self.pointIndex)
newZoom = FindClosestValidZoom(newZoom, otherZooms, DynamicCam.cameraDistanceMaxZoomFactor_max)
end
-- Update the point data
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
-- Draw current zoom indicator
if graphFrame.zoomIndicator then
graphFrame.zoomIndicator:Hide()
end
local currentZoom = GetCameraZoom()
local currentValue = DynamicCam:GetInterpolatedValue(info.situationId, info.cvarName, currentZoom)
local indicatorX, indicatorY = DataToGraph(currentZoom, currentValue, info.minValue, info.maxValue, DynamicCam.cameraDistanceMaxZoomFactor_max)
if not graphFrame.zoomIndicator then
graphFrame.zoomIndicator = CreateFrame("Frame", nil, graphFrame)
graphFrame.zoomIndicator:SetSize(POINT_RADIUS * 2 + 4, POINT_RADIUS * 2 + 4)
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-Yellow")
end
graphFrame.zoomIndicator:ClearAllPoints()
graphFrame.zoomIndicator:SetPoint("CENTER", graphFrame, "BOTTOMLEFT", indicatorX, indicatorY)
graphFrame.zoomIndicator:Show()
-- Update value labels (only the dynamic values, labels are static)
editorFrame.currentZoomValue:SetText(string.format("%.1f", currentZoom))
editorFrame.currentValueValue:SetText(string.format("%.2f", currentValue))
end
local function CreateCurveEditorFrame()
-- Increment strata counter for new editors
editorStrataCounter = editorStrataCounter + 1
-- Main frame with similar styling to TableAttributeDisplay
local frame = CreateFrame("Frame", "DynamicCamCurveEditor" .. editorStrataCounter, UIParent, "BackdropTemplate")
frame:SetSize(EDITOR_WIDTH, EDITOR_HEIGHT)
-- Offset each new editor slightly so they don't stack exactly
local offsetX = 20 + ((editorStrataCounter - 1) % 5) * 30
local offsetY = -20 - ((editorStrataCounter - 1) % 5) * 30
frame:SetPoint("TOPLEFT", SettingsPanel, "TOPRIGHT", offsetX, offsetY)
frame:SetFrameStrata("DIALOG")
frame:SetFrameLevel(BASE_FRAME_LEVEL + editorStrataCounter)
frame:SetMovable(true)
frame:EnableMouse(true)
frame:SetClampedToScreen(true)
-- Immediate dragging without threshold - raise frame level and start moving
frame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
editorStrataCounter = editorStrataCounter + 1
self:SetFrameLevel(BASE_FRAME_LEVEL + editorStrataCounter)
self:StartMoving()
end
end)
frame:SetScript("OnMouseUp", function(self, button)
if button == "LeftButton" then
self:StopMovingOrSizing()
end
end)
-- Initialize per-frame pools
frame.pointFramePool = {}
frame.activePointFrames = {}
frame.gridLinePool = {}
frame.activeGridLines = {}
frame.gridLabelPool = {}
frame.activeGridLabelsZoom = {}
frame.activeGridLabelsValue = {}
frame.curveLinePool = {}
frame.activeCurveLines = {}
-- Per-frame setting info and widget reference
frame.cvarInfo = nil
frame.ownerWidget = nil
-- Backdrop
frame:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
})
frame:SetBackdropColor(0.1, 0.1, 0.1, 0.9)
frame:SetBackdropBorderColor(0.6, 0.6, 0.6, 1)
-- Title bar
frame.titleBar = CreateFrame("Frame", nil, frame)
frame.titleBar:SetPoint("TOPLEFT", 4, -4)
frame.titleBar:SetPoint("TOPRIGHT", -4, -4)
frame.titleBar:SetHeight(20)
frame.titleBar.bg = frame.titleBar:CreateTexture(nil, "BACKGROUND")
frame.titleBar.bg:SetAllPoints()
frame.titleBar.bg:SetColorTexture(0.2, 0.2, 0.3, 1)
frame.title = frame.titleBar:CreateFontString(nil, "OVERLAY", "GameFontNormalMed2")
frame.title:SetPoint("CENTER", frame.titleBar)
frame.title:SetText(L["DynamicCam: Zoom-Based Setting"])
-- Setting name label
frame.settingLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.settingLabel:SetPoint("TOPLEFT", 15, -35)
frame.settingLabel:SetText(L["CVAR: "])
-- Graph frame (the actual drawing area)
frame.graphFrame = CreateFrame("Frame", nil, frame)
frame.graphFrame:SetSize(GRAPH_WIDTH, GRAPH_HEIGHT)
local horizontalOffset = (GRAPH_PADDING_LEFT - GRAPH_PADDING_RIGHT) / 2
frame.graphFrame:SetPoint("TOP", frame, "TOP", horizontalOffset, -65)
-- Simple background without border
frame.graphFrame.bg = frame.graphFrame:CreateTexture(nil, "BACKGROUND")
frame.graphFrame.bg:SetAllPoints()
frame.graphFrame.bg:SetColorTexture(0.05, 0.05, 0.1, 1)
-- Y-axis label (Zoom)
frame.yAxisLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
frame.yAxisLabel:SetPoint("LEFT", frame.graphFrame, "LEFT", -40, 0)
frame.yAxisLabel:SetText(L["Z\no\no\nm"])
frame.yAxisMin = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
frame.yAxisMin:SetPoint("RIGHT", frame.graphFrame, "TOPLEFT", Y_AXIS_LABEL_OFFSET, 0)
frame.yAxisMin:SetText("0")
frame.yAxisMin:SetTextColor(unpack(COLORS.gridLabel))
frame.yAxisMax = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
frame.yAxisMax:SetPoint("RIGHT", frame.graphFrame, "BOTTOMLEFT", Y_AXIS_LABEL_OFFSET, 0)
frame.yAxisMax:SetText(tostring(DynamicCam.cameraDistanceMaxZoomFactor_max))
frame.yAxisMax:SetTextColor(unpack(COLORS.gridLabel))
-- X-axis label (Value)
frame.xAxisLabel = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
frame.xAxisLabel:SetPoint("BOTTOM", frame.graphFrame, "BOTTOM", 0, -30)
frame.xAxisLabel:SetText(L["Value"])
frame.xAxisMin = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
frame.xAxisMin:SetPoint("TOP", frame.graphFrame, "BOTTOMLEFT", 0, X_AXIS_LABEL_OFFSET)
frame.xAxisMin:SetTextColor(unpack(COLORS.gridLabel))
frame.xAxisMax = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
frame.xAxisMax:SetPoint("TOP", frame.graphFrame, "BOTTOMRIGHT", 0, X_AXIS_LABEL_OFFSET)
frame.xAxisMax:SetTextColor(unpack(COLORS.gridLabel))
-- Current zoom/value display
-- Static labels
frame.currentZoomLabelText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.currentZoomLabelText:SetPoint("BOTTOMLEFT", 35, 50)
frame.currentZoomLabelText:SetText(L["Current Zoom:"])
frame.currentValueLabelText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.currentValueLabelText:SetPoint("BOTTOMLEFT", 35, 35)
frame.currentValueLabelText:SetText(L["Current Value:"])
-- Dynamic values (anchored to the right of labels)
frame.currentZoomValue = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.currentZoomValue:SetPoint("LEFT", frame.currentZoomLabelText, "RIGHT", 5, 0)
frame.currentValueValue = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.currentValueValue:SetPoint("LEFT", frame.currentValueLabelText, "RIGHT", 5, 0)
-- Yellow indicator dot for current value
frame.currentValueIndicator = CreateFrame("Frame", nil, frame)
frame.currentValueIndicator:SetSize(20, 20)
frame.currentValueIndicator:SetPoint("BOTTOMLEFT", 12, 38)
frame.currentValueIndicator.texture = frame.currentValueIndicator:CreateTexture(nil, "OVERLAY")
frame.currentValueIndicator.texture:SetAllPoints()
frame.currentValueIndicator.texture:SetTexture("Interface\\COMMON\\Indicator-Yellow")