-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNameplates.lua
More file actions
4297 lines (3714 loc) · 130 KB
/
Copy pathNameplates.lua
File metadata and controls
4297 lines (3714 loc) · 130 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
--[[
QuestTogether Nameplate Augmentation
Purpose:
- Add a quest icon on Blizzard default nameplates for quest-objective units.
- Optionally tint quest-objective health bars using an addon overlay, without mutating Blizzard bar colors.
Design constraints:
- Keep the implementation minimal and non-invasive.
- Do not replace Blizzard templates or secure handlers.
- Hook post-update paths so Blizzard remains source-of-truth for baseline behavior.
]]
local QuestTogether = _G.QuestTogether
local PLATER_QUEST_STATE_REFRESH_DELAY_SECONDS = 1.0
local PLATER_INITIAL_QUEST_LOG_UPDATED_DELAY_SECONDS = 4.1
local PLATER_INITIAL_FULL_REFRESH_DELAY_SECONDS = 5.1
local NAMEPLATE_TOOLTIP_GUID_RETRY_DELAY_SECONDS = 0.2
local NAMEPLATE_TOOLTIP_GUID_RETRY_MAX_ATTEMPTS = 4
local NAMEPLATE_SCAN_TOOLTIP_NAME = "QuestTogetherNameplateScanTooltip"
local ANNOUNCEMENT_BUBBLE_Y_OFFSET = 22
local ANNOUNCEMENT_BUBBLE_FADE_IN_SECONDS = 0.2
local ANNOUNCEMENT_BUBBLE_FADE_OUT_SECONDS = 0.4
local PERSONAL_BUBBLE_SETTINGS_DIALOG_WIDTH = 380
local PERSONAL_BUBBLE_SETTINGS_DIALOG_HEIGHT = 220
local ApplyQuestIconVisual
local EnsureQuestIcon
local ResolveNameplateUnitToken
local SafeUiNumber
local SafeText
-- Original icon used by this addon's first nameplate implementation.
QuestTogether.NAMEPLATE_QUEST_ICON_TEXTURE = "Interface\\OPTIONSFRAME\\UI-OptionsFrame-NewFeatureIcon"
QuestTogether.NAMEPLATE_QUEST_ICON_ATLAS = nil
QuestTogether.NAMEPLATE_QUEST_ICON_TEX_COORDS = nil
QuestTogether.NAMEPLATE_QUEST_ICON_WIDTH = 21
QuestTogether.NAMEPLATE_QUEST_ICON_HEIGHT = 21
-- Default burnt-orange tint for quest-objective units.
QuestTogether.NAMEPLATE_QUEST_HEALTH_COLOR = {
r = 0.95,
g = 0.45,
b = 0.05,
}
QuestTogether.NAMEPLATE_HEALTH_FILL_ATLAS = "UI-HUD-CoolDownManager-Bar"
local function ClampColorComponent(value, fallback)
local numberValue = SafeUiNumber and SafeUiNumber(value, nil) or nil
if not numberValue then
return fallback
end
if numberValue < 0 then
return 0
end
if numberValue > 1 then
return 1
end
return numberValue
end
local function IsNonEmptyString(value)
return type(value) == "string" and value ~= ""
end
local function PrintOneShotNameplateDebug(addon, key, message)
if not addon or not addon.GetRuntimeFlag or not addon.SetRuntimeFlag then
return
end
if addon:GetRuntimeFlag(key, false) then
return
end
addon:SetRuntimeFlag(key, true)
if addon.LogDebugLine then
addon:LogDebugLine(SafeText(message, ""), {
category = "nameplate",
})
elseif addon.AppendDebugLogLine then
addon:AppendDebugLogLine(SafeText(message, ""))
end
end
local function ShouldSuppressStructuredQuestTooltipSource(addon)
if not addon or not addon.CanUseStructuredQuestTooltipAPI then
return false
end
-- The retail structured tooltip path is only risky while Blizzard's shared
-- world-map tooltip/widget flow is active.
if not addon:CanUseStructuredQuestTooltipAPI() then
return false
end
if addon.API and type(addon.API.IsWorldMapVisible) == "function" then
return addon.API.IsWorldMapVisible() == true
end
return false
end
local function IsFrameForbidden(frame)
if QuestTogether and QuestTogether.IsForbiddenFrame then
return QuestTogether:IsForbiddenFrame(frame)
end
local frameType = type(frame)
if not frame or (frameType ~= "table" and frameType ~= "userdata") then
return false
end
if not frame.IsForbidden then
return false
end
-- Forbidden checks can be unavailable on some userdata-backed frames; fail open.
local ok, forbidden = pcall(frame.IsForbidden, frame)
return ok and forbidden and true or false
end
local function CanMutateFrame(frame)
if QuestTogether and QuestTogether.CanAccessForeignFrame then
return QuestTogether:CanAccessForeignFrame(frame)
end
return frame ~= nil and not IsFrameForbidden(frame)
end
function SafeText(value, fallback)
if QuestTogether and QuestTogether.SafeToString then
return QuestTogether:SafeToString(value, fallback or "")
end
local ok, text = pcall(tostring, value)
if ok then
return text
end
return fallback or ""
end
local function SafeMatch(text, pattern)
local safeText = SafeText(text, "")
if safeText == "" then
return nil
end
local ok, first, second = pcall(string.match, safeText, pattern)
if not ok then
return nil
end
return first, second
end
local function SafeTrimText(text)
if QuestTogether and QuestTogether.SafeTrimString then
return QuestTogether:SafeTrimString(text, "")
end
return SafeText(text, "")
end
local function SafeFindPlain(text, pattern)
local safeText = SafeText(text, "")
if safeText == "" then
return nil
end
local ok, index = pcall(string.find, safeText, pattern, 1, true)
if not ok then
return nil
end
return index
end
SafeUiNumber = function(value, fallback)
local numericValue = nil
if QuestTogether and QuestTogether.SafeToNumber then
numericValue = QuestTogether:SafeToNumber(value)
end
if numericValue == nil then
return fallback
end
return numericValue
end
if QuestTogether.EnsureRuntimeStateStore then
QuestTogether:EnsureRuntimeStateStore()
end
if not QuestTogether.GetNameplateStateStore then
QuestTogether.nameplateQuestTextCache = QuestTogether.nameplateQuestTextCache or {}
QuestTogether.nameplateQuestStateByGuid = QuestTogether.nameplateQuestStateByGuid or {}
QuestTogether.nameplateQuestStateByUnitToken = QuestTogether.nameplateQuestStateByUnitToken or {}
QuestTogether.nameplateQuestGuidByUnitToken = QuestTogether.nameplateQuestGuidByUnitToken or {}
QuestTogether.nameplateIconByUnitFrame = QuestTogether.nameplateIconByUnitFrame
or setmetatable({}, { __mode = "k" })
QuestTogether.nameplateHealthOverlayByUnitFrame = QuestTogether.nameplateHealthOverlayByUnitFrame
or setmetatable({}, { __mode = "k" })
QuestTogether.nameplateBubbleByUnitFrame = QuestTogether.nameplateBubbleByUnitFrame
or setmetatable({}, { __mode = "k" })
QuestTogether.nameplateBubbleStateByFrame = QuestTogether.nameplateBubbleStateByFrame
or setmetatable({}, { __mode = "k" })
QuestTogether.personalBubbleSliderHandlesByFrame = QuestTogether.personalBubbleSliderHandlesByFrame
or setmetatable({}, { __mode = "k" })
QuestTogether.personalBubbleDialogPositionByFrame = QuestTogether.personalBubbleDialogPositionByFrame
or setmetatable({}, { __mode = "k" })
QuestTogether.nameplateRefreshPendingByUnitToken = QuestTogether.nameplateRefreshPendingByUnitToken or {}
QuestTogether.nameplateRefreshGenerationByUnitToken = QuestTogether.nameplateRefreshGenerationByUnitToken or {}
QuestTogether.nameplateHealthTintRefreshPendingByUnitToken =
QuestTogether.nameplateHealthTintRefreshPendingByUnitToken or {}
QuestTogether.nameplateFullRefreshGeneration = QuestTogether.nameplateFullRefreshGeneration or 0
end
local function GetAnnouncementBubbleLifetimeSeconds()
local configuredDuration = QuestTogether:NormalizeChatBubbleDurationValue(QuestTogether:GetOption("chatBubbleDuration"))
if not configuredDuration or configuredDuration <= 0 then
configuredDuration = QuestTogether.DEFAULTS.profile.chatBubbleDuration
end
return SafeUiNumber(configuredDuration, QuestTogether.DEFAULTS.profile.chatBubbleDuration)
end
local function GetAnnouncementBubbleUnitFrame(hostFrame)
if not hostFrame or IsFrameForbidden(hostFrame) then
return nil
end
local unitFrame = hostFrame.UnitFrame or hostFrame
if IsFrameForbidden(unitFrame) then
return nil
end
return unitFrame
end
local function GetSavedPersonalBubbleDialogPosition(dialog)
if not dialog or not QuestTogether.personalBubbleDialogPositionByFrame then
return nil
end
return QuestTogether.personalBubbleDialogPositionByFrame[dialog]
end
local function SetSavedPersonalBubbleDialogPosition(dialog, position)
if not dialog or type(position) ~= "table" then
return
end
QuestTogether.personalBubbleDialogPositionByFrame[dialog] = position
end
local function GetAnnouncementBubbleState(bubble)
if not bubble or not QuestTogether.nameplateBubbleStateByFrame then
return nil
end
return QuestTogether.nameplateBubbleStateByFrame[bubble]
end
local function SetAnnouncementBubbleState(bubble, state)
if not bubble or type(state) ~= "table" then
return nil
end
QuestTogether.nameplateBubbleStateByFrame[bubble] = state
return state
end
local function ClearAnnouncementBubbleState(bubble)
if not bubble or not QuestTogether.nameplateBubbleStateByFrame then
return
end
QuestTogether.nameplateBubbleStateByFrame[bubble] = nil
end
local function ScaleBubbleMetric(baseValue, sizeScale, minimumValue)
local scaledValue = math.floor((baseValue * sizeScale) + 0.5)
if minimumValue then
return math.max(minimumValue, scaledValue)
end
return scaledValue
end
local function GetPersonalBubbleAnchorFontDefinition()
if ChatBubbleFont and ChatBubbleFont.GetFont then
local fontPath, _, fontFlags = ChatBubbleFont:GetFont()
if fontPath and fontPath ~= "" then
return fontPath, fontFlags
end
end
if GameFontHighlightMedium and GameFontHighlightMedium.GetFont then
local fontPath, _, fontFlags = GameFontHighlightMedium:GetFont()
if fontPath and fontPath ~= "" then
return fontPath, fontFlags
end
end
return STANDARD_TEXT_FONT or "Fonts\\FRIZQT__.TTF", ""
end
local function GetAnnouncementBubbleVisualConfig()
local configuredSize = QuestTogether:NormalizeChatBubbleSizeValue(QuestTogether:GetOption("chatBubbleSize"))
or QuestTogether.DEFAULTS.profile.chatBubbleSize
local sizeScale = configuredSize / 100
return {
fontSize = ScaleBubbleMetric(14, sizeScale, 10),
iconSize = ScaleBubbleMetric(18, sizeScale, 12),
iconGap = ScaleBubbleMetric(8, sizeScale, 4),
minTextWidth = ScaleBubbleMetric(48, sizeScale, 40),
maxTextWidth = ScaleBubbleMetric(220, sizeScale, 160),
inset = ScaleBubbleMetric(16, sizeScale, 12),
}
end
local function EstimateBubbleTextWidth(text, fontSize, minTextWidth, maxTextWidth)
local textValue = type(text) == "string" and text or ""
if textValue == "" then
return minTextWidth
end
local characterWidth = math.max(5, fontSize * 0.55)
local estimatedWidth = math.floor((string.len(textValue) * characterWidth) + 0.5)
return math.min(maxTextWidth, math.max(minTextWidth, estimatedWidth))
end
local function EstimateBubbleTextHeight(text, textWidth, fontSize)
local textValue = type(text) == "string" and text or ""
local lineHeight = math.max(fontSize, math.floor((fontSize * 1.2) + 0.5))
if textValue == "" then
return lineHeight
end
local characterWidth = math.max(5, fontSize * 0.55)
local maxCharsPerLine = math.max(1, math.floor(textWidth / characterWidth))
local lineCount = math.max(1, math.ceil(string.len(textValue) / maxCharsPerLine))
return lineCount * lineHeight
end
local function EnsurePersonalBubbleAnchorSelection(hostFrame)
if not hostFrame or hostFrame.Selection then
return hostFrame and hostFrame.Selection or nil
end
if not EditModeManagerFrame then
return nil
end
-- EditMode templates can be unavailable on some clients/states; fail soft and skip selection chrome.
local ok, selection = pcall(CreateFrame, "Frame", nil, hostFrame, "EditModeSystemSelectionTemplate")
if not ok or 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 "QuestTogether Bubble"
end,
})
elseif selection.SetGetLabelTextFunction then
selection:SetGetLabelTextFunction(function()
return "QuestTogether Bubble"
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 GetPersonalBubbleAnchorDialogAttachPoint()
if EditModeManagerFrame and EditModeManagerFrame:IsShown() then
return "TOPLEFT", EditModeManagerFrame, "TOPRIGHT", 16, -40
end
return "CENTER", UIParent, "CENTER", 420, 40
end
local function SavePersonalBubbleDialogPosition(dialog)
if not dialog then
return
end
local point, _, relativePoint, offsetX, offsetY = dialog:GetPoint(1)
if not point or not relativePoint then
return
end
SetSavedPersonalBubbleDialogPosition(dialog, {
point = point,
relativePoint = relativePoint,
x = offsetX,
y = offsetY,
})
end
local function GetPersonalBubbleEditSession()
return QuestTogether.personalBubbleEditSession
end
local function EnsurePersonalBubbleEditSession()
if QuestTogether.personalBubbleEditSession then
return QuestTogether.personalBubbleEditSession
end
local session = {
saved = {
chatBubbleSize = QuestTogether:NormalizeChatBubbleSizeValue(QuestTogether:GetOption("chatBubbleSize"))
or QuestTogether.DEFAULTS.profile.chatBubbleSize,
chatBubbleDuration = QuestTogether:NormalizeChatBubbleDurationValue(QuestTogether:GetOption("chatBubbleDuration"))
or QuestTogether.DEFAULTS.profile.chatBubbleDuration,
anchor = QuestTogether:DeepCopy(QuestTogether:GetPersonalBubbleAnchor()),
},
pending = false,
}
QuestTogether.personalBubbleEditSession = session
return session
end
local function SyncPersonalBubbleEditModeDirtyState()
local session = GetPersonalBubbleEditSession()
local isPending = session and session.pending or false
if not EditModeManagerFrame then
return
end
if isPending then
if EditModeManagerFrame.SetHasActiveChanges then
EditModeManagerFrame:SetHasActiveChanges(true)
end
elseif EditModeManagerFrame.CheckForSystemActiveChanges then
EditModeManagerFrame:CheckForSystemActiveChanges()
end
end
local function IsPersonalBubbleEditSnapshotEqual(snapshot)
if type(snapshot) ~= "table" then
return true
end
local currentSize = QuestTogether:NormalizeChatBubbleSizeValue(QuestTogether:GetOption("chatBubbleSize"))
or QuestTogether.DEFAULTS.profile.chatBubbleSize
local currentDuration = QuestTogether:NormalizeChatBubbleDurationValue(QuestTogether:GetOption("chatBubbleDuration"))
or QuestTogether.DEFAULTS.profile.chatBubbleDuration
local currentAnchor = QuestTogether:GetPersonalBubbleAnchor()
local savedAnchor = snapshot.anchor or QuestTogether.DEFAULT_PERSONAL_BUBBLE_ANCHOR
return currentSize == snapshot.chatBubbleSize
and currentDuration == snapshot.chatBubbleDuration
and currentAnchor.point == savedAnchor.point
and currentAnchor.relativePoint == savedAnchor.relativePoint
and currentAnchor.x == savedAnchor.x
and currentAnchor.y == savedAnchor.y
end
local function IsPersonalBubbleAtDefaultState()
local defaults = QuestTogether.DEFAULTS.profile
local anchorDefaults = QuestTogether.DEFAULT_PERSONAL_BUBBLE_ANCHOR
local currentSize = QuestTogether:NormalizeChatBubbleSizeValue(QuestTogether:GetOption("chatBubbleSize"))
or defaults.chatBubbleSize
local currentDuration = QuestTogether:NormalizeChatBubbleDurationValue(QuestTogether:GetOption("chatBubbleDuration"))
or defaults.chatBubbleDuration
local currentAnchor = QuestTogether:GetPersonalBubbleAnchor()
return currentSize == defaults.chatBubbleSize
and currentDuration == defaults.chatBubbleDuration
and currentAnchor.point == anchorDefaults.point
and currentAnchor.relativePoint == anchorDefaults.relativePoint
and currentAnchor.x == anchorDefaults.x
and currentAnchor.y == anchorDefaults.y
end
local function UpdatePersonalBubbleEditSessionDirtyState()
local session = EnsurePersonalBubbleEditSession()
session.pending = not IsPersonalBubbleEditSnapshotEqual(session.saved)
if
QuestTogether.personalBubbleEditModeDialog
and QuestTogether.personalBubbleEditModeDialog.RevertButton
then
QuestTogether.personalBubbleEditModeDialog.RevertButton:SetEnabled(session.pending)
QuestTogether.personalBubbleEditModeDialog.ResetButton:SetEnabled(not IsPersonalBubbleAtDefaultState())
end
SyncPersonalBubbleEditModeDirtyState()
end
local function ConfigureEditModeSlider(settingFrame, settingData, onValueChanged)
if not settingFrame then
return
end
if settingFrame.cbrHandles then
settingFrame.cbrHandles:Unregister()
end
local callbackHandles = QuestTogether.personalBubbleSliderHandlesByFrame[settingFrame]
if not callbackHandles then
callbackHandles = EventUtil.CreateCallbackHandleContainer()
QuestTogether.personalBubbleSliderHandlesByFrame[settingFrame] = callbackHandles
end
callbackHandles:Unregister()
callbackHandles:RegisterCallback(
settingFrame.Slider,
MinimalSliderWithSteppersMixin.Event.OnValueChanged,
function(_, value)
if type(onValueChanged) == "function" then
onValueChanged(value)
end
end,
settingFrame
)
callbackHandles:RegisterCallback(
settingFrame.Slider,
MinimalSliderWithSteppersMixin.Event.OnInteractStart,
function()
end,
settingFrame
)
callbackHandles:RegisterCallback(
settingFrame.Slider,
MinimalSliderWithSteppersMixin.Event.OnInteractEnd,
function()
end,
settingFrame
)
settingFrame.OnSliderValueChanged = function()
end
settingFrame.OnSliderInteractEnd = function()
end
settingFrame.OnSliderInteractStart = function()
end
settingFrame:SetupSetting(settingData)
settingFrame:Show()
end
function QuestTogether:ApplyPersonalBubbleEditSnapshot(snapshot)
if type(snapshot) ~= "table" then
return
end
self.personalBubbleEditSessionRestoring = true
if snapshot.chatBubbleSize then
self:SetOption("chatBubbleSize", snapshot.chatBubbleSize)
end
if snapshot.chatBubbleDuration then
self:SetOption("chatBubbleDuration", snapshot.chatBubbleDuration)
end
if snapshot.anchor then
self:SetPersonalBubbleAnchor(
snapshot.anchor.point,
snapshot.anchor.relativePoint,
snapshot.anchor.x,
snapshot.anchor.y
)
end
self.personalBubbleEditSessionRestoring = false
self:RefreshPersonalBubbleAnchorVisualState()
self:AttachPersonalBubbleEditModeDialog()
self:RefreshPersonalBubbleEditModeDialog()
end
function QuestTogether:CommitPersonalBubbleEditSession()
self.personalBubbleEditSession = nil
self.personalBubbleEditSessionRestoring = false
SyncPersonalBubbleEditModeDirtyState()
if self.personalBubbleEditModeDialog and self.personalBubbleEditModeDialog.RevertButton then
self.personalBubbleEditModeDialog.RevertButton:SetEnabled(false)
end
end
function QuestTogether:RevertPersonalBubbleEditSession()
local session = GetPersonalBubbleEditSession()
if not session then
return
end
self:ApplyPersonalBubbleEditSnapshot(session.saved)
session.pending = false
SyncPersonalBubbleEditModeDirtyState()
if self.personalBubbleEditModeDialog and self.personalBubbleEditModeDialog.RevertButton then
self.personalBubbleEditModeDialog.RevertButton:SetEnabled(false)
end
end
function QuestTogether:ResetPersonalBubbleEditSessionToDefaults()
self.personalBubbleEditSessionRestoring = true
self:SetOption("chatBubbleSize", self.DEFAULTS.profile.chatBubbleSize)
self:SetOption("chatBubbleDuration", self.DEFAULTS.profile.chatBubbleDuration)
self:ResetPersonalBubbleAnchor()
self.personalBubbleEditSessionRestoring = false
UpdatePersonalBubbleEditSessionDirtyState()
self:RefreshPersonalBubbleAnchorVisualState()
self:AttachPersonalBubbleEditModeDialog()
self:RefreshPersonalBubbleEditModeDialog()
end
local function EnsurePersonalBubbleEditModeDialog()
if QuestTogether.personalBubbleEditModeDialog then
return QuestTogether.personalBubbleEditModeDialog
end
if not EditModeManagerFrame then
return nil
end
local dialog = CreateFrame("Frame", "QuestTogetherPersonalBubbleSettingsDialog", UIParent)
dialog:SetSize(PERSONAL_BUBBLE_SETTINGS_DIALOG_WIDTH, PERSONAL_BUBBLE_SETTINGS_DIALOG_HEIGHT)
dialog:SetFrameStrata("DIALOG")
dialog:SetFrameLevel(250)
dialog:SetClampedToScreen(true)
dialog:SetMovable(true)
dialog:EnableMouse(true)
dialog:RegisterForDrag("LeftButton")
dialog:EnableKeyboard(true)
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("QuestTogether Bubble")
dialog.Title = title
local closeButton = CreateFrame("Button", nil, dialog, "UIPanelCloseButton")
closeButton:SetPoint("TOPRIGHT", dialog, "TOPRIGHT")
closeButton:SetScript("OnClick", function()
QuestTogether:DeselectPersonalBubbleAnchor()
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()
SavePersonalBubbleDialogPosition(dialog)
end)
dialog.DragHandle = dragHandle
local sizeSlider = CreateFrame("Frame", nil, dialog, "EditModeSettingSliderTemplate")
sizeSlider:SetPoint("TOPLEFT", dialog, "TOPLEFT", 24, -48)
dialog.SizeSlider = sizeSlider
local durationSlider = CreateFrame("Frame", nil, dialog, "EditModeSettingSliderTemplate")
durationSlider:SetPoint("TOPLEFT", sizeSlider, "BOTTOMLEFT", 0, -18)
dialog.DurationSlider = durationSlider
local revertButton = CreateFrame("Button", nil, dialog, "EditModeSystemSettingsDialogButtonTemplate")
revertButton:SetSize(160, 28)
revertButton:SetPoint("BOTTOMLEFT", dialog, "BOTTOMLEFT", 24, 18)
revertButton:SetText("Revert Changes")
revertButton:SetScript("OnClick", function()
QuestTogether:RevertPersonalBubbleEditSession()
end)
dialog.RevertButton = revertButton
local resetButton = CreateFrame("Button", nil, dialog, "EditModeSystemSettingsDialogButtonTemplate")
resetButton:SetSize(160, 28)
resetButton:SetPoint("BOTTOMRIGHT", dialog, "BOTTOMRIGHT", -24, 18)
resetButton:SetText("Reset To Default")
resetButton:SetScript("OnClick", function()
QuestTogether:ResetPersonalBubbleEditSessionToDefaults()
end)
dialog.ResetButton = resetButton
dialog:SetScript("OnDragStart", function(frame)
frame:StartMoving()
end)
dialog:SetScript("OnDragStop", function(frame)
frame:StopMovingOrSizing()
SavePersonalBubbleDialogPosition(frame)
end)
dialog:SetScript("OnHide", function(frame)
frame:StopMovingOrSizing()
end)
dialog:SetScript("OnKeyDown", function(_, key)
if key == "ESCAPE" then
QuestTogether:DeselectPersonalBubbleAnchor()
end
end)
QuestTogether.personalBubbleEditModeDialog = dialog
return dialog
end
local function GetAnnouncementBubbleScreenHostFrame()
if QuestTogether.announcementBubbleScreenHostFrame then
return QuestTogether.announcementBubbleScreenHostFrame
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", "QuestTogetherPersonalBubbleAnchor", parentFrame)
hostFrame:SetSize(1, 1)
hostFrame:SetFrameStrata("LOW")
hostFrame:SetFrameLevel(parentFrame:GetFrameLevel() + 5)
hostFrame:SetClampedToScreen(true)
hostFrame:SetMovable(true)
hostFrame:RegisterForDrag("LeftButton")
hostFrame:EnableMouse(false)
local background = hostFrame:CreateTexture(nil, "BACKGROUND")
background:SetPoint("TOPLEFT", hostFrame, "TOPLEFT", 6, -6)
background:SetPoint("BOTTOMRIGHT", hostFrame, "BOTTOMRIGHT", -6, 6)
background:SetColorTexture(0.03, 0.03, 0.03, 0.68)
background:Hide()
hostFrame.EditBackground = background
local border = hostFrame:CreateTexture(nil, "BORDER")
border:SetPoint("TOPLEFT", background, "TOPLEFT", 0, 0)
border:SetPoint("BOTTOMRIGHT", background, "BOTTOMRIGHT", 0, 0)
border:SetColorTexture(0.45, 0.52, 0.6, 0.35)
border:Hide()
hostFrame.EditBorder = border
local icon = hostFrame:CreateTexture(nil, "ARTWORK")
icon:SetSize(16, 16)
icon:SetPoint("LEFT", hostFrame, "LEFT", 16, 0)
ApplyQuestIconVisual(icon)
icon:Hide()
hostFrame.EditIcon = icon
local label = hostFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlightMedium")
label:SetPoint("LEFT", icon, "RIGHT", 8, 0)
label:SetJustifyH("LEFT")
label:SetJustifyV("MIDDLE")
label:SetTextColor(1, 0.82, 0, 1)
label:SetText("QuestTogether Bubble")
label:Hide()
hostFrame.EditLabel = label
hostFrame:SetScript("OnEnter", function()
QuestTogether:RefreshPersonalBubbleAnchorVisualState()
end)
hostFrame:SetScript("OnLeave", function()
QuestTogether:RefreshPersonalBubbleAnchorVisualState()
end)
hostFrame:SetScript("OnMouseDown", function(_, button)
if button ~= "LeftButton" then
return
end
QuestTogether:SelectPersonalBubbleAnchor()
end)
hostFrame:SetScript("OnDragStart", function(frame)
if not QuestTogether:IsPersonalBubbleAnchorInEditMode() then
return
end
QuestTogether:SelectPersonalBubbleAnchor()
frame:StartMoving()
end)
hostFrame:SetScript("OnDragStop", function(frame)
frame:StopMovingOrSizing()
QuestTogether:SavePersonalBubbleAnchorFromFrame(frame)
QuestTogether:AttachPersonalBubbleEditModeDialog()
end)
QuestTogether.announcementBubbleScreenHostFrame = hostFrame
QuestTogether:ApplySavedPersonalBubbleAnchor()
QuestTogether:RefreshPersonalBubbleAnchorVisualState()
hostFrame:Show()
return hostFrame
end
function QuestTogether:IsPersonalBubbleAnchorInEditMode()
return self.isEnabled and EditModeManagerFrame and EditModeManagerFrame:IsShown() and self:GetOption("showChatBubbles")
end
function QuestTogether:ApplySavedPersonalBubbleAnchor()
local hostFrame = self.announcementBubbleScreenHostFrame
if not hostFrame then
return
end
local parentFrame = hostFrame:GetParent() or UIParent
local anchor = self:GetPersonalBubbleAnchor()
hostFrame:ClearAllPoints()
hostFrame:SetPoint(anchor.point, parentFrame, anchor.relativePoint, anchor.x, anchor.y)
if self.personalBubbleEditModeDialog and self.personalBubbleEditModeDialog:IsShown() then
self:AttachPersonalBubbleEditModeDialog()
end
end
local function RoundOffset(value)
local numberValue = SafeUiNumber(value, 0)
if numberValue >= 0 then
return math.floor(numberValue + 0.5)
end
return math.ceil(numberValue - 0.5)
end
function QuestTogether:SavePersonalBubbleAnchorFromFrame(hostFrame)
if not hostFrame then
return false
end
local point, _, relativePoint, offsetX, offsetY = hostFrame:GetPoint(1)
if not point or not relativePoint then
return false
end
local changed = self:SetPersonalBubbleAnchor(point, relativePoint, RoundOffset(offsetX), RoundOffset(offsetY))
if changed and self:IsPersonalBubbleAnchorInEditMode() and not self.personalBubbleEditSessionRestoring then
UpdatePersonalBubbleEditSessionDirtyState()
self:RefreshPersonalBubbleEditModeDialog()
end
return changed
end
function QuestTogether:AttachPersonalBubbleEditModeDialog()
local dialog = self.personalBubbleEditModeDialog
if not dialog then
return
end
local savedPosition = GetSavedPersonalBubbleDialogPosition(dialog)
if savedPosition then
dialog:ClearAllPoints()
dialog:SetPoint(
savedPosition.point,
UIParent,
savedPosition.relativePoint,
savedPosition.x,
savedPosition.y
)
return
end
local point, relativeTo, relativePoint, offsetX, offsetY = GetPersonalBubbleAnchorDialogAttachPoint()
dialog:ClearAllPoints()
dialog:SetPoint(point, relativeTo, relativePoint, offsetX, offsetY)
end
function QuestTogether:RefreshPersonalBubbleEditModeDialog()
local dialog = EnsurePersonalBubbleEditModeDialog()
if not dialog then
return
end
local session = GetPersonalBubbleEditSession()
local function FormatDurationLabel(value)
local normalized = self:NormalizeChatBubbleDurationValue(value) or self.DEFAULTS.profile.chatBubbleDuration
if math.abs(normalized - math.floor(normalized)) < 0.001 then
return string.format("%d sec", normalized)
end
return string.format("%.1f sec", normalized)
end
ConfigureEditModeSlider(dialog.SizeSlider, {
displayInfo = {
setting = "chatBubbleSize",
formatter = function(value)
local normalized = self:NormalizeChatBubbleSizeValue(value) or self.DEFAULTS.profile.chatBubbleSize
return self:GetChatBubbleSizeLabel(normalized)
end,
minValue = self.CHAT_BUBBLE_SIZE_MIN,
maxValue = self.CHAT_BUBBLE_SIZE_MAX,
stepSize = self.CHAT_BUBBLE_SIZE_STEP,
},
currentValue = self:NormalizeChatBubbleSizeValue(self:GetOption("chatBubbleSize")) or self.DEFAULTS.profile.chatBubbleSize,
settingName = "Font Size",
}, function(value)
if self:SetOption("chatBubbleSize", value) and not self.personalBubbleEditSessionRestoring then
UpdatePersonalBubbleEditSessionDirtyState()
self:RefreshPersonalBubbleAnchorVisualState()
self:AttachPersonalBubbleEditModeDialog()
end
end)
ConfigureEditModeSlider(dialog.DurationSlider, {
displayInfo = {
setting = "chatBubbleDuration",
formatter = FormatDurationLabel,
minValue = self.CHAT_BUBBLE_DURATION_MIN,
maxValue = self.CHAT_BUBBLE_DURATION_MAX,
stepSize = self.CHAT_BUBBLE_DURATION_STEP,
},
currentValue = self:NormalizeChatBubbleDurationValue(self:GetOption("chatBubbleDuration"))
or self.DEFAULTS.profile.chatBubbleDuration,
settingName = "Display Duration",
}, function(value)
if self:SetOption("chatBubbleDuration", value) and not self.personalBubbleEditSessionRestoring then
UpdatePersonalBubbleEditSessionDirtyState()
self:RefreshPersonalBubbleAnchorVisualState()
self:AttachPersonalBubbleEditModeDialog()
end
end)
if dialog.RevertButton then
dialog.RevertButton:SetEnabled(session and session.pending or false)
end
if dialog.ResetButton then
dialog.ResetButton:SetEnabled(not IsPersonalBubbleAtDefaultState())
end
end
function QuestTogether:SelectPersonalBubbleAnchor()
if not self:IsPersonalBubbleAnchorInEditMode() then
return
end
EnsurePersonalBubbleEditSession()
local hostFrame = GetAnnouncementBubbleScreenHostFrame()
if not hostFrame then
return
end
if EditModeManagerFrame and EditModeManagerFrame.ClearSelectedSystem then
EditModeManagerFrame:ClearSelectedSystem()
end
self.personalBubbleAnchorSelected = true
self:RefreshPersonalBubbleAnchorVisualState()
self:AttachPersonalBubbleEditModeDialog()
self:RefreshPersonalBubbleEditModeDialog()
local dialog = EnsurePersonalBubbleEditModeDialog()
if dialog then
dialog:Show()
end
end
function QuestTogether:DeselectPersonalBubbleAnchor()
self.personalBubbleAnchorSelected = false
if self.personalBubbleEditModeDialog then
self.personalBubbleEditModeDialog:Hide()
end
self:RefreshPersonalBubbleAnchorVisualState()
end
function QuestTogether:RefreshPersonalBubbleAnchorVisualState()
local hostFrame = self.announcementBubbleScreenHostFrame
if not hostFrame then
return
end
EnsurePersonalBubbleAnchorSelection(hostFrame)
local editModeActive = self:IsPersonalBubbleAnchorInEditMode()
local uiParentLevel = SafeUiNumber(
(UIParent and UIParent.GetFrameLevel and UIParent:GetFrameLevel()) or 0,
0
)
if editModeActive then
hostFrame:SetFrameStrata("HIGH")
hostFrame:SetFrameLevel(uiParentLevel + 80)
local visualConfig = GetAnnouncementBubbleVisualConfig()
local fontPath, fontFlags = GetPersonalBubbleAnchorFontDefinition()
hostFrame.EditLabel:SetFont(fontPath, visualConfig.fontSize, fontFlags)
hostFrame.EditLabel:SetWidth(0)
hostFrame.EditLabel:SetText("QuestTogether Bubble")
local labelWidth = hostFrame.EditLabel.GetUnboundedStringWidth and hostFrame.EditLabel:GetUnboundedStringWidth() or 0
labelWidth = SafeUiNumber(labelWidth, 0)
local labelHeight = SafeUiNumber(hostFrame.EditLabel:GetStringHeight(), visualConfig.fontSize)
labelWidth = math.max(visualConfig.minTextWidth, math.min(visualConfig.maxTextWidth, labelWidth))
local anchorWidth = labelWidth + visualConfig.iconSize + visualConfig.iconGap + (visualConfig.inset * 2)
local anchorHeight = math.max(visualConfig.iconSize, labelHeight) + (visualConfig.inset * 2)
hostFrame:SetSize(anchorWidth, anchorHeight)
hostFrame.EditIcon:SetSize(visualConfig.iconSize, visualConfig.iconSize)
hostFrame.EditIcon:ClearAllPoints()
hostFrame.EditIcon:SetPoint("LEFT", hostFrame, "LEFT", visualConfig.inset, 0)
hostFrame.EditLabel:ClearAllPoints()
hostFrame.EditLabel:SetPoint("LEFT", hostFrame.EditIcon, "RIGHT", visualConfig.iconGap, 0)
hostFrame.EditLabel:SetWidth(labelWidth)
else
hostFrame:SetFrameStrata("LOW")
hostFrame:SetFrameLevel(uiParentLevel + 5)
hostFrame:SetSize(1, 1)
end
local activeBubble = self.nameplateBubbleByUnitFrame and self.nameplateBubbleByUnitFrame[hostFrame]
if activeBubble then
activeBubble:SetFrameStrata(hostFrame:GetFrameStrata() or "LOW")
activeBubble:SetFrameLevel(SafeUiNumber(hostFrame:GetFrameLevel(), 0) + 20)