Repository navigation
Expand file tree
/
Copy pathOptions.lua
More file actions
357 lines (340 loc) · 16.6 KB
/
Copy pathOptions.lua
File metadata and controls
357 lines (340 loc) · 16.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
local BuffTimers = LibStub("AceAddon-3.0"):GetAddon("BuffTimers")
local module = BuffTimers:NewModule("Config")
local L = LibStub("AceLocale-3.0"):GetLocale("BuffTimers")
BuffTimersLibSharedMedia = LibStub("LibSharedMedia-3.0", true)
local db
local exportText = ""
local importText = ""
local transferStatus
local AceConfigRegistry = LibStub("AceConfigRegistry-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local AceDBOptions = LibStub("AceDBOptions-3.0")
local AceGUI = LibStub("AceGUI-3.0")
local importErrors = {
EMPTY = "Paste a profile string first.",
TOO_LONG = "The profile string is too long.",
INVALID_FORMAT = "This is not a BuffTimers profile string.",
INVALID_DATA = "The profile string is damaged or incomplete.",
INVALID_PROFILE = "The profile data is invalid.",
}
local function SetTransferStatus(message, isError, notify)
local color = isError and "ffff4040" or "ff40ff40"
transferStatus = "|c" .. color .. message .. "|r"
if notify ~= false then
AceConfigRegistry:NotifyChange("BuffTimers")
end
end
local function SelectExportString()
if exportText == "" then
return false
end
-- AceConfig creates this option with AceGUI's bundled MultiLineEditBox widget.
-- Clipboard writes are protected, so select the text for the user's normal copy shortcut.
for index = 1, AceGUI:GetWidgetCount("MultiLineEditBox") do
local editBox = _G["MultiLineEditBox" .. index .. "Edit"]
if editBox and editBox:IsVisible() and editBox:GetText() == exportText then
editBox:SetFocus()
editBox:HighlightText()
return true
end
end
return false
end
local function GetImportError(errorCode, detail)
if errorCode == "UNSUPPORTED_VERSION" then
return L["This profile string uses an unsupported version (%s)."]:format(detail or "?")
elseif errorCode == "INVALID_VALUE" then
return L["The profile contains an invalid value for %s."]:format(detail or "?")
end
return L[importErrors[errorCode] or "The profile data is invalid."]
end
local function IsTextCustomizationDisabled()
return not db.profile.customize_text
end
function module:OnInitialize()
db = BuffTimers.db
local options = {
type = "group",
name = "BuffTimers",
args = {
time = {
type = "group",
name = L["Time"],
order = 10,
args = {
formatGroup = {
type = "group",
name = L["Format"],
inline = true,
args = {
timeFormat = {
type = "select",
name = L["Time Stamp Format"],
desc = L["Choose the format for displaying buff duration"],
values = {
["m"] = "minutes (119m)",
["hm"] = "h:mm (1:59h)",
},
get = function() return db.profile.time_stamp end,
set = function(_, value) db.profile.time_stamp = value end,
order = 1,
},
detailedTimeOnHover = {
type = "toggle",
name = L["Show detailed time on hover"],
desc = L["Show detailed time on hover when at least one minute remains"],
get = function() return db.profile.detailed_time_on_hover end,
set = function(_, value) db.profile.detailed_time_on_hover = value end,
width = "full",
order = 2,
},
},
},
secondsThresholdGroup = {
type = "group",
name = L["Seconds"],
inline = true,
args = {
showSeconds = {
type = "toggle",
name = L["Show seconds"],
desc = L["Show seconds for buff timers"],
get = function() return db.profile.seconds end,
set = function(_, value) db.profile.seconds = value end,
order = 2,
},
secondsThreshold = {
type = "range",
name = L["Show seconds below this time"],
desc = L["Only show seconds when buffs have less than this many minutes"],
width = "full",
min = 1,
max = 120,
step = 1,
get = function() return db.profile.seconds_threshold end,
set = function(_, value) db.profile.seconds_threshold = value end,
order = 3,
},
showMilliseconds = {
type = "toggle",
name = L["Show milliseconds below 5 seconds"],
desc = L["Show milliseconds for buff timers with less than 5 seconds remaining"],
width = "full",
get = function() return db.profile.milliseconds end,
set = function(_, value) db.profile.milliseconds = value end,
order = 4,
},
}
}
}
},
textGroup = {
type = "group",
name = L["Text"],
order = 15,
args = {
colorGroup = {
type = "group",
name = L["Color"],
inline = true,
args = {
yellowText = {
type = "toggle",
name = L["Always yellow text color"],
desc = L["Always use yellow for buff timer text"],
get = function() return db.profile.yellow_text end,
set = function(_, value) db.profile.yellow_text = value end,
width = "full",
order = 1,
},
coloredText = {
type = "toggle",
name = L["Add more colors to the timer"],
desc = L["Use different colors based on remaining time"],
get = function() return db.profile.colored_text end,
set = function(_, value) db.profile.colored_text = value end,
width = "full",
order = 2,
},
}
},
customizeTextGroup = {
type = "group",
name = L["Customization"],
inline = true,
args = {
enableCustomizeText = {
type = "toggle",
name = L["Enable"],
desc = L["Enable text customization"],
get = function() return db.profile.customize_text end,
set = function(_, value) BuffTimers:SetTextCustomizationEnabled(value) end,
width = "full",
order = 7,
},
verticalPosition = {
type = "range",
name = L["Text vertical position"],
desc = L["Adjust the vertical position of the timer text"],
min = BuffTimers.VERTICAL_POSITION_MIN,
max = BuffTimers.VERTICAL_POSITION_MAX,
step = 1,
get = function() return db.profile.vertical_position end,
set = function(_, value) db.profile.vertical_position = value end,
disabled = IsTextCustomizationDisabled,
order = 8,
},
fontGroup = {
type = "group",
name = L["Font"],
inline = true,
args = {
font = {
type = "select",
name = L["Font"],
desc = L["Choose the font for the timer text"],
values = function()
local fonts = BuffTimersLibSharedMedia:List("font")
local values = {}
for _, font in ipairs(fonts) do
values[font] = font
end
return values
end,
get = function() return db.profile.font end,
set = function(_, value) db.profile.font = value end,
disabled = IsTextCustomizationDisabled,
order = 1,
},
fontSize = {
type = "range",
name = L["Font Size"],
desc = L["Adjust the font size of the timer text"],
min = 1,
max = 100,
step = 1,
get = function() return db.profile.font_size end,
set = function(_, value) db.profile.font_size = value end,
disabled = IsTextCustomizationDisabled,
order = 2,
},
fontOutline = {
type = "select",
name = L["Outline"],
desc = L["Choose the outline for the timer text"],
values = {
[""] = "None",
["OUTLINE"] = "Outline",
["THICKOUTLINE"] = "Thick",
["MONOCHROME"] = "Monochrome",
},
get = function() return db.profile.font_outline end,
set = function(_, value) db.profile.font_outline = value end,
disabled = IsTextCustomizationDisabled,
order = 3,
}
}
}
}
}
},
},
importExport = {
type = "group",
name = L["Import / Export"],
desc = L["Share or restore the currently active profile."],
order = 30,
args = {
description = {
type = "description",
name = L["Share or restore the currently active profile."],
order = 1,
},
exportString = {
type = "input",
name = L["Export string"],
desc = L["Click the field and press Ctrl+A, then Ctrl+C to copy the active profile."],
multiline = 8,
width = "full",
get = function()
exportText = BuffTimers:ExportProfile()
return exportText
end,
set = function() end,
order = 2,
},
selectExport = {
type = "execute",
name = L["Select for copying"],
desc = L["Select the export string, then press Ctrl+C to copy it."],
func = function()
SetTransferStatus(L["Export string selected. Press Ctrl+C to copy it."], false, false)
-- AceConfig redraws after execute controls run. Select on the next frame so
-- the newly-created export edit box keeps focus and its selection.
C_Timer.After(0, function()
if not SelectExportString() then
SetTransferStatus(
L["Could not select the export string. Click the field and press Ctrl+A, then Ctrl+C."],
true
)
end
end)
end,
order = 3,
},
importString = {
type = "input",
name = L["Import string"],
desc = L["Paste a BuffTimers profile string here."],
multiline = 8,
width = "full",
get = function() return importText end,
set = function(_, value)
importText = value
transferStatus = nil
end,
order = 4,
},
importProfile = {
type = "execute",
name = L["Import profile"],
confirm = function()
return BuffTimers:WillImportReplaceProfile(importText)
end,
confirmText = L["A profile with this name already exists and will be replaced. Continue?"],
disabled = function() return importText:match("^%s*$") ~= nil end,
func = function()
local success, errorCode, detail = BuffTimers:ImportProfile(importText)
if success then
importText = ""
SetTransferStatus(L["The profile was imported successfully."], false)
else
SetTransferStatus(GetImportError(errorCode, detail), true)
end
end,
order = 5,
},
status = {
type = "description",
name = function() return transferStatus or "" end,
order = 6,
},
},
},
},
}
local profileOptions = AceDBOptions:GetOptionsTable(db)
profileOptions.order = 20
options.args.profiles = profileOptions
-- Register the options with AceConfig
AceConfigRegistry:RegisterOptionsTable("BuffTimers", options)
-- Create the options panel
AceConfigDialog:AddToBlizOptions("BuffTimers", "BuffTimers")
end
function module:ShowConfig()
AceConfigDialog:Open("BuffTimers")
end
SLASH_BUFFTIMERS1 = "/bufftimers"
function SlashCmdList.BUFFTIMERS()
module:ShowConfig()
end