forked from Kozoaku/XIV_Databar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.lua
660 lines (606 loc) · 21.1 KB
/
core.lua
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
local AddOnName, XIVBar = ...;
local _G = _G;
local pairs, unpack, select = pairs, unpack, select
LibStub("AceAddon-3.0"):NewAddon(XIVBar, AddOnName, "AceConsole-3.0", "AceEvent-3.0");
local L = LibStub("AceLocale-3.0"):GetLocale(AddOnName, true);
local ldb = LibStub:GetLibrary("LibDataBroker-1.1"):NewDataObject(AddOnName, {
type = "launcher",
icon = "Interface\\Icons\\Spell_Nature_StormReach",
OnClick = function(clickedframe, button)
XIVBar:ToggleConfig()
end,
})
XIVBar.L = L
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.defaults = {
profile = {
general = {
barPosition = "BOTTOM",
barPadding = 3,
moduleSpacing = 30,
barFullscreen = true,
barWidth = GetScreenWidth(),
barHoriz = 'CENTER',
barCombatHide = false,
barFlightHide = false,
useElvUI = true,
},
color = {
barColor = {
r = 0.094,
g = 0.094,
b = 0.094,
a = 0.75
},
normal = {
r = 0.8,
g = 0.8,
b = 0.8,
a = 0.75
},
inactive = {
r = 1,
g = 1,
b = 1,
a = 0.25
},
useCC = false,
useTextCC = false,
useHoverCC = true,
hover = {
r = RAID_CLASS_COLORS[XIVBar.constants.playerClass].r,
g = RAID_CLASS_COLORS[XIVBar.constants.playerClass].g,
b = RAID_CLASS_COLORS[XIVBar.constants.playerClass].b,
a = RAID_CLASS_COLORS[XIVBar.constants.playerClass].a
}
},
text = {
fontSize = 12,
smallFontSize = 11,
font = 'Homizio Bold'
},
modules = {
}
}
};
XIVBar.LSM = LibStub('LibSharedMedia-3.0');
function XIVBar:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("XIVBarDB", self.defaults, true)
self.LSM:Register(self.LSM.MediaType.FONT, 'Homizio Bold', self.constants.mediaPath.."homizio_bold.ttf")
self.frames = {}
self.fontFlags = {'', 'OUTLINE', 'THICKOUTLINE', 'MONOCHROME'}
local options = {
name = "XIV Bar",
handler = XIVBar,
type = 'group',
args = {
general = {
name = GENERAL_LABEL,
type = "group",
args = {
general = self:GetGeneralOptions()
}
}, -- general
modules = {
name = L['Modules'],
type = "group",
args = {
}
} -- modules
}
}
for name, module in self:IterateModules() do
if module['GetConfig'] ~= nil then
options.args.modules.args[name] = module:GetConfig()
end
if module['GetDefaultOptions'] ~= nil then
local oName, oTable = module:GetDefaultOptions()
self.defaults.profile.modules[oName] = oTable
end
end
self.db:RegisterDefaults(self.defaults)
LibStub("AceConfig-3.0"):RegisterOptionsTable(AddOnName, options)
self.optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(AddOnName, "XIV Bar", nil, "general")
--options.args.modules = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
self.modulesOptionFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(AddOnName, L['Modules'], "XIV Bar", "modules")
options.args.profiles = LibStub("AceDBOptions-3.0"):GetOptionsTable(self.db)
self.profilesOptionFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions(AddOnName, 'Profiles', "XIV Bar", "profiles")
self.timerRefresh = false
self:RegisterChatCommand('xivbar', 'ToggleConfig')
self:RegisterChatCommand('xb', 'ToggleConfig')
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')
if not self.timerRefresh then
C_Timer.After(5, function()
self:Refresh()
self.timerRefresh = true
end)
end
end
function XIVBar:ToggleConfig()
InterfaceOptionsFrame.selectedTab = 2;
InterfaceOptionsFrame:Show()--weird hack ; options registration is wrong in some way
InterfaceOptionsFrame_OpenToCategory("XIV Bar")
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 a = profile[name].a
-- what a stupid hacky solution, the whole config part is kind of fucked and i dread having to come fix this eventually.
-- feel like just burning it all down and writing something from scratch when seeing shit like this. terrible library.
if name == 'normal' then
-- use class color for normal color
if profile.useTextCC then
local r, g, b = self:GetClassColors()
return r, g, b, a
end
end
-- use self-picked color for normal color
return profile[name].r, profile[name].g, profile[name].b, a
end
function XIVBar:HoverColors()
local colors
local profile = self.db.profile.color
-- use self-picked color for hover color
if not profile.useHoverCC then
colors = { profile.hover.r, profile.hover.g, profile.hover.b, profile.hover.a }
-- use class color for hover color
else
local r, g, b = self:GetClassColors()
colors = { r, g, b, profile.hover.a }
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:GetFrame(name)
return self.frames[name]
end
function XIVBar:CreateMainBar()
if self.frames.bar == nil then
self:RegisterFrame('bar', CreateFrame("FRAME", "XIV_Databar", UIParent))
self.frames.bgTexture = self.frames.bgTexture or self.frames.bar:CreateTexture(nil, "BACKGROUND")
end
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:SetScript("OnEvent", function(_, event, ...)
if self.db.profile.general.barFlightHide then
if event == "VEHICLE_POWER_SHOW" then
if not XIVBar:IsVisible() then
XIVBar:Show()
end
if vehiculeIsFlight and XIVBar:IsVisible() then
XIVBar: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 XIVBar:IsVisible() then
XIVBar:Hide()
end
if event=="PET_BATTLE_CLOSE" and not XIVBar:IsVisible() then
XIVBar: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, ...)
if event=="PLAYER_REGEN_DISABLED" and XIVBar:IsVisible() then
XIVBar:Hide()
end
if event=="PLAYER_REGEN_ENABLED" and not XIVBar:IsVisible() then
XIVBar:Show()
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:Refresh()
if self.frames.bar == nil then return; end
self:HideBarEvent()
self.miniTextPosition = "TOP"
if self.db.profile.general.barPosition == 'TOP' then
hooksecurefunc("UIParent_UpdateTopFramePositions", function(self)
if(XIVBar.db.profile.general.barPosition == 'TOP') then
OffsetUI()
end
end)
OffsetUI()
self.miniTextPosition = 'BOTTOM'
else
self:ResetUI();
end
local barColor = self.db.profile.color.barColor
self.frames.bar:ClearAllPoints()
self.frames.bar:SetPoint(self.db.profile.general.barPosition)
if self.db.profile.general.barFullscreen then
self.frames.bar:SetPoint("LEFT")
self.frames.bar:SetPoint("RIGHT")
else
local relativePoint = self.db.profile.general.barHoriz
if relativePoint == 'CENTER' then
relativePoint = 'BOTTOM'
end
self.frames.bar:SetPoint(self.db.profile.general.barHoriz, self.frames.bar:GetParent(), relativePoint)
self.frames.bar:SetWidth(self.db.profile.general.barWidth)
end
self.frames.bar:SetHeight(self:GetHeight())
self.frames.bgTexture:SetColorTexture(self:GetColor('barColor'))
self.frames.bgTexture:SetAllPoints()
for name, module in self:IterateModules() do
if module['Refresh'] == nil then return; end
module:Refresh()
end
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:RGBAToHex(r, g, b, a)
a = a or 1
r = r <= 1 and r >= 0 and r or 0
g = g <= 1 and g >= 0 and g or 0
b = b <= 1 and b >= 0 and b or 0
a = a <= 1 and a >= 0 and a or 1
return string.format("%02x%02x%02x%02x", r*255, g*255, b*255, a*255)
end
function XIVBar:HexToRGBA(hex)
local rhex, ghex, bhex, ahex = string.sub(hex, 1, 2), string.sub(hex, 3, 4), string.sub(hex, 5, 6), string.sub(hex, 7, 8)
if not (rhex and ghex and bhex and ahex) then
return 0, 0, 0, 0
end
return (tonumber(rhex, 16) / 255), (tonumber(ghex, 16) / 255), (tonumber(bhex, 16) / 255), (tonumber(ahex, 16) / 255)
end
function XIVBar:PrintTable(table, prefix)
for k,v in pairs(table) do
if type(v) == 'table' then
self:PrintTable(v, prefix..'.'..k)
else
print(prefix..'.'..k..': '..tostring(v))
end
end
end
function OffsetUI()
local offset=XIVBar.frames.bar:GetHeight();
local buffsAreaTopOffset = offset;
--@non-retail@
if (PlayerFrame and not PlayerFrame:IsUserPlaced() and not PlayerFrame_IsAnimatedOut(PlayerFrame)) then
PlayerFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", -19, -4 - offset)
end
if (TargetFrame and not TargetFrame:IsUserPlaced()) then
TargetFrame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 250, -4 - offset);
end
--@end-non-retail@
local ticketStatusFrameShown = TicketStatusFrame and TicketStatusFrame:IsShown();
local gmChatStatusFrameShown = GMChatStatusFrame and GMChatStatusFrame:IsShown();
if (ticketStatusFrameShown) then
TicketStatusFrame:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -180, 0 - offset);
buffsAreaTopOffset = buffsAreaTopOffset + TicketStatusFrame:GetHeight();
end
if (gmChatStatusFrameShown) then
GMChatStatusFrame:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -170, -5 - offset);
buffsAreaTopOffset = buffsAreaTopOffset + GMChatStatusFrame:GetHeight() + 5;
end
if (not ticketStatusFrameShown and not gmChatStatusFrameShown) then
buffsAreaTopOffset = buffsAreaTopOffset + 13;
end
BuffFrame:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", -205, 0 - buffsAreaTopOffset);
end
function XIVBar:ResetUI()
if topOffsetBlizz then
UIParent_UpdateTopFramePositions = topOffsetBlizz
end
UIParent_UpdateTopFramePositions();
end
function XIVBar:GetGeneralOptions()
return {
name = GENERAL_LABEL,
type = "group",
inline = true,
args = {
positioning = {
name = L["Positioning"],
type = "group",
order = 1,
inline = true,
args = {
barLocation = {
name = L['Bar Position'],
type = "select",
order = 2,
width = "full",
values = {TOP = L['Top'], BOTTOM = L['Bottom']},
style = "dropdown",
get = function() return self.db.profile.general.barPosition; end,
set = function(info, value) self.db.profile.general.barPosition = value;
self:Refresh(); end,
},
flightHide = {
name = "Hide when in flight",
type = "toggle",
order = 1,
get = function() return self.db.profile.general.barFlightHide end,
set = function(_,val) self.db.profile.general.barFlightHide = val; self:Refresh(); end
},
fullScreen = {
name = VIDEO_OPTIONS_FULLSCREEN,
type = "toggle",
order = 4,
get = function() return self.db.profile.general.barFullscreen; end,
set = function(info, value) self.db.profile.general.barFullscreen = value; self:Refresh(); end,
},
barPosition = {
name = L['Horizontal Position'],
type = "select",
hidden = function() return self.db.profile.general.barFullscreen; end,
order = 5,
values = {LEFT = L['Left'], CENTER = L['Center'], RIGHT = L['Right']},
style = "dropdown",
get = function() return self.db.profile.general.barHoriz; end,
set = function(info, value) self.db.profile.general.barHoriz = value; self:Refresh(); end,
disabled = function() return self.db.profile.general.barFullscreen; end
},
barWidth = {
name = L['Bar Width'],
type = 'range',
order = 6,
hidden = function() return self.db.profile.general.barFullscreen; end,
min = 200,
max = GetScreenWidth(),
step = 1,
get = function() return self.db.profile.general.barWidth; end,
set = function(info, val) self.db.profile.general.barWidth = val; self:Refresh(); end,
disabled = function() return self.db.profile.general.barFullscreen; end
}
}
},
text = self:GetTextOptions(),
colors = {
name = L["Colors"],
type = "group",
inline = true,
order = 3,
args = {
barColor = {
name = L['Bar Color'],
type = "color",
order = 1,
hasAlpha = true,
set = function(info, r, g, b, a)
if not self.db.profile.color.useCC then
self:SetColor('barColor', r, g, b, a)
else
local cr,cg,cb,_ = self:GetClassColors()
self:SetColor('barColor',cr,cg,cb,a)
end
end,
get = function() return XIVBar:GetColor('barColor') end,
},
barCC = {
name = L['Use Class Color for Bar'],
desc = L["Only the alpha can be set with the color picker"],
type = "toggle",
order = 2,
set = function(info, val) XIVBar:SetColor('barColor',self:GetClassColors()); self.db.profile.color.useCC = val; self:Refresh(); end,
get = function() return self.db.profile.color.useCC end
},
textColors = self:GetTextColorOptions()
}
},
miscellanelous = {
name = L["Miscellaneous"],
type = "group",
inline = true,
order = 3,
args = {
barCombatHide = {
name = L['Hide Bar in combat'],
type = "toggle",
order = 9,
get = function() return self.db.profile.general.barCombatHide; end,
set = function(_,val) self.db.profile.general.barCombatHide = val; self:Refresh(); end
},
barPadding = {
name = L['Bar Padding'],
type = 'range',
order = 10,
min = 0,
max = 10,
step = 1,
get = function() return self.db.profile.general.barPadding; end,
set = function(info, val) self.db.profile.general.barPadding = val; self:Refresh(); end
},
moduleSpacing = {
name = L['Module Spacing'],
type = 'range',
order = 11,
min = 10,
max = 80,
step = 1,
get = function() return self.db.profile.general.moduleSpacing; end,
set = function(info, val) self.db.profile.general.moduleSpacing = val; self:Refresh(); end
},
useElvUI = {
name = L['Use ElvUI for tooltips'],
type = "toggle",
order = 12,
get = function() return self.db.profile.general.useElvUI; end,
set = function(_, val) self.db.profile.general.useElvUI = val; self:Refresh(); end
}
}
}
}
}
end
function XIVBar:GetTextOptions()
return {
name = LOCALE_TEXT_LABEL,
type = "group",
order = 2,
inline = true,
args = {
font = {
name = L['Font'],
type = "select",
dialogControl = 'LSM30_Font',
order = 1,
values = AceGUIWidgetLSMlists.font,
style = "dropdown",
get = function() return self.db.profile.text.font; end,
set = function(info, val) self.db.profile.text.font = val; self:Refresh(); end
},
fontSize = {
name = FONT_SIZE,
type = 'range',
order = 2,
min = 10,
max = 40,
step = 1,
get = function() return self.db.profile.text.fontSize; end,
set = function(info, val) self.db.profile.text.fontSize = val; self:Refresh(); end
},
smallFontSize = {
name = L['Small Font Size'],
type = 'range',
order = 2,
min = 10,
max = 20,
step = 1,
get = function() return self.db.profile.text.smallFontSize; end,
set = function(info, val) self.db.profile.text.smallFontSize = val; self:Refresh(); end
},
textFlags = {
name = L['Text Style'],
type = 'select',
style = 'dropdown',
order = 3,
values = self.fontFlags,
get = function() return self.db.profile.text.flags; end,
set = function(info, val) self.db.profile.text.flags = val; self:Refresh(); end
},
}
}
end
function XIVBar:GetTextColorOptions()
return {
name = L['Text Colors'],
type = "group",
order = 3,
inline = true,
args = {
normal = {
name = L['Normal'],
type = "color",
order = 1,
width = "double",
hasAlpha = true,
set = function(info, r, g, b, a)
if self.db.profile.color.useTextCC then
r,g,b,_=self:GetClassColors()
end
XIVBar:SetColor('normal', r, g, b, a)
end,
get = function() return XIVBar:GetColor('normal') end
},
textCC = {
name = L["Use Class Color for Text"],
desc = L["Only the alpha can be set with the color picker"],
type = "toggle",
order = 2,
set = function(_,val)
if val then
XIVBar:SetColor("normal",self:GetClassColors())
end
self.db.profile.color.useTextCC = val
end,
get = function() return self.db.profile.color.useTextCC end
},
hover = {
name = L['Hover'],
type = "color",
order = 3,
width = "double",
hasAlpha = true,
set = function(info, r, g, b, a)
if self.db.profile.color.useHoverCC then
r,g,b,_=self:GetClassColors()
end
XIVBar:SetColor('hover', r, g, b, a)
end,
get = function() return XIVBar:GetColor('hover') end,
},
hoverCC = {
name = L['Use Class Colors for Hover'],
type = "toggle",
order = 4,
set = function(_, val)
if val then
XIVBar:SetColor("hover",self:GetClassColors())
end
self.db.profile.color.useHoverCC = val; self:Refresh(); end,
get = function() return self.db.profile.color.useHoverCC end
},
inactive = {
name = L['Inactive'],
type = "color",
order = 5,
hasAlpha = true,
width = "double",
set = function(info, r, g, b, a)
XIVBar:SetColor('inactive', r, g, b, a)
end,
get = function() return XIVBar:GetColor('inactive') end
},
}
}
end