-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
64 lines (52 loc) · 1.63 KB
/
main.lua
File metadata and controls
64 lines (52 loc) · 1.63 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
local UIC_ADDON = -1
local addonWindow
---Creates a addon window.
---@return Window
local function CreateAddonWindow()
local window = SetViewOfAddon()
local titleBar = window.titleBar ---@type Window
local closeButton = titleBar.closeButton ---@type Button
local contentFrame = window.contentFrame ---@type EmptyWidget
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 window.
---@param show boolean|nil
local function ToggleAddonWindow(show)
-- If the window should be shown.
if show == nil then
show = addonWindow == nil or not addonWindow:IsVisible()
end
-- If the window should be shown and doesn't exist, create it.
if show == true and addonWindow == nil then
addonWindow = CreateAddonWindow()
addonWindow:SetDeletedHandler(function ()
addonWindow = nil
end)
end
-- If the window exists, Show or Hide it.
if addonWindow:IsValidUIObject() then
addonWindow:Show(show)
end
end
ADDON:RegisterContentTriggerFunc(UIC_ADDON, ToggleAddonWindow)
ADDON:AddEscMenuButton(5, UIC_ADDON, "optimizer", locale.addon.name)
-- ToggleAddonWindow()