-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStyleEngine.lua
More file actions
609 lines (525 loc) · 19.3 KB
/
Copy pathStyleEngine.lua
File metadata and controls
609 lines (525 loc) · 19.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
local _, WE = ...
local WHITE_TEXTURE = "Interface\\Buttons\\WHITE8X8"
local DEFAULT_FONT = "Fonts\\FRIZQT__.TTF"
local unpack = unpack or table.unpack
WE.state = WE.state or {}
WE.hot = WE.hot or {}
local function SetColor(region, color, alpha)
region:SetVertexColor(color[1], color[2], color[3], color[4] or 1)
region:SetAlpha(alpha == nil and 1 or alpha)
end
local function GetGlowTexture(shapeKey)
local shape = WE.GLOW_SHAPES[shapeKey] or WE.GLOW_SHAPES.STARBURST
return shape.texture
end
local function CreatePulse(texture)
local group = texture:CreateAnimationGroup()
group:SetLooping("NONE")
local fadeIn = group:CreateAnimation("Alpha")
fadeIn:SetOrder(1)
fadeIn:SetDuration(0.175)
fadeIn:SetSmoothing("OUT")
local fadeOut = group:CreateAnimation("Alpha")
fadeOut:SetOrder(2)
fadeOut:SetDuration(0.175)
fadeOut:SetSmoothing("IN")
group:SetScript("OnFinished", function()
texture:SetAlpha(texture.weBaseAlpha or 1)
end)
group:SetScript("OnStop", function()
texture:SetAlpha(texture.weBaseAlpha or 1)
end)
texture.wePulse = group
texture.wePulseIn = fadeIn
texture.wePulseOut = fadeOut
end
function WE.EnsureTargetRegions(target)
if not target or target.WERegions then
return target and target.WERegions
end
local live = target == SuperTrackedFrame
local regions = {}
regions.IconBackground = target:CreateTexture(live and "WEIconBackground" or nil, "BACKGROUND", nil, -8)
regions.IconBackground:SetTexture(WHITE_TEXTURE)
regions.IconBackground:SetPoint("CENTER", target.Icon, "CENTER")
regions.IconGlow = target:CreateTexture(live and "WEIconGlow" or nil, "BACKGROUND", nil, -7)
regions.IconGlow:SetTexture(GetGlowTexture("STARBURST"))
regions.IconGlow:SetBlendMode("ADD")
regions.IconGlow:SetPoint("CENTER", target.Icon, "CENTER")
CreatePulse(regions.IconGlow)
regions.IconShadow = target:CreateTexture(live and "WEIconShadow" or nil, "BACKGROUND", nil, -5)
regions.ArrowGlow = target:CreateTexture(live and "WEArrowGlow" or nil, "BACKGROUND", nil, -7)
regions.ArrowGlow:SetTexture(GetGlowTexture("STARBURST"))
regions.ArrowGlow:SetBlendMode("ADD")
regions.ArrowGlow:SetPoint("CENTER", target.Arrow, "CENTER")
CreatePulse(regions.ArrowGlow)
regions.TextBackground = target:CreateTexture(live and "WETextBackground" or nil, "BACKGROUND", nil, -8)
regions.TextBackground:SetTexture(WHITE_TEXTURE)
for _, region in pairs(regions) do
region:Hide()
end
target.WERegions = regions
return regions
end
function WE.EnsureRegions()
if SuperTrackedFrame then
return WE.EnsureTargetRegions(SuperTrackedFrame)
end
end
function WE.CaptureNativeStyle()
if WE.nativeStyle or not SuperTrackedFrame then
return
end
local text = SuperTrackedFrame.DistanceText
local font, size, flags = text:GetFont()
local r, g, b, a = text:GetTextColor()
local sr, sg, sb, sa = text:GetShadowColor()
local sx, sy = text:GetShadowOffset()
WE.nativeStyle = {
font = font or DEFAULT_FONT,
fontSize = size or 12,
fontFlags = flags or "",
textColor = { r or 1, g or 0.82, b or 0, a or 1 },
shadowColor = { sr or 0, sg or 0, sb or 0, sa or 1 },
shadowOffsetX = sx or 1,
shadowOffsetY = sy or -1,
}
end
local function HideCustomRegions(target)
if not target or not target.WERegions then
return
end
for _, region in pairs(target.WERegions) do
region:Hide()
end
end
local function RestoreIcon(target)
local icon = target.Icon
local atlas = icon:GetAtlas()
if atlas then
icon:SetAtlas(atlas, true)
else
icon:SetSize(40, 40)
end
icon:SetAlpha(1)
icon:SetDesaturated(false)
icon:SetVertexColor(1, 1, 1, 1)
end
local function CopyIconToShadow(icon, shadow)
local atlas = icon:GetAtlas()
if atlas then
shadow:SetAtlas(atlas, true)
else
shadow:SetTexture(icon:GetTexture())
shadow:SetTexCoord(icon:GetTexCoord())
end
end
function WE.ApplyIconToTarget(target, isPreview)
if not target or not target.Icon then
return
end
local db = WE.GetDB()
local iconDB = db.icon
local safeMode = db.compatibility.safeMode
local regions = WE.EnsureTargetRegions(target)
if not iconDB.enabled and not safeMode then
RestoreIcon(target)
regions.IconBackground:Hide()
regions.IconGlow:Hide()
regions.IconShadow:Hide()
else
target.Icon:SetSize(iconDB.size, iconDB.size)
target.Icon:SetAlpha(1)
target.Icon:SetDesaturated(not safeMode and iconDB.desaturate)
if not safeMode and iconDB.tintEnabled then
target.Icon:SetVertexColor(unpack(iconDB.tintColor))
else
target.Icon:SetVertexColor(1, 1, 1, 1)
end
local allowEffects = not safeMode
regions.IconBackground:SetSize(db.background.width, db.background.height)
SetColor(regions.IconBackground, db.background.color, db.background.alpha)
regions.IconBackground:SetShown(allowEffects and db.background.enabled)
regions.IconGlow:SetTexture(GetGlowTexture(iconDB.glowShape))
regions.IconGlow:SetSize(iconDB.glowSize, iconDB.glowSize)
regions.IconGlow.weBaseAlpha = iconDB.glowAlpha
SetColor(regions.IconGlow, iconDB.glowColor, iconDB.glowAlpha)
regions.IconGlow:SetShown(allowEffects and iconDB.glowEnabled)
if allowEffects and iconDB.shadowEnabled then
CopyIconToShadow(target.Icon, regions.IconShadow)
regions.IconShadow:ClearAllPoints()
regions.IconShadow:SetPoint("CENTER", target.Icon, "CENTER", iconDB.shadowOffsetX, iconDB.shadowOffsetY)
regions.IconShadow:SetSize(iconDB.size, iconDB.size)
SetColor(regions.IconShadow, iconDB.shadowColor, 1)
regions.IconShadow:Show()
else
regions.IconShadow:Hide()
end
end
if not isPreview and target.UpdateIconSize then
target:UpdateIconSize()
end
end
function WE.GetDistanceColor(distance)
local textDB = WE.GetDB().text
if not textDB.colorByDistance or not distance then
return textDB.color[1], textDB.color[2], textDB.color[3], textDB.color[4]
end
if distance <= textDB.nearDistance then
return unpack(textDB.nearColor)
end
if distance >= textDB.farDistance then
return unpack(textDB.farColor)
end
local amount = (distance - textDB.nearDistance) / (textDB.farDistance - textDB.nearDistance)
return WE.LerpColor(textDB.nearColor, textDB.farColor, amount)
end
function WE.FormatDistance(distance)
local textDB = WE.GetDB().text
local number = distance < 1000 and tostring(distance) or AbbreviateNumbers(distance)
if textDB.compact then
return number
end
local formatted
if IN_GAME_NAVIGATION_RANGE then
formatted = IN_GAME_NAVIGATION_RANGE:format(number)
else
formatted = number .. " yds"
end
return textDB.uppercase and string.upper(formatted) or formatted
end
function WE.ApplyTextToTarget(target, isPreview)
if not target or not target.DistanceText then
return
end
local db = WE.GetDB()
local textDB = db.text
local safeMode = db.compatibility.safeMode
local text = target.DistanceText
local regions = WE.EnsureTargetRegions(target)
local native = WE.nativeStyle or {
font = DEFAULT_FONT,
fontSize = 12,
fontFlags = "",
textColor = { 1, 0.82, 0, 1 },
shadowColor = { 0, 0, 0, 1 },
shadowOffsetX = 1,
shadowOffsetY = -1,
}
local requestedFont = safeMode and native.font or textDB.font
if not text:SetFont(requestedFont or DEFAULT_FONT, textDB.size, textDB.outline) then
if not text:SetFont(DEFAULT_FONT, textDB.size, textDB.outline) then
text:SetFont(native.font, textDB.size, textDB.outline)
end
end
text:ClearAllPoints()
if safeMode then
text:SetPoint("TOP", target.Icon, "BOTTOM", 0, -8)
text:SetTextColor(unpack(native.textColor))
text:SetShadowColor(unpack(native.shadowColor))
text:SetShadowOffset(native.shadowOffsetX, native.shadowOffsetY)
regions.TextBackground:Hide()
else
text:SetPoint("TOP", target.Icon, "BOTTOM", textDB.offsetX, textDB.offsetY)
text:SetTextColor(WE.GetDistanceColor(isPreview and 37 or target.distance))
if textDB.shadowEnabled then
text:SetShadowColor(unpack(textDB.shadowColor))
text:SetShadowOffset(textDB.shadowOffsetX, textDB.shadowOffsetY)
else
text:SetShadowColor(0, 0, 0, 0)
text:SetShadowOffset(0, 0)
end
regions.TextBackground:ClearAllPoints()
regions.TextBackground:SetPoint("TOPLEFT", text, "TOPLEFT", -textDB.backgroundPaddingX, textDB.backgroundPaddingY)
regions.TextBackground:SetPoint("BOTTOMRIGHT", text, "BOTTOMRIGHT", textDB.backgroundPaddingX, -textDB.backgroundPaddingY)
SetColor(regions.TextBackground, textDB.backgroundColor, textDB.backgroundAlpha)
end
if isPreview then
text:SetText(WE.FormatDistance(37))
text:SetShown(safeMode or textDB.enabled)
regions.TextBackground:SetShown(not safeMode and textDB.enabled and textDB.backgroundEnabled)
end
end
function WE.ApplyArrowToTarget(target, isPreview)
if not target or not target.Arrow then
return
end
local db = WE.GetDB()
local arrowDB = db.arrow
local safeMode = db.compatibility.safeMode
local regions = WE.EnsureTargetRegions(target)
if safeMode or not arrowDB.enabled then
target.Arrow:SetScale(1)
target.Arrow:SetAlpha(1)
target.Arrow:SetDesaturated(false)
target.Arrow:SetVertexColor(1, 1, 1, 1)
regions.ArrowGlow:Hide()
return
end
target.Arrow:SetScale(arrowDB.scale)
target.Arrow:SetAlpha(1)
target.Arrow:SetDesaturated(arrowDB.desaturate)
if arrowDB.tintEnabled then
target.Arrow:SetVertexColor(unpack(arrowDB.tintColor))
else
target.Arrow:SetVertexColor(1, 1, 1, 1)
end
regions.ArrowGlow:SetTexture(GetGlowTexture(arrowDB.glowShape))
regions.ArrowGlow:SetSize(arrowDB.glowSize, arrowDB.glowSize)
regions.ArrowGlow.weBaseAlpha = arrowDB.glowAlpha
SetColor(regions.ArrowGlow, arrowDB.tintColor, arrowDB.glowAlpha)
regions.ArrowGlow:SetShown(arrowDB.glowEnabled and (isPreview or target.Arrow:IsShown()))
end
function WE.ApplyFrame()
if not SuperTrackedFrame then
return
end
local db = WE.GetDB()
local frameDB = db.frame
local safeMode = db.compatibility.safeMode
SuperTrackedFrame:SetScale(frameDB.scale)
if safeMode then
SuperTrackedFrame:SetFrameStrata("BACKGROUND")
SuperTrackedFrame:SetEllipticalRadii(500, 200)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.Invalid, 0)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.Occluded, 0.6)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.InRange, 1)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.Disabled, 0)
else
SuperTrackedFrame:SetFrameStrata(frameDB.strata)
SuperTrackedFrame:SetEllipticalRadii(frameDB.clampRadiusX, frameDB.clampRadiusY)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.Invalid, 0)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.Occluded,
db.visibility.forceVisibleWhenOccluded and frameDB.alphaOccluded or 0.6)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.InRange, frameDB.alphaNormal)
SuperTrackedFrame:SetTargetAlphaForState(Enum.NavigationState.Disabled, 0)
end
end
function WE.ApplyIcon()
if SuperTrackedFrame and WE.GetDB().enabled and not WE.restoring then
WE.ApplyIconToTarget(SuperTrackedFrame, false)
end
end
function WE.ApplyText()
if SuperTrackedFrame and WE.GetDB().enabled and not WE.restoring then
WE.ApplyTextToTarget(SuperTrackedFrame, false)
WE.InvalidateHotState()
end
end
function WE.ApplyArrow()
if SuperTrackedFrame and WE.GetDB().enabled and not WE.restoring then
WE.ApplyArrowToTarget(SuperTrackedFrame, false)
end
end
local function VisibilityRuleHidesFrame(frame, db)
local visibility = db.visibility
local state = WE.state
if visibility.hideInCombat and state.inCombat then
return true
end
if visibility.hideWhileMounted and state.mounted then
return true
end
if visibility.hideInInstances and (state.instanceType == "party" or state.instanceType == "raid" or state.instanceType == "scenario") then
return true
end
if visibility.hideInArena and state.instanceType == "arena" then
return true
end
if visibility.hideInBattleground and (state.instanceType == "pvp" or state.instanceType == "battleground") then
return true
end
if visibility.hideNearEnabled and not frame.isClamped and state.cachedDistance
and state.cachedDistance <= visibility.hideNearDistance then
return true
end
return false
end
function WE.ApplyAlpha()
local frame = SuperTrackedFrame
local db = WE.GetDB()
if not frame or not db.enabled or db.compatibility.safeMode or WE.restoring or not frame.navFrame then
return
end
if VisibilityRuleHidesFrame(frame, db) then
frame:SetAlpha(0)
return
end
if not C_Navigation.HasValidScreenPosition() then
return
end
if frame.isClamped and db.visibility.forceVisibleWhenClamped then
frame:SetAlpha(db.frame.alphaClamped)
elseif C_Navigation.GetTargetState() == Enum.NavigationState.Occluded and db.visibility.forceVisibleWhenOccluded then
frame:SetAlpha(db.frame.alphaOccluded)
end
end
function WE.ApplyVisibility()
WE.ApplyAlpha()
end
function WE.InvalidateHotState()
WE.hot.distance = nil
WE.hot.distanceClamped = nil
WE.hot.textEnabled = nil
WE.hot.compact = nil
WE.hot.uppercase = nil
WE.hot.colorByDistance = nil
WE.hot.arrowShown = nil
if SuperTrackedFrame then
SuperTrackedFrame.distance = nil
end
end
function WE.UpdateDistanceHotPath(frame)
local db = WE.GetDB()
if not db.enabled or db.compatibility.safeMode or WE.restoring then
return
end
local distance = frame.distance
if not frame.isClamped and distance then
WE.state.cachedDistance = distance
end
local textDB = db.text
local hot = WE.hot
local changed = hot.distance ~= distance
or hot.distanceClamped ~= frame.isClamped
or hot.textEnabled ~= textDB.enabled
or hot.compact ~= textDB.compact
or hot.uppercase ~= textDB.uppercase
or hot.colorByDistance ~= textDB.colorByDistance
if changed then
hot.distance = distance
hot.distanceClamped = frame.isClamped
hot.textEnabled = textDB.enabled
hot.compact = textDB.compact
hot.uppercase = textDB.uppercase
hot.colorByDistance = textDB.colorByDistance
if distance then
frame.DistanceText:SetText(WE.FormatDistance(distance))
frame.DistanceText:SetTextColor(WE.GetDistanceColor(distance))
else
frame.DistanceText:SetTextColor(unpack(textDB.color))
end
end
local showText = textDB.enabled and not frame.isClamped
frame.DistanceText:SetShown(showText)
frame.WERegions.TextBackground:SetShown(showText and textDB.backgroundEnabled)
end
function WE.UpdateArrowHotPath(frame)
local db = WE.GetDB()
if not db.enabled or db.compatibility.safeMode or WE.restoring then
return
end
local showGlow = db.arrow.enabled and db.arrow.glowEnabled and frame.Arrow:IsShown()
if WE.hot.arrowShown ~= showGlow then
WE.hot.arrowShown = showGlow
frame.WERegions.ArrowGlow:SetShown(showGlow)
end
if frame.isClamped and not WE.hot.wasClamped and db.arrow.enabled and db.arrow.pulseWhenClamped then
WE.PlayPulse("ARROW")
end
WE.hot.wasClamped = frame.isClamped
end
function WE.PlayPulse(kind)
local frame = kind == "PREVIEW" and WE.previewFrame or SuperTrackedFrame
if not frame or not frame.WERegions then
return
end
local db = WE.GetDB()
local texture
if kind == "ARROW" then
if not db.arrow.glowEnabled then return end
texture = frame.WERegions.ArrowGlow
else
if not db.icon.glowEnabled then return end
texture = frame.WERegions.IconGlow
end
if not texture:IsShown() then
return
end
local base = texture.weBaseAlpha or texture:GetAlpha()
texture.wePulse:Stop()
texture.wePulseIn:SetFromAlpha(base)
texture.wePulseIn:SetToAlpha(1)
texture.wePulseOut:SetFromAlpha(1)
texture.wePulseOut:SetToAlpha(base)
texture.wePulse:Play()
end
function WE.RestoreBlizzardLikeStyle()
local frame = SuperTrackedFrame
if not frame then
return
end
WE.restoring = true
WE.CaptureNativeStyle()
local native = WE.nativeStyle
frame:SetScale(1)
frame:SetFrameStrata("BACKGROUND")
frame:SetEllipticalRadii(500, 200)
frame:SetTargetAlphaForState(Enum.NavigationState.Invalid, 0)
frame:SetTargetAlphaForState(Enum.NavigationState.Occluded, 0.6)
frame:SetTargetAlphaForState(Enum.NavigationState.InRange, 1)
frame:SetTargetAlphaForState(Enum.NavigationState.Disabled, 0)
RestoreIcon(frame)
if frame.UpdateIconSize then
frame:UpdateIconSize()
end
frame.DistanceText:SetFont(native.font, native.fontSize, native.fontFlags)
frame.DistanceText:SetTextColor(unpack(native.textColor))
frame.DistanceText:SetShadowColor(unpack(native.shadowColor))
frame.DistanceText:SetShadowOffset(native.shadowOffsetX, native.shadowOffsetY)
frame.DistanceText:ClearAllPoints()
frame.DistanceText:SetPoint("TOP", frame.Icon, "BOTTOM", 0, -8)
frame.Arrow:SetScale(1)
frame.Arrow:SetAlpha(1)
frame.Arrow:SetDesaturated(false)
frame.Arrow:SetVertexColor(1, 1, 1, 1)
HideCustomRegions(frame)
frame.distance = nil
WE.hot = {}
WE.restoring = false
end
function WE.ApplyAll()
local frame = SuperTrackedFrame
if not frame then
return
end
if not WE.GetDB().enabled then
WE.RestoreBlizzardLikeStyle()
return
end
WE.EnsureRegions()
WE.ApplyFrame()
WE.ApplyIcon()
WE.ApplyText()
WE.ApplyArrow()
WE.UpdateDistanceHotPath(frame)
WE.UpdateArrowHotPath(frame)
WE.ApplyVisibility()
end
function WE.HookSuperTrackedFrame()
if WE.hooksInstalled or not SuperTrackedFrame then
return
end
WE.hooksInstalled = true
hooksecurefunc(SuperTrackedFrame, "InitializeNavigationFrame", function(frame)
if frame.navFrame and WE.GetDB().enabled then
WE.ApplyAll()
end
end)
hooksecurefunc(SuperTrackedFrame, "UpdateIcon", function()
WE.ApplyIcon()
end)
hooksecurefunc(SuperTrackedFrame, "UpdateDistanceText", function(frame)
if frame.WERegions then
WE.UpdateDistanceHotPath(frame)
end
end)
hooksecurefunc(SuperTrackedFrame, "UpdateArrow", function(frame)
if frame.WERegions then
WE.UpdateArrowHotPath(frame)
end
end)
hooksecurefunc(SuperTrackedFrame, "UpdateAlpha", function()
WE.ApplyAlpha()
end)
end