-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptions.lua
More file actions
442 lines (382 loc) · 13.4 KB
/
Copy pathOptions.lua
File metadata and controls
442 lines (382 loc) · 13.4 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
local ADDON_NAME, NS = ...
local L = NS.L
local settingsRegistered = false
local categoryID
local minimapButton
local proxySettings = {}
local RESET_DIALOG_KEY = "STAYCLOSE_RESET_ALL"
local function GetDistanceUnit()
local locale = GetLocale and GetLocale() or "enUS"
return (locale == "enUS" or locale == "enGB") and "yd" or "m"
end
local function AddSection(layout, label)
if layout and CreateSettingsListSectionHeaderInitializer then
layout:AddInitializer(CreateSettingsListSectionHeaderInitializer(label))
end
end
local function GetSettingType(defaultValue)
if Settings.VarType then
if type(defaultValue) == "boolean" then
return Settings.VarType.Boolean
end
if type(defaultValue) == "number" then
return Settings.VarType.Number
end
if type(defaultValue) == "string" then
return Settings.VarType.String
end
end
return type(defaultValue)
end
local function RegisterProxy(category, key, label)
local defaultValue = NS.Defaults[key]
local setting = Settings.RegisterProxySetting(
category,
"STAYCLOSE_" .. key:upper(),
GetSettingType(defaultValue),
label,
defaultValue,
function()
return NS.GetSetting(key)
end,
function(value)
NS.SetSetting(key, value)
end
)
proxySettings[key] = setting
return setting
end
local function AddCheckbox(category, key, label, description)
local setting = RegisterProxy(category, key, label)
Settings.CreateCheckbox(category, setting, description)
end
local function AddSlider(category, key, label, description, minValue, maxValue, step, formatter)
local setting = RegisterProxy(category, key, label)
local options = Settings.CreateSliderOptions(minValue, maxValue, step)
if formatter
and options.SetLabelFormatter
and MinimalSliderWithSteppersMixin
and MinimalSliderWithSteppersMixin.Label
then
options:SetLabelFormatter(MinimalSliderWithSteppersMixin.Label.Right, formatter)
end
Settings.CreateSlider(category, setting, options, description)
end
local function AddButton(layout, label, buttonText, callback, description)
if not layout or not CreateSettingsButtonInitializer then
return
end
layout:AddInitializer(CreateSettingsButtonInitializer(
label,
buttonText,
callback,
description,
true
))
end
local function GetIconTexture()
local icon = "Interface\\Icons\\Spell_Holy_FlashHeal"
if C_AddOns and C_AddOns.GetAddOnMetadata then
icon = C_AddOns.GetAddOnMetadata(ADDON_NAME, "IconTexture") or icon
end
return icon
end
local function GetMinimapBaseRadius()
local minimapWidth = Minimap:GetWidth()
local minimapHeight = Minimap:GetHeight()
if not minimapWidth or minimapWidth <= 0 then
minimapWidth = 140
end
if not minimapHeight or minimapHeight <= 0 then
minimapHeight = minimapWidth
end
return math.min(minimapWidth, minimapHeight) * 0.5
end
local function GetCursorAngle()
local centerX, centerY = Minimap:GetCenter()
local cursorX, cursorY = GetCursorPosition()
local scale = Minimap:GetEffectiveScale()
cursorX = cursorX / scale
cursorY = cursorY / scale
local deltaX = cursorX - centerX
local deltaY = cursorY - centerY
if math.atan2 then
return math.deg(math.atan2(deltaY, deltaX)) % 360
end
if deltaX == 0 then
return deltaY >= 0 and 90 or 270
end
local angle = math.deg(math.atan(deltaY / deltaX))
if deltaX < 0 then
angle = angle + 180
elseif deltaY < 0 then
angle = angle + 360
end
return angle
end
local function GetMinimapCoordinates(angle, radius)
local x = math.cos(angle)
local y = math.sin(angle)
local shape = "ROUND"
if type(GetMinimapShape) == "function" then
local ok, value = pcall(GetMinimapShape)
if ok and type(value) == "string" then
shape = value
end
end
if shape == "SQUARE" then
local largestAxis = math.max(math.abs(x), math.abs(y))
if largestAxis > 0 then
local scale = radius / largestAxis
return x * scale, y * scale
end
end
return x * radius, y * radius
end
local function PositionMinimapButton()
if not minimapButton then
return
end
local angle = math.rad(NS.GetSetting("minimapAngle"))
local radius = GetMinimapBaseRadius() + NS.GetSetting("minimapOffset")
local x, y = GetMinimapCoordinates(angle, radius)
minimapButton:ClearAllPoints()
minimapButton:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
local function CreateMinimapButton()
if minimapButton or not Minimap or not CreateFrame then
return
end
local button = CreateFrame("Button", "StayCloseMinimapButton", Minimap)
button:SetSize(31, 31)
button:SetFrameStrata("MEDIUM")
button:SetFrameLevel(8)
button:SetMovable(true)
button:SetClampedToScreen(true)
button:RegisterForClicks("LeftButtonUp", "RightButtonUp")
button:RegisterForDrag("LeftButton")
button:SetHighlightTexture("Interface\\Minimap\\UI-Minimap-ZoomButton-Highlight")
local icon = button:CreateTexture(nil, "BACKGROUND")
icon:SetSize(20, 20)
icon:SetPoint("TOPLEFT", 7, -5)
icon:SetTexture(GetIconTexture())
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
local border = button:CreateTexture(nil, "OVERLAY")
border:SetSize(53, 53)
border:SetPoint("TOPLEFT")
border:SetTexture("Interface\\Minimap\\MiniMap-TrackingBorder")
button:SetScript("OnClick", function(_, mouseButton)
if mouseButton == "RightButton" then
NS.ShowTestAlert()
elseif NS.OpenSettings then
NS.OpenSettings()
end
end)
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText(ADDON_NAME, 1, 1, 1)
GameTooltip:AddLine(L.MINIMAP_TOOLTIP_LEFT, nil, nil, nil, true)
GameTooltip:AddLine(L.MINIMAP_TOOLTIP_RIGHT, nil, nil, nil, true)
GameTooltip:AddLine(L.MINIMAP_TOOLTIP_DRAG, nil, nil, nil, true)
GameTooltip:Show()
end)
button:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
button:SetScript("OnDragStart", function(self)
self:SetScript("OnUpdate", function()
NS.SetSetting("minimapAngle", GetCursorAngle())
end)
end)
button:SetScript("OnDragStop", function(self)
self:SetScript("OnUpdate", nil)
end)
minimapButton = button
end
function NS.UpdateMinimapButton()
CreateMinimapButton()
if not minimapButton then
return
end
PositionMinimapButton()
minimapButton:SetShown(NS.GetSetting("showMinimapButton"))
end
function NS.ResetMinimapPosition()
NS.SetSetting("minimapAngle", NS.Defaults.minimapAngle)
NS.SetSetting("minimapOffset", NS.Defaults.minimapOffset)
end
local function ApplyDefaultSettings()
NS.ResetAllSettings()
for key, setting in pairs(proxySettings) do
if setting and setting.SetValue then
setting:SetValue(NS.Defaults[key])
end
end
DEFAULT_CHAT_FRAME:AddMessage("|cff70d6ffStayClose|r: " .. L.RESET_COMPLETE)
end
local function ConfirmDefaultSettings()
if not StaticPopupDialogs or not StaticPopup_Show then
ApplyDefaultSettings()
return
end
StaticPopupDialogs[RESET_DIALOG_KEY] = StaticPopupDialogs[RESET_DIALOG_KEY] or {
text = L.RESET_CONFIRM,
button1 = ACCEPT or "Accept",
button2 = CANCEL or "Cancel",
OnAccept = ApplyDefaultSettings,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
StaticPopup_Show(RESET_DIALOG_KEY)
end
local function RegisterAddonCompartment()
if not AddonCompartmentFrame or not AddonCompartmentFrame.RegisterAddon then
return
end
AddonCompartmentFrame:RegisterAddon({
text = ADDON_NAME,
icon = GetIconTexture(),
registerForAnyClick = true,
notCheckable = true,
func = function()
NS.OpenSettings()
end,
funcOnEnter = function(button)
GameTooltip:SetOwner(button, "ANCHOR_LEFT")
GameTooltip:SetText(ADDON_NAME, 1, 1, 1)
GameTooltip:AddLine(L.SETTINGS_ENABLED_DESC, nil, nil, nil, true)
GameTooltip:Show()
end,
funcOnLeave = function()
GameTooltip:Hide()
end,
})
end
function NS.RegisterSettings()
if settingsRegistered then
return
end
settingsRegistered = true
NS.UpdateMinimapButton()
if not Settings
or not Settings.RegisterVerticalLayoutCategory
or not Settings.RegisterProxySetting
or not Settings.RegisterAddOnCategory
then
NS.OpenSettings = function()
DEFAULT_CHAT_FRAME:AddMessage("|cff70d6ffStayClose|r: " .. L.OPTIONS_UNAVAILABLE)
end
RegisterAddonCompartment()
return
end
local category, layout = Settings.RegisterVerticalLayoutCategory(L.SETTINGS_TITLE)
layout = layout or (SettingsPanel and SettingsPanel.GetLayout and SettingsPanel:GetLayout(category))
AddSection(layout, L.SETTINGS_GENERAL)
AddCheckbox(category, "enabled", L.SETTINGS_ENABLED, L.SETTINGS_ENABLED_DESC)
AddCheckbox(category, "onlyCombat", L.SETTINGS_COMBAT_ONLY, L.SETTINGS_COMBAT_ONLY_DESC)
AddCheckbox(category, "sound", L.SETTINGS_SOUND, L.SETTINGS_SOUND_DESC)
local soundSetting = RegisterProxy(category, "soundMode", L.SETTINGS_SOUND_MODE)
Settings.CreateDropdown(category, soundSetting, function()
local container = Settings.CreateControlTextContainer()
container:Add("raid", L.SOUND_RAID)
container:Add("ready", L.SOUND_READY)
container:Add("tell", L.SOUND_TELL)
return container:GetData()
end, L.SETTINGS_SOUND_MODE_DESC)
AddCheckbox(category, "repeatSound", L.SETTINGS_REPEAT_SOUND, L.SETTINGS_REPEAT_SOUND_DESC)
AddSlider(
category,
"soundCooldown",
L.SETTINGS_SOUND_COOLDOWN,
L.SETTINGS_SOUND_COOLDOWN_DESC,
2,
30,
1,
function(value)
return string.format("%d s", value)
end
)
AddCheckbox(category, "warnUnavailable", L.SETTINGS_WARN_UNAVAILABLE, L.SETTINGS_WARN_UNAVAILABLE_DESC)
AddCheckbox(category, "warnNoHealer", L.SETTINGS_WARN_NO_HEALER, L.SETTINGS_WARN_NO_HEALER_DESC)
AddSection(layout, L.SETTINGS_RANGES)
local function FormatRange(value)
return string.format("%d %s", value, GetDistanceUnit())
end
AddSlider(category, "partyDistance", L.SETTINGS_PARTY_RANGE, L.SETTINGS_PARTY_RANGE_DESC, 10, 100, 1, FormatRange)
AddSlider(category, "raidDistance", L.SETTINGS_RAID_RANGE, L.SETTINGS_RAID_RANGE_DESC, 10, 100, 1, FormatRange)
AddSlider(category, "pvpDistance", L.SETTINGS_PVP_RANGE, L.SETTINGS_PVP_RANGE_DESC, 10, 100, 1, FormatRange)
AddSection(layout, L.SETTINGS_TIMING)
local function FormatSeconds(value)
return string.format("%.1f s", value)
end
AddSlider(category, "warningDelay", L.SETTINGS_WARNING_DELAY, L.SETTINGS_WARNING_DELAY_DESC, 0, 5, 0.1, FormatSeconds)
AddSlider(category, "recoveryDelay", L.SETTINGS_RECOVERY_DELAY, L.SETTINGS_RECOVERY_DELAY_DESC, 0, 5, 0.1, FormatSeconds)
AddSlider(category, "checkInterval", L.SETTINGS_CHECK_INTERVAL, L.SETTINGS_CHECK_INTERVAL_DESC, 0.2, 10, 0.1, FormatSeconds)
AddSection(layout, L.SETTINGS_APPEARANCE)
AddSlider(
category,
"alertScale",
L.SETTINGS_SCALE,
L.SETTINGS_SCALE_DESC,
0.7,
1.5,
0.05,
function(value)
return string.format("%.2f", value)
end
)
AddSlider(
category,
"alertOpacity",
L.SETTINGS_OPACITY,
L.SETTINGS_OPACITY_DESC,
0.35,
1,
0.05,
function(value)
return string.format("%d%%", value * 100)
end
)
AddCheckbox(category, "frameLocked", L.SETTINGS_LOCKED, L.SETTINGS_LOCKED_DESC)
AddCheckbox(category, "showMinimapButton", L.SETTINGS_MINIMAP_BUTTON, L.SETTINGS_MINIMAP_BUTTON_DESC)
AddSlider(
category,
"minimapOffset",
L.SETTINGS_MINIMAP_OFFSET,
L.SETTINGS_MINIMAP_OFFSET_DESC,
-20,
20,
1,
function(value)
return string.format("%+d px", value)
end
)
AddSection(layout, L.SETTINGS_ACTIONS)
AddButton(layout, L.SETTINGS_TEST, L.BUTTON_SHOW, NS.ShowTestAlert, L.SETTINGS_TEST_DESC)
AddButton(layout, L.SETTINGS_RESET_POSITION, L.BUTTON_RESET, NS.ResetAlertPosition, L.SETTINGS_RESET_POSITION_DESC)
AddButton(
layout,
L.SETTINGS_RESET_MINIMAP,
L.BUTTON_RESET,
NS.ResetMinimapPosition,
L.SETTINGS_RESET_MINIMAP_DESC
)
AddButton(layout, L.SETTINGS_REPORT, L.BUTTON_PRINT, NS.PrintReport, L.SETTINGS_REPORT_DESC)
AddButton(
layout,
L.SETTINGS_RESET_ALL,
L.BUTTON_RESET,
ConfirmDefaultSettings,
L.SETTINGS_RESET_ALL_DESC
)
Settings.RegisterAddOnCategory(category)
categoryID = category.GetID and category:GetID() or category.ID
NS.OpenSettings = function()
if Settings.OpenToCategory and categoryID then
Settings.OpenToCategory(categoryID)
end
end
RegisterAddonCompartment()
end