Repository navigation
Expand file tree
/
Copy pathui.lua
More file actions
executable file
·2242 lines (1981 loc) · 75.2 KB
/
Copy pathui.lua
File metadata and controls
executable file
·2242 lines (1981 loc) · 75.2 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
if not Cursive.superwow then
return
end
local L = AceLibrary("AceLocale-2.2"):new("Cursive")
local utils = Cursive.utils
local filter = Cursive.filter
-- Layout constant: reserved height for (hidden) title bar area
local TITLE_BAR_HEIGHT = 12
-- Local-cache frequently used globals (avoids repeated global table lookups in hot paths)
local GetTime = GetTime
local _RealUnitExists = UnitExists
local _RealUnitHealth = UnitHealth
local _RealUnitHealthMax = UnitHealthMax
local _RealUnitName = UnitName
local _RealUnitIsDead = UnitIsDead
local _RealUnitIsVisible = UnitIsVisible
local _RealUnitAffectingCombat = UnitAffectingCombat
local _RealGetRaidTargetIndex = GetRaidTargetIndex
-- v3.2.1: Test Overlay wrappers — intercept calls for fake GUIDs
-- v3.2.1: Test Overlay wrappers — intercept ALL calls for fake GUIDs (never fall through to real API)
local TEST_PREFIX = "CURSIVE_TEST_"
local function IsTestGuid(guid)
if not guid then return false end
return string.find(guid, TEST_PREFIX, 1, true) == 1
end
local function UnitExists(guid)
if IsTestGuid(guid) then
return CursiveTestOverlay_UnitExists(guid)
end
return _RealUnitExists(guid)
end
local function UnitHealth(guid)
if IsTestGuid(guid) then
return CursiveTestOverlay_UnitHealth(guid) or 0
end
return _RealUnitHealth(guid)
end
local function UnitHealthMax(guid)
if IsTestGuid(guid) then
return CursiveTestOverlay_UnitHealthMax(guid) or 1
end
return _RealUnitHealthMax(guid)
end
local function UnitName(guid)
if IsTestGuid(guid) then
return CursiveTestOverlay_UnitName(guid)
end
return _RealUnitName(guid)
end
local function UnitIsDead(guid)
if IsTestGuid(guid) then
return false
end
return _RealUnitIsDead(guid)
end
local function UnitIsVisible(guid)
if IsTestGuid(guid) then
return true
end
return _RealUnitIsVisible(guid)
end
local function UnitAffectingCombat(guid)
if IsTestGuid(guid) then
return true
end
return _RealUnitAffectingCombat(guid)
end
local function GetRaidTargetIndex(guid)
if IsTestGuid(guid) then
return CursiveTestOverlay_GetRaidTargetIndex(guid)
end
return _RealGetRaidTargetIndex(guid)
end
local _RealUnitIsPlayer = UnitIsPlayer
local function UnitIsPlayer(guid)
if IsTestGuid(guid) then
return false -- Test units are NPCs, not players
end
return _RealUnitIsPlayer(guid)
end
local UnitIsUnit = UnitIsUnit
local UnitDebuff = UnitDebuff
local UnitBuff = UnitBuff
local UnitClass = UnitClass
local SetRaidTargetIconTexture = SetRaidTargetIconTexture
local pairs = pairs
local ipairs = ipairs
local floor = math.floor
local tinsert = table.insert
local tsort = table.sort
local getn = table.getn
local ui = CreateFrame("Frame", "CursiveUI", UIParent)
ui.border = {
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 8,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
}
ui.background = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
tile = true, tileSize = 16, edgeSize = 8,
insets = { left = 0, right = 0, top = 0, bottom = 0 }
}
ui.rootBarFrame = nil
ui.targetIndicatorSize = 8
ui.padding = 1 -- default, overridden by config.debufficonspacing in UpdateFramesFromConfig
ui.row = 1
ui.col = 1
ui.maxBarsDisplayed = false
ui.numDisplayed = 0
local function GetBarFirstSectionWidth()
local config = Cursive.db.profile
local size = 1
if config.showraidicons then
size = size + config.raidiconsize
end
if config.showtargetindicator then
size = size + ui.targetIndicatorSize
end
if size > 0 then
size = size + ui.padding
end
return size
end
local function GetBarSecondSectionWidth()
local config = Cursive.db.profile
if config.showhealthbar == false and config.showunitname == false then
return 1
end
return config.healthwidth + ui.padding
end
local function GetBarThirdSectionWidth()
local config = Cursive.db.profile
return config.maxcurses * (config.curseiconsize + ui.padding)
end
local function GetBarOtherSideSectionWidth()
local config = Cursive.db.profile
if config.orderotherside == "none" then
return 0
end
return config.maxcurses * (config.curseiconsize + ui.padding)
end
local function GetBarWidth()
-- Other Side section is anchored opposite to the main bar — it does NOT add to the main width
return GetBarFirstSectionWidth() +
GetBarSecondSectionWidth() +
GetBarThirdSectionWidth()
end
local function UpdateRootBarFrame()
local config = Cursive.db.profile
if config.showbackdrop then
ui.rootBarFrame:SetBackdrop(ui.background)
else
ui.rootBarFrame:SetBackdrop(nil)
end
ui.rootBarFrame:EnableMouse(not config.clickthrough)
ui.rootBarFrame.pos = config.anchor .. config.x .. config.y .. config.scale
ui.rootBarFrame:ClearAllPoints()
ui.rootBarFrame:SetPoint(config.anchor, config.x, config.y)
ui.rootBarFrame:SetScale(config.scale)
ui.rootBarFrame:SetAlpha(config.opacity or 1)
ui.rootBarFrame.caption:SetFont(STANDARD_TEXT_FONT, Cursive.db.profile.textsize, "THINOUTLINE")
ui.rootBarFrame.caption:SetText(Cursive.db.profile.caption)
-- Title bar permanently hidden (v3.2.2)
ui.rootBarFrame.caption:Hide()
ui.rootBarFrame:SetWidth(config.maxcol * GetBarWidth())
-- Calculate height: title area + all rows + extra spacing
local title_size = TITLE_BAR_HEIGHT + config.spacing
local total_height = title_size + (config.maxrow * (config.height + config.spacing)) + config.spacing
ui.rootBarFrame:SetHeight(total_height)
end
local function CreateRoot()
local frame = CreateFrame("Frame", Cursive.db.profile.caption, UIParent)
ui.rootBarFrame = frame
frame.id = Cursive.db.profile.caption
frame:RegisterForDrag("LeftButton")
frame:SetMovable(true)
frame:SetScript("OnDragStart", function()
this.lock = true
this:StartMoving()
end)
frame:SetScript("OnDragStop", function()
-- convert to best anchor depending on position
local new_anchor = utils.GetBestAnchor(this)
local anchor, x, y = utils.ConvertFrameAnchor(this, new_anchor)
this:ClearAllPoints()
this:SetPoint(anchor, UIParent, anchor, x, y)
-- save new position
anchor, _, _, x, y = this:GetPoint()
Cursive.db.profile.anchor, Cursive.db.profile.x, Cursive.db.profile.y = anchor, x, y
-- stop drag
this:StopMovingOrSizing()
this.lock = false
this:ClearAllPoints()
this:SetPoint(anchor, x, y)
end)
-- create title text
frame.caption = frame:CreateFontString(nil, "HIGH", "GameFontWhite")
frame.caption:SetPoint("TOPLEFT", frame, "TOPLEFT", 10, -2)
frame.caption:SetTextColor(1, 1, 1, 1)
UpdateRootBarFrame()
frame:Show()
return frame
end
ui.unitFrames = {} -- holds all unitFrames for all columns/rows
Cursive.UpdateFramesFromConfig = function()
-- Update icon spacing from config
ui.padding = Cursive.db.profile.debufficonspacing or 1
for col, rows in pairs(ui.unitFrames) do
for row, unitFrame in pairs(rows) do
if unitFrame and unitFrame:IsShown() then
unitFrame:Hide()
end
end
end
if ui.rootBarFrame then
UpdateRootBarFrame()
end
-- after 3 seconds reset the unit frames so all changes are applied
Cursive:ScheduleEvent("resetUnitFrames", Cursive.ResetUnitFrames, 3)
end
Cursive.ResetUnitFrames = function()
-- hide all existing unit frames and clear guid associations
for col, rows in pairs(ui.unitFrames) do
for row, unitFrame in pairs(rows) do
if unitFrame then
unitFrame:Hide()
unitFrame.guid = nil
end
end
end
-- v4.0.4: Keep frame objects for reuse (avoid orphans)
-- ui.unitFrames = {} -- REMOVED: causes frame orphans
-- Reapply opacity after frame rebuild
if ui.rootBarFrame then
ui.rootBarFrame:SetAlpha(Cursive.db.profile.opacity or 1)
end
end
ui.BarEnter = function()
this.parent.hover = true
-- v3.2.1: Custom tooltip for test overlay GUIDs
if IsTestGuid(this.parent.guid) then
GameTooltip_SetDefaultAnchor(GameTooltip, this)
local tData = CursiveTestOverlay_UnitName and CursiveTestOverlay_UnitName(this.parent.guid)
local hp = CursiveTestOverlay_UnitHealth and CursiveTestOverlay_UnitHealth(this.parent.guid) or 0
local maxHp = CursiveTestOverlay_UnitHealthMax and CursiveTestOverlay_UnitHealthMax(this.parent.guid) or 1
GameTooltip:ClearLines()
GameTooltip:AddLine(tData or "Test Target", 1, 0.2, 0.2)
GameTooltip:AddLine("|cFFAAAAAA[Test Overlay]|r", 0.7, 0.7, 0.7)
GameTooltip:Show()
return
end
GameTooltip_SetDefaultAnchor(GameTooltip, this)
GameTooltip:SetUnit(this.parent.guid)
GameTooltip:Show()
end
ui.BarLeave = function()
this.parent.hover = false
GameTooltip:Hide()
end
-- Format armor values with k/m suffix (hoisted to file scope to avoid per-frame closure allocation)
local function FormatArmor(v)
local n = tonumber(v) or 0
local absN = math.abs(n)
local prefix = ""
if n < 0 then prefix = "-" end
if absN >= 1000000 then
return prefix .. floor(absN / 1000000) .. "m"
elseif absN >= 10000 then
return prefix .. floor(absN / 1000) .. "k"
end
return v
end
ui.BarUpdate = function()
if not this.guid or this.guid == 0 then
this:Hide()
return
end
if (this.tick or 1) > GetTime() then
return
else
this.tick = GetTime() + 0.05
end
-- update statusbar values if it exists
if this.healthBar then
this.healthBar:SetMinMaxValues(0, UnitHealthMax(this.guid))
this.healthBar:SetValue(UnitHealth(this.guid))
-- update health bar color
local hex, r, g, b, a = utils.GetUnitColor(this.guid)
this.healthBar:SetStatusBarColor(r, g, b, a)
-- update health bar border
if this.healthBar.border then
local isTargeted = not IsTestGuid(this.guid) and UnitIsUnit("target", this.guid)
if isTargeted then
-- White for current target only
this.healthBar.border:SetBackdropBorderColor(1, 1, 1, 1)
else
-- Black default
this.healthBar.border:SetBackdropBorderColor(0, 0, 0, 1)
end
end
-- update hover glow effect
if this.hoverGlow then
if this.hover then
-- Show all 4 glow edges
for _, glow in ipairs(this.hoverGlow) do
glow:Show()
end
else
-- Hide all 4 glow edges
for _, glow in ipairs(this.hoverGlow) do
glow:Hide()
end
end
end
end
-- v4.0.5: Out-of-range / line-of-sight stripe indicator
-- v4.0.6: Throttled to 500ms per GUID (range is cached in filter.lua, LOS cached here)
-- v4.1.1 FIX (Bug #2): UnitXP("inSight", ...) returns a BOOLEAN (true/false),
-- not a number. The previous check `los == 0` was never true — LoS-blocked
-- targets returned `false` which does not equal 0, so `inSight` stayed true
-- forever. Live-verified via ClaudeBridge on 2026-04-17: subcommand is
-- "inSight" (lowercase i), return type is boolean. Correct check: `los == false`.
-- Additionally: decouple LoS from inRange. A target behind a wall IN range should
-- still show as LoS-blocked (stripes). TestOverlay override runs before UnitXP.
if this.oorFrame then
if Cursive.db.profile.oorstripes then
-- LOS check throttled independently per bar
if not this._oorTick or this._oorTick < GetTime() then
this._oorTick = GetTime() + 0.25
-- v4.1.3: OOR stripes use SPELL-range (class max with talent buffer),
-- not filter.range (which is 120y for the "Within Range" filter).
-- These are distinct semantics: filter.range decides whether the mob
-- appears at all when the filter is on; stripes tell you whether you
-- can actually cast on it right now.
local inRange = Cursive.filter.inSpellRange(this.guid)
local inSight = true
-- v4.1.1: TestOverlay LoS override (nil = no override, real API runs)
if CursiveTestOverlay_IsBlockedLoS and CursiveTestOverlay_IsBlockedLoS(this.guid) then
inSight = false
elseif UnitXP then
local ok, los = pcall(UnitXP, "inSight", "player", this.guid)
if ok and los == false then inSight = false end
end
this._oorCached = inRange and inSight
end
if this._oorCached then
this.oorFrame:Hide()
else
this.oorFrame:Show()
end
else
this.oorFrame:Hide()
end
end
-- update caption text
local name = UnitName(this.guid)
if name and this.nameText then
-- v4.1.2 FIX: SetWidth was only called at CreateBar, so the "Name Length"
-- slider had no visual effect without /reload. Apply width on each update,
-- cached to avoid redundant SetWidth calls.
local newMaxW = Cursive.db.profile.namelength or 80
if this.nameText._lastMaxW ~= newMaxW then
this.nameText:SetWidth(newMaxW)
this.nameText._lastMaxW = newMaxW
end
this.nameText:SetText(name)
end
if this.hpText then
local hp = UnitHealth(this.guid)
if GetLocale() == "zhCN" then
if hp then
if hp >= 10000 then
hp = floor(hp / 1000) / 10 .. "万"
-- elseif hp >= 1000 then
-- hp = floor(hp / 100) / 10 .. "k"
end
end
else
-- convert hp: millions → "110m", thousands → "440k", rest → raw number
if hp then
if hp >= 1000000 then
hp = floor(hp / 1000000) .. "m"
elseif hp >= 10000 then
hp = floor(hp / 1000) .. "k"
end
end
end
if hp then
local hpStr = tostring(hp)
if this.hpText._lastVal ~= hpStr then
this.hpText._lastVal = hpStr
this.hpText:SetText(hpStr)
end
end
end
-- show raid icon if existing
if this.icon then
if GetRaidTargetIndex(this.guid) and Cursive.filter.alive(this.guid) then
SetRaidTargetIconTexture(this.icon, GetRaidTargetIndex(this.guid))
this.icon:Show()
else
this.icon:Hide()
end
end
-- v3.2.1: Update armor display (NPCs only, not players)
if this.armorFrame and Cursive.db.profile.armorStatusEnabled then
local curses = Cursive.curses
if curses and not UnitIsPlayer(this.guid) then
curses:UpdateArmorCache(this.guid)
local live, total, removed = curses:GetArmorData(this.guid)
if live then
local config = Cursive.db.profile
local structure = config.armorDisplayStructure or "live+removed"
local val1, val2
-- Determine which values to show
if structure == "live+total" then
val1 = tostring(live)
val2 = tostring(total)
elseif structure == "live+removed" then
val1 = tostring(removed)
val2 = tostring(live)
elseif structure == "total+removed" then
val1 = tostring(removed)
val2 = tostring(total)
elseif structure == "live" then
val1 = tostring(live)
val2 = nil
elseif structure == "total" then
val1 = tostring(total)
val2 = nil
elseif structure == "removed" then
val1 = tostring(removed)
val2 = nil
end
local iconPos = config.armorShowIcon or "left"
-- Determine color for live value (based on thirds of total)
local liveR, liveG, liveB = 1, 1, 1
if config.armorColorIndicator and total > 0 then
local ratio = live / total
if ratio > 0.66 then
liveR, liveG, liveB = 0.2, 1.0, 0.2 -- green (high armor)
elseif ratio > 0.33 then
liveR, liveG, liveB = 1.0, 1.0, 0.2 -- yellow (medium)
else
liveR, liveG, liveB = 1.0, 0.2, 0.2 -- red (low armor)
end
end
-- Format and assign text — Live colored, Total and "/" always white
local fVal1 = FormatArmor(val1)
local fVal2 = val2 and FormatArmor(val2) or nil
this.armorText1:SetText(fVal1)
if fVal2 then
if this.armorSep then
this.armorSep:SetText("/")
this.armorSep:Show()
end
this.armorText2:SetText(fVal2)
this.armorText2:Show()
else
if this.armorSep then this.armorSep:Hide() end
this.armorText2:SetText("")
this.armorText2:Hide()
end
-- Color: Live value gets colored, everything else white
if structure == "live+total" or structure == "live" then
this.armorText1:SetTextColor(liveR, liveG, liveB)
this.armorText2:SetTextColor(1, 1, 1)
elseif structure == "live+removed" or structure == "total+removed" then
-- Live/Total is val2 in these reversed structures
this.armorText1:SetTextColor(1, 1, 1)
if structure == "live+removed" then
this.armorText2:SetTextColor(liveR, liveG, liveB)
else
this.armorText2:SetTextColor(1, 1, 1)
end
else
this.armorText1:SetTextColor(1, 1, 1)
this.armorText2:SetTextColor(1, 1, 1)
end
if this.armorIcon then
if config.armorShowIcon ~= "none" then
this.armorIcon:Show()
else
this.armorIcon:Hide()
end
end
this.armorFrame:Show()
else
this.armorFrame:Hide()
end
else
-- Player target or no curses module — hide armor
this.armorFrame:Hide()
end
end
-- update target indicator
if this.target_left then
if not IsTestGuid(this.guid) and UnitIsUnit("target", this.guid) then
this.target_left:Show()
else
this.target_left:Hide()
end
end
end
ui.BarClick = function()
-- v3.2.1: Block targeting for test overlay GUIDs
if IsTestGuid(this.parent.guid) then return end
if arg1 == "LeftButton" then
TargetUnit(this.parent.guid)
elseif arg1 == "RightButton" then
TargetUnit(this.parent.guid)
if (not PlayerFrame.inCombat) then
AttackTarget()
end
end
end
-- ============================================================
-- v3.2: Debuff icon border helpers
-- ============================================================
local BORDER_COLORS = {
ownclass = { 0, 0.8, 0 }, -- green
ownraid = { 0.8, 0, 0 }, -- red
otherclass = { 0, 0.4, 0.8 }, -- blue
otherraid = { 0.6, 0, 0.8 }, -- purple
}
-- Class colors for border coloring (matches CursiveOptionsUI CLASS_COLORS)
-- Class colors at 0.9 for timer text — OUTLINE provides dark edge
local TIMER_CLASS_COLORS = {
Warrior = { 0.70, 0.55, 0.39 },
Rogue = { 0.90, 0.86, 0.37 },
Hunter = { 0.60, 0.75, 0.41 },
Mage = { 0.37, 0.72, 0.85 },
Warlock = { 0.52, 0.46, 0.71 },
Priest = { 0.90, 0.90, 0.90 },
Druid = { 0.90, 0.44, 0.04 },
Shaman = { 0.00, 0.40, 0.78 },
Paladin = { 0.86, 0.50, 0.66 },
Item = { 0.45, 0.45, 0.45 },
}
-- Class colors darkened (~70%) for thin borders — standard colors wash out on 1-2px lines
local BORDER_CLASS_COLORS = {
Warrior = { 0.55, 0.43, 0.30 },
Rogue = { 0.70, 0.67, 0.29 },
Hunter = { 0.47, 0.58, 0.32 },
Mage = { 0.29, 0.56, 0.66 },
Warlock = { 0.41, 0.36, 0.55 },
Priest = { 0.70, 0.70, 0.70 },
Druid = { 0.70, 0.34, 0.03 },
Shaman = { 0.00, 0.31, 0.61 },
Paladin = { 0.67, 0.39, 0.51 },
Item = { 0.30, 0.30, 0.30 },
}
-- Creates border textures on borderFrame itself.
-- Uses OVERLAY layer so they render over the icon but under FontStrings on parent.
local function CreateDebuffBorder(borderFrame)
local border = {}
border.top = borderFrame:CreateTexture(nil, "OVERLAY")
border.top:SetPoint("TOPLEFT", borderFrame, "TOPLEFT", 0, 0)
border.top:SetPoint("TOPRIGHT", borderFrame, "TOPRIGHT", 0, 0)
local bw = (Cursive.db and Cursive.db.profile and Cursive.db.profile.borderwidth) or 2
border.top:SetHeight(bw)
border.top:SetTexture(1, 1, 1, 1)
border.top:Hide()
border.bottom = borderFrame:CreateTexture(nil, "OVERLAY")
border.bottom:SetPoint("BOTTOMLEFT", borderFrame, "BOTTOMLEFT", 0, 0)
border.bottom:SetPoint("BOTTOMRIGHT", borderFrame, "BOTTOMRIGHT", 0, 0)
border.bottom:SetHeight(bw)
border.bottom:SetTexture(1, 1, 1, 1)
border.bottom:Hide()
border.left = borderFrame:CreateTexture(nil, "OVERLAY")
border.left:SetPoint("TOPLEFT", borderFrame, "TOPLEFT", 0, 0)
border.left:SetPoint("BOTTOMLEFT", borderFrame, "BOTTOMLEFT", 0, 0)
border.left:SetWidth(bw)
border.left:SetTexture(1, 1, 1, 1)
border.left:Hide()
border.right = borderFrame:CreateTexture(nil, "OVERLAY")
border.right:SetPoint("TOPRIGHT", borderFrame, "TOPRIGHT", 0, 0)
border.right:SetPoint("BOTTOMRIGHT", borderFrame, "BOTTOMRIGHT", 0, 0)
border.right:SetWidth(bw)
border.right:SetTexture(1, 1, 1, 1)
border.right:Hide()
return border
end
local function SetBorderColor(border, r, g, b)
local alpha = 0.85
if Cursive.db and Cursive.db.profile and Cursive.db.profile.borderopacity then
alpha = Cursive.db.profile.borderopacity / 100
end
border.top:SetVertexColor(r, g, b, alpha)
border.bottom:SetVertexColor(r, g, b, alpha)
border.left:SetVertexColor(r, g, b, alpha)
border.right:SetVertexColor(r, g, b, alpha)
border.top:Show()
border.bottom:Show()
border.left:Show()
border.right:Show()
end
local function HideBorder(border)
if border then
border.top:Hide()
border.bottom:Hide()
border.left:Hide()
border.right:Hide()
end
end
-- Determine border color for a debuff icon based on config and curse data
-- Returns r,g,b or nil if no border should be shown
-- Determine class color for timer text based on debuff source class
local function GetTimerClassColor(curseData)
if not curseData then return nil end
local debuffClass = nil
-- Try shared debuff metadata (spellID → debuffKey → class)
if curseData.spellID and Cursive.curses and Cursive.curses.sharedDebuffSpellLookup then
local debuffKey = Cursive.curses.sharedDebuffSpellLookup[curseData.spellID]
if debuffKey and Cursive.curses.sharedDebuffMeta[debuffKey] then
debuffClass = Cursive.curses.sharedDebuffMeta[debuffKey].class
end
end
-- Fallback for own debuffs not in shared debuffs: use player class
if not debuffClass and curseData.currentPlayer then
local _, playerClass = UnitClass("player")
if playerClass then
debuffClass = string.lower(playerClass)
end
end
if debuffClass then
local classKey = string.upper(string.sub(debuffClass, 1, 1)) .. string.sub(debuffClass, 2)
local cc = TIMER_CLASS_COLORS[classKey]
if cc then
return cc[1], cc[2], cc[3]
end
end
return nil
end
-- Hoisted helpers for GetDebuffBorderColor (avoids per-call closure allocation)
local function ResolveBorderMode(val)
if val == true then return "green" end
if not val or val == false or val == "off" then return "off" end
return val
end
local function ResolveBorderColor(mode, curseData)
if mode == "green" then return 0, 0.8, 0 end
if mode == "red" then return 0.8, 0, 0 end
if mode == "black" then return 0.1, 0.1, 0.1 end
if mode == "classcolor" then
local debuffClass = nil
if curseData.spellID and Cursive.curses and Cursive.curses.sharedDebuffSpellLookup then
local debuffKey = Cursive.curses.sharedDebuffSpellLookup[curseData.spellID]
if debuffKey and Cursive.curses.sharedDebuffMeta[debuffKey] then
debuffClass = Cursive.curses.sharedDebuffMeta[debuffKey].class
end
end
if not debuffClass then
local _, playerClass = UnitClass("player")
if playerClass then debuffClass = string.lower(playerClass) end
end
if debuffClass then
local classKey = string.upper(string.sub(debuffClass, 1, 1)) .. string.sub(debuffClass, 2)
local cc = BORDER_CLASS_COLORS[classKey]
if cc then return cc[1], cc[2], cc[3] end
end
return 0, 0.8, 0 -- fallback green
end
return nil
end
local function GetDebuffBorderColor(curseData, curseName, guid)
if not curseData or not curseName then return nil end
local config = Cursive.db.profile
if not config then return nil end
local ownclassMode = ResolveBorderMode(config.borderownclass)
local ownraidMode = ResolveBorderMode(config.borderownraid)
local otherclassMode = ResolveBorderMode(config.borderotherclass)
local otherraidMode = ResolveBorderMode(config.borderotherraid)
-- Fast exit if all borders are off
if ownclassMode == "off" and ownraidMode == "off" and otherclassMode == "off" and otherraidMode == "off" then
return nil
end
-- Normalize curseName: "winter's chill" → "winterschill" to match shareddebuffs keys
local normalized = Cursive.curses.nameToNormalized[curseName] or string.gsub(string.lower(curseName), "[%s']", "")
-- Determine ownership: currentPlayer for personal tracking, playerOwnedCasts for shared debuffs
local isOwn = (curseData.currentPlayer == true)
if not isOwn and guid and Cursive.curses and Cursive.curses.playerOwnedCasts then
local ownCasts = Cursive.curses.playerOwnedCasts[guid]
if ownCasts and ownCasts[normalized] then
local castTime = ownCasts[normalized]
if (GetTime() - castTime) < 600 then
isOwn = true
end
end
end
-- Determine if this is a raid debuff (exists in shareddebuffs config)
local isRaid = false
local sd = config.shareddebuffs
if sd then
if sd[normalized] ~= nil then
isRaid = true
elseif curseData.sharedDebuffKey and sd[curseData.sharedDebuffKey] ~= nil then
isRaid = true
end
end
-- Resolve border color based on ownership + raid status
local mode = "off"
if isOwn and isRaid then
mode = ownraidMode
elseif isOwn and (not isRaid) then
mode = ownclassMode
elseif (not isOwn) and isRaid then
mode = otherraidMode
elseif (not isOwn) and (not isRaid) then
mode = otherclassMode
end
if mode ~= "off" then
return ResolveBorderColor(mode, curseData)
end
return nil
end
-- v3.2.1: Create armor display elements (shield icon + text)
local function CreateArmorDisplay(unitFrame, parentSection, config)
local armorFrame = CreateFrame("Frame", nil, parentSection)
armorFrame:SetHeight(config.height)
armorFrame:SetWidth(80) -- will auto-adjust with text
armorFrame:EnableMouse(false)
-- Position: stored on frame for later anchoring (needs unitFrame.icon reference)
armorFrame._position = config.armorPosition
armorFrame._invertbars = config.invertbars
-- Shield icon
local shieldIcon = armorFrame:CreateTexture(nil, "OVERLAY")
shieldIcon:SetWidth(config.height - 2)
shieldIcon:SetHeight(config.height - 2)
shieldIcon:SetTexture("Interface\\Icons\\INV_Shield_06")
shieldIcon:SetTexCoord(0.05, 0.82, 0.05, 0.82)
unitFrame.armorIcon = shieldIcon
-- Armor text (primary value — fixed width, right-aligned for column alignment)
local fontSize = floor((config.armorTextSize or config.textsize or 10) * (config.fontscale or 1) + 0.5)
local armorText1 = armorFrame:CreateFontString(nil, "OVERLAY", "GameFontWhite")
armorText1:SetFont(STANDARD_TEXT_FONT, fontSize, "OUTLINE")
armorText1:SetJustifyH("RIGHT")
armorText1:SetWidth(36) -- fixed width for consistent "/" alignment
unitFrame.armorText1 = armorText1
-- Separator "/"
local armorSep = armorFrame:CreateFontString(nil, "OVERLAY", "GameFontWhite")
armorSep:SetFont(STANDARD_TEXT_FONT, fontSize, "OUTLINE")
armorSep:SetJustifyH("CENTER")
armorSep:SetTextColor(1, 1, 1)
armorSep:SetWidth(10)
unitFrame.armorSep = armorSep
-- Armor text (secondary value — left-aligned)
local armorText2 = armorFrame:CreateFontString(nil, "OVERLAY", "GameFontWhite")
armorText2:SetFont(STANDARD_TEXT_FONT, fontSize, "OUTLINE")
armorText2:SetJustifyH("LEFT")
armorText2:SetWidth(36)
unitFrame.armorText2 = armorText2
-- Position icon + text based on armorShowIcon setting
local iconPos = config.armorShowIcon or "left"
if iconPos == "none" then
shieldIcon:Hide()
armorText1:SetPoint("LEFT", armorFrame, "LEFT", -3, 0)
armorSep:SetPoint("LEFT", armorText1, "RIGHT", 0, 0)
armorText2:SetPoint("LEFT", armorSep, "RIGHT", 0, 0)
elseif iconPos == "left" then
shieldIcon:SetPoint("LEFT", armorFrame, "LEFT", -3, 0)
armorText1:SetPoint("LEFT", shieldIcon, "RIGHT", -3, 0)
armorSep:SetPoint("LEFT", armorText1, "RIGHT", 0, 0)
armorText2:SetPoint("LEFT", armorSep, "RIGHT", 0, 0)
elseif iconPos == "center" then
armorText1:SetPoint("LEFT", armorFrame, "LEFT", -3, 0)
shieldIcon:SetPoint("LEFT", armorText1, "RIGHT", 3, 0)
armorText2:SetPoint("LEFT", shieldIcon, "RIGHT", 3, 0)
armorSep:Hide() -- icon replaces separator
elseif iconPos == "right" then
armorText1:SetPoint("LEFT", armorFrame, "LEFT", -3, 0)
armorSep:SetPoint("LEFT", armorText1, "RIGHT", 0, 0)
armorText2:SetPoint("LEFT", armorSep, "RIGHT", 0, 0)
shieldIcon:SetPoint("LEFT", armorText2, "RIGHT", -4, 0) -- 4px gap to text (was 0)
end
armorFrame:Hide()
unitFrame.armorFrame = armorFrame
end
local function CreateBarFirstSection(unitFrame, guid)
local config = Cursive.db.profile
local firstSection = CreateFrame("Frame", "Cursive1stSection", unitFrame)
if config.invertbars then
-- When inverted, position relative to second section (rightmost)
firstSection:SetPoint("LEFT", unitFrame.secondSection, "RIGHT", 0, 0)
else
-- Normal positioning (leftmost)
firstSection:SetPoint("LEFT", unitFrame, "LEFT", 0, 0)
end
firstSection:SetWidth(GetBarFirstSectionWidth())
firstSection:SetHeight(config.height)
firstSection:EnableMouse(false)
unitFrame.firstSection = firstSection
-- create target indicator
if config.showtargetindicator then
local targetLeft = firstSection:CreateTexture(nil, "OVERLAY")
targetLeft:SetWidth(ui.targetIndicatorSize)
targetLeft:SetHeight(8)
if config.invertbars then
targetLeft:SetPoint("RIGHT", firstSection, "RIGHT", 0, 0)
targetLeft:SetTexture("Interface\\AddOns\\Cursive\\img\\target-right")
else
targetLeft:SetPoint("LEFT", unitFrame, "LEFT", 0, 0)
targetLeft:SetTexture("Interface\\AddOns\\Cursive\\img\\target-left")
end
targetLeft:Hide()
unitFrame.target_left = targetLeft
end
-- create raid icon textures
if config.showraidicons then
local icon = firstSection:CreateTexture(nil, "OVERLAY")
icon:SetWidth(config.raidiconsize)
icon:SetHeight(config.raidiconsize)
if config.invertbars then
icon:SetPoint("LEFT", firstSection, "LEFT", 2, 0)
else
icon:SetPoint("RIGHT", firstSection, "RIGHT", -2, 0)
end
icon:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
icon:Hide()
unitFrame.icon = icon
end
-- v3.2.1: Create armor display elements (position "default" = near raid icon)
if config.armorStatusEnabled and config.armorPosition == "default" then
CreateArmorDisplay(unitFrame, firstSection, config)
-- Anchor armor frame relative to raid icon or health bar
if unitFrame.armorFrame then
unitFrame.armorFrame:ClearAllPoints()
local gap = 21 -- 3px base + 18px extra spacing
local xOff = config.armorPositionOffset or 0
if unitFrame.icon and config.showraidicons then
-- Raid icon visible: anchor to icon
if config.invertbars then
unitFrame.armorFrame:SetPoint("LEFT", unitFrame.icon, "RIGHT", gap + xOff, 0)
else
unitFrame.armorFrame:SetPoint("RIGHT", unitFrame.icon, "LEFT", -gap + xOff, 0)
end
else
-- No raid icon: anchor to section edge
if config.invertbars then
unitFrame.armorFrame:SetPoint("LEFT", firstSection, "LEFT", gap + xOff, 0)
else
unitFrame.armorFrame:SetPoint("RIGHT", firstSection, "RIGHT", -gap + xOff, 0)
end
end
end
end
end
local function CreateBarSecondSection(unitFrame, guid)
local config = Cursive.db.profile
local secondSection = CreateFrame("Button", "Cursive2ndSection", unitFrame)
if config.invertbars then
-- When inverted, position relative to third section (which is created first)
secondSection:SetPoint("LEFT", unitFrame.thirdSection, "RIGHT", 0, 0)
else
-- Normal positioning relative to first section
secondSection:SetPoint("LEFT", unitFrame.firstSection, "RIGHT", 0, 0)
end
secondSection:SetWidth(GetBarSecondSectionWidth())
secondSection:SetHeight(config.height)
unitFrame.secondSection = secondSection
secondSection.parent = unitFrame
secondSection:RegisterForClicks("LeftButtonUp", "RightButtonUp")
secondSection:SetScript("OnClick", ui.BarClick)
secondSection:SetScript("OnEnter", ui.BarEnter)
secondSection:SetScript("OnLeave", ui.BarLeave)
-- create health bar
if config.showhealthbar then
local healthBar = CreateFrame("StatusBar", "CursiveHealthBar", secondSection)
healthBar:SetStatusBarTexture(config.bartexture)
healthBar:SetStatusBarColor(1, .8, .2, 1)
healthBar:SetMinMaxValues(0, 100)
healthBar:SetValue(20)
healthBar:SetPoint("LEFT", secondSection, "LEFT", ui.padding, 0)
healthBar:SetWidth(config.healthwidth)
healthBar:SetHeight(config.height)
unitFrame.healthBar = healthBar
local hp = healthBar:CreateFontString(nil, "HIGH", "GameFontWhite")