-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.lua
More file actions
579 lines (529 loc) · 19.8 KB
/
Options.lua
File metadata and controls
579 lines (529 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
SimpleBars_colors = {}
SimpleBars_options = {}
local CLASS_COLORS = {
["WARRIOR"] = { r = 0.78, g = 0.61, b = 0.43, hex = "C79C6E" },
["MAGE"] = { r = 0.41, g = 0.80, b = 0.94, hex = "69CCF0" },
["ROGUE"] = { r = 1.00, g = 0.96, b = 0.41, hex = "FFF569" },
["DRUID"] = { r = 1.00, g = 0.49, b = 0.04, hex = "FF7D0A" },
["HUNTER"] = { r = 0.67, g = 0.83, b = 0.45, hex = "ABD473" },
["SHAMAN"] = { r = 0.0, g = 0.44, b = 0.87, hex = "0070DE" },
["PRIEST"] = { r = 1.00, g = 1.00, b = 1.00, hex = "FFFFFF" },
["WARLOCK"] = { r = 0.58, g = 0.51, b = 0.79, hex = "9482C9" },
["PALADIN"] = { r = 0.96, g = 0.55, b = 0.73, hex = "F58CBA" }
}
local _, class = UnitClass("player")
local classColor = CLASS_COLORS[class]
local classColorNorm = RAID_CLASS_COLORS[class]
local _G = getfenv(0)
local reset = {
config = function()
local dialog = StaticPopupDialogs["SIMPLEBARS_RESET"]
dialog.text = "Confirm that you want to reset the options to default?"
dialog.OnAccept = function()
SimpleBars_options = nil
SimpleBarsDB = nil
ReloadUI()
end
StaticPopup_Show("SIMPLEBARS_RESET")
end
}
SimpleBars_defaultOpt = {
{ text = "Toggles", default = nil, type = "header" },
{
text = "Enable Class Color",
default = true,
type = "checkbox",
config = "useClassColorForHealth",
func = function()
SB_UpdateHealth(_G["SimpleBars_HealthBar"], _G["SimpleBars_HealthBarText"])
end
},
{
text = "Enable Health Display",
default = true,
type = "checkbox",
config = "enableHealth",
func = function()
SB_UpdateHealthVisibility()
end
},
{
text = "Enable Power Display",
default = true,
type = "checkbox",
config = "enableMana",
func = function()
SB_UpdateManaVisibility()
end
},
{
text = "Enable Pet Display",
default = true,
type = "checkbox",
config = "enablePet",
func = function()
SB_UpdatePetVisibility()
end
},
{
text = "Enable Combat Fading",
default = true,
type = "checkbox",
config = "oocFade",
func = function()
SB_UpdateFade()
end
},
{
text = "Enable Text Mouseover",
default = true,
type = "checkbox",
config = "mouseOverText",
func = function()
--SB_UpdateFade()
end
},
{ text = "Appearance", default = nil, type = "header" },
{
text = "Out of Combat Alpha",
default = "1",
type = "text",
config = "oocFadeAlpha",
key = nil,
func = function()
SB_UpdateFade()
end
},
{
text = "Health Bar Height",
default = "20",
type = "text",
config = "healthFrame",
key = "height",
func = function()
SB_UpdateHealthVisibility()
end
},
{
text = "Health Bar Width",
default = "150",
type = "text",
config = "healthFrame",
key = "width",
func = function()
SB_UpdateHealthVisibility()
end
},
{
text = "Power Bar Height",
default = "20",
type = "text",
config = "manaFrame",
key = "height",
func = function()
SB_UpdateManaVisibility()
end
},
{
text = "Power Bar Width",
default = "150",
type = "text",
config = "manaFrame",
key = "width",
func = function()
SB_UpdateManaVisibility()
end
},
{
text = "Pet Bar Height",
default = "20",
type = "text",
config = "petFrame",
key = "height",
func = function()
SB_UpdatePetVisibility()
end
},
{
text = "Pet Bar Width",
default = "75",
type = "text",
config = "petFrame",
key = "width",
func = function()
SB_UpdatePetVisibility()
end
},
{ text = "Global", default = nil, type = "header" },
{
text = "Font Select",
default = "",
type = "dropdown_font",
config = "globalFont",
func = function()
SB_UpdateHealthVisibility()
SB_UpdateManaVisibility()
end
},
{
text = "Main Bars Text Size",
default = "14",
type = "text",
config = "mainFontSize",
key = nil,
func = function()
SB_UpdateHealthVisibility()
SB_UpdateManaVisibility()
end
},
{
text = "Pet Bar Text Size",
default = "12",
type = "text",
config = "petFontSize",
key = nil,
func = function()
SB_UpdatePetVisibility()
end
},
{
text = "Border Select",
default = "",
type = "dropdown_border",
config = "globalBorder",
func = function()
SB_UpdateBorder()
end
},
{
text = "Border Size",
default = "14",
type = "text",
config = "borderSize",
key = nil,
func = function()
SB_UpdateBorder()
end
},
{
text = "Border Inset",
default = "14",
type = "text",
config = "borderInset",
key = nil,
func = function()
SB_UpdateBorder()
end
},
}
StaticPopupDialogs["SIMPLEBARS_RESET"] = {
button1 = CONFIRM,
button2 = CANCEL,
timeout = 0,
whileDead = 1,
hideOnEscape = 1,
}
SimpleBarsOptions = CreateFrame("Frame", "SimpleBarsOptions", UIParent)
local opt = SimpleBarsOptions
opt:Hide()
opt:SetWidth(280)
opt:SetHeight(550)
opt:SetPoint("CENTER", 0, 0)
opt:SetFrameStrata("HIGH")
opt:SetMovable(true)
opt:EnableMouse(true)
opt:SetClampedToScreen(true)
opt:RegisterEvent("ADDON_LOADED")
opt:RegisterEvent("PLAYER_ENTERING_WORLD")
opt:SetScript("OnEvent", function()
if arg1 == "SimpleBars" then
opt:LoadConfig()
opt:CreateOptionsEntries(SimpleBars_defaultOpt)
if sbBrowserIcon and SimpleBars_options["minimapbutton"] == "0" then
sbBrowserIcon:Hide()
end
end
SimpleBars.api.CreateBackdrop(opt, nil, true, 1)
SimpleBars.api.SkinButton(opt.close, 1, .5, .5)
SimpleBars.api.SkinButton(opt.save)
end)
opt:SetScript("OnMouseDown", function()
this:StartMoving()
end)
opt:SetScript("OnMouseUp", function()
this:StopMovingOrSizing()
end)
opt:SetScript("OnShow", function()
this:UpdateOptionsEntries()
end)
opt.vertPos = 40
table.insert(UISpecialFrames, "SimpleBarsOptions")
local _, title = GetAddOnInfo("SimpleBars")
if title then
opt.path = "Interface\\AddOns\\SimpleBars"
opt.version = tostring(GetAddOnMetadata("SimpleBars", "Version"))
end
opt.title = opt:CreateFontString("Status", "LOW", "GameFontNormal")
opt.title:SetFontObject(GameFontWhite)
opt.title:SetPoint("TOP", opt, "TOP", 0, -12)
opt.title:SetJustifyH("LEFT")
opt.title:SetFont(STANDARD_TEXT_FONT, 14)
opt.title:SetText("|cff" .. classColor.hex .. "SimpleBars|r Options")
opt.texture = opt:CreateTexture("SimpleBarsTitleTex", "ARTWORK", nil, 0)
opt.texture:SetTexture("Interface\\AddOns\\SimpleBars\\Media\\header.blp")
opt.texture:ClearAllPoints()
opt.texture:SetPoint("TOPLEFT", opt, "TOPLEFT", 10, -10)
opt.texture:SetPoint("TOPRIGHT", opt, "TOPRIGHT", -10, -10)
opt.texture:SetHeight(20)
opt.close = CreateFrame("Button", "SimpleBarsOptionsClose", opt)
opt.close:SetPoint("TOPRIGHT", opt, "TOPRIGHT", -4, -6)
opt.close:SetWidth(28)
opt.close:SetHeight(28)
opt.close.texture = opt.close:CreateTexture("SimpleBarsDialogCloseTex")
opt.close.texture:SetTexture("Interface\\AddOns\\SimpleBars\\Media\\close.blp")
opt.close.texture:ClearAllPoints()
opt.close.texture:SetPoint("TOPLEFT", opt.close, "TOPLEFT", 8, -8)
opt.close.texture:SetPoint("BOTTOMRIGHT", opt.close, "BOTTOMRIGHT", -8, 8)
opt.close.texture:SetVertexColor(1, .25, .25, 1)
opt.close:SetScript("OnClick", function()
this:GetParent():Hide()
end)
opt.save = CreateFrame("Button", "SimpleBarsOptionsSave", opt)
opt.save:SetWidth(160)
opt.save:SetHeight(32)
opt.save:SetPoint("BOTTOM", 0, 10)
opt.save:SetScript("OnClick", ReloadUI)
opt.save.text = opt.save:CreateFontString("Caption", "LOW", "GameFontWhite")
opt.save.text:SetAllPoints(opt.save)
opt.save.text:SetFont(STANDARD_TEXT_FONT, 14, "OUTLINE")
opt.save.text:SetText("Confirm & Reload")
function opt:LoadConfig()
if not SimpleBarsDB then
SimpleBarsDB = {}
end
for id, data in pairs(SimpleBars_defaultOpt) do
if data.config and SimpleBarsDB[data.config] == nil then
SimpleBarsDB[data.config] = data.default
end
end
end
local maxHeight, maxWidth = 0, 0
local width, height = 230, 29
local maxText = 130
local configFrames = {}
function opt:CreateOptionsEntries(config)
local count = 1
for _, data in pairs(config) do
if data.type then
local frame = CreateFrame("Frame", "SimpleBarsOptions" .. count, opt)
configFrames[data.text] = frame
frame.caption = frame:CreateFontString("Status", "LOW", "GameFontWhite")
frame.caption:SetFont(STANDARD_TEXT_FONT, 12, "OUTLINE")
frame.caption:SetPoint("LEFT", 20, 0)
frame.caption:SetJustifyH("LEFT")
frame.caption:SetText(data.text)
maxText = max(maxText, frame.caption:GetStringWidth())
if data.type == "header" then
frame.caption:SetPoint("LEFT", 10, 0)
frame.caption:SetTextColor(classColorNorm.r, classColorNorm.g, classColorNorm.b)
frame.caption:SetFont(STANDARD_TEXT_FONT, 16, "OUTLINE")
elseif data.type == "checkbox" then
frame.input = CreateFrame("CheckButton", nil, frame, "UICheckButtonTemplate")
--frame.input:SetNormalTexture("")
--frame.input:SetPushedTexture("")
--frame.input:SetHighlightTexture("")
SimpleBars.api.CreateBackdrop(frame.input, nil, true)
frame.input:SetWidth(25)
frame.input:SetHeight(25)
frame.input:SetPoint("RIGHT", -20, 0)
frame.input.config = data.config
frame.input.func = data.func
if SimpleBarsDB[data.config] == true then
frame.input:SetChecked()
end
frame.input:SetScript("OnClick", function()
SimpleBarsDB[frame.input.config] = not SimpleBarsDB[frame.input.config]
if SimpleBarsDB[frame.input.config] == true then
SimpleBarsDB[frame.input.config] = true
else
SimpleBarsDB[frame.input.config] = false
end
if this.func and type(this.func) == "function" then
this.func()
end
--SimpleBars:ResetAll()
end)
elseif data.type == "text" then
frame.input = CreateFrame("EditBox", nil, frame)
frame.input:SetTextColor(classColorNorm.r, classColorNorm.g, classColorNorm.b)
frame.input:SetJustifyH("RIGHT")
frame.input:SetTextInsets(5, 5, 5, 5)
frame.input:SetWidth(32)
frame.input:SetHeight(16)
frame.input:SetPoint("RIGHT", -20, 0)
frame.input:SetFontObject(GameFontNormal)
frame.input:SetAutoFocus(false)
frame.input:SetMaxLetters(3)
frame.input.config = data.config
frame.input.func = data.func
frame.input.key = data.key
if data.key then
frame.input:SetText(tostring(SimpleBarsDB[frame.input.config][frame.input.key]))
else
frame.input:SetText(tostring(SimpleBarsDB[frame.input.config]))
end
frame.input:SetScript("OnEscapePressed", function(self)
this:ClearFocus()
end)
frame.input:SetScript("OnTextChanged", function(self)
local newValue = tonumber(this:GetText())
if newValue then
if this.key then
SimpleBarsDB[this.config][this.key] = newValue
else
SimpleBarsDB[this.config] = newValue
end
end
if this.func and type(this.func) == "function" then
this.func()
end
end)
frame.input:SetScript("OnEnterPressed", function()
this:ClearFocus()
end)
local b = CreateFrame("Frame", nil, frame.input)
b:SetPoint("TOPLEFT", frame.input, "TOPLEFT", -15, 8)
b:SetPoint("BOTTOMRIGHT", frame.input, "BOTTOMRIGHT", 7, -10)
b:SetBackdrop({
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\AddOns\\SimpleBars\\Media\\Border\\border.blp",
tile = false,
tileSize = 16,
edgeSize = 16,
insets = { left = 8, right = 8, top = 8, bottom = 8 }
})
b:SetBackdropColor(0.25, 0.25, 0.25, 1)
b:SetBackdropBorderColor(.4, .4, .4, 1)
b:SetFrameLevel(frame.input:GetFrameLevel() - 1)
elseif data.type == "dropdown_font" then
frame.input = CreateFrame("Frame", "SimpleBarsFontDropdown" .. tostring(math.random(1000)), frame,
"UIDropDownMenuTemplate")
frame.input:SetPoint("RIGHT", frame, "RIGHT", -115, 0)
frame.input.config = data.config
frame.input.func = data.func
UIDropDownMenu_Initialize(frame.input, function(self, level)
local fontNames = {}
for fontName in pairs(SimpleBarsDB.fonts) do
table.insert(fontNames, fontName)
end
table.sort(fontNames)
for _, fontName in ipairs(fontNames) do
local fontPath = SimpleBarsDB.fonts[fontName]
local info = {}
info.text = fontName
info.value = fontPath
info.func = function()
-- Save the selected font to the database
SimpleBarsDB[frame.input.config] = info.value
-- Set the selected value in the dropdown
UIDropDownMenu_SetSelectedValue(frame.input, SimpleBarsDB[frame.input.config])
-- Call the provided function if it exists
frame.input.func()
end
UIDropDownMenu_AddButton(info, level)
end
end)
if SimpleBarsDB[data.config] then
UIDropDownMenu_SetSelectedValue(frame.input, SimpleBarsDB[data.config])
else
UIDropDownMenu_SetSelectedValue(frame.input, SimpleBarsDB.fonts["Blank"]) -- Set to default value
end
elseif data.type == "dropdown_border" then
frame.input = CreateFrame("Frame", "SimpleBarsBorderDropdown" .. tostring(math.random(1000)), frame,
"UIDropDownMenuTemplate")
frame.input:SetPoint("RIGHT", frame, "RIGHT", -115, 0)
frame.input.config = data.config
frame.input.func = data.func
UIDropDownMenu_Initialize(frame.input, function(self, level)
local borderNames = {}
for borderName in pairs(SimpleBarsDB.borders) do
table.insert(borderNames, borderName)
end
table.sort(borderNames)
for _, borderName in ipairs(borderNames) do
local borderPath = SimpleBarsDB.borders[borderName]
SB_print("Adding border:", borderName, borderPath)
if borderName and borderPath then
local info = {}
info.text = borderName
info.value = borderPath
info.func = function()
-- Save the selected border to the database
SimpleBarsDB[frame.input.config] = info.value
-- Set the selected value in the dropdown
UIDropDownMenu_SetSelectedValue(frame.input, SimpleBarsDB[frame.input.config])
-- Call the provided function if it exists
if frame.input.func then
frame.input.func()
end
end
UIDropDownMenu_AddButton(info, level)
else
SB_print("Error: Missing border data - borderName:", borderName, " borderPath:", borderPath)
end
end
end)
if SimpleBarsDB[data.config] then
UIDropDownMenu_SetSelectedValue(frame.input, SimpleBarsDB[data.config])
else
UIDropDownMenu_SetSelectedValue(frame.input, SimpleBarsDB.borders["Simple"]) -- Set to default value
end
end
if frame.input and SimpleBars.api.emulated then
frame.input:SetWidth(frame.input:GetWidth() / .6)
frame.input:SetHeight(frame.input:GetHeight() / .6)
frame.input:SetScale(.8)
if frame.input.SetTextInsets then
frame.input:SetTextInsets(8, 8, 8, 8)
end
end
count = count + 1
end
end
width = maxText + 100
local column, row = 1, 0
for _, data in pairs(config) do
if data.type then
row = row + (data.type == "header" and row > 1 and 2 or 1)
if row > 20 and data.type == "header" then
column, row = column + 1, 1
end
maxWidth, maxHeight = max(maxWidth, column), max(maxHeight, row)
local spacer = (column - 1) * 20
local x, y = (column - 1) * width, -(row - 1) * height
local frame = configFrames[data.text]
frame:SetWidth(width)
frame:SetHeight(height)
frame:SetPoint("TOPLEFT", opt, "TOPLEFT", x + spacer + 10, y - 40)
end
end
local spacer = (maxWidth - 1) * 20
opt:SetWidth(maxWidth * width + spacer + 20)
opt:SetHeight(maxHeight * height + 100)
end
function opt:UpdateOptionsEntries()
for _, data in pairs(SimpleBars_defaultOpt) do
if data.type and configFrames[data.text] then
if data.type == "checkbox" then
configFrames[data.text].input:SetChecked((SimpleBarsDB[data.config] == true and true or nil))
elseif data.type == "text" then
if data.key then
configFrames[data.text].input:SetText(tostring(SimpleBarsDB[configFrames[data.text].input.config]
[configFrames[data.text].input.key]))
else
configFrames[data.text].input:SetText(tostring(SimpleBarsDB[configFrames[data.text].input.config]))
end
end
end
end
end