-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.lua
More file actions
61 lines (49 loc) · 1.61 KB
/
settings.lua
File metadata and controls
61 lines (49 loc) · 1.61 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
local addonSettingsWindow
---Create a addon settings window.
---@return Window
local function CreateAddonSettingsWindow()
local window = SetViewOfAddonSettings()
local titleBar = window.titleBar ---@type Window
local closeButton = titleBar.closeButton ---@type Button
window:SetSounds("bag")
window:SetCloseOnEscape(true)
window:EnableHidingIsRemove(true)
window:SetAlphaAnimation(0, 1, .1, .1)
window:SetStartAnimation(true, true)
window:SetUILayer("normal")
window:SetHandler("OnScale", function (self)
CorrectWidgetScreenPos(window)
end)
titleBar:SetHandler("OnDragStart", function ()
window:StartMoving()
end)
titleBar:SetHandler("OnDragStop", function ()
window:StopMovingOrSizing()
CorrectWidgetScreenPos(window)
end)
closeButton:SetHandler("OnClick", function ()
window:Show(false)
end)
return window
end
---Toggles the addon settings window.
---@param show boolean|nil
local function ToggleAddonSettingsWindow(show)
-- If the window should be shown.
if show == nil then
show = addonSettingsWindow == nil or not addonSettingsWindow:IsVisible()
end
-- If the window should be shown and doesn't exist, create it.
if show == true and addonSettingsWindow == nil then
addonSettingsWindow = CreateAddonSettingsWindow()
addonSettingsWindow:SetDeletedHandler(function ()
addonSettingsWindow = nil
end)
end
-- If the window exists, Show or Hide it.
if addonSettingsWindow:IsValidUIObject() then
addonSettingsWindow:Show(show)
end
end
UIParent:SetEventHandler("UI_ADDON", ToggleAddonSettingsWindow)
-- ToggleAddonSettingsWindow()