Repository navigation
Expand file tree
/
Copy pathcore.lua
More file actions
1055 lines (906 loc) · 34.5 KB
/
Copy pathcore.lua
File metadata and controls
1055 lines (906 loc) · 34.5 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
local AddOnName = ...;
---@class XIVBar : AceAddon-3.0, AceConsole-3.0, AceEvent-3.0
local XIVBar = select(2, ...);
local _G = _G;
local pairs, select = pairs, select
local AceAddon = _G.LibStub('AceAddon-3.0')
AceAddon:NewAddon(XIVBar, AddOnName, "AceConsole-3.0", "AceEvent-3.0");
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName, true);
LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(AddOnName, {
type = "launcher",
icon = "Interface\\Icons\\Spell_Nature_StormReach",
OnClick = function() XIVBar:ToggleConfig() end
})
XIVBar.Changelog = {}
XIVBar.L = L ---@type XIV_DatabarLocale
_G.XIV_Databar_Continued_OnAddonCompartmentClick = function()
XIVBar:ToggleConfig()
end
XIVBar.constants = {
mediaPath = "Interface\\AddOns\\" .. AddOnName .. "\\media\\",
playerName = UnitName("player"),
playerClass = select(2, UnitClass("player")),
playerLevel = UnitLevel("player"),
playerFactionLocal = select(2, UnitFactionGroup("player")),
playerRealm = GetRealmName(),
popupPadding = 10
}
XIVBar.LSM = LibStub('LibSharedMedia-3.0');
function XIVBar:OnInitialize()
-- Capture before AceDB creates a profile for a brand-new install.
local sv = _G.XIVBarDB
self._hadPriorInstall = type(sv) == "table"
and type(sv.profiles) == "table"
and next(sv.profiles) ~= nil
-- Omit default profile so new characters get a per-character "Name - Realm" profile.
-- Existing profileKeys (e.g. "Default") are preserved by AceDB.
self.db = LibStub("AceDB-3.0"):New("XIVBarDB", self.defaults)
self.LSM:Register(self.LSM.MediaType.FONT, 'Homizio Bold',
self.constants.mediaPath .. "homizio_bold.ttf")
self.frames = {}
self.fontFlags = {'', 'OUTLINE', 'THICKOUTLINE', 'MONOCHROME'}
self:SetupOptions()
-- Module defaults are appended in SetupOptions; re-register so AceDB copies them
-- into already-initialized sections and strips them correctly on logout.
self.db:RegisterDefaults(self.defaults)
self.timerRefresh = false
self:RegisterChatCommand('xivc', 'ToggleConfig')
self:RegisterChatCommand('xivbar', 'ToggleConfig')
self:RegisterChatCommand('xbc', 'ToggleConfig')
-- Defer so the chat frame is ready (OnInitialize is too early for reliable chat).
local function printStartupChatMessages()
if self.PrintLoadMessage then
self:PrintLoadMessage()
end
if self.MaybeAnnounceAddonUpdate then
self:MaybeAnnounceAddonUpdate()
end
end
if C_Timer and C_Timer.After then
C_Timer.After(2, printStartupChatMessages)
else
printStartupChatMessages()
end
end
local function AddChatMessage(message)
if DEFAULT_CHAT_FRAME and DEFAULT_CHAT_FRAME.AddMessage then
DEFAULT_CHAT_FRAME:AddMessage(message)
else
print(message)
end
end
function XIVBar:GetChatPrefix()
return "|cffffd100XIV Databar|r |cffb0b0b0Continued|r"
end
function XIVBar.ColorizeCommands(_, text)
if type(text) ~= "string" then return text end
local out = {}
local index = 1
while true do
local startPos, endPos, cmd = text:find("(/%w+)", index)
if not startPos then
table.insert(out, text:sub(index))
break
end
table.insert(out, text:sub(index, startPos - 1))
table.insert(out, "|cffffd100" .. cmd .. "|r")
index = endPos + 1
end
return table.concat(out)
end
function XIVBar:PrintLoadMessage()
if not (self.db and self.db.profile and self.db.profile.general) then return end
if self.db.profile.general.disableLoginMessage then return end
local prefix = self:GetChatPrefix()
local body = self:ColorizeCommands(
L["ADDON_LOADED_MSG"] or "loaded, type /xivc to open settings."
)
AddChatMessage(prefix .. " " .. body)
end
function XIVBar:OpenChangelogCategory()
local settings = _G["Settings"]
local openLegacyCategory = _G["InterfaceOptionsFrame_OpenToCategory"]
local category = self.changelogCategory or self.optionsCategory or "XIV Databar Continued"
if settings and settings.OpenToCategory then
settings.OpenToCategory(category)
elseif openLegacyCategory then
openLegacyCategory(category)
end
end
function XIVBar:ScheduleOpenChangelogAfterCombat()
if self._changelogOpenAfterCombat then return end
self._changelogOpenAfterCombat = true
local frame = self._changelogCombatFrame
if not frame then
frame = CreateFrame("Frame")
self._changelogCombatFrame = frame
end
frame:RegisterEvent("PLAYER_REGEN_ENABLED")
frame:SetScript("OnEvent", function(eventFrame, event)
if event ~= "PLAYER_REGEN_ENABLED" then return end
eventFrame:UnregisterEvent("PLAYER_REGEN_ENABLED")
eventFrame:SetScript("OnEvent", nil)
self._changelogOpenAfterCombat = nil
if self.OpenChangelogCategory then
self:OpenChangelogCategory()
end
end)
end
function XIVBar:HandleChangelogChatLink()
if InCombatLockdown() then
AddChatMessage(self:GetChatPrefix() .. ": " ..
(L["CHANGELOG_AFTER_COMBAT"] or "Changelog will open after combat ends"))
self:ScheduleOpenChangelogAfterCombat()
return
end
self:OpenChangelogCategory()
end
function XIVBar:MaybeAnnounceAddonUpdate()
if not (self.db and self.db.profile and self.db.profile.general) then return end
local currentVersion = C_AddOns.GetAddOnMetadata(AddOnName, "Version") or ""
-- Hotfix tags (e.g. 5.6.1-fix1): seed silently, no [Open Changelog] announce.
if currentVersion:lower():find("fix", 1, true) then
self.db.profile.general.lastChangelogAnnounce = currentVersion
return
end
local lastAnnounce = self.db.profile.general.lastChangelogAnnounce or ""
if lastAnnounce == "" then
-- Brand-new install: seed silently. Existing profiles: fall through and announce.
if not self._hadPriorInstall then
self.db.profile.general.lastChangelogAnnounce = currentVersion
return
end
elseif lastAnnounce == currentVersion then
return
end
local versionText = "|cffffd100" .. currentVersion .. "|r"
local linkText = "|cffdb6233[" .. (L["OPEN_CHANGELOG"] or "Open Changelog") .. "]|r"
local link = "|Hxivcchangelog:1|h" .. linkText .. "|h"
local body = (L["UPDATE_ANNOUNCE"] or "got updated to %s,"):format(versionText)
AddChatMessage(self:GetChatPrefix() .. " " .. body .. " " .. link)
self.db.profile.general.lastChangelogAnnounce = currentVersion
end
if not XIVBar._XIVC_ChangelogChatLinkHooked then
XIVBar._XIVC_ChangelogChatLinkHooked = true
hooksecurefunc("SetItemRef", function(link)
if type(link) ~= "string" then return end
local linkType = strsplit(":", link, 2)
if linkType ~= "xivcchangelog" then return end
if XIVBar and XIVBar.HandleChangelogChatLink then
XIVBar:HandleChangelogChatLink()
end
end)
end
-- Bump when the setup prompt must be shown again (e.g. after changing who gets it).
local PROFILE_SETUP_VERSION = 4
function XIVBar:GetCharacterProfileKey()
return self.constants.playerName .. " - " .. self.constants.playerRealm
end
function XIVBar:HasCompletedProfileSetup()
return (self.db.char.profileSetupVersion or 0) >= PROFILE_SETUP_VERSION
end
function XIVBar:MarkProfileSetupDone()
self.db.char.profileSetupVersion = PROFILE_SETUP_VERSION
-- Clear the early boolean flag that could silently suppress the Default prompt.
self.db.char.profileSetupDone = nil
self.profileSetupPending = nil
end
function XIVBar:HasDefaultProfile()
return self.db.profiles and rawget(self.db.profiles, "Default") ~= nil
end
function XIVBar:GetSharedProfileForCopy()
local pending = self.profileSetupPending
local charKey = (pending and pending.charKey) or self:GetCharacterProfileKey()
local candidate = pending and pending.preferred
if candidate and candidate ~= charKey then
return candidate
end
if self:HasDefaultProfile() then
return "Default"
end
return nil
end
-- copyShared: nil/false = blank personal profile; true = personal profile copied from shared/Default.
function XIVBar:CreatePersonalProfileFromSetup(copyShared)
local pending = self.profileSetupPending
local charKey = (pending and pending.charKey) or self:GetCharacterProfileKey()
local baseProfile = copyShared and self:GetSharedProfileForCopy() or nil
self:MarkProfileSetupDone()
if self.db:GetCurrentProfile() ~= charKey then
self.db:SetProfile(charKey)
end
if copyShared and baseProfile and baseProfile ~= charKey then
self.db:CopyProfile(baseProfile, true)
else
self.db:ResetProfile()
end
end
function XIVBar:UseSharedDefaultFromSetup()
self:MarkProfileSetupDone()
if self.db:GetCurrentProfile() ~= "Default" then
self.db:SetProfile("Default")
end
end
function XIVBar:MaybeShowProfileSetupPrompt()
if not self.db or self:HasCompletedProfileSetup() then
return
end
local charKey = self:GetCharacterProfileKey()
local current = self.db:GetCurrentProfile()
if current == "Default" then
-- Legacy shared profile: full migration dialog.
self.profileSetupPending = {
mode = "migrate",
preferred = "Default",
sourceProfile = current,
charKey = charKey,
isLegacyDefault = true,
}
self:ShowProfileSetupDialog("migrate")
return
end
if current == charKey and self:HasDefaultProfile() then
-- New character on a blank personal profile: offer shared Default or stay fresh.
self.profileSetupPending = {
mode = "newchar",
preferred = "Default",
sourceProfile = current,
charKey = charKey,
}
self:ShowProfileSetupDialog("newchar")
return
end
-- Custom profile, or first character with no Default yet.
self:MarkProfileSetupDone()
end
function XIVBar:CreateMainBar()
if self.frames.bar == nil then
local bar = CreateFrame("FRAME", "XIV_Databar", UIParent)
self:RegisterFrame('bar', bar)
self.frames.bgTexture = self.frames.bgTexture or bar:CreateTexture(nil, "BACKGROUND")
-- Create guide lines
local guides = CreateFrame("FRAME", nil, UIParent)
guides:SetAllPoints()
guides:Hide()
-- Vertical center line
local centerLine = guides:CreateTexture(nil, "OVERLAY")
centerLine:SetColorTexture(1, 1, 1, 0.3)
centerLine:SetWidth(2)
centerLine:SetPoint("TOP", UIParent, "TOP", 0, 0)
centerLine:SetPoint("BOTTOM", UIParent, "BOTTOM", 0, 0)
-- Horizontal center line
local hCenterLine = guides:CreateTexture(nil, "OVERLAY")
hCenterLine:SetColorTexture(1, 1, 1, 0.3)
hCenterLine:SetHeight(2)
hCenterLine:SetPoint("LEFT", UIParent, "LEFT", 0, 0)
hCenterLine:SetPoint("RIGHT", UIParent, "RIGHT", 0, 0)
-- Edge markers
local edgeMarkerSize = 40
local edgeMarkerThickness = 2
-- Top edge markers
local topLeft = guides:CreateTexture(nil, "OVERLAY")
topLeft:SetColorTexture(1, 1, 1, 0.3)
topLeft:SetSize(edgeMarkerSize, edgeMarkerThickness)
topLeft:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0)
local topRight = guides:CreateTexture(nil, "OVERLAY")
topRight:SetColorTexture(1, 1, 1, 0.3)
topRight:SetSize(edgeMarkerSize, edgeMarkerThickness)
topRight:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0)
-- Bottom edge markers
local bottomLeft = guides:CreateTexture(nil, "OVERLAY")
bottomLeft:SetColorTexture(1, 1, 1, 0.3)
bottomLeft:SetSize(edgeMarkerSize, edgeMarkerThickness)
bottomLeft:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0)
local bottomRight = guides:CreateTexture(nil, "OVERLAY")
bottomRight:SetColorTexture(1, 1, 1, 0.3)
bottomRight:SetSize(edgeMarkerSize, edgeMarkerThickness)
bottomRight:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", 0, 0)
-- Vertical edge markers
local leftTop = guides:CreateTexture(nil, "OVERLAY")
leftTop:SetColorTexture(1, 1, 1, 0.3)
leftTop:SetSize(edgeMarkerThickness, edgeMarkerSize)
leftTop:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, 0)
local leftBottom = guides:CreateTexture(nil, "OVERLAY")
leftBottom:SetColorTexture(1, 1, 1, 0.3)
leftBottom:SetSize(edgeMarkerThickness, edgeMarkerSize)
leftBottom:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", 0, 0)
local rightTop = guides:CreateTexture(nil, "OVERLAY")
rightTop:SetColorTexture(1, 1, 1, 0.3)
rightTop:SetSize(edgeMarkerThickness, edgeMarkerSize)
rightTop:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, 0)
local rightBottom = guides:CreateTexture(nil, "OVERLAY")
rightBottom:SetColorTexture(1, 1, 1, 0.3)
rightBottom:SetSize(edgeMarkerThickness, edgeMarkerSize)
rightBottom:SetPoint("BOTTOMRIGHT", UIParent, "BOTTOMRIGHT", 0, 0)
self.frames.guides = guides
-- Set initial frame level instead of strata
bar:SetFrameLevel(1)
-- Make the bar movable
bar:SetMovable(true)
bar:EnableMouse(true)
bar:RegisterForDrag("LeftButton")
-- Snap threshold in pixels
local SNAP_THRESHOLD = 20
-- Helper function to check if a value is within the snap threshold
local function IsWithinThreshold(value, target, threshold)
return math.abs(value - target) <= threshold
end
-- Helper function to get the center coordinates of the bar
local function GetBarCenter(frame)
local width, height = frame:GetSize()
local x, y = frame:GetCenter()
return x, y, width, height
end
-- Helper function to snap to nearest point if within threshold
local function GetSnappedPosition(frame)
local screenWidth, screenHeight = UIParent:GetWidth(), UIParent:GetHeight()
local centerX, centerY, barWidth = GetBarCenter(frame)
local point
local xOffset
local yOffset
local snapped = false
-- Check horizontal position
if IsWithinThreshold(centerX, screenWidth/2, SNAP_THRESHOLD) then
point = "CENTER"
xOffset = 0
snapped = true
elseif IsWithinThreshold(centerX - barWidth/2, 0, SNAP_THRESHOLD) then
point = "LEFT"
xOffset = 0
snapped = true
elseif IsWithinThreshold(centerX + barWidth/2, screenWidth, SNAP_THRESHOLD) then
point = "RIGHT"
xOffset = 0
snapped = true
else
point = "CENTER"
xOffset = centerX - screenWidth/2
end
-- Check vertical position
if IsWithinThreshold(centerY, 0, SNAP_THRESHOLD) then
yOffset = 0
point = "BOTTOM" .. (point ~= "CENTER" and point or "")
snapped = true
elseif IsWithinThreshold(centerY, screenHeight, SNAP_THRESHOLD) then
yOffset = 0
point = "TOP" .. (point ~= "CENTER" and point or "")
snapped = true
else
yOffset = centerY - screenHeight/2
end
return point, point, xOffset, yOffset, snapped
end
bar:SetScript("OnDragStart", function(frame)
if not XIVBar.db.profile.general.locked and not XIVBar.db.profile.general.barFullscreen then
frame:StartMoving()
XIVBar.frames.guides:Show()
end
end)
bar:SetScript("OnDragStop", function(frame)
if not XIVBar.db.profile.general.barFullscreen then
frame:StopMovingOrSizing()
XIVBar.frames.guides:Hide()
-- Get final position with snapping
local point, relativePoint, xOffset, yOffset = GetSnappedPosition(frame)
-- Save position
XIVBar.db.profile.general.point = point
XIVBar.db.profile.general.relativePoint = relativePoint
XIVBar.db.profile.general.xOffset = xOffset
XIVBar.db.profile.general.yOffset = yOffset
-- Apply position
frame:ClearAllPoints()
frame:SetPoint(point, UIParent, relativePoint, xOffset, yOffset)
XIVBar:Refresh()
end
end)
end
end
function XIVBar:ResetUI()
if UIParent_UpdateTopFramePositions then
UIParent_UpdateTopFramePositions()
end
end
function XIVBar:OnEnable()
self:CreateMainBar()
self:Refresh()
self.db.RegisterCallback(self, 'OnProfileCopied', 'Refresh')
self.db.RegisterCallback(self, 'OnProfileChanged', 'Refresh')
self.db.RegisterCallback(self, 'OnProfileReset', 'Refresh')
C_Timer.After(1, function()
if XIVBar and XIVBar.db then
XIVBar:MaybeShowProfileSetupPrompt()
end
end)
if not self.timerRefresh then
C_Timer.After(5, function()
self:Refresh()
self.timerRefresh = true
end)
end
end
function XIVBar:ToggleConfig()
local settings = _G["Settings"]
local openLegacyCategory = _G["InterfaceOptionsFrame_OpenToCategory"]
if settings and settings.OpenToCategory then
if self.optionsCategory then
settings.OpenToCategory(self.optionsCategory)
else
settings.OpenToCategory("XIV Bar Continued")
end
elseif openLegacyCategory then
local category = self.optionsCategory or "XIV Bar Continued"
openLegacyCategory(category)
else
self:Print("Impossible d'ouvrir les options sur cette version du client.")
end
end
function XIVBar:SetColor(name, r, g, b, a)
self.db.profile.color[name].r = r
self.db.profile.color[name].g = g
self.db.profile.color[name].b = b
self.db.profile.color[name].a = a
self:Refresh()
end
function XIVBar:GetColor(name)
local profile = self.db.profile.color
local r, g, b, a = profile[name].r, profile[name].g, profile[name].b, profile[name].a
if name == 'normal' and profile.useTextCC then
r, g, b = self:GetClassColors()
elseif name == 'barColor' and profile.useCC then
r, g, b = self:GetClassColors()
elseif name == 'hover' and profile.useHoverCC then
r, g, b = self:GetClassColors()
end
return r, g, b, a or 1
end
-- Pass nil year for SHORTDATENOYEAR (calendar/lockout dates without year).
function XIVBar:FormatLocalizedDate(day, month, year)
day, month = tonumber(day), tonumber(month)
if not (day and month) then
return nil
end
if year ~= nil then
year = tonumber(year)
if not year then
return nil
end
return FormatShortDate(day, month, year)
end
return FormatShortDate(day, month)
end
-- Accept YYYY-MM-DD or YYYY/MM/DD
function XIVBar:FormatLocalizedDateString(dateString)
if type(dateString) ~= "string" then
return dateString
end
local y, m, d = dateString:match("^(%d%d%d%d)[%-%/](%d%d)[%-%/](%d%d)$")
if not y then
return dateString
end
return self:FormatLocalizedDate(d, m, y) or dateString
end
function XIVBar:HoverColors()
local colors
local profile = self.db.profile.color
local hoverAlpha = profile.hover.a or 1
-- use self-picked color for hover color
if not profile.useHoverCC then
colors = {
profile.hover.r, profile.hover.g, profile.hover.b, hoverAlpha
}
-- use class color for hover color
else
local r, g, b = self:GetClassColors()
colors = {r, g, b, hoverAlpha}
end
return colors
end
function XIVBar:RegisterFrame(name, frame)
frame:SetScript('OnHide',
function() self:SendMessage('XIVBar_FrameHide', name) end)
frame:SetScript('OnShow',
function() self:SendMessage('XIVBar_FrameShow', name) end)
self.frames[name] = frame
end
function XIVBar:RegisterMouseoverHoldFrame(frame, keepVisibleWhileShown)
if not frame then
return
end
self.mouseoverHoldFrames = self.mouseoverHoldFrames or {}
self.mouseoverHoldFrames[frame] = true
frame._xivKeepVisibleWhileShown = (keepVisibleWhileShown ~= false)
end
function XIVBar:GetPopupDismissLayer()
if self.popupDismissLayer then
return self.popupDismissLayer
end
local layer = CreateFrame("BUTTON", nil, UIParent)
layer:SetAllPoints(UIParent)
layer:Hide()
layer:EnableMouse(true)
layer:RegisterForClicks("AnyUp", "AnyDown")
layer:SetFrameStrata("TOOLTIP")
layer:SetFrameLevel(1)
layer:SetScript("OnClick", function()
XIVBar:HideActivePopup()
end)
self.popupDismissLayer = layer
return layer
end
function XIVBar:ShowPopup(popup)
if not popup then
return
end
local layer = self:GetPopupDismissLayer()
if self.activePopup and self.activePopup ~= popup and self.activePopup.Hide then
self.activePopup:Hide()
end
self.activePopup = popup
if not popup._xivPopupAutoCloseHooked then
popup._xivPopupAutoCloseHooked = true
popup:HookScript("OnHide", function(frame)
if XIVBar.activePopup == frame then
XIVBar.activePopup = nil
if XIVBar.popupDismissLayer then
XIVBar.popupDismissLayer:Hide()
end
end
end)
end
layer:ClearAllPoints()
layer:SetAllPoints(UIParent)
layer:SetFrameStrata(popup:GetFrameStrata() or "TOOLTIP")
local popupLevel = popup:GetFrameLevel() or 1
layer:SetFrameLevel(math.max(1, popupLevel - 1))
layer:Show()
popup:Show()
end
function XIVBar:HidePopup(popup)
if not popup then
return
end
popup:Hide()
if self.activePopup == popup then
self.activePopup = nil
if self.popupDismissLayer then
self.popupDismissLayer:Hide()
end
end
end
function XIVBar:HideActivePopup()
if self.activePopup and self.activePopup.Hide then
self.activePopup:Hide()
return
end
if self.popupDismissLayer then
self.popupDismissLayer:Hide()
end
end
--- Get the frame with the specified name
---@param name string name of the frame as supplied to RegisterFrame
---@return Frame
function XIVBar:GetFrame(name) return self.frames[name] end
function XIVBar:HideBarEvent()
local bar = self:GetFrame("bar")
local vehiculeIsFlight = false;
bar:UnregisterAllEvents()
bar.OnEvent = nil
bar:RegisterEvent("PET_BATTLE_OPENING_START")
bar:RegisterEvent("PET_BATTLE_CLOSE")
bar:RegisterEvent("TAXIMAP_CLOSED")
bar:RegisterEvent("VEHICLE_POWER_SHOW")
bar:RegisterEvent("PLAYER_ENTERING_WORLD")
bar:RegisterEvent("ZONE_CHANGED_NEW_AREA")
bar:SetScript("OnEvent", function(_, event)
local barFrame = XIVBar:GetFrame("bar")
-- Handle zone changes and instance transitions
if event == "PLAYER_ENTERING_WORLD" or event == "ZONE_CHANGED_NEW_AREA" then
C_Timer.After(0.5, function()
if not barFrame:IsVisible() then
barFrame:Show()
end
-- Full refresh of the bar and modules
XIVBar:Refresh()
-- Force update module positions
XIVBar:ResetUI()
end)
return
end
if self.db.profile.general.barFlightHide then
if event == "VEHICLE_POWER_SHOW" then
if not barFrame:IsVisible() then barFrame:Show() end
if vehiculeIsFlight and barFrame:IsVisible() then
barFrame:Hide()
end
end
if event == "TAXIMAP_CLOSED" then
vehiculeIsFlight = true
C_Timer.After(1, function()
vehiculeIsFlight = false
end)
end
end
if event == "PET_BATTLE_OPENING_START" and barFrame:IsVisible() then
barFrame:Hide()
end
if event == "PET_BATTLE_CLOSE" and not barFrame:IsVisible() then
barFrame:Show()
end
end)
if self.db.profile.general.barCombatHide then
bar:RegisterEvent("PLAYER_REGEN_ENABLED")
bar:RegisterEvent("PLAYER_REGEN_DISABLED")
bar:HookScript("OnEvent", function(_, event)
local barFrame = XIVBar:GetFrame("bar")
if event == "PLAYER_REGEN_DISABLED" and barFrame:IsVisible() then
barFrame:Hide()
end
if event == "PLAYER_REGEN_ENABLED" and not barFrame:IsVisible() then
barFrame:Show()
-- Refresh modules when showing after combat
XIVBar:Refresh()
end
end)
else
if bar:IsEventRegistered("PLAYER_REGEN_ENABLED") then
bar:UnregisterEvent("PLAYER_REGEN_ENABLED")
elseif bar:IsEventRegistered("PLAYER_REGEN_DISABLED") then
bar:UnregisterEvent("PLAYER_REGEN_DISABLED")
end
end
end
function XIVBar:GetHeight()
return (self.db.profile.text.fontSize * 2) +
self.db.profile.general.barPadding
end
function XIVBar:ApplySavedBarOffset()
if self.frames.bar == nil then return end
if self.db.profile.general.barFullscreen then return end
if InCombatLockdown() then return end
local point = self.db.profile.general.point
if not point then return end
self.frames.bar:ClearAllPoints()
self.frames.bar:SetPoint(
point,
UIParent,
self.db.profile.general.relativePoint,
self.db.profile.general.xOffset,
self.db.profile.general.yOffset
)
end
function XIVBar:Refresh()
if self.frames.bar == nil then return; end
self:HideBarEvent()
self.miniTextPosition = "TOP"
if self.db.profile.general.barPosition == 'TOP' then
self.miniTextPosition = 'BOTTOM'
else
self:ResetUI();
end
if not InCombatLockdown() then
self.frames.bar:ClearAllPoints()
end
-- Use saved position if not in fullscreen mode
if not self.db.profile.general.barFullscreen then
-- If we have a saved custom position, use it
if self.db.profile.general.point then
self:ApplySavedBarOffset()
else
-- Initial position based on barHoriz and barPosition
self.frames.bar:SetPoint(self.db.profile.general.barPosition, UIParent, self.db.profile.general.barPosition)
if self.db.profile.general.barHoriz == 'LEFT' then
self.frames.bar:SetPoint("LEFT", UIParent, "LEFT", self.db.profile.general.barMargin, 0)
elseif self.db.profile.general.barHoriz == 'RIGHT' then
self.frames.bar:SetPoint("RIGHT", UIParent, "RIGHT", -self.db.profile.general.barMargin, 0)
else -- CENTER
self.frames.bar:SetPoint(self.db.profile.general.barHoriz, UIParent, self.db.profile.general.barHoriz, 0, 0)
end
end
self.frames.bar:SetWidth(self.db.profile.general.barWidth)
else
if not InCombatLockdown() then
self.frames.bar:SetPoint(self.db.profile.general.barPosition)
self.frames.bar:SetPoint("LEFT", self.db.profile.general.barMargin, 0)
self.frames.bar:SetPoint("RIGHT", -self.db.profile.general.barMargin, 0)
end
end
if not InCombatLockdown() then
self.frames.bar:SetHeight(self:GetHeight())
self.frames.bgTexture:SetColorTexture(self:GetColor('barColor'))
self.frames.bgTexture:SetAllPoints()
end
for _, module in self:IterateModules() do
if module['Refresh'] == nil then return; end
module:Refresh()
end
self:UpdateMouseoverScripts()
end
function XIVBar:GetFont(size)
return self.LSM:Fetch(self.LSM.MediaType.FONT, self.db.profile.text.font),
size, self.fontFlags[self.db.profile.text.flags]
end
function XIVBar:GetClassColors()
return RAID_CLASS_COLORS[self.constants.playerClass].r,
RAID_CLASS_COLORS[self.constants.playerClass].g,
RAID_CLASS_COLORS[self.constants.playerClass].b,
self.db.profile.color.barColor.a
end
function XIVBar:UpdateMouseoverScripts()
local bar = XIVBar.frames and XIVBar.frames.bar
if not bar then return end
local function IsMouseOverBar()
if bar:IsMouseOver() then
return true
end
if XIVBar.mouseoverHoldFrames then
for frame in pairs(XIVBar.mouseoverHoldFrames) do
if frame then
local isShown = frame.IsShown and frame:IsShown()
local isVisible = frame.IsVisible and frame:IsVisible()
if isShown and isVisible then
if frame:IsMouseOver() or frame._xivKeepVisibleWhileShown then
return true
end
end
end
end
end
return false
end
local function IsBarChild(frame)
local parent = frame and frame:GetParent()
while parent do
if parent == bar then
return true
end
parent = parent:GetParent()
end
return false
end
local function EnsureMouseoverAnimations()
if bar._xivFadeInGroup and bar._xivFadeOutGroup then
return
end
bar._xivFadeInGroup = bar:CreateAnimationGroup()
bar._xivFadeIn = bar._xivFadeInGroup:CreateAnimation("Alpha")
bar._xivFadeIn:SetOrder(1)
bar._xivFadeIn:SetDuration(0.15)
bar._xivFadeInGroup:SetScript("OnFinished", function()
bar:SetAlpha(1)
end)
bar._xivFadeOutGroup = bar:CreateAnimationGroup()
bar._xivFadeOut = bar._xivFadeOutGroup:CreateAnimation("Alpha")
bar._xivFadeOut:SetOrder(1)
bar._xivFadeOut:SetDuration(0.15)
bar._xivFadeOutGroup:SetScript("OnFinished", function()
bar:SetAlpha(0)
end)
end
local function PlayAlpha(group, anim, fromAlpha, toAlpha)
if group:IsPlaying() then
group:Stop()
end
anim:SetFromAlpha(fromAlpha)
anim:SetToAlpha(toAlpha)
group:Play()
end
local showBar
local hideBarIfOut
local function HookMouseoverFrame(frame)
if not (frame and frame.EnableMouse) then
return
end
if frame._xivMouseoverHooksInstalled then
return
end
frame:EnableMouse(true)
if frame._xivKeepVisibleWhileShown then
frame._xivMouseoverHooksInstalled = true
return
end
if not frame.HookScript then
return
end
frame._xivMouseoverHooksInstalled = true
frame:HookScript('OnEnter', showBar)
frame:HookScript('OnLeave', hideBarIfOut)
end
showBar = function()
bar._xivHidePending = false
if not bar._xivMouseoverEnabled then
return
end
if bar._xivMouseoverVisible then
return
end
EnsureMouseoverAnimations()
if bar._xivFadeOutGroup and bar._xivFadeOutGroup:IsPlaying() then
bar._xivFadeOutGroup:Stop()
end
bar._xivMouseoverVisible = true
PlayAlpha(bar._xivFadeInGroup, bar._xivFadeIn, bar:GetAlpha(), 1)
end
hideBarIfOut = function()
-- Petit délai pour laisser le curseur passer d'un enfant à l'autre sans clignoter
if bar._xivHidePending then return end
bar._xivHidePending = true
bar._xivHideToken = (bar._xivHideToken or 0) + 1
local token = bar._xivHideToken
C_Timer.After(0.12, function()
bar._xivHidePending = false
if token ~= bar._xivHideToken then
return
end
if not bar._xivMouseoverEnabled then
return
end
if not IsMouseOverBar() then
EnsureMouseoverAnimations()
if bar._xivFadeInGroup and bar._xivFadeInGroup:IsPlaying() then
bar._xivFadeInGroup:Stop()
end
bar._xivMouseoverVisible = false
PlayAlpha(bar._xivFadeOutGroup, bar._xivFadeOut, bar:GetAlpha(), 0)
end
end)
end
if XIVBar.db and XIVBar.db.profile and XIVBar.db.profile.general.showOnMouseover then
bar._xivMouseoverEnabled = true
bar._xivMouseoverVisible = false
bar._xivHidePending = false
bar:SetAlpha(0)
bar:SetScript('OnEnter', showBar)