-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
458 lines (430 loc) · 15.6 KB
/
Copy pathConfig.lua
File metadata and controls
458 lines (430 loc) · 15.6 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
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
--[[ RaidLeadKit - slash commands + Interface Options panel ]]
local RLK = RaidLeadKit
function RLK:OpenOptions()
InterfaceOptionsFrame_OpenToCategory(self.options)
InterfaceOptionsFrame_OpenToCategory(self.options) -- the first call only opens the frame
end
function RLK:ResetPosition()
self.db.point = { "CENTER", "CENTER", 0, 200 }
self.button:ClearAllPoints()
self.button:SetPoint("CENTER", UIParent, "CENTER", 0, 200)
end
-- ---------------------------------------------------------------------------
-- slash
-- ---------------------------------------------------------------------------
SLASH_RAIDLEADKIT1 = "/rlk"
SLASH_RAIDLEADKIT2 = "/raidleadkit"
SlashCmdList["RAIDLEADKIT"] = function(msg)
local cmd = string.lower(strtrim(msg or ""))
local db = RLK.db
if cmd == "" or cmd == "config" then
RLK:OpenOptions()
elseif cmd == "minor" then
db.showMinor = not db.showMinor
RLK:ApplySettings()
RLK:Print("minor debuffs " .. (db.showMinor and "shown" or "hidden"))
elseif cmd == "lock" then
db.locked = not db.locked
RLK:Print("button " .. (db.locked and "locked" or "unlocked"))
elseif cmd == "show" or cmd == "hide" then
db.hidden = cmd == "hide"
RLK:ApplySettings()
elseif cmd == "toggle" then
RLK:TogglePanel()
elseif cmd == "loot" then
db.lootWarning = not db.lootWarning
RLK:Print("master loot warning " .. (db.lootWarning and "on" or "off"))
elseif cmd == "loottest" then
RLK:WarnLoot(true)
elseif cmd == "clearmarks" then
RLK:ClearMarks()
RLK:Print("raid marks cleared")
elseif cmd == "reset" then
RLK:ResetPosition()
db.hidden = false
RLK:ApplySettings()
else
RLK:Print("commands: config | toggle | minor | lock | show | hide | reset | loot | loottest | clearmarks")
end
if RLK.RefreshOptions then RLK:RefreshOptions() end
end
-- ---------------------------------------------------------------------------
-- options panel
-- ---------------------------------------------------------------------------
-- One column, every widget placed below the previous one by a running y.
local PAD = 16
local widgetCount = 0
local function uniqueName(kind)
widgetCount = widgetCount + 1
return "RaidLeadKit" .. kind .. widgetCount
end
local function header(parent, y, text)
local fs = parent:CreateFontString(nil, "ARTWORK", "GameFontNormal")
fs:SetPoint("TOPLEFT", PAD, y)
fs:SetText(text)
return y - 22
end
local function check(parent, y, label, get, set)
local cb = CreateFrame("CheckButton", uniqueName("Check"), parent, "InterfaceOptionsCheckButtonTemplate")
cb:SetPoint("TOPLEFT", PAD - 4, y)
_G[cb:GetName() .. "Text"]:SetText(label)
cb:SetScript("OnClick", function(s) set(s:GetChecked() and true or false) end)
cb.get = get
return cb, y - 26
end
function RLK:InitConfig()
local db = self.db
local options = CreateFrame("Frame", "RaidLeadKitOptions", UIParent)
options.name = "|cffff2020Raid|rLeadKit"
self.options = options
-- everything sits in a scroll frame: the options area is not tall enough
-- for all of it
local scroll = CreateFrame("ScrollFrame", "RaidLeadKitOptionsScroll", options, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", 4, -4)
scroll:SetPoint("BOTTOMRIGHT", -26, 4)
local panel = CreateFrame("Frame", nil, scroll)
panel:SetWidth(420)
panel:SetHeight(1)
scroll:SetScrollChild(panel)
local checks, radios = {}, {}
local y = -PAD
local title = panel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetPoint("TOPLEFT", PAD, y)
title:SetText("|cffff2020Raid|rLeadKit")
y = y - 22
local note = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
note:SetPoint("TOPLEFT", PAD, y)
note:SetText("Left-click the button for the checklist, right-click for these options, drag to move it.")
y = y - 24
-- 1. button and panel
y = header(panel, y, "Button")
local cb
cb, y = check(panel, y, "Show the button", function() return not db.hidden end,
function(v) db.hidden = not v self:ApplySettings() end)
checks[#checks + 1] = cb
cb, y = check(panel, y, "Lock the button in place", function() return db.locked end,
function(v) db.locked = v end)
checks[#checks + 1] = cb
cb, y = check(panel, y, "Show minor debuffs (cast speed, melee hit, healing, judgements)",
function() return db.showMinor end, function(v) db.showMinor = v self:ApplySettings() end)
checks[#checks + 1] = cb
-- Two keys can open the checklist, like any action in Esc > Key Bindings
-- (where the same two show): click a button, then press a key or a
-- combination; right-click clears it. Two, because the game names a key by
-- the character it types: one key is "]" in one layout and "ї" in another.
local BINDING = "RAIDLEADKIT_TOGGLE"
local MODIFIERS = { LSHIFT = true, RSHIFT = true, LCTRL = true, RCTRL = true, LALT = true, RALT = true }
local keyButtons = {}
local function keyOf(slot)
return (select(slot, GetBindingKey(BINDING)))
end
-- Puts key (nil clears) in a slot. The game keeps an action's keys in the
-- order they were bound, so all of them are bound again in slot order.
local function setSlot(slot, key)
local keys = { GetBindingKey(BINDING) }
for _, k in ipairs(keys) do SetBinding(k) end
keys[slot] = key
for i = 1, 2 do
if keys[i] and (i == slot or keys[i] ~= key) then SetBinding(keys[i], BINDING) end
end
SaveBindings(GetCurrentBindingSet())
end
local function refreshKeys()
for slot, b in ipairs(keyButtons) do
local key = keyOf(slot)
b:SetText("Key " .. slot .. ": " .. (key and GetBindingText(key, "KEY_") or "not set"))
end
end
for slot = 1, 2 do
local b = CreateFrame("Button", uniqueName("Key"), panel, "UIPanelButtonTemplate")
b:SetPoint("TOPLEFT", PAD + (slot - 1) * 190, y - 2)
b:SetWidth(180)
b:SetHeight(22)
b:RegisterForClicks("LeftButtonUp", "RightButtonUp")
b:SetScript("OnClick", function(s, mouse)
if InCombatLockdown() then
self:Print("key bindings cannot change in combat")
return
end
if mouse == "RightButton" then
setSlot(slot, nil)
refreshKeys()
return
end
s.waiting = true
s:SetText("Press a key (Esc cancels)")
s:EnableKeyboard(true)
end)
b:SetScript("OnKeyDown", function(s, key)
if not s.waiting or MODIFIERS[key] then return end
s.waiting = false
s:EnableKeyboard(false)
if key ~= "ESCAPE" then
local combo = (IsAltKeyDown() and "ALT-" or "") .. (IsControlKeyDown() and "CTRL-" or "")
.. (IsShiftKeyDown() and "SHIFT-" or "") .. key
local before = GetBindingAction(combo)
setSlot(slot, combo)
local was = (before and before ~= "" and before ~= BINDING)
and (" (it was " .. (_G["BINDING_NAME_" .. before] or before) .. ")") or ""
self:Print("checklist key " .. slot .. ": " .. GetBindingText(combo, "KEY_") .. was)
end
refreshKeys()
end)
b:SetScript("OnHide", function(s)
s.waiting = false
s:EnableKeyboard(false)
end)
keyButtons[slot] = b
end
local keyNote = panel:CreateFontString(nil, "ARTWORK", "GameFontDisableSmall")
keyNote:SetPoint("TOPLEFT", PAD, y - 28)
keyNote:SetText("Keys that open the checklist; right-click a button to clear it.")
y = y - 46
y = header(panel, y - 4, "Raid leader")
cb, y = check(panel, y, "Warn me on a boss pull when master loot is not set",
function() return db.lootWarning end, function(v) db.lootWarning = v end)
checks[#checks + 1] = cb
local test = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
test:SetPoint("TOPLEFT", PAD + 24, y)
test:SetWidth(120)
test:SetHeight(20)
test:SetText("Test the warning")
test:SetScript("OnClick", function() self:WarnLoot(true) end)
y = y - 26
-- sliders: label above, value in the label, applied as it moves
local sliders = {}
local function slider(label, minV, maxV, step, lowText, highText, show, get, set)
y = y - 18
local s = CreateFrame("Slider", uniqueName("Slider"), panel, "OptionsSliderTemplate")
local name = s:GetName()
s:SetPoint("TOPLEFT", PAD + 4, y)
s:SetWidth(220)
s:SetMinMaxValues(minV, maxV)
s:SetValueStep(step)
_G[name .. "Low"]:SetText(lowText)
_G[name .. "High"]:SetText(highText)
s:SetScript("OnValueChanged", function(_, v)
v = math.floor(v / step + 0.5) * step
_G[name .. "Text"]:SetText(label .. ": " .. show(v))
if get() ~= v then set(v) end
end)
s.refresh = function()
s:SetValue(get())
_G[name .. "Text"]:SetText(label .. ": " .. show(get()))
end
sliders[#sliders + 1] = s
y = y - 40
end
local px = function(v) return v .. " px" end
slider("Button size", 16, 64, 1, "16", "64", px,
function() return db.buttonSize end,
function(v) db.buttonSize = v self:ApplySettings() end)
slider("Icon size", 12, 48, 1, "12", "48", px,
function() return db.iconSize end,
function(v) db.iconSize = v self:ApplySettings() end)
slider("Rows per column", 4, 30, 1, "4", "30", tostring,
function() return db.rows end,
function(v) db.rows = v self:ApplySettings() end)
-- 2. where the panel opens
y = header(panel, y, "The checklist opens")
for _, a in ipairs(self.ANCHORS) do
local r = CreateFrame("CheckButton", uniqueName("Radio"), panel, "UIRadioButtonTemplate")
r:SetPoint("TOPLEFT", PAD, y)
_G[r:GetName() .. "Text"]:SetText(a.label)
r.key = a.key
r:SetScript("OnClick", function()
db.anchor = a.key
self:RefreshOptions()
self:ApplySettings()
end)
radios[#radios + 1] = r
y = y - 20
end
y = y - 12
local reset = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
reset:SetPoint("TOPLEFT", PAD, y)
reset:SetWidth(160)
reset:SetHeight(22)
reset:SetText("Reset button position")
reset:SetScript("OnClick", function() self:ResetPosition() end)
y = y - 26
-- ------------------------------------------------------------------
-- marking rules
-- ------------------------------------------------------------------
-- A row per enemy: its name or npc id, and the mark it should get. "A"
-- means auto: any mark no other rule asks for by name.
y = header(panel, y - 10, "Marking")
local markNote = panel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
markNote:SetPoint("TOPLEFT", PAD, y)
markNote:SetWidth(390)
markNote:SetJustifyH("LEFT")
markNote:SetText("Hold left Ctrl + left Shift and point at them: everyone on this list is marked as "
.. "the mouse goes over. Add by name or npc id, pick a mark in the row, or A for any free one. "
.. "Names can be edited: type over one and press Enter.")
y = y - 12
y = y - 12
y = y - 26
local ICON_SIZE, ICON_GAP = 16, 2
local KEY_WIDTH = 126
local PICKER_X = KEY_WIDTH + 18
local DEL_X = PICKER_X + 9 * (ICON_SIZE + ICON_GAP) + 6
-- nine buttons: A, then the eight marks. get()/set() say which one is on.
local function iconPicker(parent, x, top, get, set)
local buttons = {}
-- the chosen one keeps a yellow frame and full colour, the rest fade
local function refresh()
for _, b in ipairs(buttons) do
local on = get() == b.icon
if on then b.check:Show() else b.check:Hide() end
b.dim:SetAlpha(on and 1 or 0.4)
end
end
for i = 0, 8 do
local b = CreateFrame("Button", nil, parent)
b:SetWidth(ICON_SIZE)
b:SetHeight(ICON_SIZE)
b:SetPoint("TOPLEFT", x + i * (ICON_SIZE + ICON_GAP), top)
b.icon = i
if i == 0 then
-- auto stands next to eight coloured marks, so it gets a frame
-- of its own and a bright letter
b:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8", edgeSize = 1 })
b:SetBackdropColor(0.15, 0.15, 0.18, 1)
b:SetBackdropBorderColor(0.9, 0.75, 0.2, 1)
local fs = b:CreateFontString(nil, "ARTWORK", "GameFontNormal")
fs:SetAllPoints()
fs:SetText("A")
fs:SetTextColor(1, 0.9, 0.3)
b.dim = fs
else
local tex = b:CreateTexture(nil, "ARTWORK")
tex:SetAllPoints()
tex:SetTexture(RLK.MARK_ICONS[i][1])
b.dim = tex
end
b.check = CreateFrame("Frame", nil, b)
b.check:SetPoint("TOPLEFT", -2, 2)
b.check:SetPoint("BOTTOMRIGHT", 2, -2)
b.check:SetBackdrop({ edgeFile = "Interface\\Buttons\\WHITE8X8", edgeSize = 2 })
b.check:SetBackdropBorderColor(1, 0.9, 0.2, 1)
b.check:Hide()
b:SetScript("OnClick", function()
set(b.icon)
refresh()
end)
b:SetScript("OnEnter", function(s)
GameTooltip:SetOwner(s, "ANCHOR_RIGHT")
GameTooltip:SetText(b.icon == 0 and "Any free mark" or RLK.MARK_ICONS[b.icon][2])
GameTooltip:Show()
end)
b:SetScript("OnLeave", function() GameTooltip:Hide() end)
buttons[#buttons + 1] = b
end
refresh()
return refresh
end
-- a new rule is just a name; its mark is picked in the row it becomes
local keyBox = CreateFrame("EditBox", uniqueName("Edit"), panel, "InputBoxTemplate")
keyBox:SetPoint("TOPLEFT", PAD + 6, y)
keyBox:SetWidth(KEY_WIDTH)
keyBox:SetHeight(20)
keyBox:SetAutoFocus(false)
local targetBtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
targetBtn:SetPoint("LEFT", keyBox, "RIGHT", 10, 0)
targetBtn:SetWidth(70)
targetBtn:SetHeight(20)
targetBtn:SetText("Target")
targetBtn:SetScript("OnClick", function()
if not UnitExists("target") then
self:Print("no target")
return
end
keyBox:SetText(UnitName("target") or "")
keyBox:ClearFocus()
end)
local addBtn = CreateFrame("Button", nil, panel, "UIPanelButtonTemplate")
addBtn:SetPoint("LEFT", targetBtn, "RIGHT", 6, 0)
addBtn:SetWidth(60)
addBtn:SetHeight(20)
addBtn:SetText("Add")
local function addRule()
local ok, why = self:AddRule(keyBox:GetText(), 0)
if ok then
keyBox:SetText("")
keyBox:ClearFocus()
self:RefreshMarkRules()
elseif why then
self:Print(why)
end
end
addBtn:SetScript("OnClick", addRule)
keyBox:SetScript("OnEnterPressed", addRule)
y = y - 30
local listTop = y
local markRows = {}
function self:RefreshMarkRules()
local rules = db.markRules
for _, r in ipairs(markRows) do r:Hide() end
for i, rule in ipairs(rules) do
local r = markRows[i]
if r then
r.rule = rule
else
r = CreateFrame("Frame", nil, panel)
r:SetHeight(20)
r:SetWidth(390)
-- the key is editable in place; Enter or leaving the box saves
r.box = CreateFrame("EditBox", uniqueName("Edit"), r, "InputBoxTemplate")
r.box:SetPoint("LEFT", 6, 0)
r.box:SetWidth(KEY_WIDTH)
r.box:SetHeight(20)
r.box:SetAutoFocus(false)
local function commit(save)
local ok, why
if save then ok, why = self:SetRuleKey(r.index, r.box:GetText()) end
if why then self:Print(why) end
local rl = db.markRules[r.index]
-- an empty or taken key leaves the rule as it was
if rl and not ok then r.box:SetText(tostring(rl.key)) end
r.box:ClearFocus()
end
r.box:SetScript("OnEnterPressed", function() commit(true) end)
r.box:SetScript("OnEditFocusLost", function() commit(true) end)
r.box:SetScript("OnEscapePressed", function() commit(false) end)
r.del = CreateFrame("Button", nil, r, "UIPanelButtonTemplate")
r.del:SetPoint("LEFT", DEL_X, 0)
r.del:SetWidth(20)
r.del:SetHeight(20)
r.del:SetText("-")
r.del:SetScript("OnClick", function()
self:RemoveRule(r.index)
self:RefreshMarkRules()
end)
r.rule = rule -- the picker below reads it right away
r.refreshPicker = iconPicker(r, PICKER_X, 1,
function() return r.rule and r.rule.icon end,
function(v) if r.rule then r.rule.icon = v end end)
markRows[i] = r
end
r.index = i
r:ClearAllPoints()
r:SetPoint("TOPLEFT", PAD, listTop - (i - 1) * 22)
r.box:SetText(tostring(rule.key))
r.box:SetCursorPosition(0)
r.refreshPicker()
r:Show()
end
panel:SetHeight(-(listTop - #rules * 22) + PAD * 2)
end
self:RefreshMarkRules()
function self:RefreshOptions()
for _, c in ipairs(checks) do c:SetChecked(c.get()) end
for _, r in ipairs(radios) do r:SetChecked(r.key == db.anchor) end
for _, s in ipairs(sliders) do s.refresh() end
refreshKeys()
self:RefreshMarkRules()
end
options:SetScript("OnShow", function() self:RefreshOptions() end)
InterfaceOptions_AddCategory(options)
end