Repository navigation
Expand file tree
/
Copy pathOptions.lua
More file actions
182 lines (166 loc) · 5.32 KB
/
Copy pathOptions.lua
File metadata and controls
182 lines (166 loc) · 5.32 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
---@type string
local addonName = ...
---@class Whetstone
local ns = select(2, ...)
---@class WhetstoneOptions
local Options = {}
ns.Options = Options
ns.DEFAULTS = {
shown = true,
locked = false,
hideInCombat = false,
point = "CENTER",
relPoint = "CENTER",
x = 0,
y = -150,
showIcon = true,
showNames = true,
fullBar = false,
showBar = true,
showBonus = true,
showSecondary = true,
showWeapons = true,
allWeapons = false,
hideMaxed = false,
vertical = false,
perLine = 6,
scale = 1,
spacing = 4,
bgAlpha = 0.6,
border = true,
texture = "Blizzard",
font = "Default",
fontSize = 10,
flash = true,
sound = true,
chatAlerts = true,
}
---@class OptionRow
---@field header string?
---@field key string?
---@field label string?
---@field tooltip string?
---@field slider SliderRange?
---@field media MediaKind?
---@class SliderRange
---@field min number
---@field max number
---@field step number
---@field format string
---@type OptionRow[]
local LAYOUT = {
{ header = "Display" },
{ key = "showIcon", label = "Show skill icons" },
{ key = "showNames", label = "Show skill names" },
{
key = "fullBar",
label = "Full-height bars",
tooltip = "The progress bar fills the tile, with the text drawn on top of it.",
},
{ key = "showBar", label = "Show progress bar" },
{ key = "showBonus", label = "Show skill bonuses", tooltip = "Racial and gear bonuses, such as (+5)." },
{ key = "showSecondary", label = "Show secondary skills" },
{ key = "showWeapons", label = "Show weapon skills" },
{
key = "allWeapons",
label = "Show every weapon skill",
tooltip = "Otherwise a weapon skill shows while its weapon is equipped or after it gains a point this session.",
},
{ key = "hideMaxed", label = "Hide maxed skills" },
{ key = "vertical", label = "Vertical layout" },
{ key = "perLine", label = "Tiles per line", slider = { min = 1, max = 20, step = 1, format = "%d" } },
{ header = "Behaviour" },
{ key = "shown", label = "Show bar" },
{ key = "locked", label = "Lock position" },
{ key = "hideInCombat", label = "Hide in combat" },
{ header = "Alerts" },
{ key = "flash", label = "Flash on skill-up" },
{ key = "sound", label = "Sound when capped or ready to train" },
{ key = "chatAlerts", label = "Chat message when capped or ready to train" },
{ header = "Appearance" },
{ key = "scale", label = "Scale", slider = { min = 0.5, max = 2, step = 0.05, format = "%.2f" } },
{ key = "spacing", label = "Tile spacing", slider = { min = 0, max = 20, step = 1, format = "%d" } },
{ key = "bgAlpha", label = "Background opacity", slider = { min = 0, max = 1, step = 0.05, format = "%.2f" } },
{ key = "border", label = "Show border" },
{ key = "texture", label = "Bar texture", media = "statusbar" },
{ key = "font", label = "Font", media = "font" },
{ key = "fontSize", label = "Font size", slider = { min = 8, max = 14, step = 1, format = "%d" } },
}
local VAR_TYPES = {
boolean = Settings.VarType.Boolean,
number = Settings.VarType.Number,
string = Settings.VarType.String,
}
function Options:Init()
local category, layout = Settings.RegisterVerticalLayoutCategory(addonName)
self.category = category
for _, row in ipairs(LAYOUT) do
if row.header then
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(row.header))
else
local default = ns.DEFAULTS[row.key]
local setting = Settings.RegisterProxySetting(
category,
addonName .. "_" .. row.key,
VAR_TYPES[type(default)],
row.label,
default,
function() return ns.db[row.key] end,
function(value)
ns.db[row.key] = value
ns.Bar:Apply()
end
)
local slider, media = row.slider, row.media
if media then
Settings.CreateDropdown(category, setting, function()
local container = Settings.CreateControlTextContainer()
for _, name in ipairs(ns.Media.List(media)) do
container:Add(name, name)
end
return container:GetData()
end, row.tooltip)
elseif slider then
local options = Settings.CreateSliderOptions(slider.min, slider.max, slider.step)
options:SetLabelFormatter(
MinimalSliderWithSteppersMixin.Label.Right,
function(value) return slider.format:format(value) end
)
Settings.CreateSlider(category, setting, options, row.tooltip)
else
Settings.CreateCheckbox(category, setting, row.tooltip)
end
end
end
layout:AddInitializer(
CreateSettingsButtonInitializer("Position", "Reset position", function() ns.Bar:ResetPosition() end, nil, true)
)
for _, kind in ipairs(ns.KIND_ORDER) do
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(ns.KINDS[kind].label))
for _, skill in ipairs(ns.SKILLS) do
if skill.kind == kind then self:AddSkillCheckbox(category, skill) end
end
end
Settings.RegisterAddOnCategory(category)
end
---@param skill Skill
function Options:AddSkillCheckbox(category, skill)
local setting = Settings.RegisterProxySetting(
category,
addonName .. "_skill_" .. skill.name,
Settings.VarType.Boolean,
skill.name,
true,
function() return not ns.db.hidden[skill.name] end,
function(value)
ns.db.hidden[skill.name] = not value or nil
ns.Bar:Refresh()
end
)
Settings.CreateCheckbox(category, setting)
end
function Options:Open()
-- OpenSettingsPanel is protected, so addon code cannot call it in combat.
if InCombatLockdown() then return ns.Print(ERR_NOT_IN_COMBAT) end
Settings.OpenToCategory(self.category:GetID())
end