-
Notifications
You must be signed in to change notification settings - Fork 7
/
ArenaLiveCore.lua
276 lines (225 loc) · 9.39 KB
/
ArenaLiveCore.lua
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
--[[ ArenaLive Core Functions
Created by: Vadrak
Creation Date: 13.05.2013
Last Update: 02.06.2013
This function set builds the base for the new core of ArenaLive. These functions will take control over any ArenaLive based handlers and addons.
The so called "handlers", which are defined in their respective files, control the way how certain frame types behave for any ArenaLive based
addon. I hope I can reduce the addon's needed performance this way, so that it always will be a fun experience playing with ArenaLive UnitFrames.
]]--
function print(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
-- *** GENERAL FUNCTIONS ***
local addonName = "ArenaLiveCore";
-- Local version is said to be faster.
local ArenaLiveCore = ArenaLiveCore;
ArenaLiveCore.debug = false;
function wipe(table)
for k,v in pairs(table) do
k = nil
end
end
table.wipe = wipe
-- Register Slash-Commands
local slashCommandFunctions = {};
SLASH_ARENALIVECORE1, SLASH_ARENALIVECORE2 = "/alive", "/arenalivecore";
function ArenaLiveCore:RegisterSlashCommand(modifier, description, execFunc)
if ( slashCommandFunctions[modifier] ) then
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_ADD_SLASHCMD_MODIFIER_ALREADY_IN_USE"), modifier), "error");
else
slashCommandFunctions[modifier] = {};
slashCommandFunctions[modifier]["function"] = execFunc;
slashCommandFunctions[modifier]["description"] = description;
end
end
function SlashCmdList.ARENALIVECORE(msg, editbox)
if ( not msg or msg == "" ) then
InterfaceOptionsFrame_Show();
InterfaceOptionsFrame_OpenToFrame(ArenaLiveOptions);
elseif ( msg == "info" ) then
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_SLASHCMD_MODIFIER_LIST")));
for modifier, cmdTable in pairs(slashCommandFunctions) do
if ( cmdTable["description"] ) then
print(tostring(modifier)..": "..tostring(cmdTable["description"]));
end
end
else
if ( slashCommandFunctions[msg] and slashCommandFunctions[msg]["function"] ) then
slashCommandFunctions[msg]["function"]();
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_SLASHCMD_MODIFIER_DOESNT_EXIST"), msg), "error");
end
end
end
--[[ Function: Message
Handles all kinds of messages.
Arguments:
msg: The message to post to the DEFAULT_CHAT_FRAME
messageType: Can either be "error" for an error message, "debug" for debug message.
For every other value or nil it will print a general message to the DEFAULT_CHAT_FRAME.
]]--
function ArenaLiveCore:Message(msg, messageType)
if ( messageType == "error" ) then
print("|cFFFF0000ArenaLive Error:|r "..tostring(msg));
elseif ( messageType == "debug" ) then
if ( ArenaLiveCore.debug ) then
print("|cFFFF0000ArenaLive Debug:|r "..tostring(msg));
end
else
print("|cFFFF0000ArenaLive:|r "..tostring(msg));
end
end
-- Some language clients need other Fonts to show every information correctly (e.g. Russian and Korean).
-- UPDATE: This function is no longer needed as I found out that you can define alternative fonts for different languages.
--[[function ArenaLiveCore:ChangeFonts()
local fontStyle = ArenaLiveCore:GetLocalisation(addonName, "FONTSTYLE");
if ( fontStyle ~= "Fonts\\FRIZQT__.TTF" ) then
ArenaLiveFont_Name:SetFont(fontStyle, 12, "OUTLINE");
ArenaLiveFont_NameSmall:SetFont(fontStyle, 10, "OUTLINE");
ArenaLiveFont_NameVerySmall:SetFont(fontStyle, 8, "OUTLINE");
ArenaLiveFont_Level:SetFont(fontStyle, 10, "OUTLINE");
ArenaLiveFont_StatusBarTextVeryLarge:SetFont(fontStyle, 14, "OUTLINE");
ArenaLiveFont_StatusBarTextLarge:SetFont(fontStyle, 12, "OUTLINE");
ArenaLiveFont_StatusBarText:SetFont(fontStyle, 10, "OUTLINE");
ArenaLiveFont_StatusBarTextSmall:SetFont(fontStyle, 8, "OUTLINE");
ArenaLiveFont_StatusBarTextVerySmall:SetFont(fontStyle, 6, "OUTLINE");
ArenaLiveFont_CooldownText:SetFont(fontStyle, 24, "OUTLINE");
end
end]]--
-- *** COREHANDLER FUNCTIONS ***
--[[ Cores directly influence the behaviour of ArenaLiveCore and are able to set up handlers with additional functions to interact with those cores.
Most of my standard cores attach all their functions directly to the ArenaLiveCore frame and don't add themselves to this core list. But if
a core needs to attach some basic functions to handlers that register for it (e.g. EventCore), it is needed to register it via the functions below
and create a function named "CoreName.SetupHandler" which sets up the handlers.
]]--
-- I set up an extra table for our core references, because then they can't interfere with the base functions.
ArenaLiveCore.cores = {};
--[[ Function: AddCore
Adds a new core to ArenaLiveCore.
Arguments:
name: The name the core should take
Returns:
The table that will "contain" the core.
]]--
function ArenaLiveCore:AddCore(name)
-- Create the new core handler or display an error message, if a core handler with that name already exists.
if ( not ArenaLiveCore.cores[name] ) then
ArenaLiveCore.cores[name] = {};
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_ADD_CORE_ALREADY_EXISTS"), name), "error");
end
return ArenaLiveCore.cores[name];
end
--[[ Function: RemoveCore
Removes a set core functions form the addon's core.
Arguments:
name: Name of the core that should be removed/diabled
]]--
function ArenaLiveCore:RemoveCore(name)
-- Create the new core handler or display an error message, if a core handler with that name already exists.
if ( ArenaLiveCore.cores[name] ) then
ArenaLiveCore.cores[name] = nil;
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_DELETE_CORE_DOESNT_EXISTS"), name), "error");
end
end
--[[ Function: GetCore
Returns the table for the specified core, if it exists.
Arguments:
name: Name of the core that should
Returns:
the table that contains the specified core.
]]--
function ArenaLiveCore:GetCore(name)
-- Return core handler or display an error message, if a core handler with that name doesn't exist.
if ( ArenaLiveCore.cores[name] ) then
return ArenaLiveCore.cores[name];
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_GET_CORE_DOESNT_EXISTS"), name), "error");
end
end
-- *** HANDLER FUNCTIONS ***
-- I set up an extra table for our handler references, because then they can't interfere with the base functions.
ArenaLiveCore.handlers = {};
--[[ Function: AddHandler
Adds a new handler to ArenaLiveCore.
Arguments:
name: The name the handler should take
...: A list of cores the assigned handler wants to register for.
This will be mostly the case for the event and localisation handlers.
Returns:
The table that will "contain" the handler.
]]--
function ArenaLiveCore:AddHandler(name, ...)
local coreString;
local numCores = select('#', ...) or 0;
-- Create the new handler or display an error message, if a handler with that name already exists.
if ( not self.handlers[name] ) then
self.handlers[name] = {};
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_ADD_HANDLER_ALREADY_EXISTS"), name), "error");
end
if ( numCores > 0 ) then
for i = 1, numCores do
coreString = select(i, ...);
if ( ArenaLiveCore.cores[coreString] ) then
if ( ArenaLiveCore.cores[coreString].SetupHandler ) then
ArenaLiveCore.cores[coreString]:SetupHandler(self.handlers[name]);
end
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_REGISTER_HANDLER_FOR_CORE_DOESNT_EXISTS"), name, coreString, coreString), "error");
end
end
end
return self.handlers[name];
end
--[[ Function: RemoveHandler
Removes a Handler form the core.
Arguments:
name: Name of the handler that should be removed/diabled
]]--
function ArenaLiveCore:RemoveHandler(name)
if ( self.handlers[name] ) then
self.handlers[name] = nil;
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_DELETE_HANDLER_DOESNT_EXISTS"), name), "error");
end
end
--[[ Function: RemoveAllHandlers
This function removes all handlers from the core.
]]--
function ArenaLiveCore:RemoveAllHandlers()
table.wipe(ArenaLiveCore.handlers);
end
--[[ Function: GetHandler
This function removes all handlers from the core.
Arguments:
handlerName: String - Name of the handler that should be returned.
Returns:
handler: The required handler.
]]--
function ArenaLiveCore:GetHandler(handlerName)
local handler;
if ( ArenaLiveCore.handlers[handlerName] ) then
return ArenaLiveCore.handlers[handlerName];
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_GET_HANDLER_DOESNT_EXISTS"), handlerName), "error");
end
end
-- *** FRAME FUNCTIONS ***
--[[ Function: AddFrame
Sets up a frame to contain all ArenaLiveCore specific functions. I.e. it attaches some base functions to it, that can be used
to register it for handlers etc.
Arguments:
frame: The frame that needs to be registered.
handlerName: The name of an already registered handler.
...: A list of arguments that the handler needs to register the frame.
]]--
function ArenaLiveCore:AddFrame(frame, handlerName, ...)
local frameName = tostring(frame:GetName());
if ( self.handlers[handlerName] ) then
self.handlers[handlerName]:AddFrame(frame, ...);
else
ArenaLiveCore:Message(string.format(ArenaLiveCore:GetLocalisation(addonName, "ERR_ADD_FRAME_HANDLER_DOESNT_EXISTS"), frameName, handlerName), "error");
end
end