-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUI.lua
More file actions
645 lines (575 loc) · 25.4 KB
/
UI.lua
File metadata and controls
645 lines (575 loc) · 25.4 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
local addonName, ns = ...
ns.ui = {}
local FRAME_WIDTH = 300
local FRAME_HEIGHT_BASE = 494 -- no extras (no anti-crit, no personal CDs)
local FRAME_HEIGHT_EXTENDED = 560 -- worst case: anti-crit header (~18) + personal CDs (~46)
local FRAME_HEIGHT = FRAME_HEIGHT_BASE -- initial; adjusted at render time
local PADDING = 14
local ROW_HEIGHT = 20
local BUFF_ROW_H = 22
local COLOR_GREEN = { 0.20, 0.85, 0.30 }
local COLOR_RED = { 0.90, 0.25, 0.25 }
local COLOR_GOLD = { 0.85, 0.70, 0.30 }
local COLOR_GREY = { 0.55, 0.55, 0.55 }
local COLOR_MUTED_LABEL = { 0.78, 0.78, 0.78 }
local function setColor(fs, rgb)
fs:SetTextColor(rgb[1], rgb[2], rgb[3])
end
local function formatPct(v)
return string.format("%.2f%%", v or 0)
end
local function shouldCatchOutsideClicks()
local db = UncrushableHelperDB
return db and db.global and db.global.closeOnOutsideClick == true
end
-- LibDataBroker + LibDBIcon trigger. Both libs are embedded in every
-- packaged build via embeds.xml, so we can assume LibStub is available.
local ldb = LibStub and LibStub("LibDataBroker-1.1", true)
local icon = LibStub and LibStub("LibDBIcon-1.0", true)
local dataObject
if ldb then
dataObject = ldb:NewDataObject("UncrushableHelper", {
type = "launcher",
text = "UH",
icon = "Interface\\Icons\\Ability_Warrior_ShieldMastery",
OnClick = function(_, btn)
if btn == "RightButton" then
if ns.OpenSettings then ns:OpenSettings() end
else
ns:ToggleMain()
end
end,
OnTooltipShow = function(tt)
tt:AddLine("Uncrushable Helper")
local snap = ns.state.snapshot
if snap and snap.mode == "block" then
local status = snap.isUncrushable and "|cff33ff55UNCRUSHABLE|r" or "|cffff5555CRUSHABLE|r"
tt:AddDoubleLine("Total", formatPct(snap.total), 1, 1, 1, 1, 1, 1)
tt:AddLine(status)
end
tt:AddLine("Left-click: open/close", 1, 1, 1)
tt:AddLine("Right-click: settings", 1, 1, 1)
tt:AddLine("/uh debug · /uh reset", 0.7, 0.7, 0.7)
end,
})
end
local ldbRegisterFrame = CreateFrame("Frame")
ldbRegisterFrame:RegisterEvent("PLAYER_LOGIN")
ldbRegisterFrame:SetScript("OnEvent", function(self)
UncrushableHelperPerCharDB = UncrushableHelperPerCharDB or {}
UncrushableHelperPerCharDB.minimap = UncrushableHelperPerCharDB.minimap or {}
if icon and dataObject then
if not icon:IsRegistered("UncrushableHelper") then
icon:Register("UncrushableHelper", dataObject, UncrushableHelperPerCharDB.minimap)
end
end
self:UnregisterAllEvents()
end)
local mainFrame
local header, titleFS, closeBtn
local totalFS, statusFS, subtitleFS
local titleHoverFrame
local breakdown = {}
local antiCritSection
local buffRows = {}
local personalCDRows = {}
local buffsHeaderFS
local personalCDsHeaderFS
local footerFS
local outsideCatcher
local function setFramePosition(f)
local point = UncrushableHelperPerCharDB
and UncrushableHelperPerCharDB.mainFrame
and UncrushableHelperPerCharDB.mainFrame.point
f:ClearAllPoints()
if point and point[1] then
f:SetPoint(point[1], UIParent, point[3] or point[1], point[4] or 0, point[5] or 0)
else
f:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
end
end
local function persistFramePosition(f)
UncrushableHelperPerCharDB.mainFrame = UncrushableHelperPerCharDB.mainFrame or {}
local point, _, relPoint, x, y = f:GetPoint()
UncrushableHelperPerCharDB.mainFrame.point = { point, "UIParent", relPoint, x, y }
end
local function buildOutsideCatcher()
if outsideCatcher then return end
outsideCatcher = CreateFrame("Frame", nil, UIParent)
outsideCatcher:SetAllPoints(UIParent)
outsideCatcher:SetFrameStrata("MEDIUM")
outsideCatcher:EnableMouse(true)
outsideCatcher:SetScript("OnMouseDown", function() ns:HideMain() end)
outsideCatcher:Hide()
end
local function showRowTooltip(self)
local d = self.tooltipData
if not d then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(d.label, 1, 0.82, 0)
GameTooltip:AddDoubleLine("Live:", string.format("%.2f%%", d.live), 1, 1, 1, 1, 1, 1)
if d.delta and d.delta > 0 then
GameTooltip:AddDoubleLine("Planned buffs:", string.format("+%.2f%%", d.delta), 1, 1, 1, 0.45, 0.70, 1.0)
GameTooltip:AddDoubleLine("Projected:", string.format("%.2f%%", d.projected), 1, 1, 1, 0.20, 0.85, 0.30)
end
GameTooltip:Show()
end
local function showTitleTooltip(self)
local d = self.tooltipData
if not d then return end
GameTooltip:SetOwner(self, "ANCHOR_BOTTOM")
GameTooltip:SetText(d.title or "Avoidance", 1, 0.82, 0)
GameTooltip:AddDoubleLine("Live:", string.format("%.2f%%", d.live or 0), 1, 1, 1, 1, 1, 1)
if d.delta and d.delta > 0 then
GameTooltip:AddDoubleLine("Planned buffs:", string.format("+%.2f%%", d.delta), 1, 1, 1, 0.45, 0.70, 1.0)
GameTooltip:AddDoubleLine("Projected:", string.format("%.2f%%", d.projected or 0), 1, 1, 1, 0.20, 0.85, 0.30)
end
if d.liveVerdict then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Live: " .. d.liveVerdict, 0.75, 0.75, 0.75, true)
end
GameTooltip:Show()
end
local function hideTooltip()
GameTooltip:Hide()
end
local function showAntiCritTooltip(self)
local d = self.tooltipData
if not d then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText("Anti-crit reduction sources", 1, 0.82, 0)
GameTooltip:AddDoubleLine(
string.format("Defense (%d above 350)", d.defenseAbove350),
string.format("-%.2f%%", d.fromDefense),
1, 1, 1, 1, 1, 1)
if d.fromTalents and d.fromTalents > 0 then
GameTooltip:AddDoubleLine("Survival of the Fittest",
string.format("-%.2f%%", d.fromTalents),
1, 1, 1, 1, 1, 1)
end
GameTooltip:AddDoubleLine(
string.format("Resilience (%d rating)", d.resilienceRating),
string.format("-%.2f%%", d.fromResilience),
1, 1, 1, 1, 1, 1)
GameTooltip:AddLine(" ")
GameTooltip:AddDoubleLine("Total reduction:",
string.format("-%.2f%%", d.total),
1, 1, 1, 0.20, 0.85, 0.30)
GameTooltip:AddDoubleLine("Boss crit chance (cap):",
string.format("%.2f%%", d.target),
1, 1, 1, 1, 1, 1)
GameTooltip:Show()
end
local function makeRow(parent, yOffset, label)
local row = CreateFrame("Frame", nil, parent)
row:SetSize(FRAME_WIDTH - 2 * PADDING, ROW_HEIGHT)
row:SetPoint("TOPLEFT", parent, "TOPLEFT", PADDING, yOffset)
row:EnableMouse(true)
row:SetScript("OnEnter", showRowTooltip)
row:SetScript("OnLeave", hideTooltip)
local left = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
left:SetPoint("LEFT", row, "LEFT", 0, 0)
left:SetText(label)
setColor(left, COLOR_MUTED_LABEL)
local right = row:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
right:SetPoint("RIGHT", row, "RIGHT", 0, 0)
right:SetJustifyH("RIGHT")
return { frame = row, label = left, value = right }
end
local function buildBuffRow(parent, index)
local row = CreateFrame("Frame", nil, parent)
row:SetSize(FRAME_WIDTH - 2 * PADDING, BUFF_ROW_H)
row:EnableMouse(true)
local check = CreateFrame("CheckButton", nil, row, "UICheckButtonTemplate")
check:SetSize(20, 20)
check:SetPoint("LEFT", row, "LEFT", 0, 0)
local text = row:CreateFontString(nil, "OVERLAY", "GameFontNormal")
text:SetPoint("LEFT", check, "RIGHT", 4, 0)
text:SetPoint("RIGHT", row, "RIGHT", 0, 0)
text:SetJustifyH("LEFT")
row.check = check
row.text = text
return row
end
local function buildMainFrame()
if mainFrame then return mainFrame end
mainFrame = CreateFrame(
"Frame",
"UHMainFrame",
UIParent,
BackdropTemplateMixin and "BackdropTemplate" or nil
)
mainFrame:SetSize(FRAME_WIDTH, FRAME_HEIGHT)
mainFrame:SetFrameStrata("HIGH")
mainFrame:SetMovable(true)
mainFrame:EnableMouse(true)
mainFrame:RegisterForDrag("LeftButton")
mainFrame:SetScript("OnDragStart", mainFrame.StartMoving)
mainFrame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
persistFramePosition(self)
end)
mainFrame:SetClampedToScreen(true)
if mainFrame.SetBackdrop then
mainFrame:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 8,
edgeSize = 12,
})
if mainFrame.SetBackdropColor then
mainFrame:SetBackdropColor(0.07, 0.07, 0.09, 0.92)
end
if mainFrame.SetBackdropBorderColor then
mainFrame:SetBackdropBorderColor(0.78, 0.64, 0.30, 0.95)
end
end
-- Header
header = CreateFrame("Frame", nil, mainFrame)
header:SetPoint("TOPLEFT", mainFrame, "TOPLEFT", 0, 0)
header:SetPoint("TOPRIGHT", mainFrame, "TOPRIGHT", 0, 0)
header:SetHeight(30)
titleFS = header:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
titleFS:SetPoint("LEFT", header, "LEFT", PADDING, 0)
titleFS:SetText("Uncrushable Helper")
closeBtn = CreateFrame("Button", nil, header, "UIPanelCloseButton")
closeBtn:SetPoint("RIGHT", header, "RIGHT", -4, 0)
closeBtn:SetScript("OnClick", function() ns:HideMain() end)
-- Static target label. The addon always calculates against a +3 raid
-- boss (the only TBC target where crushing blows exist, and therefore
-- the only scenario where the 102.4% cap is meaningful). A previous
-- iteration exposed this as a dropdown with +0/+1/+2/+3 options, but
-- the selector added complexity without changing the addon's core
-- purpose — everything else is just informational. Kept as a passive
-- label so users immediately see what context the numbers reflect.
local targetLabel = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
targetLabel:SetPoint("TOP", header, "BOTTOM", 0, -6)
targetLabel:SetText("Target: Raid boss (+3)")
-- Big total
totalFS = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalHuge")
totalFS:SetPoint("TOP", targetLabel, "BOTTOM", 0, -2)
totalFS:SetText("--")
statusFS = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
statusFS:SetPoint("TOP", totalFS, "BOTTOM", 0, -4)
statusFS:SetText("")
-- "Including N planned buffs" — one-line blue hint when the primary
-- number reflects planned-buff simulation. Empty when nothing planned.
-- The live value (and its verdict) is intentionally NOT shown inline
-- here — it lives in the title-area hover tooltip to keep the header
-- uncluttered.
subtitleFS = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
subtitleFS:SetPoint("TOP", statusFS, "BOTTOM", 0, -2)
subtitleFS:SetText("")
-- Breakdown rows (Miss/Dodge/Parry/Block). yStart accounts for the
-- dropdown + big total + status + simulated line stack above.
local yStart = -160
breakdown.miss = makeRow(mainFrame, yStart, "Miss")
breakdown.dodge = makeRow(mainFrame, yStart - ROW_HEIGHT - 2, "Dodge")
breakdown.parry = makeRow(mainFrame, yStart - 2*(ROW_HEIGHT+2), "Parry")
breakdown.block = makeRow(mainFrame, yStart - 3*(ROW_HEIGHT+2), "Block")
-- Anti-crit cap section. Shown for any tank-shaped character (druid or
-- block-mode warrior/paladin). Renders a single header line with the
-- goal status; the per-source breakdown (defense / SotF / resilience)
-- lives in a hover tooltip to keep the main window compact. Hidden in
-- no-verdict mode.
antiCritSection = CreateFrame("Frame", nil, mainFrame)
antiCritSection:SetSize(FRAME_WIDTH - 2 * PADDING, 0)
antiCritSection:SetPoint("TOPLEFT", breakdown.block.frame, "BOTTOMLEFT", 0, -6)
antiCritSection:EnableMouse(true)
antiCritSection:SetScript("OnEnter", showAntiCritTooltip)
antiCritSection:SetScript("OnLeave", hideTooltip)
antiCritSection.headerFS = antiCritSection:CreateFontString(nil, "OVERLAY", "GameFontNormal")
antiCritSection.headerFS:SetPoint("TOPLEFT", antiCritSection, "TOPLEFT", 0, 0)
antiCritSection.headerFS:SetJustifyH("LEFT")
antiCritSection:Hide()
-- Buffs section header. Anchored below antiCritSection so its vertical
-- position flows with whatever the section's current height is — we
-- don't need to branch on class or mode here; the section sets height
-- to 0 when there's no anti-crit content, collapsing this back to a
-- minimal gap below the breakdown rows.
buffsHeaderFS = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
buffsHeaderFS:SetPoint("TOPLEFT", antiCritSection, "BOTTOMLEFT", 0, -10)
buffsHeaderFS:SetText("Raid buffs — check = active · click to plan")
setColor(buffsHeaderFS, COLOR_MUTED_LABEL)
-- Buff rows (built lazily from trackedAurasOrder)
if ns.trackedAurasOrder then
for i, key in ipairs(ns.trackedAurasOrder) do
local row = buildBuffRow(mainFrame, i)
row:SetPoint("TOPLEFT", buffsHeaderFS, "BOTTOMLEFT", 0, -(i - 1) * BUFF_ROW_H - 4)
row.check:SetScript("OnClick", function(self)
if ns.aura:IsActive(key) then
-- Auto-detected buffs can't be toggled off manually; snap back.
self:SetChecked(true)
return
end
local value = ns.aura:TogglePlanned(key)
self:SetChecked(value)
-- Toggling planned changes the simulated total — re-render
-- synchronously so the UI reflects the new projection
-- immediately, without waiting for the next event tick.
if ns.Publish then ns:Publish() end
end)
buffRows[key] = row
end
end
-- Personal cooldowns section — class-gated. Only built if the player's
-- class has at least one matching entry (Holy Shield for paladins,
-- Shield Block for warriors). Visibility of the section is further
-- gated on `mode == "block"` at render time: a paladin without a
-- shield gets the frame sized for the base layout and the section
-- stays hidden.
local classFile = ns.state and ns.state.classFile
local personalRowsData = ns.aura and ns.aura.ListPersonalCDsForUI
and ns.aura:ListPersonalCDsForUI(classFile)
or {}
if #personalRowsData > 0 then
personalCDsHeaderFS = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
local lastRaidKey = ns.trackedAurasOrder[#ns.trackedAurasOrder]
local lastRaidRow = buffRows[lastRaidKey]
personalCDsHeaderFS:SetPoint("TOPLEFT", lastRaidRow, "BOTTOMLEFT", 0, -10)
personalCDsHeaderFS:SetText("Personal cooldowns — check = active · click to plan")
setColor(personalCDsHeaderFS, COLOR_MUTED_LABEL)
for i, rowData in ipairs(personalRowsData) do
local key = rowData.key
local row = buildBuffRow(mainFrame, i)
row:SetPoint("TOPLEFT", personalCDsHeaderFS, "BOTTOMLEFT", 0, -(i - 1) * BUFF_ROW_H - 4)
row.check:SetScript("OnClick", function(self)
if ns.aura:IsActive(key) then
self:SetChecked(true)
return
end
local value = ns.aura:TogglePlanned(key)
self:SetChecked(value)
if ns.Publish then ns:Publish() end
end)
personalCDRows[key] = row
end
end
footerFS = mainFrame:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
footerFS:SetPoint("BOTTOM", mainFrame, "BOTTOM", 0, 8)
footerFS:SetText("/uh toggle · /uh config · /uh debug")
-- Invisible hover region covering the title block (big total + status
-- + subtitle + live line). Hovering it surfaces a GameTooltip with the
-- base/planned/projected breakdown, the same way per-row hover does.
-- The frame is created AFTER all four fontstrings exist so we can
-- anchor it to them.
titleHoverFrame = CreateFrame("Frame", nil, mainFrame)
titleHoverFrame:SetPoint("TOPLEFT", totalFS, "TOPLEFT", -40, 4)
titleHoverFrame:SetPoint("BOTTOMRIGHT", subtitleFS, "BOTTOMRIGHT", 40, -2)
titleHoverFrame:EnableMouse(true)
titleHoverFrame:SetScript("OnEnter", showTitleTooltip)
titleHoverFrame:SetScript("OnLeave", hideTooltip)
-- ESC-to-close support.
tinsert(UISpecialFrames, "UHMainFrame")
mainFrame:SetScript("OnHide", function()
if UncrushableHelperPerCharDB and UncrushableHelperPerCharDB.mainFrame then
UncrushableHelperPerCharDB.mainFrame.shown = false
end
if outsideCatcher then outsideCatcher:Hide() end
end)
setFramePosition(mainFrame)
mainFrame:Hide()
return mainFrame
end
local function applySnapshotToFrame(snap)
if not snap then return end
local sim = snap.simulated or { delta = { count = 0, miss = 0, dodge = 0, parry = 0, block = 0 }, total = snap.total or 0 }
local delta = sim.delta or { count = 0, miss = 0, dodge = 0, parry = 0, block = 0 }
local plannedCount = delta.count or 0
local hasPlanned = plannedCount > 0
local BLUE = { 0.45, 0.70, 1.0 }
-- Primary display is the projected value. When plannedCount = 0 the
-- projected equals the live value, so this collapses naturally to the
-- old behavior for characters without planned buffs toggled.
totalFS:SetText(formatPct(sim.total))
if snap.mode == "block" then
if sim.isUncrushable then
setColor(totalFS, COLOR_GREEN)
setColor(statusFS, COLOR_GREEN)
statusFS:SetText("UNCRUSHABLE")
else
setColor(totalFS, COLOR_RED)
setColor(statusFS, COLOR_RED)
statusFS:SetText(string.format("CRUSHABLE — short by %s", formatPct(sim.shortBy or 0)))
end
elseif snap.mode == "druid-special" then
setColor(totalFS, COLOR_GOLD)
setColor(statusFS, COLOR_GOLD)
statusFS:SetText("N/A — Druid (no block on table)")
else
setColor(totalFS, COLOR_GOLD)
setColor(statusFS, COLOR_GOLD)
statusFS:SetText("No shield — informational only")
end
-- Subtitle "Including N planned buffs" + live line. Only when there's
-- a planned buff whose effect isn't already baked into the live stats.
if hasPlanned then
local buffsLbl = plannedCount == 1 and "buff" or "buffs"
subtitleFS:SetText(string.format("Including %d planned %s", plannedCount, buffsLbl))
setColor(subtitleFS, BLUE)
else
subtitleFS:SetText("")
end
-- Breakdown: rows show projected values. When plannedCount = 0 the
-- projected equals live; when N > 0 each row reflects the post-buff
-- state. Tooltip on hover reveals the base/delta/projected split.
local function projectedFor(key)
return (snap[key] or 0) + (delta[key] or 0)
end
-- Paint the value blue when a planned buff contributes to this
-- component, so "which stat is getting a projection bump" is
-- readable at a glance without hovering for the tooltip.
local function paintRow(row, key, applicable)
if applicable == false then
row.value:SetText("n/a")
setColor(row.label, COLOR_GREY)
setColor(row.value, COLOR_GREY)
return
end
row.value:SetText(formatPct(projectedFor(key)))
setColor(row.label, COLOR_MUTED_LABEL)
local d = delta[key] or 0
if d > 0.005 then
setColor(row.value, BLUE)
else
setColor(row.value, { 1, 1, 1 })
end
end
paintRow(breakdown.miss, "miss", true)
paintRow(breakdown.dodge, "dodge", true)
paintRow(breakdown.parry, "parry", true)
paintRow(breakdown.block, "block", snap.components.block.applicable)
-- Per-row tooltip payload. Consumed by showRowTooltip on hover.
breakdown.miss.frame.tooltipData = { label = "Miss", live = snap.miss or 0, delta = delta.miss or 0, projected = projectedFor("miss") }
breakdown.dodge.frame.tooltipData = { label = "Dodge", live = snap.dodge or 0, delta = delta.dodge or 0, projected = projectedFor("dodge") }
breakdown.parry.frame.tooltipData = { label = "Parry", live = snap.parry or 0, delta = delta.parry or 0, projected = projectedFor("parry") }
if snap.components.block.applicable then
breakdown.block.frame.tooltipData = { label = "Block", live = snap.block or 0, delta = delta.block or 0, projected = projectedFor("block") }
else
breakdown.block.frame.tooltipData = nil
end
-- Title hover tooltip payload: aggregate across all four components.
if titleHoverFrame then
local titleDelta = (delta.miss or 0) + (delta.dodge or 0) + (delta.parry or 0) + (delta.block or 0)
local liveVerdict
if hasPlanned and snap.mode == "block" then
liveVerdict = snap.isUncrushable
and "UNCRUSHABLE"
or string.format("CRUSHABLE — short by %s", formatPct(snap.shortBy or 0))
end
titleHoverFrame.tooltipData = {
title = "Avoidance vs raid boss (+3)",
live = snap.total or 0,
delta = titleDelta,
projected = sim.total or 0,
liveVerdict = liveVerdict,
}
end
-- Personal-cooldowns section visibility. Rows only apply to shield-
-- wearing tanks; hide them when the player isn't in block mode.
local showPersonalCDs = personalCDsHeaderFS ~= nil and snap.mode == "block"
if personalCDsHeaderFS then
if showPersonalCDs then
personalCDsHeaderFS:Show()
for _, row in pairs(personalCDRows) do row:Show() end
else
personalCDsHeaderFS:Hide()
for _, row in pairs(personalCDRows) do row:Hide() end
end
end
-- Anti-crit section. One header line; the per-source breakdown lives
-- in the GameTooltip on hover (set up via tooltipData).
if snap.antiCrit then
local ac = snap.antiCrit
antiCritSection:Show()
local statusTag = ac.ok
and " |cff33ff55OK|r"
or string.format(" |cffff5555short by %s|r", formatPct(ac.shortBy))
antiCritSection.headerFS:SetText(string.format(
"Anti-crit goal: %s needed%s",
formatPct(ac.target), statusTag))
setColor(antiCritSection.headerFS, ac.ok and COLOR_GREEN or COLOR_RED)
antiCritSection.tooltipData = {
target = ac.target,
defenseAbove350 = math.max(0, (snap.defenseSkill or 0) - 350),
fromDefense = ac.fromDefense,
fromTalents = ac.fromTalents,
resilienceRating = ac.resilienceRating or 0,
fromResilience = ac.fromResilience,
total = ac.total,
}
antiCritSection:SetHeight(18)
else
antiCritSection:Hide()
antiCritSection:SetHeight(0)
antiCritSection.tooltipData = nil
end
-- Frame height. Extended when EITHER personal cooldowns are visible
-- OR the anti-crit section is visible. Both modes (block and
-- druid-special) populate anti-crit, so this also covers druids;
-- block-mode tanks get both sections stacked, so the extended height
-- needs to fit anti-crit (~90px) + personal CDs (~46px).
local wantsExtended = showPersonalCDs or snap.antiCrit ~= nil
local targetHeight = wantsExtended and FRAME_HEIGHT_EXTENDED or FRAME_HEIGHT_BASE
if mainFrame:GetHeight() ~= targetHeight then
mainFrame:SetHeight(targetHeight)
end
end
local function refreshBuffRowTable(rowTable)
for key, row in pairs(rowTable) do
local isActive = ns.aura:IsActive(key)
local isPlanned = ns.aura:IsPlanned(key)
local label = ns.trackedAurasLabels[key] or key
row.check:SetChecked(isActive or isPlanned)
if isActive then
setColor(row.text, COLOR_GREEN)
row.text:SetText(label .. " (active)")
elseif isPlanned then
setColor(row.text, { 0.45, 0.70, 1.0 })
row.text:SetText(label .. " (planned)")
else
setColor(row.text, COLOR_MUTED_LABEL)
row.text:SetText(label)
end
end
end
local function refreshBuffRows()
if not mainFrame then return end
refreshBuffRowTable(buffRows)
refreshBuffRowTable(personalCDRows)
end
function ns.ui:OnSnapshotChanged(snap)
if not mainFrame then return end
applySnapshotToFrame(snap)
refreshBuffRows()
end
function ns.ui:RefreshBuffRows()
refreshBuffRows()
end
function ns.ui:ResetPosition()
if not mainFrame then return end
setFramePosition(mainFrame)
end
function ns:ShowMain()
local f = buildMainFrame()
if ns.state.snapshot then applySnapshotToFrame(ns.state.snapshot) end
refreshBuffRows()
f:Show()
if UncrushableHelperPerCharDB and UncrushableHelperPerCharDB.mainFrame then
UncrushableHelperPerCharDB.mainFrame.shown = true
end
if shouldCatchOutsideClicks() then
buildOutsideCatcher()
outsideCatcher:Show()
end
end
function ns:HideMain()
if mainFrame then mainFrame:Hide() end
end
function ns:ToggleMain()
if mainFrame and mainFrame:IsShown() then
ns:HideMain()
else
ns:ShowMain()
end
end