forked from phuein/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewAddon.lua
More file actions
200 lines (178 loc) · 7.03 KB
/
Copy pathNewAddon.lua
File metadata and controls
200 lines (178 loc) · 7.03 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
NewAddon = {
name = "NewAddon", -- Matches folder and Manifest file names.
version = "1.0",
author = "Developer",
color = "DDFFEE", -- Used in menu titles and so on.
menuName = "NewAddon Options", -- Unique identifier for menu object.
-- Default settings.
savedVariables = {},
}
local LAM = LibStub("LibAddonMenu-2.0")
-- Wraps text with a color.
local function Colorize(text, color)
-- Default to addon's .color.
if not color then color = NewAddon.color end
text = "|c" .. color .. text .. "|c"
end
-- Settings menu.
local panelData = {
type = "panel",
name = NewAddon.menuName,
displayName = Colorize(NewAddon.menuName),
author = Colorize(NewAddon.author, "AAF0BB"),
version = Colorize(NewAddon.version, "AA00FF"),
slashCommand = "/newaddon",
registerForRefresh = true,
registerForDefaults = true,
}
local optionsTable = {
[1] = {
type = "header",
name = "My Header",
width = "full", --or "half" (optional)
},
[2] = {
type = "description",
--title = "My Title", --(optional)
title = nil, --(optional)
text = "My description text to display.",
width = "full", --or "half" (optional)
},
[3] = {
type = "dropdown",
name = "My Dropdown",
tooltip = "Dropdown's tooltip text.",
choices = {"table", "of", "choices"},
getFunc = function() return "of" end,
setFunc = function(var) print(var) end,
width = "half", --or "half" (optional)
warning = "Will need to reload the UI.", --(optional)
},
[4] = {
type = "dropdown",
name = "My Dropdown",
tooltip = "Dropdown's tooltip text.",
choices = {"table", "of", "choices"},
getFunc = function() return "of" end,
setFunc = function(var) print(var) end,
width = "half", --or "half" (optional)
warning = "Will need to reload the UI.", --(optional)
},
[5] = {
type = "slider",
name = "My Slider",
tooltip = "Slider's tooltip text.",
min = 0,
max = 20,
step = 1, --(optional)
getFunc = function() return 3 end,
setFunc = function(value) d(value) end,
width = "half", --or "half" (optional)
default = 5, --(optional)
},
[6] = {
type = "button",
name = "My Button",
tooltip = "Button's tooltip text.",
func = function() d("button pressed!") end,
width = "half", --or "half" (optional)
warning = "Will need to reload the UI.", --(optional)
},
[7] = {
type = "submenu",
name = "Submenu Title",
tooltip = "My submenu tooltip", --(optional)
controls = {
[1] = {
type = "checkbox",
name = "My Checkbox",
tooltip = "Checkbox's tooltip text.",
getFunc = function() return true end,
setFunc = function(value) d(value) end,
width = "half", --or "half" (optional)
warning = "Will need to reload the UI.", --(optional)
},
[2] = {
type = "colorpicker",
name = "My Color Picker",
tooltip = "Color Picker's tooltip text.",
getFunc = function() return 1, 0, 0, 1 end, --(alpha is optional)
setFunc = function(r,g,b,a) print(r, g, b, a) end, --(alpha is optional)
width = "half", --or "half" (optional)
warning = "warning text",
},
[3] = {
type = "editbox",
name = "My Editbox",
tooltip = "Editbox's tooltip text.",
getFunc = function() return "this is some text" end,
setFunc = function(text) print(text) end,
isMultiline = false, --boolean
width = "half", --or "half" (optional)
warning = "Will need to reload the UI.", --(optional)
default = "", --(optional)
},
},
},
[8] = {
type = "custom",
reference = "MyAddonCustomControl", --unique name for your control to use as reference
refreshFunc = function(customControl) end, --(optional) function to call when panel/controls refresh
width = "half", --or "half" (optional)
},
[9] = {
type = "texture",
image = "EsoUI\\Art\\ActionBar\\abilityframe64_up.dds",
imageWidth = 64, --max of 250 for half width, 510 for full
imageHeight = 64, --max of 100
tooltip = "Image's tooltip text.", --(optional)
width = "half", --or "half" (optional)
},
}
NewAddon.AnimateText = function()
-- Avoid playing the animation over itself.
if not NewAddonActive:IsHidden() then return end
-- Has an event ID number, so it's from the RegisterForUpdate.
if e then
EVENT_MANAGER:UnregisterForUpdate(NewAddon.name)
end
local animation, timeline = CreateSimpleAnimation(ANIMATION_ALPHA, NewAddonActive)
NewAddonActive:SetHidden(false)
animation:SetAlphaValues(NewAddonActive:GetAlpha(), 1)
animation:SetDuration(3000)
-- Fade-out after fade-in.
timeline:SetHandler('OnStop', function()
local animation, timeline = CreateSimpleAnimation(ANIMATION_ALPHA, NewAddonActive)
animation:SetAlphaValues(NewAddonActive:GetAlpha(), 0)
animation:SetDuration(3000)
timeline:SetHandler('OnStop', function()
NewAddonActive:SetHidden(true)
end)
timeline:PlayFromStart()
end)
timeline:PlayFromStart()
end
NewAddon.Activated = function(e)
EVENT_MANAGER:UnregisterForEvent(NewAddon.name, EVENT_PLAYER_ACTIVATED)
d(NewAddon.name .. GetString(SI_NEW_ADDON_MESSAGE)) -- Prints to chat.
ZO_AlertNoSuppression(UI_ALERT_CATEGORY_ALERT, nil,
NewAddon.name .. GetString(SI_NEW_ADDON_MESSAGE)) -- Top-right alert.
-- Animate the xml UI center text, after a delay.
EVENT_MANAGER:RegisterForUpdate(NewAddon.name, 3000, NewAddon.AnimateText)
end
-- When player is ready, after everything has been loaded.
EVENT_MANAGER:RegisterForEvent(NewAddon.name, EVENT_PLAYER_ACTIVATED, NewAddon.Activated)
NewAddon.OnAddOnLoaded = function(event, addonName)
if addonName ~= NewAddon.name then return end
EVENT_MANAGER:UnregisterForEvent(NewAddon.name, EVENT_ADD_ON_LOADED)
-- Register addon panel after loading.
LAM:RegisterAddonPanel(NewAddon.menuName, panelData)
LAM:RegisterOptionControls(NewAddon.menuName, optionsTable)
NewAddon.savedVariables = ZO_SavedVars:New("NewAddonSavedVariables", 1, nil, NewAddon.savedVariables)
-- Slash commands must be lowercase. Set to nil to disable.
SLASH_COMMANDS["/newaddon"] = NewAddon.AnimateText
-- Reset autocomplete cache to update it.
SLASH_COMMAND_AUTO_COMPLETE:InvalidateSlashCommandCache()
end
-- When any addon is loaded, but before UI (Chat) is loaded.
EVENT_MANAGER:RegisterForEvent(NewAddon.name, EVENT_ADD_ON_LOADED, NewAddon.OnAddOnLoaded)