Repository navigation
Expand file tree
/
Copy pathConfig.lua
More file actions
399 lines (366 loc) · 13.7 KB
/
Copy pathConfig.lua
File metadata and controls
399 lines (366 loc) · 13.7 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
local _, BS = ...
local VIS = { "always", "aura", "proc" }
local VIS_TEXT = { always = "Always", aura = "While aura active", proc = "While proc active" }
local MAX_SPELLS = 8 -- ponytail: no scrolling in the spell list; a bar holds "one or a few" spells
local RIGHT = 210
local f, selected, dragFrom
local listRows, spellRows, pickRows = {}, {}, {}
local function changed()
BS.Changed()
BS.RefreshConfig()
end
local function text(parent, s, x, y, font)
local fs = parent:CreateFontString(nil, "OVERLAY", font or "GameFontNormalSmall")
fs:SetPoint("TOPLEFT", x, y)
fs:SetText(s)
return fs
end
local function button(parent, s, w, x, y, onClick)
local b = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
b:SetSize(w, 22)
b:SetText(s)
if x then b:SetPoint("TOPLEFT", x, y) end
if onClick then b:SetScript("OnClick", onClick) end
return b
end
local function input(parent, x, y, w, numeric, set)
local e = CreateFrame("EditBox", nil, parent, "InputBoxTemplate")
e:SetSize(w, 20)
e:SetPoint("TOPLEFT", x + 6, y)
e:SetAutoFocus(false)
e:SetScript("OnEnterPressed", e.ClearFocus)
e:SetScript("OnEscapePressed", function(self) BS.RefreshConfig(); self:ClearFocus() end)
e:SetScript("OnEditFocusLost", function(self)
local v = self:GetText()
if numeric then v = tonumber(v) end
if v and v ~= "" then set(v); changed() else BS.RefreshConfig() end
end)
return e
end
local function checkbox(parent, s, x, y, onClick)
local c = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
c:SetSize(24, 24)
c:SetPoint("TOPLEFT", x, y)
local fs = c.Text or c.text
if fs then fs:SetText(s) end
c:SetScript("OnClick", function(self) onClick(self:GetChecked()) end)
return c
end
local function scroll(parent, x, y, w, h)
local sf = CreateFrame("ScrollFrame", nil, parent, "UIPanelScrollFrameTemplate")
sf:SetPoint("TOPLEFT", x, y)
sf:SetSize(w, h)
local child = CreateFrame("Frame", nil, sf)
child:SetSize(w, 1)
sf:SetScrollChild(child)
return child
end
local function window(name, w, h, title)
local d = CreateFrame("Frame", name, UIParent, "BasicFrameTemplateWithInset")
d:SetSize(w, h)
d:SetFrameStrata("DIALOG")
d:SetToplevel(true)
d:EnableMouse(true)
if d.TitleText then d.TitleText:SetText(title) end
return d
end
------------------------------------------------------------------------
-- Bar list (top = top layer, drag to reorder)
------------------------------------------------------------------------
local function listRow(i)
if listRows[i] then return listRows[i] end
local r = CreateFrame("Button", nil, f.list)
r:SetSize(166, 20)
r:SetPoint("TOPLEFT", 0, -(i - 1) * 22)
r:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight", "ADD")
r.text = r:CreateFontString(nil, "OVERLAY", "GameFontHighlightLeft")
r.text:SetPoint("LEFT", 4, 0)
r.text:SetPoint("RIGHT", -4, 0)
r:RegisterForDrag("LeftButton")
r:SetScript("OnClick", function(self)
selected = BS.profile.bars[self.index]
BS.RefreshConfig()
end)
r:SetScript("OnDragStart", function(self) dragFrom = self.index end)
r:SetScript("OnDragStop", function()
local bars = BS.profile.bars
for _, o in ipairs(listRows) do
if dragFrom and o:IsShown() and o:IsMouseOver() and o.index ~= dragFrom then
table.insert(bars, o.index, table.remove(bars, dragFrom))
changed()
break
end
end
dragFrom = nil
end)
listRows[i] = r
return r
end
------------------------------------------------------------------------
-- Spell list + picker
------------------------------------------------------------------------
local function spellRow(i)
if spellRows[i] then return spellRows[i] end
local r = CreateFrame("Frame", nil, f.right)
r:SetSize(420, 20)
r:SetPoint("TOPLEFT", RIGHT, -180 - (i - 1) * 22)
r.icon = r:CreateTexture(nil, "ARTWORK")
r.icon:SetSize(18, 18)
r.icon:SetPoint("LEFT")
r.name = r:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
r.name:SetPoint("LEFT", 24, 0)
r.name:SetWidth(220)
r.name:SetJustifyH("LEFT")
r.display = button(r, "", 60, nil, nil, function()
local sp = selected.spells[i]
sp.display = sp.display == "bar" and "icon" or "bar"
changed()
end)
r.display:SetPoint("LEFT", 250, 0)
r.remove = button(r, "X", 24, nil, nil, function()
table.remove(selected.spells, i)
changed()
end)
r.remove:SetPoint("LEFT", 316, 0)
spellRows[i] = r
return r
end
local function pickRow(i)
if pickRows[i] then return pickRows[i] end
local r = CreateFrame("Button", nil, f.picker.list)
r:SetSize(210, 20)
r:SetPoint("TOPLEFT", 0, -(i - 1) * 22)
r:SetHighlightTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight", "ADD")
r.icon = r:CreateTexture(nil, "ARTWORK")
r.icon:SetSize(18, 18)
r.icon:SetPoint("LEFT")
r.text = r:CreateFontString(nil, "OVERLAY", "GameFontHighlightLeft")
r.text:SetPoint("LEFT", 24, 0)
r:SetScript("OnClick", function(self)
table.insert(selected.spells, { baseSpell = self.sp.baseSpell, name = self.sp.name, display = "icon" })
f.picker:Hide()
changed()
end)
pickRows[i] = r
return r
end
local function showPicker()
local p = f.picker
if not p then
p = window(nil, 260, 420, "Add spell")
p:SetParent(f)
p:SetPoint("TOPLEFT", f, "TOPRIGHT", 4, 0)
local hint = text(p, "Lists spells in Blizzard's Cooldown Manager.\nMissing one? Add it there first.", 14, -32, "GameFontHighlightSmall")
hint:SetJustifyH("LEFT")
button(p, "Open Cooldown Manager", 180, 14, -62, function()
if not pcall(function() CooldownViewerSettings:SetShown(not CooldownViewerSettings:IsShown()) end) then
print("|cffC79C6EBar Stack|r: open it from Options > Gameplay Enhancements > Cooldown Manager.")
end
end)
p.empty = text(p, "No spells found. Is the Cooldown Manager on?", 14, -96, "GameFontDisableSmall")
p.list = scroll(p, 12, -96, 210, 310)
f.picker = p
end
local spells = BS.AvailableSpells()
p.list:SetHeight(math.max(1, #spells * 22))
for i, sp in ipairs(spells) do
local r = pickRow(i)
r.sp = sp
r.icon:SetTexture(sp.icon or 134400)
r.text:SetText(sp.name)
r:Show()
end
for i = #spells + 1, #pickRows do pickRows[i]:Hide() end
p.empty:SetShown(#spells == 0)
p:Show()
end
------------------------------------------------------------------------
-- Export / import
------------------------------------------------------------------------
local function showText(mode)
local d = f.textDialog
if not d then
d = window(nil, 420, 260, "Profile string")
d:SetParent(f)
d:SetPoint("CENTER", f)
d:SetFrameLevel(f:GetFrameLevel() + 50)
local sf = CreateFrame("ScrollFrame", nil, d, "UIPanelScrollFrameTemplate")
sf:SetPoint("TOPLEFT", 12, -30)
sf:SetPoint("BOTTOMRIGHT", -32, 44)
d.edit = CreateFrame("EditBox", nil, sf)
d.edit:SetMultiLine(true)
d.edit:SetFontObject(ChatFontNormal)
d.edit:SetWidth(370)
d.edit:SetAutoFocus(false)
d.edit:SetScript("OnEscapePressed", function() d:Hide() end)
sf:SetScrollChild(d.edit)
d.status = d:CreateFontString(nil, "OVERLAY", "GameFontRedSmall")
d.status:SetPoint("BOTTOMLEFT", 14, 16)
d.ok = button(d, "Import", 100, nil, nil, function()
if BS.Import(d.edit:GetText()) then
d:Hide()
selected = nil
BS.RefreshConfig()
else
d.status:SetText("Not a valid Bar Stack string.")
end
end)
d.ok:SetPoint("BOTTOMRIGHT", -14, 10)
f.textDialog = d
end
d.status:SetText("")
d.ok:SetShown(mode == "import")
d.edit:SetText(mode == "export" and (BS.Export() or "Export is unavailable on this client.") or "")
d:Show()
d.edit:SetFocus()
d.edit:HighlightText()
end
local function pickColor()
local b = selected
local r0, g0, b0 = BS.Hex(b.style.color)
local function set(r, g, bl)
b.style.color = ("#%02X%02X%02X"):format(math.floor(r * 255 + 0.5), math.floor(g * 255 + 0.5), math.floor(bl * 255 + 0.5))
changed()
end
ColorPickerFrame:SetupColorPickerAndShow({
r = r0, g = g0, b = b0,
swatchFunc = function() set(ColorPickerFrame:GetColorRGB()) end,
cancelFunc = function() set(r0, g0, b0) end,
})
end
------------------------------------------------------------------------
-- Window
------------------------------------------------------------------------
local function build()
f = window("BarStackConfig", 660, 500, "Bar Stack")
f:SetPoint("CENTER")
f:SetMovable(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f:SetScript("OnHide", function()
if BS.preview then BS.preview = false; BS.Apply() end
end)
tinsert(UISpecialFrames, "BarStackConfig")
-- left: bar list
text(f, "Bars (top = top layer, drag to reorder)", 14, -32)
f.list = scroll(f, 12, -50, 166, 330)
button(f, "New", 58, 12, -388, function()
selected = BS.NewBar()
changed()
end)
button(f, "Copy", 58, 72, -388, function()
if not selected then return end
local copy = CopyTable(selected)
copy.id, copy.name = nil, selected.name .. " copy"
table.insert(BS.profile.bars, tIndexOf(BS.profile.bars, selected), BS.NormalizeBar(copy))
selected = copy
changed()
end)
button(f, "Delete", 58, 132, -388, function()
local i = selected and tIndexOf(BS.profile.bars, selected)
if i then table.remove(BS.profile.bars, i); selected = nil; changed() end
end)
-- right: selected bar
f.empty = text(f, "No bars yet. Click New to create one.", RIGHT, -60, "GameFontDisable")
local r = CreateFrame("Frame", nil, f)
r:SetAllPoints()
f.right = r
text(r, "Name", RIGHT, -32)
f.name = input(r, RIGHT, -46, 200, false, function(v) selected.name = v end)
text(r, "Visibility", 430, -32)
f.vis = button(r, "", 170, 430, -46, function()
selected.visibility = VIS[(tIndexOf(VIS, selected.visibility) or 0) % #VIS + 1]
changed()
end)
local nums = {
{ "Width", function(v) selected.size.w = BS.Clamp(v, 1, 2000) end },
{ "Height", function(v) selected.size.h = BS.Clamp(v, 1, 2000) end },
{ "Offset X", function(v) selected.offset.x = BS.Clamp(v, -2000, 2000) end },
{ "Offset Y", function(v) selected.offset.y = BS.Clamp(v, -2000, 2000) end },
}
f.nums = {}
for i, n in ipairs(nums) do
local x = RIGHT + (i - 1) * 80
text(r, n[1], x, -78)
f.nums[i] = input(r, x, -92, 60, true, n[2])
end
f.orient = button(r, "", 110, RIGHT, -124, function()
selected.orientation = selected.orientation == "vertical" and "horizontal" or "vertical"
changed()
end)
f.tex = button(r, "", 120, RIGHT + 118, -124, function()
selected.style.texture = selected.style.texture == "flat" and "blizzard" or "flat"
changed()
end)
button(r, "Color", 70, RIGHT + 246, -124, pickColor)
f.swatch = r:CreateTexture(nil, "ARTWORK")
f.swatch:SetSize(20, 20)
f.swatch:SetPoint("TOPLEFT", RIGHT + 322, -125)
text(r, "Spells", RIGHT, -160)
f.add = button(r, "Add spell", 100, RIGHT + 236, -154, showPicker)
-- bottom: stack + tools
text(f, "Stack", 14, -420)
text(f, "Scale", 60, -420, "GameFontHighlightSmall")
f.scale = input(f, 92, -416, 40, true, function(v) BS.profile.stack.scale = BS.Clamp(v, 0.3, 3) end)
text(f, "Opacity", 150, -420, "GameFontHighlightSmall")
f.alpha = input(f, 194, -416, 40, true, function(v) BS.profile.stack.alpha = BS.Clamp(v, 0, 1) end)
f.inCombat = checkbox(f, "Show in combat", 260, -414, function(on) BS.profile.stack.showInCombat = on; changed() end)
f.outCombat = checkbox(f, "Show out of combat", 400, -414, function(on) BS.profile.stack.showOutOfCombat = on; changed() end)
f.preview = checkbox(f, "Show all bars", 12, -452, function(on)
BS.preview = on
BS.Apply()
end)
button(f, "Export", 80, 400, -454, function() showText("export") end)
button(f, "Import", 80, 486, -454, function() showText("import") end)
f.combatNote = text(f, "Changes apply after combat.", 140, -458, "GameFontRedSmall")
end
function BS.RefreshConfig()
if not (f and f:IsShown()) then return end
local bars = BS.profile.bars
if not tContains(bars, selected) then selected = bars[1] end
f.list:SetHeight(math.max(1, #bars * 22))
for i, b in ipairs(bars) do
local row = listRow(i)
row.index = i
row.text:SetText(("|cff888888%d|r %s"):format(#bars - i + 1, b.name))
if b == selected then row:LockHighlight() else row:UnlockHighlight() end
row:Show()
end
for i = #bars + 1, #listRows do listRows[i]:Hide() end
local s = BS.profile.stack
f.scale:SetText(tostring(s.scale))
f.alpha:SetText(tostring(s.alpha))
f.inCombat:SetChecked(s.showInCombat)
f.outCombat:SetChecked(s.showOutOfCombat)
f.preview:SetChecked(BS.preview == true)
f.combatNote:SetShown(BS.pending == true)
f.right:SetShown(selected ~= nil)
f.empty:SetShown(selected == nil)
if f.picker and not selected then f.picker:Hide() end
local b = selected
if not b then return end
f.name:SetText(b.name)
f.vis:SetText(VIS_TEXT[b.visibility])
local vals = { b.size.w, b.size.h, b.offset.x, b.offset.y }
for i, e in ipairs(f.nums) do e:SetText(tostring(vals[i])) end
f.orient:SetText(b.orientation == "vertical" and "Vertical" or "Horizontal")
f.tex:SetText("Texture: " .. b.style.texture)
f.swatch:SetColorTexture(BS.Hex(b.style.color))
f.add:SetEnabled(#b.spells < MAX_SPELLS)
for i, sp in ipairs(b.spells) do
local row = spellRow(i)
row.icon:SetTexture((C_Spell and BS.try(C_Spell.GetSpellTexture, sp.baseSpell)) or 134400)
row.name:SetText(sp.name or ("Spell " .. sp.baseSpell))
row.display:SetText(sp.display == "bar" and "Bar" or "Icon")
row.display:SetShown(b.visibility ~= "always")
row:Show()
end
for i = #b.spells + 1, #spellRows do spellRows[i]:Hide() end
end
function BS.ToggleConfig()
if not BS.profile then return end
if not f then build() end
f:SetShown(not f:IsShown())
BS.RefreshConfig()
end