-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.lua
More file actions
287 lines (252 loc) · 9.55 KB
/
Copy pathOptions.lua
File metadata and controls
287 lines (252 loc) · 9.55 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
local NoPoizen = _G.NoPoizen
if not NoPoizen then
return
end
NoPoizen.optionControls = NoPoizen.optionControls or {}
local function CreateSectionLabel(parent, text, x, y, fontObject)
local label = parent:CreateFontString(nil, "OVERLAY", fontObject or "GameFontHighlight")
label:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
label:SetText(text)
return label
end
local function CreateCheckbox(parent, optionKey, text, tooltipText, x, y)
local checkbox = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
checkbox:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("LEFT", checkbox, "RIGHT", 6, 0)
label:SetText(text)
checkbox.Label = label
if type(tooltipText) == "string" and tooltipText ~= "" then
checkbox.tooltipText = tooltipText
end
checkbox:SetScript("OnClick", function(self)
NoPoizen:ApplyOptionsControlValue(optionKey, self:GetChecked() == true)
NoPoizen:RefreshOptionsWindow()
end)
return checkbox
end
local function SetSliderEnabled(slider, enabled)
if not slider then
return
end
slider:SetEnabled(enabled)
if slider.Text then
slider.Text:SetTextColor(enabled and 1 or 0.5, enabled and 0.82 or 0.5, enabled and 0 or 0.5)
end
if slider.Low then
slider.Low:SetTextColor(enabled and 1 or 0.6, enabled and 1 or 0.6, enabled and 1 or 0.6)
end
if slider.High then
slider.High:SetTextColor(enabled and 1 or 0.6, enabled and 1 or 0.6, enabled and 1 or 0.6)
end
slider:SetAlpha(enabled and 1 or 0.5)
end
function NoPoizen:RefreshOptionsWindow()
if not self.optionControls then
return
end
local controls = self.optionControls
controls.database = self.db
if controls.enabled then
controls.enabled:SetChecked(self:GetOption("enabled") == true)
end
if controls.showVisualIndicator then
controls.showVisualIndicator:SetChecked(self:GetOption("showVisualIndicator") == true)
end
if controls.playAudioIndicator then
controls.playAudioIndicator:SetChecked(self:GetOption("playAudioIndicator") == true)
end
if controls.playSatisfiedAudioIndicator then
controls.playSatisfiedAudioIndicator:SetChecked(self:GetOption("playSatisfiedAudioIndicator") == true)
end
local currentVolume = self:NormalizeAudioVolume(self:GetOption("audioVolume")) or self.DEFAULTS.audioVolume
if controls.audioVolumeSlider then
controls.audioVolumeSlider.npUpdating = true
controls.audioVolumeSlider:SetValue(currentVolume)
controls.audioVolumeSlider.npUpdating = false
end
if controls.audioVolumeValue then
controls.audioVolumeValue:SetText(string.format("%d%%", math.floor((currentVolume * 100) + 0.5)))
end
local currentSatisfiedVolume = self:NormalizeAudioVolume(self:GetOption("satisfiedAudioVolume"))
or self.DEFAULTS.satisfiedAudioVolume
if controls.satisfiedAudioVolumeSlider then
controls.satisfiedAudioVolumeSlider.npUpdating = true
controls.satisfiedAudioVolumeSlider:SetValue(currentSatisfiedVolume)
controls.satisfiedAudioVolumeSlider.npUpdating = false
end
if controls.satisfiedAudioVolumeValue then
controls.satisfiedAudioVolumeValue:SetText(
string.format("%d%%", math.floor((currentSatisfiedVolume * 100) + 0.5))
)
end
local audioEnabled = self:GetOption("playAudioIndicator") == true
SetSliderEnabled(controls.audioVolumeSlider, audioEnabled)
local satisfiedAudioEnabled = self:GetOption("playSatisfiedAudioIndicator") == true
SetSliderEnabled(controls.satisfiedAudioVolumeSlider, satisfiedAudioEnabled)
end
function NoPoizen:ApplyOptionsControlValue(optionKey, value)
if not self.optionControls or self.optionControls.database ~= self.db then
self:RefreshOptionsWindow()
return false
end
return self:SetOption(optionKey, value)
end
function NoPoizen:OpenOptionsWindow()
if self:IsHUDRestricted() then
return false
end
-- Retry registration if Settings was unavailable during ADDON_LOADED.
self:InitializeOptionsWindow()
if not (Settings and Settings.OpenToCategory and self.optionsCategory and self.optionsCategory.GetID) then
return false
end
Settings.OpenToCategory(self.optionsCategory:GetID())
return true
end
function NoPoizen:TryRegisterOptionsCategory()
if self.optionsCategory then
self.pendingOptionsRegistration = nil
return true
end
self.pendingOptionsRegistration = true
if self:IsHUDRestricted() or not self.optionsFrame then
return false
end
if not (Settings and Settings.RegisterCanvasLayoutCategory and Settings.RegisterAddOnCategory) then
return false
end
-- Use the supported canvas registration API; never add fields to its category.
local category = Settings.RegisterCanvasLayoutCategory(self.optionsFrame, "NoPoizen")
if not category then
return false
end
Settings.RegisterAddOnCategory(category)
self.optionsCategory = category
self.pendingOptionsRegistration = nil
return true
end
function NoPoizen:InitializeOptionsWindow()
self:EnsureHUDLifecycleFrame()
if self:IsHUDRestricted() then
self.pendingOptionsRegistration = true
return
end
if self.optionsFrame then
self:TryRegisterOptionsCategory()
return
end
local frame = CreateFrame("Frame", "NoPoizenOptionsPanel")
frame.name = "NoPoizen"
local title = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", frame, "TOPLEFT", 16, -16)
title:SetText("NoPoizen")
local subtitle = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
subtitle:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
subtitle:SetText("Rogue poison reminder settings.")
local enabled = CreateCheckbox(frame, "enabled", "Enable NoPoizen", nil, 16, -66)
CreateSectionLabel(frame, "Indicators", 16, -108, "GameFontHighlight")
local showVisualIndicator = CreateCheckbox(
frame,
"showVisualIndicator",
"Show visual indicator when poisons are missing",
"Show missing poison icons near the center of the screen.",
16,
-132
)
local playAudioIndicator = CreateCheckbox(
frame,
"playAudioIndicator",
"Play audio indicator when poisons are missing",
"Play the NoPoizen alert sound once when entering a missing-poison state.",
16,
-160
)
local audioVolumeSlider = CreateFrame("Slider", nil, frame, "OptionsSliderTemplate")
audioVolumeSlider:SetPoint("TOPLEFT", frame, "TOPLEFT", 32, -212)
audioVolumeSlider:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -48, -212)
audioVolumeSlider:SetMinMaxValues(self.AUDIO_VOLUME_MIN, self.AUDIO_VOLUME_MAX)
audioVolumeSlider:SetValueStep(self.AUDIO_VOLUME_STEP)
if audioVolumeSlider.SetObeyStepOnDrag then
audioVolumeSlider:SetObeyStepOnDrag(true)
end
if audioVolumeSlider.Text then
audioVolumeSlider.Text:SetText("Audio indicator volume")
end
if audioVolumeSlider.Low then
audioVolumeSlider.Low:SetText("0%")
end
if audioVolumeSlider.High then
audioVolumeSlider.High:SetText("100%")
end
local audioVolumeValue = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
audioVolumeValue:SetPoint("TOP", audioVolumeSlider, "BOTTOM", 0, -4)
audioVolumeValue:SetText("")
audioVolumeSlider:SetScript("OnValueChanged", function(slider, value)
local normalized = NoPoizen:NormalizeAudioVolume(value) or NoPoizen.DEFAULTS.audioVolume
audioVolumeValue:SetText(string.format("%d%%", math.floor((normalized * 100) + 0.5)))
if slider.npUpdating then
return
end
NoPoizen:ApplyOptionsControlValue("audioVolume", normalized)
end)
local playSatisfiedAudioIndicator = CreateCheckbox(
frame,
"playSatisfiedAudioIndicator",
"Play sound when poison requirements are satisfied",
"Play a sound once when transitioning from missing poisons to fully satisfied.",
16,
-266
)
local satisfiedAudioVolumeSlider = CreateFrame("Slider", nil, frame, "OptionsSliderTemplate")
satisfiedAudioVolumeSlider:SetPoint("TOPLEFT", frame, "TOPLEFT", 32, -318)
satisfiedAudioVolumeSlider:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -48, -318)
satisfiedAudioVolumeSlider:SetMinMaxValues(self.AUDIO_VOLUME_MIN, self.AUDIO_VOLUME_MAX)
satisfiedAudioVolumeSlider:SetValueStep(self.AUDIO_VOLUME_STEP)
if satisfiedAudioVolumeSlider.SetObeyStepOnDrag then
satisfiedAudioVolumeSlider:SetObeyStepOnDrag(true)
end
if satisfiedAudioVolumeSlider.Text then
satisfiedAudioVolumeSlider.Text:SetText("Satisfied sound volume")
end
if satisfiedAudioVolumeSlider.Low then
satisfiedAudioVolumeSlider.Low:SetText("0%")
end
if satisfiedAudioVolumeSlider.High then
satisfiedAudioVolumeSlider.High:SetText("100%")
end
local satisfiedAudioVolumeValue = frame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
satisfiedAudioVolumeValue:SetPoint("TOP", satisfiedAudioVolumeSlider, "BOTTOM", 0, -4)
satisfiedAudioVolumeValue:SetText("")
satisfiedAudioVolumeSlider:SetScript("OnValueChanged", function(slider, value)
local normalized = NoPoizen:NormalizeAudioVolume(value) or NoPoizen.DEFAULTS.satisfiedAudioVolume
satisfiedAudioVolumeValue:SetText(string.format("%d%%", math.floor((normalized * 100) + 0.5)))
if slider.npUpdating then
return
end
NoPoizen:ApplyOptionsControlValue("satisfiedAudioVolume", normalized)
end)
self.optionControls = {
enabled = enabled,
showVisualIndicator = showVisualIndicator,
playAudioIndicator = playAudioIndicator,
audioVolumeSlider = audioVolumeSlider,
audioVolumeValue = audioVolumeValue,
playSatisfiedAudioIndicator = playSatisfiedAudioIndicator,
satisfiedAudioVolumeSlider = satisfiedAudioVolumeSlider,
satisfiedAudioVolumeValue = satisfiedAudioVolumeValue,
}
CreateSectionLabel(
frame,
"Move and scale the indicator with /np edit while out of combat.",
16,
-382,
"GameFontHighlightSmall"
)
frame:SetScript("OnShow", function()
NoPoizen:RefreshOptionsWindow()
end)
self.optionsFrame = frame
self:TryRegisterOptionsCategory()
self:RefreshOptionsWindow()
end