Repository navigation
Expand file tree
/
Copy pathSettings.lua
More file actions
414 lines (366 loc) · 15 KB
/
Copy pathSettings.lua
File metadata and controls
414 lines (366 loc) · 15 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
local _, L = ...
----------------------------------
-- Native settings panel
----------------------------------
-- Every option is a proxy setting over L.cfg (ImmersionSetup), so values keep
-- falling back to L.defaults the same way L.Get does, and the panel's
-- "Defaults" button resets through the same setters (side effects included).
local VarType = Settings.VarType
local PREFIX = _:upper() .. '_'
function L.GetSettingVariable(key)
return PREFIX .. key
end
local function Round(value, step)
return floor(value / step + 0.5) * step
end
local function CreateOptions(list)
return function()
local container = Settings.CreateControlTextContainer()
for _, option in ipairs(type(list) == 'function' and list() or list) do
container:Add(option[1], option[2])
end
return container:GetData()
end
end
----------------------------------
-- Builders
----------------------------------
local function Register(category, key, name, varType, onSet)
local default = L.defaults[key]
if default == nil then
if varType == VarType.Boolean then
default = false
elseif varType == VarType.String then
default = ''
else
default = 0
end
end
local function GetValue()
local value = L.Get(key)
if varType == VarType.Boolean then
return not not value
elseif type(value) ~= varType then
return default
end
return value
end
local function SetValue(value)
L.cfg[key] = value
if onSet then onSet(value) end
end
return Settings.RegisterProxySetting(category, L.GetSettingVariable(key), varType, name, default, GetValue, SetValue)
end
local function Header(layout, name, tooltip)
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(name, tooltip))
end
local function Checkbox(category, key, name, tooltip, onSet)
return Settings.CreateCheckbox(category, Register(category, key, name, VarType.Boolean, onSet), tooltip)
end
local function Slider(category, key, name, min, max, step, tooltip, onSet)
local setting = Register(category, key, name, VarType.Number, function(value)
value = Round(value, step)
L.cfg[key] = value
if onSet then onSet(value) end
end)
local fmt = step < 1 and '%.1f' or '%d'
local options = Settings.CreateSliderOptions(min, max, step)
options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right, function(value)
return fmt:format(Round(value, step))
end)
return Settings.CreateSlider(category, setting, options, tooltip)
end
local function Dropdown(category, key, name, varType, list, tooltip, onSet)
local setting = Register(category, key, name, varType, onSet)
return Settings.CreateDropdown(category, setting, CreateOptions(list), tooltip)
end
local function Keybind(category, layout, key, name, validate, tooltip)
local setting = Register(category, key, name, VarType.String, function(value)
-- false marks an explicit unbind, so L.Get won't fall back to the default key.
L.cfg[key] = value ~= '' and value or false
end)
local initializer = Settings.CreateControlInitializer('ImmersionKeybindControlTemplate', setting, nil, tooltip)
initializer.data.validate = validate
layout:AddInitializer(initializer)
return initializer
end
local function Button(layout, name, text, onClick, tooltip)
local initializer = CreateSettingsButtonInitializer(name, text, onClick, tooltip, true)
layout:AddInitializer(initializer)
return initializer
end
local function DependsOn(parent, predicate, ...)
for i = 1, select('#', ...) do
select(i, ...):SetParentInitializer(parent, predicate)
end
end
----------------------------------
-- Option lists
----------------------------------
local stratas = {
{ 'LOW', L['Low'] },
{ 'MEDIUM', L['Medium'] },
{ 'HIGH', L['High'] },
{ 'DIALOG', L['Dialog'] },
{ 'FULLSCREEN', L['Fullscreen'] },
{ 'FULLSCREEN_DIALOG', L['Fullscreen dialog'] },
{ 'TOOLTIP', L['Tooltip'] },
}
local modifiers = {
{ 'SHIFT', SHIFT_KEY_TEXT },
{ 'CTRL', CTRL_KEY_TEXT },
{ 'ALT', ALT_KEY_TEXT },
{ 'NOMOD', NONE },
}
local titleanis = {
{ 0, OFF },
{ 1, SPELL_CAST_TIME_INSTANT },
{ 5, FAST },
{ 10, SLOW },
}
local function GetVoices()
local list = {}
for _, voice in ipairs(C_VoiceChat.GetTtsVoices() or {}) do
list[#list + 1] = { voice.voiceID + 1, voice.name }
end
return list
end
local function GetModifierText(key)
for _, option in ipairs(modifiers) do
if option[1] == key then return option[2] end
end
end
-- Matches the delay formula in Text.lua, used to preview the text speed option.
local function GetTextSpeedTooltip()
local sample = 'I need help with these quests.'
local fmt = D_SECONDS:gsub('%%[ds]', '%%.2f')
local function Line(label, divisor)
local time = (strlen(sample) / (math.log(strlen(sample)) / math.log(30^(1 / divisor)))) + L.TEXT_TIME_PADDING
return ('%s = %d\n"%s"\n -> %s'):format(label, divisor, sample, fmt:format(time))
end
return L['Change the speed of text delivery.'] .. '\n\n' ..
Line(MINIMUM, 5) .. '\n\n' .. Line(DEFAULT, 15) .. '\n\n' .. Line(MAXIMUM, 40)
end
----------------------------------
-- Pages
----------------------------------
local function BuildGeneral(category, layout)
Header(layout, LOCK_FOCUS_FRAME)
Checkbox(category, 'boxlock', MODEL .. ' / ' .. LOCALE_TEXT_LABEL)
Checkbox(category, 'titlelock', QUESTS_LABEL .. ' / ' .. GOSSIP_OPTIONS)
Header(layout, L['Behavior'])
Slider(category, 'delaydivisor', L['Text speed'], 5, 40, 1, GetTextSpeedTooltip())
local progression = Checkbox(category, 'disableprogression', L['Disable automatic text progress'],
L['Stop NPCs from automatically proceeding to the next line of dialogue.'])
DependsOn(progression, function() return not L.Get('disableprogression') end,
Checkbox(category, 'showprogressbar', L['Show text progress bar']))
Header(layout, MOUSE_LABEL)
local noConsolePort = function() return not ConsolePort end
Checkbox(category, 'flipshortcuts', L['Flip mouse functions'], L.GetListString(
L['Left click is used to handle text.'],
L['Right click is used to accept/hand in quests.'])):AddModifyPredicate(noConsolePort)
Checkbox(category, 'immersivemode', L['Immersive mode'],
L['Use your primary mouse button to read through text, accept/turn in quests and select the best available gossip option.'])
:AddModifyPredicate(noConsolePort)
Header(layout, L['Hide interface'])
DependsOn(Checkbox(category, 'hideui', L['Hide interface'], L['Hide my user interface when interacting with an NPC.']),
function() return L.Get('hideui') end,
Checkbox(category, 'hideminimap', L['Hide minimap'], nil, function(value)
L.ToggleIgnoreFrame(Minimap, not value)
L.ToggleIgnoreFrame(MinimapCluster, not value)
end),
Checkbox(category, 'hidetracker', L['Hide objective tracker'], nil, function(value)
L.ToggleIgnoreFrame(ObjectiveTrackerFrame, not value)
end),
Checkbox(category, 'hidetooltip', L['Hide tooltip']))
Header(layout, PLAYBACK)
Checkbox(category, 'onthefly', QUICKBUTTON_NAME_EVERYTHING,
L["The quest/gossip text doesn't vanish when you stop interacting with the NPC or when accepting a new quest. Instead, it vanishes at the end of the text sequence. This allows you to maintain your immersive experience when speed leveling."])
Checkbox(category, 'supertracked', OBJECTIVES_TRACKER_LABEL,
L["When a quest is supertracked (clicked on in the objective tracker, or set automatically by proximity), the quest text will play if nothing else is obstructing it."])
Header(layout, TEXT_TO_SPEECH)
DependsOn(Checkbox(category, 'ttsenabled', TEXT_TO_SPEECH, L["Reads quest text aloud using text-to-speech based on options selected."]),
function() return L.Get('ttsenabled') end,
Slider(category, 'ttsvolume', TEXT_TO_SPEECH_ADJUST_VOLUME, 1, 100, 1),
Slider(category, 'ttsrate', TEXT_TO_SPEECH_ADJUST_RATE, -5, 5, 0.1),
Dropdown(category, 'ttsvoice', VOICE, VarType.Number, GetVoices),
Dropdown(category, 'ttsfemalevoice', L['Female voice'], VarType.Number, GetVoices),
Dropdown(category, 'ttsmalevoice', L['Male voice'], VarType.Number, GetVoices))
Header(layout, L['Hook talking head'])
Checkbox(category, 'movetalkinghead', VIDEO_OPTIONS_ENABLED,
L["The regular talking head frame appears in the same place as Immersion when you're not interacting with anything and on top of Immersion if they are visible at the same time."])
end
local function BuildKeybindings(category, layout)
local list = L.GetListString(QUESTS_LABEL, GOSSIP_OPTIONS)
Keybind(category, layout, 'accept', ACCEPT, L.ValidateKey,
L.GetListString(ACCEPT, NEXT, CONTINUE, COMPLETE_QUEST, SPELL_CAST_TIME_INSTANT .. ': ' .. (GetModifierText(L('inspect')) or NONE)))
Keybind(category, layout, 'goodbye', GOODBYE .. '/' .. CLOSE .. ' (' .. KEY_ESCAPE .. ')', L.ValidateKey, list)
Keybind(category, layout, 'reset', RESET, L.ValidateKey)
Checkbox(category, 'enablenumbers', '[1-9] ' .. PET_BATTLE_SELECT_AN_ACTION, list)
end
local function BuildGamepad(category, layout)
local tooltip = L['Press a gamepad button to assign it. Hints shown by ConsolePort follow these.']
for _, action in ipairs({
{ 'padaccept', ACCEPT };
{ 'padinspect', INSPECT };
{ 'padnext', NEXT };
{ 'padgoodbye', GOODBYE };
{ 'padup', L['Previous option'] };
{ 'paddown', L['Next option'] };
{ 'padleft', L['Previous item'] };
{ 'padright', L['Next item'] };
}) do
Keybind(category, layout, action[1], action[2], L.ValidatePadKey, tooltip)
end
end
local function BuildDisplay(category, layout)
local frame = L.frame
local talkbox = frame.TalkBox
Dropdown(category, 'anidivisor', L['Dynamic offset'], VarType.Number, titleanis)
Dropdown(category, 'strata', L['Frame strata'], VarType.String, stratas, nil, function(value)
frame:SetFrameStrata(value)
talkbox:SetFrameStrata(value)
end)
Slider(category, 'scale', L['Global scale'], 0.5, 1.5, 0.1, nil, function(value)
frame:SetScale(value)
end)
Header(layout, MODEL .. ' / ' .. LOCALE_TEXT_LABEL, L['Customize the talking head frame.'])
Checkbox(category, 'solidbackground', L['Solid background'], nil, function(value)
talkbox.BackgroundFrame.SolidBackground:SetShown(value)
talkbox.Elements:SetBackdrop(value and L.Backdrops.TALKBOX_SOLID or L.Backdrops.TALKBOX)
end)
Checkbox(category, 'disablebgtextures', L['Disable overlay backgrounds'])
Checkbox(category, 'disableglowani', L['Disable sheen animation'])
Checkbox(category, 'disableportrait', L['Disable portrait border'], nil, function(value)
talkbox.PortraitFrame:SetShown(not value)
talkbox.MainFrame.Model.PortraitBG:SetShown(not value)
end)
Checkbox(category, 'disableanisequence', L['Disable model animations'])
Checkbox(category, 'disableboxhighlight', L['Disable mouseover highlight'])
Slider(category, 'boxscale', L['Scale'], 0.5, 1.5, 0.1, nil, function(value)
talkbox:SetScale(value)
end)
Button(layout, RESET_POSITION, RESET, function()
L.Set('boxpoint', L.defaults.boxpoint)
L.Set('boxoffsetX', L.defaults.boxoffsetX)
L.Set('boxoffsetY', L.defaults.boxoffsetY)
talkbox.extraY = 0
talkbox.offsetX = L('boxoffsetX')
talkbox.offsetY = L('boxoffsetY')
talkbox:ClearAllPoints()
talkbox:SetPoint(L('boxpoint'), UIParent, L('boxoffsetX'), L('boxoffsetY'))
end)
Header(layout, QUESTS_LABEL .. ' / ' .. GOSSIP_OPTIONS, L['Change the placement and scale of your dialogue options.'])
Slider(category, 'titlescale', L['Scale'], 0.5, 1.5, 0.1, nil, function(value)
frame.TitleButtons:SetScale(value)
end)
Checkbox(category, 'gossipatcursor', L['Show at mouse location'])
Header(layout, QUEST_OBJECTIVES .. ' / ' .. QUEST_REWARDS)
Slider(category, 'elementscale', L['Scale'], 0.5, 1.5, 0.1, nil, function(value)
talkbox.Elements:SetScale(value)
end)
Dropdown(category, 'inspect', INSPECT .. ' (' .. ITEMS .. ')', VarType.String, modifiers)
end
function L.SetupSettings()
local category, layout = Settings.RegisterVerticalLayoutCategory(_)
BuildGeneral(category, layout)
for _, page in ipairs({
{ KEY_BINDINGS, BuildKeybindings };
{ L['Gamepad'], BuildGamepad };
{ DISPLAY, BuildDisplay };
}) do
page[2](Settings.RegisterVerticalLayoutSubcategory(category, page[1]))
end
Settings.RegisterAddOnCategory(category)
L.settingsCategory = category
end
function L.OpenSettings()
Settings.OpenToCategory(L.settingsCategory:GetID())
end
----------------------------------
-- Keybind control
----------------------------------
-- The Settings API has no keybind widget for addon-defined keys, so this row
-- captures a single raw key (or gamepad button) and stores it in the setting.
-- Right click or Escape unbinds.
local IGNORED_KEYS = {
LSHIFT = true, RSHIFT = true, LCTRL = true, RCTRL = true,
LALT = true, RALT = true, UNKNOWN = true,
}
ImmersionKeybindControlMixin = CreateFromMixins(SettingsControlMixin)
function ImmersionKeybindControlMixin:OnLoad()
SettingsControlMixin.OnLoad(self)
local button = self.Button
button:RegisterForClicks('LeftButtonUp', 'RightButtonUp')
button:SetScript('OnClick', function(_, mouseButton) self:OnButtonClick(mouseButton) end)
button:SetScript('OnKeyDown', function(_, key) self:OnInput(key) end)
button:SetScript('OnGamePadButtonDown', function(_, key) self:OnInput(key) end)
button:SetScript('OnHide', function() self:SetCapturing(false) end)
button:SetScript('OnEnter', function() self.Tooltip:OnEnter() end)
button:SetScript('OnLeave', function() self.Tooltip:OnLeave() end)
end
function ImmersionKeybindControlMixin:Init(initializer)
SettingsControlMixin.Init(self, initializer)
self:SetCapturing(false)
self:EvaluateState()
end
function ImmersionKeybindControlMixin:Release()
self:SetCapturing(false)
SettingsControlMixin.Release(self)
end
function ImmersionKeybindControlMixin:OnSettingValueChanged(setting, value)
SettingsControlMixin.OnSettingValueChanged(self, setting, value)
self:Refresh()
end
function ImmersionKeybindControlMixin:EvaluateState()
SettingsListElementMixin.EvaluateState(self)
local enabled = self:IsEnabled()
self.Button:SetEnabled(enabled)
self:DisplayEnabled(enabled)
end
function ImmersionKeybindControlMixin:Refresh()
local key = self:GetSetting():GetValue()
if self.capturing then
self.Button:SetText(L['Press a key...'])
elseif key ~= '' then
self.Button:SetText(GetBindingText(key))
else
self.Button:SetText(GRAY_FONT_COLOR:WrapTextInColorCode(NOT_BOUND))
end
end
function ImmersionKeybindControlMixin:SetCapturing(capturing)
local button = self.Button
self.capturing = capturing
button:EnableKeyboard(capturing)
if button.EnableGamePadButton then
button:EnableGamePadButton(capturing)
end
if capturing then
button:LockHighlight()
else
button:UnlockHighlight()
end
if self.data then
self:Refresh()
end
end
function ImmersionKeybindControlMixin:OnButtonClick(mouseButton)
if mouseButton == 'RightButton' then
self:SetCapturing(false)
self:GetSetting():SetValue('')
else
self:SetCapturing(not self.capturing)
end
end
function ImmersionKeybindControlMixin:OnInput(key)
if not self.capturing or IGNORED_KEYS[key] then return end
self:SetCapturing(false)
if key == 'ESCAPE' then
self:GetSetting():SetValue('')
return
end
local valid = self.data.validate(key)
if valid then
self:GetSetting():SetValue(valid)
end
end