-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexampleaddon.lua
More file actions
123 lines (102 loc) · 3.59 KB
/
exampleaddon.lua
File metadata and controls
123 lines (102 loc) · 3.59 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
local UIC_EXAMPLEADDON = 12345678
local exampleAddonWindow
---Saves the UIBound of the widget.
---@param widget Widget
---@param key string
local function SaveUIBound(widget, key)
local bound = {}
bound.x, bound.y = widget:GetEffectiveOffset()
bound.width, bound.height = widget:GetExtent()
local uiBound = {
bound = bound,
screenResolution = {
x = UIParent:GetScreenWidth(),
y = UIParent:GetScreenHeight(),
scale = UIParent:GetUIScale(),
},
}
UIParent:SetUIBound(key, uiBound)
end
---Creates a example addon window.
---@return Window
local function CreateExampleAddonWindow()
local window = SetViewOfExampleAddon()
local titleBar = window.titleBar ---@type Window
local closeButton = titleBar.closeButton ---@type Button
local bodyTextbox = window.bodyTextbox ---@type Textbox
local checkButton = window.checkButton ---@type CheckButton
local resetUIButton = window.resetUIButton ---@type Button
local saveUIButton = window.saveUIButton ---@type Button
local settingsButton = window.settingsButton ---@type Button
window:SetSounds("bag")
window:SetCloseOnEscape(true)
window:EnableHidingIsRemove(true)
window:SetAlphaAnimation(0, 1, .1, .1)
window:SetStartAnimation(true, true)
window:SetUILayer("system")
window:SetResizingBorderSize(
WINDOW.RESIZE_BORDER_SIZE.LEFT,
WINDOW.RESIZE_BORDER_SIZE.TOP,
WINDOW.RESIZE_BORDER_SIZE.RIGHT,
WINDOW.RESIZE_BORDER_SIZE.BOTTOM
)
window:SetMinResizingExtent(WINDOW.MIN_WIDTH, WINDOW.MIN_HEIGHT)
window:SetMaxResizingExtent(WINDOW.MAX_WIDTH, WINDOW.MAX_HEIGHT)
window:UseResizing(true)
window:SetHandler("OnScale", function (self)
end)
CorrectWidgetScreenPos(window)
titleBar:SetHandler("OnDragStart", function ()
window:StartMoving()
end)
titleBar:SetHandler("OnDragStop", function ()
window:StopMovingOrSizing()
CorrectWidgetScreenPos(window)
end)
closeButton:SetHandler("OnClick", function ()
window:Show(false)
end)
window:SetHandler("OnUpdate", function ()
bodyTextbox:SetAutoResize(true)
end)
checkButton:SetHandler("OnClick", function ()
exampleAddonWindow.modalEnabled = not exampleAddonWindow.modalEnabled
exampleAddonWindow:SetWindowModal(exampleAddonWindow.modalEnabled)
end)
resetUIButton:SetHandler("OnClick", function ()
window:SetDefaultUIBound()
SaveUIBound(window, WINDOW.UIBOUND_NAME)
ADDON:ChatLog(locale.addon.resetUIText)
end)
saveUIButton:SetHandler("OnClick", function ()
CorrectWidgetScreenPos(exampleAddonWindow)
SaveUIBound(window, WINDOW.UIBOUND_NAME)
ADDON:ChatLog(locale.addon.saveUIText)
end)
settingsButton:SetHandler("OnClick", function ()
ADDON:FireAddon(ADDON:GetName())
end)
return window
end
---Toggles the example addon window.
---@param show boolean|nil
local function ToggleExampleAddonWindow(show)
-- If the window should be shown.
if show == nil then
show = exampleAddonWindow == nil or not exampleAddonWindow:IsVisible()
end
-- If the window should be shown and doesn't exist, create it.
if show == true and exampleAddonWindow == nil then
exampleAddonWindow = CreateExampleAddonWindow()
exampleAddonWindow:SetDeletedHandler(function ()
exampleAddonWindow = nil
end)
end
-- If the window exists, Show or Hide it.
if exampleAddonWindow then
exampleAddonWindow:Show(show)
end
end
ADDON:RegisterContentTriggerFunc(UIC_EXAMPLEADDON, ToggleExampleAddonWindow)
ADDON:AddEscMenuButton(5, UIC_EXAMPLEADDON, "optimizer", locale.addon.name)
-- ToggleExampleAddonWindow()