Repository navigation
Expand file tree
/
Copy pathBar.lua
More file actions
825 lines (740 loc) · 32.3 KB
/
Copy pathBar.lua
File metadata and controls
825 lines (740 loc) · 32.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
local addonName, ns = ...
local L = ns.L
local state = ns.state
local WHITE = "Interface\\Buttons\\WHITE8x8"
local NUM_SEGMENTS = 20
local BORDER = 2 -- bronze border in pixels
local INNER_SHADOW = 1 -- dark line between border and fill
local TEXT_FADE_DURATION = 0.15
local GLOW_SIZE = 6
local GRADIENT_SHADE = 0.55 -- brightness of the bottom edge when shading is on
local ANIM_DURATION = 0.4
local FLASH_DURATION = 0.8
-- Rested glow: alpha range of the slow pulse and of the soft glow above and below the bar.
local REST_GLOW_MIN_ALPHA = 0.15
local REST_GLOW_MAX_ALPHA = 0.45
local REST_GLOW_HALO_ALPHA = 0.25
-- Classic style: Blizzard's frame has pointed ends that are transparent outside the outline, so a
-- full-width rectangle peeks out at the corners. Pull the fill in a little at both ends.
local CLASSIC_END_INSET = 3
-- Blizzard's original experience bar textures, used by the Classic style.
local CLASSIC_ATLAS = {
background = "UI-HUD-ExperienceBar-Background",
prediction = "UI-HUD-ExperienceBar-Fill-Prediction",
}
local WHITE_COLOR = CreateColor(1, 1, 1)
-- Dark background and bronze border like the Forever action bars.
-- The fill colors come from the settings (ns.GetColor).
local COLORS = {
border = CreateColor(0.62, 0.48, 0.27, 1),
borderLight = CreateColor(0.86, 0.70, 0.44, 1), -- top edge: like embossed metal
borderDark = CreateColor(0.36, 0.26, 0.14, 1), -- bottom edge
innerShadow = CreateColor(0, 0, 0, 0.8), -- separates the border from any fill color
background = CreateColor(0.04, 0.05, 0.09, 1),
divider = CreateColor(0, 0, 0, 0.55),
dividerHighlight = CreateColor(1, 1, 1, 0.12),
restGlow = CreateColor(1.00, 0.82, 0.35),
}
local Bar = {}
ns.Bar = Bar
local function Colorize(text, color)
return WrapTextInColorCode(text, color:GenerateHexColor())
end
-- Without shading, the fill matches the chosen color exactly.
local function SetFillColor(tex, color, alpha)
local r, g, b = color:GetRGB()
local shade = XPForeverDB.fillGradient and GRADIENT_SHADE or 1
tex:SetGradient("VERTICAL", CreateColor(r * shade, g * shade, b * shade, alpha), CreateColor(r, g, b, alpha))
end
local function CreateFill(parent, subLevel)
local tex = parent:CreateTexture(nil, "ARTWORK", nil, subLevel)
tex:SetTexture(WHITE)
tex:Hide()
return tex
end
-- Modern style: solid fill (with optional shading).
local function UseColorFill(tex, color, alpha)
tex.atlas = nil
tex:SetTexture(WHITE)
tex:SetTexCoord(0, 1, 0, 1)
tex:SetDesaturated(false)
SetFillColor(tex, color, alpha)
end
-- Classic style: Blizzard's original texture. SetSpan crops it later instead of squashing it.
-- If the atlas is missing in the client, the solid fill is used.
local function UseAtlasFill(tex, atlas, color, alpha, desaturate)
local info = C_Texture.GetAtlasInfo(atlas)
if not info then
UseColorFill(tex, color, alpha)
return
end
tex:SetAtlas(atlas)
tex.atlas = info
tex:SetDesaturated(desaturate or false)
-- Explicitly replace the Modern style's shading with a flat color,
-- otherwise its darkening stays on Blizzard's texture.
local r, g, b = color:GetRGB()
local flat = CreateColor(r, g, b, alpha)
tex:SetGradient("VERTICAL", flat, flat)
tex:SetVertexColor(r, g, b, alpha)
end
-- Stretches a texture over the range [from, to] (fractions 0..1) of the bar. Atlas textures are cropped
-- like in Blizzard's StatusBar so they stay undistorted at any fill level.
local function SetSpan(tex, from, to)
local width = Bar.inner:GetWidth()
from = math.max(0, math.min(from, 1))
to = math.max(0, math.min(to, 1))
if to <= from or width <= 0 then
tex:Hide()
return
end
tex:ClearAllPoints()
tex:SetPoint("TOPLEFT", Bar.inner, "TOPLEFT", from * width, 0)
tex:SetPoint("BOTTOMLEFT", Bar.inner, "BOTTOMLEFT", from * width, 0)
tex:SetWidth(math.max((to - from) * width, 1))
local atlas = tex.atlas
if atlas then
local left, right = atlas.leftTexCoord, atlas.rightTexCoord
tex:SetTexCoord(left + (right - left) * from, left + (right - left) * to,
atlas.topTexCoord, atlas.bottomTexCoord)
end
tex:Show()
end
local function CreateText(parent, justify, fontObject)
local text = parent:CreateFontString(nil, "OVERLAY", fontObject or "GameFontHighlightSmall")
text:SetJustifyH(justify)
text:SetShadowOffset(1, -1)
return text
end
-- Keep Blizzard frames hidden: the game sets their alpha back to 1 at runtime (measured with /xpf debug;
-- not found in the Lua code). So undo every attempt to show them right away and also enforce it on
-- every redraw.
local silenced = setmetatable({}, { __mode = "k" })
local function Silence(frame)
frame:SetAlpha(0)
frame:EnableMouse(false)
if not silenced[frame] then
silenced[frame] = true
hooksecurefunc(frame, "SetAlpha", function(self, alpha)
if alpha and alpha > 0 then self:SetAlpha(0) end
end)
frame:HookScript("OnShow", function(self) self:SetAlpha(0) end)
end
end
-- Hide Blizzard's experience bar including its rested marker. Its container stays, so the action bar
-- layout in Edit Mode doesn't shift and the bar can still be moved there.
local function HideBlizzardBar()
if not (StatusTrackingBarManager and StatusTrackingBarInfo) then return end
local index = StatusTrackingBarInfo.BarsEnum.Experience
for _, container in ipairs(StatusTrackingBarManager.barContainers or {}) do
local bar = container.bars and container.bars[index]
if bar then
Silence(bar)
-- The marker doesn't know about quest XP and would sit in the wrong place.
if bar.ExhaustionTick then Silence(bar.ExhaustionTick) end
end
end
end
-- Four lines along the inside of `frame` (thickness pixels wide). For borders that must not cover
-- a fill.
local function CreateEdges(parent, frame, thickness, color, layer, subLevel)
local edges = {
{ "TOPLEFT", "TOPRIGHT", nil, thickness },
{ "BOTTOMLEFT", "BOTTOMRIGHT", nil, thickness },
{ "TOPLEFT", "BOTTOMLEFT", thickness, nil },
{ "TOPRIGHT", "BOTTOMRIGHT", thickness, nil },
}
local lines = {}
for _, edge in ipairs(edges) do
local line = parent:CreateTexture(nil, layer, nil, subLevel)
line:SetColorTexture(color:GetRGBA())
line:SetPoint(edge[1], frame, edge[1])
line:SetPoint(edge[2], frame, edge[2])
if edge[3] then line:SetWidth(edge[3]) end
if edge[4] then line:SetHeight(edge[4]) end
table.insert(lines, line)
end
return lines
end
-- Golden glow while resting, inspired by the player frame's glow.
-- Only the frame's alpha is animated: alpha animations directly on textures with
-- SetGradient turned them white.
local function CreateRestGlow(f)
-- Bar:Anchor sets the position: Modern around our bar, Classic around Blizzard's frame.
local restGlow = CreateFrame("Frame", nil, f)
restGlow:SetAllPoints()
restGlow:Hide()
-- Modern: golden border edges over the bronze border plus a soft glow above and below.
restGlow.modernPieces = CreateEdges(restGlow, restGlow, BORDER, COLORS.restGlow, "OVERLAY")
-- Classic: Blizzard's frame art laid over it in gold with additive blending (exactly the same shape).
restGlow.classicFrame = restGlow:CreateTexture(nil, "OVERLAY")
restGlow.classicFrame:SetBlendMode("ADD")
local r, g, b = COLORS.restGlow:GetRGB()
local glowTop = restGlow:CreateTexture(nil, "BACKGROUND")
glowTop:SetTexture(WHITE)
glowTop:SetPoint("BOTTOMLEFT", restGlow, "TOPLEFT")
glowTop:SetPoint("BOTTOMRIGHT", restGlow, "TOPRIGHT")
glowTop:SetHeight(GLOW_SIZE)
glowTop:SetGradient("VERTICAL", CreateColor(r, g, b, REST_GLOW_HALO_ALPHA), CreateColor(r, g, b, 0))
local glowBottom = restGlow:CreateTexture(nil, "BACKGROUND")
glowBottom:SetTexture(WHITE)
glowBottom:SetPoint("TOPLEFT", restGlow, "BOTTOMLEFT")
glowBottom:SetPoint("TOPRIGHT", restGlow, "BOTTOMRIGHT")
glowBottom:SetHeight(GLOW_SIZE)
glowBottom:SetGradient("VERTICAL", CreateColor(r, g, b, 0), CreateColor(r, g, b, REST_GLOW_HALO_ALPHA))
table.insert(restGlow.modernPieces, glowTop)
table.insert(restGlow.modernPieces, glowBottom)
local breathe = restGlow:CreateAnimationGroup()
breathe:SetLooping("BOUNCE")
local fade = breathe:CreateAnimation("Alpha")
fade:SetFromAlpha(REST_GLOW_MIN_ALPHA)
fade:SetToAlpha(REST_GLOW_MAX_ALPHA)
fade:SetDuration(2)
fade:SetSmoothing("IN_OUT")
return restGlow, breathe
end
-- The same animated "Zzz" art as on the player portrait.
local function CreateRestIcon(parent)
local restIcon = CreateFrame("Frame", nil, parent)
restIcon:SetSize(20, 20)
restIcon:SetPoint("RIGHT", -4, 1)
restIcon:Hide()
local restTexture = restIcon:CreateTexture(nil, "ARTWORK")
restTexture:SetAtlas("UI-HUD-UnitFrame-Player-Rest-Flipbook")
restTexture:SetSize(22, 22)
restTexture:SetPoint("CENTER")
local restAnim = restIcon:CreateAnimationGroup()
restAnim:SetLooping("REPEAT")
local flipBook = restAnim:CreateAnimation("FlipBook")
flipBook:SetTarget(restTexture)
flipBook:SetDuration(1.5)
flipBook:SetFlipBookRows(7)
flipBook:SetFlipBookColumns(6)
flipBook:SetFlipBookFrames(42)
flipBook:SetFlipBookFrameWidth(0)
flipBook:SetFlipBookFrameHeight(0)
return restIcon, restAnim
end
function Bar:Init()
if self.frame then return end
local f = CreateFrame("Frame", "XPForeverBar", UIParent)
f:SetFrameStrata("MEDIUM")
f:EnableMouse(true)
self.frame = f
local border = f:CreateTexture(nil, "BACKGROUND", nil, -1)
border:SetAllPoints()
border:SetColorTexture(COLORS.border:GetRGBA())
-- Metal effect: lighter top edge, darker bottom edge of the bronze border.
local borderTop = f:CreateTexture(nil, "BACKGROUND")
borderTop:SetColorTexture(COLORS.borderLight:GetRGBA())
borderTop:SetPoint("TOPLEFT")
borderTop:SetPoint("TOPRIGHT")
borderTop:SetHeight(1)
local borderBottom = f:CreateTexture(nil, "BACKGROUND")
borderBottom:SetColorTexture(COLORS.borderDark:GetRGBA())
borderBottom:SetPoint("BOTTOMLEFT")
borderBottom:SetPoint("BOTTOMRIGHT")
borderBottom:SetHeight(1)
-- Parts only the Modern style shows (in Classic, Blizzard's frame takes over).
self.modernParts = { border, borderTop, borderBottom }
local inner = CreateFrame("Frame", nil, f)
self.inner = inner
local background = inner:CreateTexture(nil, "BACKGROUND")
background:SetAllPoints()
self.background = background
self.xpFill = CreateFill(inner, 2)
self.questFill = CreateFill(inner, 1)
self.restedFill = CreateFill(inner, 0)
self.spark = inner:CreateTexture(nil, "ARTWORK", nil, 3)
self.spark:SetColorTexture(1, 1, 1, 0.9)
self.spark:SetBlendMode("ADD")
self.spark:SetWidth(2)
self.restGlow, self.restGlowAnim = CreateRestGlow(f)
-- Flash on XP gain: its own frame between fills and dividers. The frame's alpha is animated,
-- not the texture (alpha animations on textures turned them white).
local flashFrame = CreateFrame("Frame", nil, inner)
flashFrame:SetAllPoints()
flashFrame:SetFrameLevel(inner:GetFrameLevel() + 1)
flashFrame:Hide()
self.flashFrame = flashFrame
self.flashTexture = flashFrame:CreateTexture(nil, "ARTWORK")
self.flashTexture:SetBlendMode("ADD")
local flashAnim = flashFrame:CreateAnimationGroup()
local flashFade = flashAnim:CreateAnimation("Alpha")
flashFade:SetFromAlpha(0.6)
flashFade:SetToAlpha(0)
flashFade:SetDuration(FLASH_DURATION)
flashFade:SetSmoothing("OUT")
flashAnim:SetScript("OnFinished", function() flashFrame:Hide() end)
self.flashAnim = flashAnim
-- Drives the glide animation; OnUpdate is only set while it runs.
self.animator = CreateFrame("Frame", nil, f)
local overlay = CreateFrame("Frame", nil, inner)
overlay:SetAllPoints()
overlay:SetFrameLevel(inner:GetFrameLevel() + 5)
-- Dividers as an "engraving": a dark line plus a light edge to its right, so they stay
-- subtle on the empty background and visible on colored fills.
self.dividers = {}
for i = 1, NUM_SEGMENTS - 1 do
local divider = overlay:CreateTexture(nil, "BACKGROUND")
divider:SetColorTexture(COLORS.divider:GetRGBA())
divider:SetWidth(1)
divider.highlight = overlay:CreateTexture(nil, "BACKGROUND")
divider.highlight:SetColorTexture(COLORS.dividerHighlight:GetRGBA())
divider.highlight:SetWidth(1)
divider.highlight:SetPoint("TOPLEFT", divider, "TOPRIGHT")
divider.highlight:SetPoint("BOTTOMLEFT", divider, "BOTTOMRIGHT")
self.dividers[i] = divider
end
-- Dark inner line over the fills: border and fill stay distinguishable with any color.
for _, line in ipairs(CreateEdges(overlay, inner, INNER_SHADOW, COLORS.innerShadow, "BORDER")) do
table.insert(self.modernParts, line)
end
self.overlay = overlay
-- Separate frame for the hover texts so they can fade in and out together.
local texts = CreateFrame("Frame", nil, overlay)
texts:SetAllPoints()
texts:SetAlpha(0)
self.texts = texts
-- One line of the chosen text items; lines that are too long are cut with "…".
self.hoverText = CreateText(texts, "CENTER")
self.hoverText:SetPoint("LEFT", 6, 0)
self.hoverText:SetPoint("RIGHT", -6, 0)
self.hoverText:SetWordWrap(false)
-- Percentage: gold with a thin outline, no extra shadow.
self.percentText = CreateText(overlay, "CENTER", "GameFontNormal")
self.percentText:SetPoint("CENTER", 0, 0)
self.percentText:SetShadowOffset(0, 0)
local font, size = self.percentText:GetFont()
self.percentText:SetFont(font, size, "OUTLINE")
self.percentFont = { font, size }
-- The Zzz shares its spot with the bar text and fades the opposite way.
self.restIcon, self.restIconAnim = CreateRestIcon(overlay)
-- React to the size of inner: only then is its width guaranteed to be computed.
inner:SetScript("OnSizeChanged", function(_, width) self:Layout(width) end)
f:SetScript("OnEnter", function()
self.hovered = true
self:UpdateTextVisibility()
if XPForeverDB.showTooltip then self:ShowTooltip() end
end)
f:SetScript("OnLeave", function()
self.hovered = false
self:UpdateTextVisibility()
GameTooltip_Hide()
end)
f:SetScript("OnMouseUp", function(_, button)
if button == "LeftButton" and IsControlKeyDown() then
ns.ResetSession()
if self.hovered and XPForeverDB.showTooltip then self:ShowTooltip() end
elseif button == "LeftButton" then
ns.ToggleInfoText()
elseif button == "RightButton" then
ns.Options:Open()
end
end)
-- Blizzard spreads experience, reputation and other bars over two containers and reshuffles them
-- on changes (e.g. tracking a reputation). Re-anchor afterwards.
if StatusTrackingBarManager then
for _, container in ipairs(StatusTrackingBarManager.barContainers or {}) do
container:HookScript("OnSizeChanged", function() self:Anchor() end)
hooksecurefunc(container, "ApplyPendingBarToShow", function() self:Anchor() end)
end
end
HideBlizzardBar()
end
-- Apply settings that don't need to be set again on every XP update.
local function IsClassic()
return XPForeverDB.barStyle == "classic"
end
-- True while a fill still has its default color (and opacity).
local function IsDefaultLook(colorKey, opacityKey)
local db = XPForeverDB
return db[colorKey]:lower() == ns.GetDefault(colorKey):lower()
and (not opacityKey or db[opacityKey] == ns.GetDefault(opacityKey))
end
-- Classic: Blizzard's texture while a fill keeps its default look, otherwise the color from the settings.
-- Tinted Blizzard textures were invisible in Forever, so a chosen color is a solid fill like in Modern.
local function UseClassicFill(tex, atlas, colorKey, opacityKey)
local alpha = opacityKey and XPForeverDB[opacityKey] / 100 or 1
if IsDefaultLook(colorKey, opacityKey) then
UseAtlasFill(tex, atlas, WHITE_COLOR, 1)
else
UseColorFill(tex, ns.GetColor(colorKey), alpha)
end
end
-- Fills per style: solid in Modern; Blizzard's textures or the chosen colors in Classic.
function Bar:UpdateFills()
local db = XPForeverDB
local questColor, questAlpha = ns.GetColor("colorQuest"), db.questOpacity / 100
if not IsClassic() then
self.fillStyle = nil
UseColorFill(self.xpFill, ns.GetColor("colorXP"), 1)
UseColorFill(self.questFill, questColor, questAlpha)
UseColorFill(self.restedFill, ns.GetColor("colorRested"), db.restedOpacity / 100)
return
end
local style = table.concat({ db.colorXP, db.colorQuest, db.questOpacity, db.colorRested,
db.restedOpacity, tostring(db.fillGradient) }, ":")
if self.fillStyle == style then return end
self.fillStyle = style
-- XP is always solid: Blizzard's fill texture showed a dark, growing gap at the start of the bar.
UseColorFill(self.xpFill, ns.GetColor("colorXP"), 1)
-- Quest XP doesn't exist in the original, so it is always a solid fill.
UseColorFill(self.questFill, questColor, questAlpha)
UseClassicFill(self.restedFill, CLASSIC_ATLAS.prediction, "colorRested", "restedOpacity")
end
function Bar:ApplySettings()
if not self.frame then return end
local db = XPForeverDB
local classic = IsClassic()
-- Border: our own bronze border in Modern, Blizzard's frame and dividers in Classic (the container stays visible).
for _, part in ipairs(self.modernParts) do part:SetShown(not classic) end
local insetX = classic and CLASSIC_END_INSET or BORDER
local insetY = classic and 0 or BORDER
self.inner:ClearAllPoints()
self.inner:SetPoint("TOPLEFT", insetX, -insetY)
self.inner:SetPoint("BOTTOMRIGHT", -insetX, insetY)
if classic and C_Texture.GetAtlasInfo(CLASSIC_ATLAS.background) then
self.background:SetAtlas(CLASSIC_ATLAS.background)
else
self.background:SetColorTexture(COLORS.background:GetRGBA())
end
self.fillStyle = nil
self:UpdateFills()
for _, divider in ipairs(self.dividers) do
divider:SetShown(db.showSegments and not classic)
divider.highlight:SetShown(db.showSegments and not classic)
end
-- Percentage: gold with outline in Modern, like Blizzard's bar text in Classic.
if classic then
self.percentText:SetFontObject("TextStatusBarText")
self.percentText:SetTextColor(HIGHLIGHT_FONT_COLOR:GetRGB())
self.percentText:SetShadowOffset(1, -1)
else
self.percentText:SetFont(self.percentFont[1], self.percentFont[2], "OUTLINE")
self.percentText:SetTextColor(NORMAL_FONT_COLOR:GetRGB())
self.percentText:SetShadowOffset(0, 0)
end
self.percentText:SetShown(db.showPercent)
self.restIcon:SetScale(classic and 0.8 or 1)
self:Anchor()
self:UpdateTextVisibility(true)
self:UpdateResting()
end
-- The container in which Blizzard currently shows (or is about to show) the experience bar.
-- When tracking a reputation, the experience bar ends up in the second container.
local function FindXPContainer()
if StatusTrackingBarManager and StatusTrackingBarInfo then
local xpIndex = StatusTrackingBarInfo.BarsEnum.Experience
for _, container in ipairs(StatusTrackingBarManager.barContainers or {}) do
if container.shownBarIndex == xpIndex or container.pendingBarToShowIndex == xpIndex then
return container
end
end
end
return MainStatusTrackingBarContainer
end
-- Modern: centered on Blizzard's experience bar container (own height), above its frame.
-- Classic: exactly on Blizzard's (hidden) experience bar, below its frame and dividers.
-- In both cases Edit Mode moves our bar along.
function Bar:Anchor()
local f = self.frame
local container = FindXPContainer()
local blizzardBar = container and container.bars and StatusTrackingBarInfo
and container.bars[StatusTrackingBarInfo.BarsEnum.Experience]
f:ClearAllPoints()
if IsClassic() and blizzardBar then
f:SetAllPoints(blizzardBar)
f:SetFrameStrata("LOW")
f:SetFrameLevel(blizzardBar:GetFrameLevel() + 1)
elseif container then
f:SetPoint("CENTER", container, "CENTER")
f:SetWidth(container:GetWidth())
f:SetHeight(XPForeverDB.height)
f:SetFrameStrata("MEDIUM")
f:SetFrameLevel(container:GetFrameLevel() + 20)
else
f:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 90)
f:SetSize(1192, XPForeverDB.height)
end
-- Texts always on top, also above Blizzard's frame in the Classic style.
self.overlay:SetFrameStrata("MEDIUM")
self.overlay:SetFrameLevel((container and container:GetFrameLevel() or f:GetFrameLevel()) + 25)
-- Rested glow: around our bar in Modern, around Blizzard's frame in Classic (above its art).
local glow = self.restGlow
glow:ClearAllPoints()
glow:SetFrameStrata("MEDIUM")
local frameArt = container and container.BarFrameTexture
local classicGlow = IsClassic() and frameArt and frameArt:GetAtlas()
if classicGlow then
glow:SetAllPoints(container)
glow:SetFrameLevel(container:GetFrameLevel() + 15)
glow.classicFrame:SetAtlas(classicGlow)
glow.classicFrame:ClearAllPoints()
glow.classicFrame:SetAllPoints(frameArt)
glow.classicFrame:SetVertexColor(COLORS.restGlow:GetRGB())
else
glow:SetAllPoints(f)
glow:SetFrameLevel(f:GetFrameLevel() + 1)
end
glow.classicFrame:SetShown(classicGlow and true or false)
for _, piece in ipairs(glow.modernPieces) do piece:SetShown(not classicGlow) end
-- The info text follows the topmost bar and has to move along.
if ns.InfoText.frame then ns.InfoText:Anchor() end
end
-- Developer diagnostics (/xpf debug): geometry of our fill and every visible region of Blizzard's
-- experience bar container that overlaps the first segment. Helps to find what covers the bar's start.
-- Textures have no GetEffectiveAlpha; their alpha times the parent frame's effective alpha.
local function EffectiveAlpha(region)
if region.GetEffectiveAlpha then return region:GetEffectiveAlpha() end
return region:GetAlpha() * region:GetParent():GetEffectiveAlpha()
end
local function DescribeRegion(region)
local info = {
name = region:GetDebugName(),
type = region:GetObjectType(),
left = region:GetLeft(), right = region:GetRight(),
alpha = EffectiveAlpha(region),
}
if region.GetDrawLayer then
info.layer, info.subLevel = region:GetDrawLayer()
info.atlas = region.GetAtlas and region:GetAtlas()
info.texture = region.GetTexture and region:GetTexture()
else
info.strata, info.level = region:GetFrameStrata(), region:GetFrameLevel()
end
return info
end
function Bar:DebugInfo()
if not self.frame then return nil end
local inner, fill = self.inner, self.xpFill
local result = {
style = XPForeverDB.barStyle,
innerLeft = inner:GetLeft(), innerRight = inner:GetRight(),
fillLeft = fill:GetLeft(), fillRight = fill:GetRight(), fillShown = fill:IsShown(),
fillTexCoord = { fill:GetTexCoord() },
fillAtlas = fill:GetAtlas(), fillTexture = fill:GetTexture(), fillAlpha = fill:GetAlpha(),
display = self.display and CopyTable(self.display),
animating = self.animator:GetScript("OnUpdate") ~= nil,
flashShown = self.flashFrame:IsShown(), flashAlpha = self.flashFrame:GetAlpha(),
overlapping = {},
}
local left = inner:GetLeft()
local width = inner:GetWidth()
if not left or width <= 0 then return result end
local segmentEnd = left + width / 20
local function Visit(frame)
if not frame:IsVisible() then return end
local regions = { frame }
for _, region in ipairs({ frame:GetRegions() }) do table.insert(regions, region) end
for _, region in ipairs(regions) do
local rLeft, rRight = region:GetLeft(), region:GetRight()
if region:IsVisible() and EffectiveAlpha(region) > 0 and rLeft and rRight
and rLeft < segmentEnd and rRight > left then
table.insert(result.overlapping, DescribeRegion(region))
end
end
for _, child in ipairs({ frame:GetChildren() }) do Visit(child) end
end
local container = FindXPContainer()
if container then Visit(container) end
Visit(self.frame)
return result
end
-- Bar text depending on the setting: on mouseover, always or never. Fades smoothly.
-- The percentage and the Zzz make room for the text and fade the opposite way.
function Bar:UpdateTextVisibility(instant)
local texts = self.texts
local mode = XPForeverDB.barTextMode
local visible = mode == "always" or (mode == "hover" and self.hovered)
local target = (visible and ns.HasTextItems("bar")) and 1 or 0
local function apply(alpha)
texts:SetAlpha(alpha)
self.restIcon:SetAlpha(1 - alpha)
self.percentText:SetAlpha(1 - alpha)
end
if instant then
apply(target)
texts:SetScript("OnUpdate", nil)
return
end
texts:SetScript("OnUpdate", function(_, elapsed)
local step = elapsed / TEXT_FADE_DURATION
local alpha = texts:GetAlpha()
alpha = target > alpha and math.min(alpha + step, target) or math.max(alpha - step, target)
apply(alpha)
if alpha == target then texts:SetScript("OnUpdate", nil) end
end)
end
-- While resting (inn, capital city): show the Zzz icon and let the frame glow golden (glow optional).
function Bar:UpdateResting()
if not self.frame then return end
local db = XPForeverDB
local show = IsResting() and db.showRestIndicator
local glow = show and db.showRestGlow
self.restIcon:SetShown(show)
self.restGlow:SetShown(glow)
if show then self.restIconAnim:Play() else self.restIconAnim:Stop() end
if glow then self.restGlowAnim:Play() else self.restGlowAnim:Stop() end
end
function Bar:Layout(width)
local segmentWidth = width / NUM_SEGMENTS
for i, divider in ipairs(self.dividers) do
divider:ClearAllPoints()
divider:SetPoint("TOP", self.inner, "TOPLEFT", segmentWidth * i, 0)
divider:SetPoint("BOTTOM", self.inner, "BOTTOMLEFT", segmentWidth * i, 0)
end
self:Refresh()
end
-- Target state of the bar as fractions (0..1): end of XP, of quest XP and of rested XP.
local function ComputeTarget()
local db = XPForeverDB
local max = state.max > 0 and state.max or 1
local questXP = db.showQuestXP and state.questXP or 0
local rested = db.showRestedXP and state.rested or 0
return {
xp = state.xp / max,
quest = (state.xp + questXP) / max,
rested = (state.xp + questXP + rested) / max,
level = state.level,
}
end
local function SameTarget(a, b)
return a.level == b.level and math.abs(a.xp - b.xp) < 1e-6
and math.abs(a.quest - b.quest) < 1e-6 and math.abs(a.rested - b.rested) < 1e-6
end
local function EaseOut(progress)
return 1 - (1 - progress) ^ 3
end
function Bar:Draw(display)
SetSpan(self.xpFill, 0, display.xp)
SetSpan(self.questFill, display.xp, display.quest)
SetSpan(self.restedFill, display.quest, display.rested)
local x = math.min(display.xp, 1) * self.inner:GetWidth()
self.spark:ClearAllPoints()
self.spark:SetPoint("TOP", self.inner, "TOPLEFT", x, 0)
self.spark:SetPoint("BOTTOM", self.inner, "BOTTOMLEFT", x, 0)
self.spark:SetShown(display.xp > 0 and display.xp < 1)
end
-- The newly gained section flashes briefly in a lighter XP color.
function Bar:Flash(from, to)
if to <= from then return end
local r, g, b = ns.GetColor("colorXP"):GetRGB()
self.flashTexture:SetColorTexture(r + (1 - r) * 0.5, g + (1 - g) * 0.5, b + (1 - b) * 0.5, 1)
SetSpan(self.flashTexture, from, to)
self.flashFrame:Show()
self.flashAnim:Restart()
end
-- Plays a sequence of target states one after another. RESET_STEP empties the bar (after a level-up).
local RESET_STEP = {}
function Bar:PlaySteps(steps)
self.steps = steps
self.goal = steps[#steps]
self:NextStep()
end
function Bar:NextStep()
local step = table.remove(self.steps, 1)
if not step then
self.animator:SetScript("OnUpdate", nil)
self.goal = nil
return
end
if step == RESET_STEP then
self.display = { xp = 0, quest = 0, rested = 0, level = self.goal.level }
return self:NextStep()
end
local from = CopyTable(self.display)
local elapsed = 0
self.animator:SetScript("OnUpdate", function(_, delta)
elapsed = elapsed + delta
local progress = EaseOut(math.min(elapsed / ANIM_DURATION, 1))
for _, key in ipairs({ "xp", "quest", "rested" }) do
self.display[key] = from[key] + (step[key] - from[key]) * progress
end
self.display.level = step.level
self:Draw(self.display)
if progress >= 1 then self:NextStep() end
end)
end
function Bar:StopAnimation()
self.animator:SetScript("OnUpdate", nil)
self.steps, self.goal = nil, nil
end
function Bar:Refresh()
local f = self.frame
if not f then return end
if not ns.ShouldShow() then
f:Hide()
return
end
f:Show()
self:UpdateFills()
HideBlizzardBar()
local target = ComputeTarget()
local display = self.display
if not display or not XPForeverDB.animate or not f:IsVisible() then
self:StopAnimation()
self.display = target
self:Draw(target)
elseif target.level > display.level then
-- Level-up: fill to the end first, then start over to the new value.
self:Flash(display.xp, 1)
self:PlaySteps({ { xp = 1, quest = 1, rested = 1, level = display.level }, RESET_STEP, target })
elseif not SameTarget(target, self.goal or display) then
if target.xp > display.xp then self:Flash(display.xp, target.xp) end
self:PlaySteps({ target })
elseif not self.goal then
-- No change, but e.g. a new width: redraw the current state.
self:Draw(display)
end
self:RefreshText()
end
function Bar:RefreshText()
local f = self.frame
if not (f and f:IsShown()) then return end
local percent = state.xp / math.max(state.max, 1) * 100
self.percentText:SetText(ns.FormatPercent(percent) .. " %")
self.hoverText:SetText(ns.BuildText("bar"))
end
function Bar:ShowTooltip()
local tooltip = GameTooltip
local questColor, restedColor = ns.GetColor("colorQuest"), ns.GetColor("colorRested")
tooltip:SetOwner(self.frame, "ANCHOR_TOP")
tooltip:SetText(L.tooltipTitle)
if ns.IsQuestReady() then
tooltip:AddLine(Colorize(L.levelUpReady, questColor))
end
if IsResting() then
tooltip:AddLine(Colorize(L.restingNow, restedColor))
end
local xpText = string.format("%s / %s", ns.FormatNumber(state.xp), ns.FormatNumber(state.max))
tooltip:AddDoubleLine(L.tooltipXP, xpText, 1, 1, 1, 1, 1, 1)
tooltip:AddDoubleLine(L.tooltipRemaining, ns.FormatNumber(state.max - state.xp), 1, 1, 1, 1, 1, 1)
if state.questXP > 0 then
tooltip:AddDoubleLine(L.tooltipQuests:format(state.questCount), "+" .. ns.FormatNumber(state.questXP),
1, 1, 1, questColor:GetRGB())
end
if state.rested > 0 then
tooltip:AddDoubleLine(L.rested, "+" .. ns.FormatNumber(state.rested), 1, 1, 1, restedColor:GetRGB())
end
local gained, elapsed = ns.GetSessionStats()
tooltip:AddLine(" ")
local sessionText = string.format("+%s (%s)", ns.FormatNumber(gained), ns.FormatDuration(elapsed))
tooltip:AddDoubleLine(L.tooltipSession, sessionText, 1, 1, 1, 1, 1, 1)
local rate = ns.GetRate()
if rate then
tooltip:AddDoubleLine(L.perHour, ns.FormatNumber(rate * 3600), 1, 1, 1, 1, 1, 1)
end
local kills = ns.GetKillsToLevel()
if kills then
tooltip:AddDoubleLine(L.tooltipKills, "~" .. ns.FormatNumber(kills), 1, 1, 1, 1, 1, 1)
end
tooltip:AddLine(" ")
tooltip:AddLine(ns.ClickHint("LeftButton", nil, L.actionToggleInfo, L.hintToggleInfo), GRAY_FONT_COLOR:GetRGB())
tooltip:AddLine(ns.ClickHint("LeftButton", "CTRL", L.actionResetSession, L.hintResetSession),
GRAY_FONT_COLOR:GetRGB())
tooltip:AddLine(ns.ClickHint("RightButton", nil, L.actionOptions, L.hintOptions), GRAY_FONT_COLOR:GetRGB())
tooltip:AddLine(" ")
tooltip:AddLine(ns.BrandLine(), GRAY_FONT_COLOR:GetRGB())
tooltip:Show()
end