-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.lua
More file actions
241 lines (207 loc) · 8.32 KB
/
Options.lua
File metadata and controls
241 lines (207 loc) · 8.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
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
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:SetOption(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
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:OpenOptionsWindow()
if not self.optionsFrame then
self:InitializeOptionsWindow()
end
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:InitializeOptionsWindow()
if self.optionsFrame then
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.")
CreateSectionLabel(frame, "Indicators", 16, -74, "GameFontHighlight")
local showVisualIndicator = CreateCheckbox(
frame,
"showVisualIndicator",
"Show visual indicator when poisons are missing",
"Show missing poison icons near the center of the screen.",
16,
-98
)
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,
-126
)
local audioVolumeSlider = CreateFrame("Slider", nil, frame, "OptionsSliderTemplate")
audioVolumeSlider:SetPoint("TOPLEFT", frame, "TOPLEFT", 32, -178)
audioVolumeSlider:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -48, -178)
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:SetOption("audioVolume", normalized)
end)
local playSatisfiedAudioIndicator = CreateCheckbox(
frame,
"playSatisfiedAudioIndicator",
"Play sound when poison requirements are satisfied",
"Play hahaha.wav once when transitioning from missing poisons to fully satisfied.",
16,
-232
)
local satisfiedAudioVolumeSlider = CreateFrame("Slider", nil, frame, "OptionsSliderTemplate")
satisfiedAudioVolumeSlider:SetPoint("TOPLEFT", frame, "TOPLEFT", 32, -284)
satisfiedAudioVolumeSlider:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -48, -284)
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:SetOption("satisfiedAudioVolume", normalized)
end)
self.optionControls = {
showVisualIndicator = showVisualIndicator,
playAudioIndicator = playAudioIndicator,
audioVolumeSlider = audioVolumeSlider,
audioVolumeValue = audioVolumeValue,
playSatisfiedAudioIndicator = playSatisfiedAudioIndicator,
satisfiedAudioVolumeSlider = satisfiedAudioVolumeSlider,
satisfiedAudioVolumeValue = satisfiedAudioVolumeValue,
}
frame:SetScript("OnShow", function()
NoPoizen:RefreshOptionsWindow()
end)
self.optionsFrame = frame
if not (Settings and Settings.RegisterCanvasLayoutCategory and Settings.RegisterAddOnCategory) then
self:Print("Settings API is unavailable; addon options could not be registered.")
self.optionsCategory = nil
return
end
local category = Settings.RegisterCanvasLayoutCategory(frame, frame.name, frame.name)
Settings.RegisterAddOnCategory(category)
self.optionsCategory = category
self:RefreshOptionsWindow()
end