-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.lua
More file actions
364 lines (312 loc) · 13.1 KB
/
Copy pathOptions.lua
File metadata and controls
364 lines (312 loc) · 13.1 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
local addonName, SNEK = ...
local Settings = _G.Settings
local InterfaceOptions_AddCategory = _G.InterfaceOptions_AddCategory
SNEK.Options = {}
local O = SNEK.Options
local configFrame
local stub
local capturingFor = nil
local captureFrame
local function RefreshBindingLabels()
if not configFrame then return end
local function setLabel(key, bindingName)
local label = configFrame[key .. "BindLabel"]
if label then
local current = GetBindingKey(bindingName)
label:SetText(current and ("|cff00ff00" .. current .. "|r") or "|cffaaaaaaNot bound|r")
end
end
setLabel("toggle", "SNEK_TOGGLE_RECORDER")
setLabel("reset", "SNEK_RESET")
for i = 1, 10 do
setLabel("key" .. i, "SNEK_KEY" .. i)
end
end
local function StartKeyCapture(bindingName, friendlyName)
if capturingFor then return end
capturingFor = bindingName
print("|cff00ff00S.N.E.K.:|r Press a key for \"" .. friendlyName .. "\" (ESC = cancel)")
if not captureFrame then
captureFrame = CreateFrame("Frame", nil, UIParent)
captureFrame:EnableKeyboard(true)
captureFrame:SetPropagateKeyboardInput(false)
captureFrame:SetScript("OnKeyDown", function(self, key)
if key == "ESCAPE" then
capturingFor = nil
self:Hide()
print("|cffff9900S.N.E.K.:|r Keybind cancelled.")
return
end
local old = GetBindingKey(capturingFor)
while old do
SetBinding(old, nil)
old = GetBindingKey(capturingFor)
end
SetBinding(key, capturingFor)
SaveBindings(GetCurrentBindingSet())
capturingFor = nil
self:Hide()
print("|cff00ff00S.N.E.K.:|r Bound to |cffffff00" .. key .. "|r")
RefreshBindingLabels()
end)
end
captureFrame:SetFrameStrata("FULLSCREEN_DIALOG")
captureFrame:Show()
end
local function SaveNumber(box, dbKey)
local val = tonumber(box:GetText())
if val and val >= 0 then
SNEK.DB.Get()[dbKey] = val
end
end
local function CreateConfigFrame()
local f = CreateFrame("Frame", "SNEKConfigFrame", UIParent, "BasicFrameTemplateWithInset")
f:SetSize(460, 520)
f:SetPoint("CENTER")
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:Hide()
f.TitleText:SetText("S.N.E.K. Options")
local help = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
help:SetPoint("TOPLEFT", 16, -32)
help:SetPoint("TOPRIGHT", -150, -32)
help:SetJustifyH("LEFT")
help:SetText("Important: changes are saved immediately!")
help:SetTextColor(1.0, 0.82, 0.0)
-- Scroll frame (leaves room for title bar + pinned notice)
local scrollFrame = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
scrollFrame:SetPoint("TOPLEFT", 12, -54)
scrollFrame:SetPoint("BOTTOMRIGHT", -32, 24)
local content = CreateFrame("Frame", nil, scrollFrame)
content:SetSize(400, 720) -- tall enough for all options
scrollFrame:SetScrollChild(content)
local y = -8
-- Enable
local enableCheck = CreateFrame("CheckButton", nil, content, "UICheckButtonTemplate")
enableCheck:SetPoint("TOPLEFT", 8, y)
enableCheck:SetSize(28, 28)
local enableLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
enableLabel:SetPoint("LEFT", enableCheck, "RIGHT", 6, 0)
enableLabel:SetText("Enable S.N.E.K.")
enableCheck:SetScript("OnClick", function(self)
local db = SNEK.DB.Get()
db.enabled = self:GetChecked()
SNEK_Reset()
print(db.enabled and "|cff00ff00S.N.E.K.:|r Enabled." or "|cffff9900S.N.E.K.:|r Disabled.")
end)
f.enableCheck = enableCheck
y = y - 36
-- Timing
local timingHeader = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
timingHeader:SetPoint("TOPLEFT", 8, y)
timingHeader:SetText("Timing")
y = y - 26
local function MakeNumberRow(text, key)
local label = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOPLEFT", 18, y)
label:SetText(text)
local box = CreateFrame("EditBox", nil, content, "InputBoxTemplate")
box:SetSize(60, 20)
box:SetPoint("LEFT", label, "RIGHT", 8, 0)
box:SetAutoFocus(false)
box:SetScript("OnTextChanged", function(self) SaveNumber(self, key) end)
box:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
f[key .. "Box"] = box
y = y - 26
end
MakeNumberRow("Initial delay after finalize (seconds):", "initialDelay")
MakeNumberRow("Delay between messages (seconds):", "delay")
MakeNumberRow("Sequence limit:", "sequenceLimit")
y = y - 8
-- Auto-finalize on limit
local autoCheck = CreateFrame("CheckButton", nil, content, "UICheckButtonTemplate")
autoCheck:SetPoint("TOPLEFT", 14, y)
autoCheck:SetSize(24, 24)
local autoLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
autoLabel:SetPoint("LEFT", autoCheck, "RIGHT", 4, 0)
autoLabel:SetText("Auto-finalize when sequence limit is reached")
autoCheck:SetScript("OnClick", function(self)
SNEK.DB.Get().autoFinalizeOnLimit = self:GetChecked()
end)
f.autoCheck = autoCheck
y = y - 32
-- Feedback & Minimap & Playback
local feedHeader = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
feedHeader:SetPoint("TOPLEFT", 8, y)
feedHeader:SetText("Feedback, Minimap & Playback")
y = y - 26
local feedbackCheck = CreateFrame("CheckButton", nil, content, "UICheckButtonTemplate")
feedbackCheck:SetPoint("TOPLEFT", 14, y)
feedbackCheck:SetSize(24, 24)
local feedbackLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
feedbackLabel:SetPoint("LEFT", feedbackCheck, "RIGHT", 4, 0)
feedbackLabel:SetText("Show key-press feedback while recording")
feedbackCheck:SetScript("OnClick", function(self)
SNEK.DB.Get().showKeyFeedback = self:GetChecked()
end)
f.feedbackCheck = feedbackCheck
y = y - 26
local minimapCheck = CreateFrame("CheckButton", nil, content, "UICheckButtonTemplate")
minimapCheck:SetPoint("TOPLEFT", 14, y)
minimapCheck:SetSize(24, 24)
local minimapLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
minimapLabel:SetPoint("LEFT", minimapCheck, "RIGHT", 4, 0)
minimapLabel:SetText("Show minimap icon")
minimapCheck:SetScript("OnClick", function(self)
SNEK.DB.Get().showMinimap = self:GetChecked()
SNEK.Minimap.UpdateVisibility()
end)
f.minimapCheck = minimapCheck
y = y - 26
local sayCheck = CreateFrame("CheckButton", nil, content, "UICheckButtonTemplate")
sayCheck:SetPoint("TOPLEFT", 14, y)
sayCheck:SetSize(24, 24)
local sayLabel = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
sayLabel:SetPoint("LEFT", sayCheck, "RIGHT", 4, 0)
sayLabel:SetText("Playback in /say (requires MessageQueue addon installed)")
sayCheck:SetScript("OnClick", function(self)
SNEK.DB.Get().useSayChat = self:GetChecked()
end)
f.sayCheck = sayCheck
y = y - 32
-- Control Keybindings
local ctrlHeader = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
ctrlHeader:SetPoint("TOPLEFT", 8, y)
ctrlHeader:SetText("Control Keys")
y = y - 26
local function MakeBindRow(text, which, bindingName)
local label = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOPLEFT", 18, y)
label:SetText(text)
local bindLabel = content:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
bindLabel:SetPoint("LEFT", label, "RIGHT", 8, 0)
bindLabel:SetWidth(100)
bindLabel:SetJustifyH("LEFT")
f[which .. "BindLabel"] = bindLabel
local btn = CreateFrame("Button", nil, content, "UIPanelButtonTemplate")
btn:SetSize(90, 22)
btn:SetPoint("LEFT", bindLabel, "RIGHT", 6, 0)
btn:SetText("Set Key")
btn:SetScript("OnClick", function()
StartKeyCapture(bindingName, text)
end)
y = y - 26
end
MakeBindRow("Toggle Recorder:", "toggle", "SNEK_TOGGLE_RECORDER")
MakeBindRow("Reset / Abort:", "reset", "SNEK_RESET")
y = y - 10
-- Key labels + bindings
local keyHeader = content:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
keyHeader:SetPoint("TOPLEFT", 8, y)
keyHeader:SetText("Recordable Keys (empty label = ignored)")
y = y - 26
for i = 1, 10 do
local label = content:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOPLEFT", 18, y)
label:SetText("Key " .. i .. ":")
local box = CreateFrame("EditBox", nil, content, "InputBoxTemplate")
box:SetSize(120, 20)
box:SetPoint("LEFT", label, "RIGHT", 6, 0)
box:SetAutoFocus(false)
box:SetScript("OnTextChanged", function(self)
SNEK.DB.Get().labels[i] = self:GetText() or ""
end)
box:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
f["label" .. i .. "Box"] = box
local bindLabel = content:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
bindLabel:SetPoint("LEFT", box, "RIGHT", 10, 0)
bindLabel:SetWidth(90)
bindLabel:SetJustifyH("LEFT")
f["key" .. i .. "BindLabel"] = bindLabel
local btn = CreateFrame("Button", nil, content, "UIPanelButtonTemplate")
btn:SetSize(70, 20)
btn:SetPoint("LEFT", bindLabel, "RIGHT", 4, 0)
btn:SetText("Set")
btn:SetScript("OnClick", function()
StartKeyCapture("SNEK_KEY" .. i, "Key " .. i)
end)
y = y - 24
end
-- Store content height for potential future use
content:SetHeight(math.abs(y) + 20)
-- Reset Sequence button (pinned to outer frame, top-right)
local resetBtn = CreateFrame("Button", nil, f, "UIPanelButtonTemplate")
resetBtn:SetSize(120, 24)
resetBtn:SetPoint("TOPRIGHT", -16, -28)
resetBtn:SetText("Reset Sequence")
resetBtn:SetScript("OnClick", SNEK_Reset)
local versionLabel = f:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
versionLabel:SetPoint("BOTTOM", 0, 10)
versionLabel:SetText("S.N.E.K. v" .. SNEK.VERSION)
versionLabel:SetTextColor(0.7, 0.7, 0.7)
f:SetScript("OnShow", function()
local db = SNEK.DB.Get()
f.enableCheck:SetChecked(db.enabled == true)
f.initialDelayBox:SetText(tostring(db.initialDelay or 2.5))
f.delayBox:SetText(tostring(db.delay or 2.8))
f.sequenceLimitBox:SetText(tostring(db.sequenceLimit or 7))
f.autoCheck:SetChecked(db.autoFinalizeOnLimit == true)
f.feedbackCheck:SetChecked(db.showKeyFeedback ~= false)
f.minimapCheck:SetChecked(db.showMinimap ~= false)
f.sayCheck:SetChecked(db.useSayChat == true)
for i = 1, 10 do
f["label" .. i .. "Box"]:SetText(db.labels[i] or "")
end
RefreshBindingLabels()
scrollFrame:SetVerticalScroll(0)
end)
return f
end
local function BuildStub()
stub = CreateFrame("Frame", "SNEKStubPanel", UIParent)
stub.name = "S.N.E.K."
local title = stub:CreateFontString(nil, "ARTWORK", "GameFontNormalHuge")
title:SetPoint("CENTER", stub, "CENTER", 0, 50)
title:SetText("|cff00ff00S.N.E.K.|r")
local version = stub:CreateFontString(nil, "ARTWORK", "GameFontHighlight")
version:SetPoint("TOP", title, "BOTTOM", 0, -10)
version:SetText("Version " .. SNEK.VERSION .. " – Sequence Next Enqueued Key")
local open = CreateFrame("Button", nil, stub)
open:SetPoint("TOP", version, "BOTTOM", 0, -24)
local openText = open:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
openText:SetText("/snek")
open:SetFontString(openText)
open:SetSize(openText:GetStringWidth() + 16, 28)
openText:SetPoint("CENTER")
openText:SetTextColor(1, 0.82, 0)
open:SetScript("OnEnter", function() openText:SetTextColor(0, 0.9, 1) end)
open:SetScript("OnLeave", function() openText:SetTextColor(1, 0.82, 0) end)
open:SetScript("OnClick", function() O.Open() end)
local hint = stub:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
hint:SetPoint("TOP", open, "BOTTOM", 0, -16)
hint:SetText("Click the command above or the minimap button to open options.")
end
function O.Open()
if not configFrame then
configFrame = CreateConfigFrame()
end
configFrame:Show()
end
function O.Toggle()
if not configFrame then
configFrame = CreateConfigFrame()
end
if configFrame:IsShown() then
configFrame:Hide()
else
configFrame:Show()
end
end
function O.Register()
if stub then return end
BuildStub()
if Settings and Settings.RegisterCanvasLayoutCategory and Settings.RegisterAddOnCategory then
local category = Settings.RegisterCanvasLayoutCategory(stub, "S.N.E.K.")
Settings.RegisterAddOnCategory(category)
elseif InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory(stub)
end
end