-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHUDWidget.lua
More file actions
710 lines (627 loc) · 20.8 KB
/
HUDWidget.lua
File metadata and controls
710 lines (627 loc) · 20.8 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
local NoPoizen = _G.NoPoizen
if not NoPoizen then
return
end
local function EnsurePoisonIndicatorSelection(hostFrame)
if not hostFrame or hostFrame.Selection then
return hostFrame and hostFrame.Selection or nil
end
if not EditModeManagerFrame then
return nil
end
local selection = CreateFrame("Frame", nil, hostFrame, "EditModeSystemSelectionTemplate")
if not selection then
return nil
end
selection:SetAllPoints()
selection:SetFrameLevel(hostFrame:GetFrameLevel() + 20)
selection:EnableMouse(false)
selection:Hide()
if selection.SetSystem then
selection:SetSystem({
GetSystemName = function()
return "NoPoizen"
end,
})
elseif selection.SetGetLabelTextFunction then
selection:SetGetLabelTextFunction(function()
return "NoPoizen"
end)
end
if selection.Label then
selection.Label:Hide()
end
selection.UpdateLabelVisibility = function(frame)
if frame.Label then
frame.Label:Hide()
end
if frame.HorizontalLabel then
frame.HorizontalLabel:Hide()
end
if frame.VerticalLabel then
frame.VerticalLabel:Hide()
end
end
hostFrame.Selection = selection
return selection
end
local function SaveDialogPosition(dialog)
if not dialog then
return
end
local point, _, relativePoint, offsetX, offsetY = dialog:GetPoint(1)
if not point or not relativePoint then
return
end
dialog.qtUserPlaced = {
point = point,
relativePoint = relativePoint,
x = offsetX,
y = offsetY,
}
end
local function GetDefaultDialogPoint()
-- Keep settings dialog independent from widget scaling/position updates.
return "CENTER", UIParent, "CENTER", 380, 0
end
local function GetPoisonIndicatorEditSession()
return NoPoizen.poisonIndicatorEditSession
end
local function EnsurePoisonIndicatorEditSession()
if NoPoizen.poisonIndicatorEditSession then
return NoPoizen.poisonIndicatorEditSession
end
NoPoizen.poisonIndicatorEditSession = {
saved = {
widgetScale = NoPoizen:NormalizeWidgetScale(NoPoizen:GetOption("widgetScale")) or NoPoizen.DEFAULTS.widgetScale,
anchor = NoPoizen:DeepCopy(NoPoizen:GetIndicatorAnchor()),
},
pending = false,
}
return NoPoizen.poisonIndicatorEditSession
end
local function SyncEditModeDirtyState()
local session = GetPoisonIndicatorEditSession()
local pending = session and session.pending or false
if not EditModeManagerFrame then
return
end
if pending then
if EditModeManagerFrame.SetHasActiveChanges then
EditModeManagerFrame:SetHasActiveChanges(true)
end
elseif EditModeManagerFrame.CheckForSystemActiveChanges then
EditModeManagerFrame:CheckForSystemActiveChanges()
end
end
local function IsSnapshotEqual(snapshot)
if type(snapshot) ~= "table" then
return true
end
local currentScale = NoPoizen:NormalizeWidgetScale(NoPoizen:GetOption("widgetScale")) or NoPoizen.DEFAULTS.widgetScale
local currentAnchor = NoPoizen:GetIndicatorAnchor()
local savedAnchor = snapshot.anchor or NoPoizen.DEFAULT_INDICATOR_ANCHOR
return currentScale == snapshot.widgetScale
and currentAnchor.point == savedAnchor.point
and currentAnchor.relativePoint == savedAnchor.relativePoint
and currentAnchor.x == savedAnchor.x
and currentAnchor.y == savedAnchor.y
end
local function IsAtDefaultState()
local defaults = NoPoizen.DEFAULTS
local anchorDefaults = NoPoizen.DEFAULT_INDICATOR_ANCHOR
local currentScale = NoPoizen:NormalizeWidgetScale(NoPoizen:GetOption("widgetScale")) or defaults.widgetScale
local currentAnchor = NoPoizen:GetIndicatorAnchor()
return currentScale == defaults.widgetScale
and currentAnchor.point == anchorDefaults.point
and currentAnchor.relativePoint == anchorDefaults.relativePoint
and currentAnchor.x == anchorDefaults.x
and currentAnchor.y == anchorDefaults.y
end
local function UpdateEditSessionPendingState()
local session = EnsurePoisonIndicatorEditSession()
session.pending = not IsSnapshotEqual(session.saved)
if NoPoizen.poisonIndicatorEditDialog then
if NoPoizen.poisonIndicatorEditDialog.RevertButton then
NoPoizen.poisonIndicatorEditDialog.RevertButton:SetEnabled(session.pending)
end
if NoPoizen.poisonIndicatorEditDialog.ResetButton then
NoPoizen.poisonIndicatorEditDialog.ResetButton:SetEnabled(not IsAtDefaultState())
end
end
SyncEditModeDirtyState()
end
local function EnsurePoisonIndicatorEditDialog()
if NoPoizen.poisonIndicatorEditDialog then
return NoPoizen.poisonIndicatorEditDialog
end
if not EditModeManagerFrame then
return nil
end
local dialog = CreateFrame("Frame", "NoPoizenIndicatorSettingsDialog", UIParent)
dialog:SetSize(320, 168)
dialog:SetFrameStrata("DIALOG")
dialog:SetFrameLevel(250)
dialog:SetMovable(true)
dialog:SetClampedToScreen(true)
dialog:EnableMouse(true)
dialog:RegisterForDrag("LeftButton")
dialog:Hide()
local border = CreateFrame("Frame", nil, dialog, "DialogBorderTranslucentTemplate")
border:SetAllPoints()
dialog.Border = border
local title = dialog:CreateFontString(nil, "ARTWORK", "GameFontHighlightLarge")
title:SetPoint("TOP", dialog, "TOP", 0, -15)
title:SetText("NoPoizen Indicator")
dialog.Title = title
local closeButton = CreateFrame("Button", nil, dialog, "UIPanelCloseButton")
closeButton:SetPoint("TOPRIGHT", dialog, "TOPRIGHT")
closeButton:SetScript("OnClick", function()
NoPoizen:DeselectPoisonIndicatorAnchor()
end)
dialog.CloseButton = closeButton
local dragHandle = CreateFrame("Frame", nil, dialog)
dragHandle:SetPoint("TOPLEFT", dialog, "TOPLEFT", 8, -8)
dragHandle:SetPoint("TOPRIGHT", closeButton, "TOPLEFT", -4, -8)
dragHandle:SetHeight(28)
dragHandle:EnableMouse(true)
dragHandle:RegisterForDrag("LeftButton")
dragHandle:SetScript("OnDragStart", function()
dialog:StartMoving()
end)
dragHandle:SetScript("OnDragStop", function()
dialog:StopMovingOrSizing()
SaveDialogPosition(dialog)
end)
dialog.DragHandle = dragHandle
local slider = CreateFrame("Slider", nil, dialog, "OptionsSliderTemplate")
slider:SetPoint("TOPLEFT", dialog, "TOPLEFT", 24, -62)
slider:SetPoint("TOPRIGHT", dialog, "TOPRIGHT", -24, -62)
slider:SetMinMaxValues(NoPoizen.WIDGET_SCALE_MIN, NoPoizen.WIDGET_SCALE_MAX)
slider:SetValueStep(NoPoizen.WIDGET_SCALE_STEP)
if slider.SetObeyStepOnDrag then
slider:SetObeyStepOnDrag(true)
end
if slider.Text then
slider.Text:SetText("Indicator Scale")
end
if slider.Low then
slider.Low:SetText(string.format("%.1fx", NoPoizen.WIDGET_SCALE_MIN))
end
if slider.High then
slider.High:SetText(string.format("%.1fx", NoPoizen.WIDGET_SCALE_MAX))
end
local sliderValue = dialog:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
sliderValue:SetPoint("TOP", slider, "BOTTOM", 0, -4)
sliderValue:SetText("")
dialog.ScaleValueText = sliderValue
dialog.ScaleSlider = slider
slider:SetScript("OnValueChanged", function(_, value)
local normalized = NoPoizen:NormalizeWidgetScale(value) or NoPoizen.DEFAULTS.widgetScale
dialog.ScaleValueText:SetText(string.format("%.2fx", normalized))
if dialog.qtUpdatingSlider then
return
end
if NoPoizen:SetOption("widgetScale", normalized) and not NoPoizen.poisonIndicatorEditSessionRestoring then
UpdateEditSessionPendingState()
NoPoizen:AttachPoisonIndicatorEditDialog()
end
end)
local revertButton = CreateFrame("Button", nil, dialog, "UIPanelButtonTemplate")
revertButton:SetSize(128, 24)
revertButton:SetPoint("BOTTOMLEFT", dialog, "BOTTOMLEFT", 24, 18)
revertButton:SetText("Revert Changes")
revertButton:SetScript("OnClick", function()
NoPoizen:RevertPoisonIndicatorEditSession()
end)
dialog.RevertButton = revertButton
local resetButton = CreateFrame("Button", nil, dialog, "UIPanelButtonTemplate")
resetButton:SetSize(128, 24)
resetButton:SetPoint("BOTTOMRIGHT", dialog, "BOTTOMRIGHT", -24, 18)
resetButton:SetText("Reset To Default")
resetButton:SetScript("OnClick", function()
NoPoizen:ResetPoisonIndicatorEditSessionToDefaults()
end)
dialog.ResetButton = resetButton
dialog:SetScript("OnDragStart", function(frame)
frame:StartMoving()
end)
dialog:SetScript("OnDragStop", function(frame)
frame:StopMovingOrSizing()
SaveDialogPosition(frame)
end)
dialog:SetScript("OnHide", function(frame)
frame:StopMovingOrSizing()
end)
dialog:SetScript("OnKeyDown", function(_, key)
if key == "ESCAPE" then
NoPoizen:DeselectPoisonIndicatorAnchor()
end
end)
NoPoizen.poisonIndicatorEditDialog = dialog
return dialog
end
local function GetDefaultEditModeRows()
local rows = {}
local poisonCatalog = NoPoizen.poisonCatalog or {}
for _, category in ipairs({ "lethal", "nonLethal" }) do
local row = {
category = category,
icons = {},
}
for _, spell in ipairs(poisonCatalog[category] or {}) do
table.insert(row.icons, {
category = category,
spellID = spell.spellID,
name = spell.fallbackName,
icon = (C_Spell and C_Spell.GetSpellTexture and C_Spell.GetSpellTexture(spell.spellID))
or (GetSpellTexture and GetSpellTexture(spell.spellID))
or 134400,
})
end
if #row.icons > 0 then
table.insert(rows, row)
end
end
return rows
end
local function GetCategoryLabel(category)
if category == "lethal" then
return "Lethal Poisons"
end
if category == "nonLethal" then
return "Non-Lethal Poisons"
end
return tostring(category)
end
local function LayoutIndicatorRows(hostFrame, indicatorRows)
hostFrame.iconTextures = hostFrame.iconTextures or {}
hostFrame.rowLabels = hostFrame.rowLabels or {}
local iconSize = 40
local columnSpacing = 6
local rowSpacing = 10
local paddingX = 12
local paddingY = 10
local labelGap = 2
local textureIndex = 0
local maxColumns = 0
for _, row in ipairs(indicatorRows) do
maxColumns = math.max(maxColumns, #(row.icons or {}))
end
local width = math.max(1, (maxColumns * iconSize) + (math.max(0, maxColumns - 1) * columnSpacing) + (paddingX * 2))
local cursorY = paddingY
for rowIndex, row in ipairs(indicatorRows) do
if not hostFrame.rowLabels[rowIndex] then
hostFrame.rowLabels[rowIndex] = hostFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
end
local rowLabel = hostFrame.rowLabels[rowIndex]
rowLabel:ClearAllPoints()
rowLabel:SetPoint("TOP", hostFrame, "TOP", 0, -cursorY)
rowLabel:SetText(GetCategoryLabel(row.category))
rowLabel:Show()
local labelHeight = rowLabel:GetStringHeight() or 12
cursorY = cursorY + labelHeight + labelGap
local rowIconCount = #(row.icons or {})
local rowWidth = (rowIconCount * iconSize) + (math.max(0, rowIconCount - 1) * columnSpacing)
local rowStartX = (width - rowWidth) / 2
for columnIndex, iconData in ipairs(row.icons or {}) do
textureIndex = textureIndex + 1
if not hostFrame.iconTextures[textureIndex] then
hostFrame.iconTextures[textureIndex] = hostFrame:CreateTexture(nil, "ARTWORK")
end
local texture = hostFrame.iconTextures[textureIndex]
texture:SetTexture(iconData.icon or 134400)
texture:SetSize(iconSize, iconSize)
texture:ClearAllPoints()
texture:SetPoint(
"TOPLEFT",
hostFrame,
"TOPLEFT",
rowStartX + ((columnIndex - 1) * (iconSize + columnSpacing)),
-cursorY
)
texture:Show()
end
cursorY = cursorY + iconSize
if rowIndex < #indicatorRows then
cursorY = cursorY + rowSpacing
end
end
for index = textureIndex + 1, #hostFrame.iconTextures do
if hostFrame.iconTextures[index] then
hostFrame.iconTextures[index]:Hide()
end
end
for index = #indicatorRows + 1, #hostFrame.rowLabels do
if hostFrame.rowLabels[index] then
hostFrame.rowLabels[index]:Hide()
end
end
local rowCount = #indicatorRows
local height = rowCount > 0 and (cursorY + paddingY) or 1
hostFrame:SetSize(width, height)
end
function NoPoizen:IsPoisonIndicatorInEditMode()
return self.isEnabled and EditModeManagerFrame and EditModeManagerFrame:IsShown()
end
function NoPoizen:ApplySavedIndicatorAnchor()
local hostFrame = self.poisonIndicatorHostFrame
if not hostFrame then
return
end
local anchor = self:GetIndicatorAnchor()
hostFrame:ClearAllPoints()
hostFrame:SetPoint(anchor.point, hostFrame:GetParent() or UIParent, anchor.relativePoint, anchor.x, anchor.y)
if self.poisonIndicatorEditDialog and self.poisonIndicatorEditDialog:IsShown() then
self:AttachPoisonIndicatorEditDialog()
end
end
function NoPoizen:SaveIndicatorAnchorFromFrame(hostFrame)
if not hostFrame then
return false
end
local point, _, relativePoint, x, y = hostFrame:GetPoint(1)
if not point or not relativePoint then
return false
end
local changed = self:SetIndicatorAnchor(point, relativePoint, x, y)
if changed and self:IsPoisonIndicatorInEditMode() and not self.poisonIndicatorEditSessionRestoring then
UpdateEditSessionPendingState()
self:RefreshPoisonIndicatorEditDialog()
end
return changed
end
function NoPoizen:EnsurePoisonIndicatorWidget()
if self.poisonIndicatorHostFrame then
return self.poisonIndicatorHostFrame
end
local parentFrame = UIParent or (C_UI and C_UI.GetUIParent and C_UI.GetUIParent()) or nil
if not parentFrame then
return nil
end
local hostFrame = CreateFrame("Frame", "NoPoizenIndicatorAnchor", parentFrame)
hostFrame:SetSize(1, 1)
hostFrame:SetFrameStrata("MEDIUM")
hostFrame:SetFrameLevel(parentFrame:GetFrameLevel() + 1)
hostFrame:SetClampedToScreen(true)
hostFrame:SetMovable(true)
hostFrame:RegisterForDrag("LeftButton")
hostFrame:EnableMouse(false)
local background = hostFrame:CreateTexture(nil, "BACKGROUND")
background:SetAllPoints()
background:SetColorTexture(0.03, 0.03, 0.03, 0.7)
background:Hide()
hostFrame.EditBackground = background
local border = hostFrame:CreateTexture(nil, "BORDER")
border:SetAllPoints()
border:SetColorTexture(0.8, 0.2, 0.2, 0.4)
border:Hide()
hostFrame.EditBorder = border
local label = hostFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
label:SetPoint("BOTTOM", hostFrame, "TOP", 0, 6)
label:SetText("NoPoizen")
label:Hide()
hostFrame.EditLabel = label
hostFrame:SetScript("OnMouseDown", function(_, button)
if button ~= "LeftButton" then
return
end
NoPoizen:SelectPoisonIndicatorAnchor()
end)
hostFrame:SetScript("OnDragStart", function(frame)
if not NoPoizen:IsPoisonIndicatorInEditMode() then
return
end
NoPoizen:SelectPoisonIndicatorAnchor()
frame:StartMoving()
end)
hostFrame:SetScript("OnDragStop", function(frame)
frame:StopMovingOrSizing()
NoPoizen:SaveIndicatorAnchorFromFrame(frame)
NoPoizen:AttachPoisonIndicatorEditDialog()
end)
self.poisonIndicatorHostFrame = hostFrame
self:ApplySavedIndicatorAnchor()
self:RefreshPoisonIndicatorVisualState()
return hostFrame
end
function NoPoizen:ApplyPoisonIndicatorEditSnapshot(snapshot)
if type(snapshot) ~= "table" then
return
end
self.poisonIndicatorEditSessionRestoring = true
if snapshot.widgetScale then
self:SetOption("widgetScale", snapshot.widgetScale)
end
if snapshot.anchor then
self:SetIndicatorAnchor(snapshot.anchor.point, snapshot.anchor.relativePoint, snapshot.anchor.x, snapshot.anchor.y)
end
self.poisonIndicatorEditSessionRestoring = false
self:RefreshPoisonIndicatorVisualState()
self:AttachPoisonIndicatorEditDialog()
self:RefreshPoisonIndicatorEditDialog()
end
function NoPoizen:CommitPoisonIndicatorEditSession()
self.poisonIndicatorEditSession = nil
self.poisonIndicatorEditSessionRestoring = false
SyncEditModeDirtyState()
if self.poisonIndicatorEditDialog and self.poisonIndicatorEditDialog.RevertButton then
self.poisonIndicatorEditDialog.RevertButton:SetEnabled(false)
end
end
function NoPoizen:RevertPoisonIndicatorEditSession()
local session = GetPoisonIndicatorEditSession()
if not session then
return
end
self:ApplyPoisonIndicatorEditSnapshot(session.saved)
session.pending = false
SyncEditModeDirtyState()
if self.poisonIndicatorEditDialog and self.poisonIndicatorEditDialog.RevertButton then
self.poisonIndicatorEditDialog.RevertButton:SetEnabled(false)
end
end
function NoPoizen:ResetPoisonIndicatorEditSessionToDefaults()
self.poisonIndicatorEditSessionRestoring = true
self:SetOption("widgetScale", self.DEFAULTS.widgetScale)
self:ResetIndicatorAnchor()
self.poisonIndicatorEditSessionRestoring = false
UpdateEditSessionPendingState()
self:RefreshPoisonIndicatorVisualState()
self:AttachPoisonIndicatorEditDialog()
self:RefreshPoisonIndicatorEditDialog()
end
function NoPoizen:AttachPoisonIndicatorEditDialog()
local dialog = self.poisonIndicatorEditDialog
if not dialog then
return
end
if dialog.qtUserPlaced then
dialog:ClearAllPoints()
dialog:SetPoint(
dialog.qtUserPlaced.point,
UIParent,
dialog.qtUserPlaced.relativePoint,
dialog.qtUserPlaced.x,
dialog.qtUserPlaced.y
)
return
end
local point, relativeTo, relativePoint, offsetX, offsetY = GetDefaultDialogPoint()
dialog:ClearAllPoints()
dialog:SetPoint(point, relativeTo, relativePoint, offsetX, offsetY)
end
function NoPoizen:RefreshPoisonIndicatorEditDialog()
local dialog = EnsurePoisonIndicatorEditDialog()
if not dialog then
return
end
local session = GetPoisonIndicatorEditSession()
local currentScale = self:NormalizeWidgetScale(self:GetOption("widgetScale")) or self.DEFAULTS.widgetScale
dialog.qtUpdatingSlider = true
dialog.ScaleSlider:SetValue(currentScale)
dialog.ScaleValueText:SetText(string.format("%.2fx", currentScale))
dialog.qtUpdatingSlider = false
if dialog.RevertButton then
dialog.RevertButton:SetEnabled(session and session.pending or false)
end
if dialog.ResetButton then
dialog.ResetButton:SetEnabled(not IsAtDefaultState())
end
end
function NoPoizen:SelectPoisonIndicatorAnchor()
if not self:IsPoisonIndicatorInEditMode() then
return
end
EnsurePoisonIndicatorEditSession()
self.poisonIndicatorAnchorSelected = true
self:RefreshPoisonIndicatorVisualState()
self:AttachPoisonIndicatorEditDialog()
self:RefreshPoisonIndicatorEditDialog()
local dialog = EnsurePoisonIndicatorEditDialog()
if dialog then
dialog:Show()
end
end
function NoPoizen:DeselectPoisonIndicatorAnchor()
self.poisonIndicatorAnchorSelected = false
if self.poisonIndicatorEditDialog then
self.poisonIndicatorEditDialog:Hide()
end
self:RefreshPoisonIndicatorVisualState()
end
function NoPoizen:RefreshPoisonIndicatorVisualState()
local hostFrame = self:EnsurePoisonIndicatorWidget()
if not hostFrame then
return
end
EnsurePoisonIndicatorSelection(hostFrame)
local editModeActive = self:IsPoisonIndicatorInEditMode()
local state = self.currentPoisonState or {}
local shouldShowRuntime = self.isEnabled and state.showIndicator
local indicatorRows = state.indicatorRows or {}
if editModeActive and #indicatorRows == 0 then
indicatorRows = GetDefaultEditModeRows()
end
local shouldShow = editModeActive or shouldShowRuntime
if shouldShow and #indicatorRows == 0 then
shouldShow = false
end
if shouldShow then
LayoutIndicatorRows(hostFrame, indicatorRows)
hostFrame:SetScale(self:NormalizeWidgetScale(self:GetOption("widgetScale")) or self.DEFAULTS.widgetScale)
hostFrame:Show()
else
hostFrame:Hide()
end
hostFrame:EnableMouse(editModeActive)
if hostFrame.EditBackground then
hostFrame.EditBackground:SetShown(editModeActive and shouldShow)
end
if hostFrame.EditBorder then
hostFrame.EditBorder:SetShown(editModeActive and shouldShow)
end
if hostFrame.EditLabel then
hostFrame.EditLabel:SetShown(editModeActive and shouldShow)
end
if hostFrame.Selection then
if editModeActive and shouldShow then
if self.poisonIndicatorAnchorSelected then
hostFrame.Selection:ShowSelected()
else
hostFrame.Selection:ShowHighlighted()
end
else
hostFrame.Selection:Hide()
end
end
if not editModeActive then
self.poisonIndicatorAnchorSelected = false
if self.poisonIndicatorEditDialog then
self.poisonIndicatorEditDialog:Hide()
end
end
end
function NoPoizen:UpdatePoisonIndicator(state)
self.currentPoisonState = state
self:RefreshPoisonIndicatorVisualState()
end
function NoPoizen:TryInstallPoisonIndicatorEditModeHooks()
if self.poisonIndicatorEditModeHooksInstalled then
return
end
if not EditModeManagerFrame or not EditModeManagerFrame.HookScript then
return
end
self:EnsurePoisonIndicatorWidget()
EnsurePoisonIndicatorEditDialog()
EditModeManagerFrame:HookScript("OnShow", function()
EnsurePoisonIndicatorEditSession()
NoPoizen:RefreshPoisonIndicatorVisualState()
NoPoizen:RefreshPoisonIndicatorEditDialog()
end)
EditModeManagerFrame:HookScript("OnHide", function()
NoPoizen:DeselectPoisonIndicatorAnchor()
end)
hooksecurefunc(EditModeManagerFrame, "SelectSystem", function(_, systemFrame)
local hostFrame = NoPoizen.poisonIndicatorHostFrame
if hostFrame and systemFrame ~= hostFrame then
NoPoizen:DeselectPoisonIndicatorAnchor()
end
end)
hooksecurefunc(EditModeManagerFrame, "ClearSelectedSystem", function()
NoPoizen:DeselectPoisonIndicatorAnchor()
end)
hooksecurefunc(EditModeManagerFrame, "SaveLayouts", function()
NoPoizen:CommitPoisonIndicatorEditSession()
end)
hooksecurefunc(EditModeManagerFrame, "RevertAllChanges", function()
NoPoizen:RevertPoisonIndicatorEditSession()
end)
if EditModeManagerFrame.RevertAllChangesButton and EditModeManagerFrame.RevertAllChangesButton.HookScript then
EditModeManagerFrame.RevertAllChangesButton:HookScript("OnClick", function()
NoPoizen:RevertPoisonIndicatorEditSession()
end)
end
self.poisonIndicatorEditModeHooksInstalled = true
end