-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPullSize_Config.lua
More file actions
332 lines (306 loc) · 14.6 KB
/
PullSize_Config.lua
File metadata and controls
332 lines (306 loc) · 14.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
-- PullSize config panel.
-- Built on AceConfig-3.0 + AceConfigDialog-3.0. Layout: every control lives
-- directly in its section's inline group with an explicit width. Ace's Flow
-- layout packs them left-to-right and wraps when the row is full. We don't
-- wrap controls in SimpleGroup column containers because Ace forces inline
-- groups to width "fill" regardless of what we pass.
local ADDON = "PullSize"
local AceConfig = LibStub and LibStub("AceConfig-3.0", true)
local AceConfigDialog = LibStub and LibStub("AceConfigDialog-3.0", true)
local AceConfigRegistry = LibStub and LibStub("AceConfigRegistry-3.0", true)
------------------------------------------------------------------------------
-- DB accessors
------------------------------------------------------------------------------
local function DB() return _G.PullSizeDB end
local function getBreakpoint(i) return DB().thresholds[i] end
------------------------------------------------------------------------------
-- Distance presets
------------------------------------------------------------------------------
local PRESETS = {
melee = { label = "Melee", yards = 10 },
midranged = { label = "Mid-Ranged", yards = 25 },
ranged = { label = "Ranged", yards = 40 },
custom = { label = "Custom", yards = nil },
}
local PRESET_ORDER = { "melee", "midranged", "ranged", "custom" }
local function GetEffectiveDistance()
local d = DB()
local p = PRESETS[d.distancePreset]
if p and p.yards then return p.yards end
return d.instanceDistance
end
local function ApplyDistanceFromConfig()
if PullSize.ApplyInstanceDistance then
PullSize.ApplyInstanceDistance(GetEffectiveDistance())
end
end
local function PresetSelectValues()
local t = {}
for _, key in ipairs(PRESET_ORDER) do
local p = PRESETS[key]
local label = p.label
if p.yards then label = label .. " (" .. p.yards .. " yd)" end
t[key] = label
end
return t
end
local function RefreshPanel()
if AceConfigRegistry and AceConfigRegistry.NotifyChange then
AceConfigRegistry:NotifyChange(ADDON)
end
end
------------------------------------------------------------------------------
-- Column widths. Tuned by eye against the panel content area.
------------------------------------------------------------------------------
local COL_DISP = 0.95 -- Display section: 3 controls in one row
local COL_NP = 1.4 -- Nameplate: dropdown's frame allocation
local COL_NP_SLIDER = 1.4 -- Custom Distance slider's frame allocation
local COL_NP_SPACER = 0.2 -- Visible gap between dropdown and slider
local BP_COL_LABEL = 1.2
local BP_COL_SWATCH = 0.5
local BP_COL_RIGHT = 1.3
------------------------------------------------------------------------------
-- Breakpoint row factory: label + swatch + count, all in one inline group.
------------------------------------------------------------------------------
local function BreakpointRow(i, order)
return {
type = "group", inline = true, name = "", order = order,
args = {
label = {
type = "description", order = 1,
name = "Breakpoint " .. i,
width = BP_COL_LABEL,
fontSize = "medium",
},
color = {
type = "color", order = 2, name = "",
desc = "Display color when count meets Breakpoint " .. i .. ".",
width = BP_COL_SWATCH,
get = function()
local t = getBreakpoint(i)
return t[2], t[3], t[4]
end,
set = function(_, r, g, b)
local t = getBreakpoint(i)
t[2], t[3], t[4] = r, g, b
if PullSize.RefreshDisplay then PullSize.RefreshDisplay() end
end,
},
count = {
type = "range", order = 3, name = "",
desc = "Enemy count at which Breakpoint " .. i .. " activates.",
width = BP_COL_RIGHT,
min = 1, max = 30, step = 1,
get = function() return getBreakpoint(i)[1] end,
set = function(_, v)
getBreakpoint(i)[1] = v
if PullSize.RefreshDisplay then PullSize.RefreshDisplay() end
end,
},
},
}
end
------------------------------------------------------------------------------
-- The full Ace options table
------------------------------------------------------------------------------
local function BuildOptions()
return {
type = "group",
name = ADDON,
args = {
-- Defaults button at the top.
restoreDefaults = {
type = "execute", order = 0,
name = "Restore Defaults",
desc = "Reset all PullSize settings (font size, lock state, breakpoint colors and counts, distance preset, etc.) to their built-in defaults.",
confirm = true,
confirmText = "Reset all PullSize settings to their defaults? Your custom colors, counts, and other preferences will be lost.",
func = function()
if PullSize.RestoreDefaults then
PullSize.RestoreDefaults()
end
RefreshPanel()
end,
},
----------------------------------------------------------------
-- Section: Display.
-- Row 1: Font Size | Lock Display | Hide Out of Combat
-- Row 2: Reset Position (alone, under Font Size)
----------------------------------------------------------------
display = {
type = "group", inline = true, name = "Display", order = 10,
args = {
fontSize = {
type = "range", name = "Font Size", order = 1,
desc = "Size of the count text.",
width = COL_DISP,
min = 24, max = 72, step = 1,
get = function() return DB().fontSize end,
set = function(_, v)
DB().fontSize = v
if PullSize.RefreshDisplay then PullSize.RefreshDisplay() end
end,
},
locked = {
type = "toggle", name = "Lock Display", order = 2,
desc = "Prevent the display from being moved by dragging.",
width = COL_DISP,
get = function() return DB().locked end,
set = function(_, v)
DB().locked = v
if PullSize.RefreshDisplay then PullSize.RefreshDisplay() end
end,
},
hideOOC = {
type = "toggle", name = "Hide Out of Combat", order = 3,
desc = "Hide the display when not in combat.",
width = COL_DISP,
get = function() return DB().hideOutOfCombat end,
set = function(_, v)
DB().hideOutOfCombat = v
if PullSize.RefreshDisplay then PullSize.RefreshDisplay() end
end,
},
resetPos = {
type = "execute", name = "Reset Position", order = 4,
desc = "Move the display back to the screen center.",
width = COL_DISP,
func = function()
if PullSize.ResetDisplayPosition then
PullSize.ResetDisplayPosition()
end
end,
},
},
},
----------------------------------------------------------------
-- Section: Nameplate Distance.
-- Row 1: description text (full width)
-- Row 2: spacer (creates clearance for "Distance Preset" label
-- below it which would otherwise clip)
-- Row 3: Auto-Set | Distance Preset | Custom Distance
----------------------------------------------------------------
nameplate = {
type = "group", inline = true, name = "Nameplate Distance", order = 20,
args = {
info = {
type = "description", order = 1, width = "full",
name = "PullSize counts visible hostile nameplates.",
},
spacer = {
type = "description", order = 2, width = "full",
name = "\n",
},
autoSet = {
type = "toggle", name = "Auto-Set in Instances", order = 5,
desc = "When entering a dungeon, raid, or delve, set the nameplate distance to the value below. Restore your saved value on exit.",
width = COL_NP,
get = function() return DB().autoSetDistance end,
set = function(_, v) DB().autoSetDistance = v end,
},
preset = {
type = "select", name = "Distance Preset", order = 3,
desc = "Choose a preset for your role, or pick Custom to set a specific value.",
width = COL_NP,
values = PresetSelectValues,
sorting = PRESET_ORDER,
get = function() return DB().distancePreset end,
set = function(_, v)
local prev = DB().distancePreset
DB().distancePreset = v
if v == "custom" and prev ~= "custom" and PRESETS[prev] and PRESETS[prev].yards then
DB().instanceDistance = PRESETS[prev].yards
end
ApplyDistanceFromConfig()
RefreshPanel()
end,
},
presetSpacer = {
-- Horizontal padding between Preset and Custom Distance.
type = "description", order = 3.5, name = " ", width = 0.2,
},
customDistance = {
type = "range", name = "Custom Distance", order = 4,
desc = "Nameplate distance in yards. Only used when the preset is Custom.",
width = COL_NP_SLIDER,
min = 5, max = 60, step = 1,
get = function() return DB().instanceDistance end,
set = function(_, v)
DB().instanceDistance = v
ApplyDistanceFromConfig()
end,
disabled = function() return DB().distancePreset ~= "custom" end,
},
},
},
----------------------------------------------------------------
-- Section: Enemy Count Breakpoints
----------------------------------------------------------------
breakpoints = {
type = "group", inline = true, name = "Enemy Count Breakpoints", order = 30,
args = {
-- Below row: label, swatch, dim checkbox.
belowRow = {
type = "group", inline = true, name = "", order = 1,
args = {
label = {
type = "description", order = 1, name = "Below Breakpoint 1",
width = BP_COL_LABEL, fontSize = "medium",
},
color = {
type = "color", order = 2, name = "",
desc = "Display color when count is below Breakpoint 1.",
width = BP_COL_SWATCH,
get = function()
local b = DB().belowColor
return b[1], b[2], b[3]
end,
set = function(_, r, g, b)
local c = DB().belowColor
c[1], c[2], c[3] = r, g, b
if PullSize.RefreshDisplay then PullSize.RefreshDisplay() end
end,
},
dim = {
type = "toggle", order = 3, name = "Dim Below Breakpoint 1",
desc = "Use a dimmed color when the count is below the first breakpoint.",
width = BP_COL_RIGHT,
get = function() return DB().dimBelowThreshold end,
set = function(_, v)
DB().dimBelowThreshold = v
if PullSize.RefreshDisplay then PullSize.RefreshDisplay() end
end,
},
},
},
bp1 = BreakpointRow(1, 2),
bp2 = BreakpointRow(2, 3),
bp3 = BreakpointRow(3, 4),
},
},
},
}
end
------------------------------------------------------------------------------
-- Boot
------------------------------------------------------------------------------
local boot = CreateFrame("Frame")
boot:RegisterEvent("ADDON_LOADED")
boot:SetScript("OnEvent", function(self, event, addon)
if addon ~= ADDON then return end
self:UnregisterEvent("ADDON_LOADED")
if not (AceConfig and AceConfigDialog) then
print("|cffff6600[PullSize]|r AceConfig is unavailable; settings panel disabled. Use slash commands.")
return
end
AceConfig:RegisterOptionsTable(ADDON, BuildOptions)
AceConfigDialog:AddToBlizOptions(ADDON, ADDON)
PullSize.OpenSettings = function()
local id = AceConfigDialog.BlizOptionsIDMap and AceConfigDialog.BlizOptionsIDMap[ADDON]
if id and Settings and Settings.OpenToCategory then
Settings.OpenToCategory(id)
elseif Settings and Settings.OpenToCategory then
Settings.OpenToCategory(ADDON)
end
end
end)