Repository navigation
Expand file tree
/
Copy pathSettings.lua
More file actions
564 lines (483 loc) · 16.8 KB
/
Copy pathSettings.lua
File metadata and controls
564 lines (483 loc) · 16.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
local addonName, ns = ...
ShieldFramesDB = ShieldFramesDB or {}
local ADDON_DESCRIPTION = "ShieldFrames is a small and lightweight addon that displays absorb shields on unit frames. The goal is to provide important shield information at a glance without clutter or complexity."
local function DB()
return ns.GetDB()
end
local function RefreshFrames()
if ns.RefreshAllFrames then
ns.RefreshAllFrames()
end
end
local function RefreshFramesDeferred()
C_Timer.After(0, RefreshFrames)
end
local function CreateCheckbox(category, key, label, tooltip)
local setting = Settings.RegisterProxySetting(
category,
addonName .. "_" .. key,
Settings.VarType.Boolean,
label,
ns.defaults[key],
function()
if DB()[key] == nil then
return ns.defaults[key]
end
return DB()[key]
end,
function(value)
DB()[key] = value
end
)
local init = Settings.CreateCheckbox(category, setting, tooltip)
setting:SetValueChangedCallback(RefreshFramesDeferred)
return init
end
local function FormatOpacityValue(value)
return string.format("%.2f", value / 100)
end
local function CreateOpacitySlider(category, key, label, tooltip)
local setting = Settings.RegisterProxySetting(
category,
addonName .. "_" .. key,
Settings.VarType.Number,
label,
ns.defaults[key],
function()
return DB()[key] or ns.defaults[key]
end,
function(value)
DB()[key] = math.floor(value + 0.5)
end
)
local options = Settings.CreateSliderOptions(5, 100, 5)
if options.SetMinLabel then
options:SetMinLabel("Low")
end
if options.SetMaxLabel then
options:SetMaxLabel("High")
end
options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right, FormatOpacityValue)
local init = Settings.CreateSlider(category, setting, options, tooltip)
setting:SetValueChangedCallback(RefreshFramesDeferred)
return init
end
local function GetGlowColorComponents()
local color = DB().glowColor
if type(color) ~= "table" then
color = ns.defaults.glowColor
end
return color.r or ns.defaults.glowColor.r,
color.g or ns.defaults.glowColor.g,
color.b or ns.defaults.glowColor.b
end
local function SetGlowColor(r, g, b, shouldRefresh)
DB().glowColor = { r = r, g = g, b = b }
if shouldRefresh ~= false then
RefreshFramesDeferred()
end
end
local function RestorePickerColor(setColor, previousR, previousG, previousB, onSwatchUpdate)
setColor(previousR, previousG, previousB, false)
if onSwatchUpdate then
onSwatchUpdate()
end
if ns.RestoreAllBlizzGlowFadeStates then
ns.RestoreAllBlizzGlowFadeStates()
end
RefreshFramesDeferred()
end
local function PrepareColorPickerFrame(anchorFrame)
if not ColorPickerFrame then
return
end
ColorPickerFrame:Hide()
ColorPickerFrame:SetParent(UIParent)
ColorPickerFrame:SetFrameStrata("FULLSCREEN_DIALOG")
local frameLevel = 1000
if anchorFrame and anchorFrame.GetFrameLevel then
frameLevel = anchorFrame:GetFrameLevel() + 100
elseif SettingsPanel and SettingsPanel.GetFrameLevel then
frameLevel = SettingsPanel:GetFrameLevel() + 100
end
ColorPickerFrame:SetFrameLevel(frameLevel)
ColorPickerFrame:SetClampedToScreen(true)
ColorPickerFrame:ClearAllPoints()
ColorPickerFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
end
local function OpenRGBColorPicker(getComponents, setColor, onSwatchUpdate, anchorFrame)
if not ColorPickerFrame then
return
end
local r, g, b = getComponents()
local previousR, previousG, previousB = r, g, b
local settingsWasOpen = SettingsPanel and SettingsPanel:IsShown()
local restoredSettings = false
local function ApplyColor(newR, newG, newB)
setColor(newR, newG, newB)
if onSwatchUpdate then
onSwatchUpdate()
end
end
local function RestoreSettingsPanel()
if restoredSettings or not settingsWasOpen then
return
end
restoredSettings = true
C_Timer.After(0, function()
if Settings and Settings.OpenToCategory and ns.categoryID then
Settings.OpenToCategory(ns.categoryID)
elseif SettingsPanel then
ShowUIPanel(SettingsPanel)
end
end)
end
local function OnPickerCancel(restore)
local r, g, b
if type(restore) == "table" then
r = restore.r or restore[1]
g = restore.g or restore[2]
b = restore.b or restore[3]
end
if not r and ColorPickerFrame.GetPreviousValues then
r, g, b = ColorPickerFrame:GetPreviousValues()
end
if r then
RestorePickerColor(setColor, r, g, b, onSwatchUpdate)
else
RestorePickerColor(setColor, previousR, previousG, previousB, onSwatchUpdate)
end
end
local function BeginColorPickerSession()
if settingsWasOpen then
HideUIPanel(SettingsPanel)
end
PrepareColorPickerFrame(anchorFrame)
local previousOnHide = ColorPickerFrame:GetScript("OnHide")
ColorPickerFrame:SetScript("OnHide", function(self, ...)
if previousOnHide then
previousOnHide(self, ...)
end
RestoreSettingsPanel()
self:SetScript("OnHide", previousOnHide)
end)
end
if ColorPickerFrame.SetupColorPickerAndShow then
BeginColorPickerSession()
ColorPickerFrame:SetupColorPickerAndShow({
r = r,
g = g,
b = b,
hasOpacity = false,
swatchFunc = function()
ApplyColor(ColorPickerFrame:GetColorRGB())
end,
cancelFunc = OnPickerCancel,
})
return
end
BeginColorPickerSession()
ColorPickerFrame.hasOpacity = false
ColorPickerFrame.previousValues = { r = previousR, g = previousG, b = previousB }
ColorPickerFrame.func = function()
ApplyColor(ColorPickerFrame:GetColorRGB())
end
ColorPickerFrame.cancelFunc = OnPickerCancel
ColorPickerFrame.swatchFunc = function()
ApplyColor(ColorPickerFrame:GetColorRGB())
end
ColorPickerFrame:SetColorRGB(r, g, b)
ColorPickerFrame:Show()
end
local function HideListElementChrome(frame)
if frame.Checkbox then
frame.Checkbox:Hide()
end
if frame.Button then
frame.Button:Hide()
end
if frame.Control then
frame.Control:Hide()
end
if frame.NewFeature then
frame.NewFeature:Hide()
end
end
local function UpdateGlowSwatch(swatch)
if not swatch then
return
end
local r, g, b = GetGlowColorComponents()
if swatch.UpdateColor then
swatch:UpdateColor(r, g, b)
elseif swatch.Swatch and swatch.Swatch.SetColorRGB then
swatch.Swatch:SetColorRGB(r, g, b)
elseif swatch.SetColorRGB then
swatch:SetColorRGB(r, g, b)
elseif swatch.Swatch and swatch.Swatch.SetColorTexture then
swatch.Swatch:SetColorTexture(r, g, b)
elseif swatch.ColorFill and swatch.ColorFill.SetColorTexture then
swatch.ColorFill:SetColorTexture(r, g, b)
elseif swatch.Color and swatch.Color.SetColorTexture then
swatch.Color:SetColorTexture(r, g, b)
end
end
local COLOR_PICKER_WIDTH = 140
local COLOR_PICKER_HEIGHT = 26
local COLOR_PICKER_SWATCH_MARGIN = 5
local COLOR_PICKER_ARROW_ZONE = 36
local function CreateSimpleArrow(parent)
local arrow = parent:CreateTexture(nil, "OVERLAY")
arrow:SetSize(10, 6)
arrow:SetPoint("CENTER", parent, "CENTER", 0, 0)
local ok = pcall(function()
arrow:SetAtlas("common-icon-backarrow")
if arrow.SetRotation then
arrow:SetRotation(math.rad(90))
end
if arrow.SetDesaturated then
arrow:SetDesaturated(true)
end
arrow:SetVertexColor(0.62, 0.62, 0.62)
end)
if not ok then
arrow:SetTexture("Interface\\Buttons\\UI-ScrollBar-ScrollDownButton-Up")
arrow:SetTexCoord(0.25, 0.75, 0.3, 0.7)
arrow:SetVertexColor(0.62, 0.62, 0.62)
end
return arrow
end
local function CreateGlowColorPickerButton(parent, onClick)
local picker = CreateFrame("Button", nil, parent, "BackdropTemplate")
picker:SetSize(COLOR_PICKER_WIDTH, COLOR_PICKER_HEIGHT)
picker:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = false,
edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
picker:SetBackdropColor(0.11, 0.11, 0.11, 1)
picker:SetBackdropBorderColor(0.48, 0.48, 0.48, 1)
local swatchWidth = COLOR_PICKER_WIDTH - COLOR_PICKER_ARROW_ZONE - (COLOR_PICKER_SWATCH_MARGIN * 2)
local swatchHeight = COLOR_PICKER_HEIGHT - (COLOR_PICKER_SWATCH_MARGIN * 2)
picker.Swatch = CreateFrame("Frame", nil, picker, "BackdropTemplate")
picker.Swatch:SetSize(swatchWidth, swatchHeight)
picker.Swatch:SetPoint("LEFT", COLOR_PICKER_SWATCH_MARGIN, 0)
picker.Swatch:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = false,
edgeSize = 8,
insets = { left = 2, right = 2, top = 2, bottom = 2 },
})
picker.ArrowZone = CreateFrame("Frame", nil, picker)
picker.ArrowZone:SetPoint("TOPRIGHT", -COLOR_PICKER_SWATCH_MARGIN, -COLOR_PICKER_SWATCH_MARGIN)
picker.ArrowZone:SetPoint("BOTTOMRIGHT", COLOR_PICKER_SWATCH_MARGIN, COLOR_PICKER_SWATCH_MARGIN)
picker.ArrowZone:SetWidth(COLOR_PICKER_ARROW_ZONE)
picker.Arrow = CreateSimpleArrow(picker.ArrowZone)
function picker:UpdateColor(r, g, b)
self.Swatch:SetBackdropColor(r, g, b, 1)
self.Swatch:SetBackdropBorderColor(0.28, 0.28, 0.28, 1)
end
picker:SetScript("OnClick", onClick)
picker:SetScript("OnEnter", function(self)
self:SetBackdropBorderColor(0.62, 0.62, 0.62, 1)
end)
picker:SetScript("OnLeave", function(self)
self:SetBackdropBorderColor(0.48, 0.48, 0.48, 1)
end)
return picker
end
local function CanUseCustomInitializers()
return ScrollBoxFactoryInitializerMixin
and SettingsElementHierarchyMixin
and SettingsSearchableElementMixin
and CreateFromMixins
end
local function CreateAboutDescriptionInitializer()
local AboutDescriptionInitializer = CreateFromMixins(
ScrollBoxFactoryInitializerMixin,
SettingsElementHierarchyMixin,
SettingsSearchableElementMixin
)
function AboutDescriptionInitializer:Init()
ScrollBoxFactoryInitializerMixin.Init(self, "SettingsListElementTemplate")
self.data = {
name = "About ShieldFrames",
tooltip = ADDON_DESCRIPTION,
}
self:AddSearchTags("About", "ShieldFrames", "description")
end
function AboutDescriptionInitializer:GetExtent()
return 84
end
function AboutDescriptionInitializer:InitFrame(frame)
frame:SetSize(280, 84)
HideListElementChrome(frame)
if not frame.cbrHandles then
frame.cbrHandles = Settings.CreateCallbackHandleContainer()
end
if frame.Text then
frame.Text:Hide()
end
if not frame.descBox then
frame.descBox = CreateFrame("Frame", nil, frame, "BackdropTemplate")
frame.descBox:SetPoint("TOPLEFT", 16, -4)
frame.descBox:SetPoint("BOTTOMRIGHT", -16, 4)
frame.descBox:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
tileSize = 16,
edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
frame.descBox:SetBackdropColor(0.09, 0.09, 0.09, 0.92)
frame.descBox:SetBackdropBorderColor(0.35, 0.35, 0.35, 0.9)
frame.descText = frame.descBox:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
frame.descText:SetPoint("TOPLEFT", 10, -8)
frame.descText:SetPoint("BOTTOMRIGHT", -10, 8)
frame.descText:SetJustifyH("LEFT")
frame.descText:SetJustifyV("TOP")
frame.descText:SetWordWrap(true)
frame.descText:SetSpacing(2)
frame.descText:SetText(ADDON_DESCRIPTION)
end
end
function AboutDescriptionInitializer:Resetter(frame)
if frame.cbrHandles then
frame.cbrHandles:Unregister()
end
end
local initializer = CreateFromMixins(AboutDescriptionInitializer)
initializer:Init()
return initializer
end
local function CreateGlowColorInitializer()
local GlowColorInitializer = CreateFromMixins(
ScrollBoxFactoryInitializerMixin,
SettingsElementHierarchyMixin,
SettingsSearchableElementMixin
)
function GlowColorInitializer:Init()
ScrollBoxFactoryInitializerMixin.Init(self, "SettingsListElementTemplate")
self.data = {
name = "Glow Color",
tooltip = "Tint for the overshield edge glow.",
}
self:AddSearchTags("Glow Color", "color")
end
function GlowColorInitializer:GetExtent()
return 26
end
function GlowColorInitializer:InitFrame(frame)
frame:SetSize(280, 26)
HideListElementChrome(frame)
if not frame.cbrHandles then
frame.cbrHandles = Settings.CreateCallbackHandleContainer()
end
frame.data = self.data
frame.Text:SetFontObject("GameFontNormal")
frame.Text:SetText("Glow Color")
frame.Text:ClearAllPoints()
frame.Text:SetPoint("LEFT", 16, 0)
frame.Text:SetPoint("RIGHT", frame, "CENTER", -85, 0)
frame.Text:SetJustifyH("LEFT")
frame.Text:Show()
local function UpdateSwatch()
UpdateGlowSwatch(frame.colorPicker)
end
if not frame.colorPicker then
frame.colorPicker = CreateGlowColorPickerButton(frame, function(button)
OpenRGBColorPicker(GetGlowColorComponents, SetGlowColor, UpdateSwatch, button)
end)
frame.colorPicker:ClearAllPoints()
frame.colorPicker:SetPoint("LEFT", frame, "CENTER", -74, 0)
UpdateSwatch()
else
UpdateSwatch()
end
end
function GlowColorInitializer:Resetter(frame)
if frame.cbrHandles then
frame.cbrHandles:Unregister()
end
end
local initializer = CreateFromMixins(GlowColorInitializer)
initializer:Init()
return initializer
end
local function CreateAboutDescription(layout)
if CanUseCustomInitializers() then
layout:AddInitializer(CreateAboutDescriptionInitializer())
return
end
layout:AddInitializer(CreateSettingsButtonInitializer(
addonName,
"View on GitHub",
function()
if OpenURL then
OpenURL("https://github.com/WaffleBar/ShieldFrames")
end
end,
ADDON_DESCRIPTION,
true
))
end
local function CreateGlowColorRow(layout)
if CanUseCustomInitializers() then
layout:AddInitializer(CreateGlowColorInitializer())
return
end
layout:AddInitializer(CreateSettingsButtonInitializer(
"Glow Color",
"Choose Color",
function()
OpenRGBColorPicker(GetGlowColorComponents, SetGlowColor)
end,
"Tint for the overshield edge glow.",
true
))
end
local function InitializeSettings()
local category, layout = Settings.RegisterVerticalLayoutCategory(addonName)
Settings.RegisterAddOnCategory(category)
ns.categoryID = category:GetID()
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("About"))
CreateAboutDescription(layout)
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer("General"))
CreateCheckbox(
category,
"enabled",
"Enable ShieldFrames",
"Show overshield absorb overlays on supported Blizzard unit frames."
)
CreateOpacitySlider(
category,
"overlayOpacity",
"Overlay Opacity",
"Transparency of the overshield fill drawn over the health bar."
)
CreateCheckbox(
category,
"showGlow",
"Show Edge Glow",
"Draw a bright edge on the left side of the overshield overlay."
)
CreateOpacitySlider(
category,
"glowOpacity",
"Glow Opacity",
"Brightness of the overshield edge glow."
)
CreateGlowColorRow(layout)
end
EventUtil.ContinueOnPlayerLogin(function()
if ns.MigrateSavedSettings then
ns.MigrateSavedSettings()
elseif ns.MergeDefaults then
ns.MergeDefaults()
end
InitializeSettings()
end)