-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathFarmIt2.lua
359 lines (313 loc) · 10 KB
/
FarmIt2.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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
------------------------
-- EVENT REGISTRATION --
------------------------
function FI_OnLoad(self)
self:RegisterEvent("ADDON_LOADED");
self:RegisterEvent("BAG_UPDATE");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("CHAT_MSG_MONEY");
self:RegisterEvent("CHAT_MSG_CURRENCY");
self:RegisterEvent("CHAT_MSG_COMBAT_HONOR_GAIN");
self:RegisterEvent("CURRENCY_DISPLAY_UPDATE");
SlashCmdList["farmit"] = FI_Command;
SLASH_farmit1 = "/farmit";
StaticPopupDialogs["RELOAD"] = {
text = "This action will reload your game interface. Are you sure?",
button1 = "RELOAD",
button2 = "Cancel",
OnAccept = function()
ReloadUI();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["STYLE"] = {
text = "Changing FarmIt's graphical theme requires reloading your game interface. Are you sure?",
button1 = "OK",
button2 = "Cancel",
OnAccept = function()
-- replace function before popup call!
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
StaticPopupDialogs["RESET"] = {
text = "This will reset FarmIt to default settings, and reload your game interface. Are you sure?",
button1 = "RESET",
button2 = "Cancel",
OnAccept = function()
FI_Reset();
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
showAlert = true,
}
StaticPopupDialogs["DELETE"] = {
text = "NOTE: Removing a bar destroys it completely and requires an interface reload. "..
"If you don't want to do that right now, try hiding the bar with the command: /farmit show %s",
button1 = "DELETE",
button2 = "Cancel",
OnAccept = function()
-- replace function before popup call!
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
}
end
--------------------------------------------------------------------------------
-- EVENT HANDLER
--------------------------------------------------------------------------------
function FI_OnEvent(self, event, ...)
local arg = ...;
-- debug
local filter = "BAG_UPDATE";
if FI_SV_CONFIG and FI_SV_CONFIG.debug and (event ~= filter) and arg then
if (type(arg) == "table") then
print("OnEvent() fired: "..event); --debug
else
print("OnEvent() fired: "..event.." "..arg); --debug
end
end
-- event dispatch
if (event == "ADDON_LOADED") and (arg == "FarmIt2") then
FI_ADDON_LOADED = true;
self:UnregisterEvent("ADDON_LOADED");
FI_LOADING = true;
FI_Init();
FI_Render();
FI_Load();
FI_LOADING = false;
elseif (FI_ADDON_LOADED == true) then
if (event == "BAG_UPDATE") and (FI_ADDON_LOADED == true) then
FI_Update(arg);
elseif (event == "CURRENCY_DISPLAY_UPDATE") or (event == "CHAT_MSG_CURRENCY") or (event == "CHAT_MSG_COMBAT_HONOR_GAIN") then
FI_Update_Currency(event);
elseif (event == "CHAT_MSG_MONEY") then
FI_Update_Money(event, arg);
elseif (event == "PLAYER_REGEN_ENABLED") then
-- fix for item-button secure header interfering with quicksize while in combat
FI_UI();
end
end
end
--------------------------------------------------------------------------------
-- COMMAND DISPATCHER
--------------------------------------------------------------------------------
function FI_Command( input, editbox )
--------------------------------------------------
-- PARSE INPUT
--------------------------------------------------
local cmd, arg, val, val2, val3 = strsplit(' ', input);
--------------------------------------------------
-- COMMANDS
--------------------------------------------------
cmd = strlower(cmd);
if (cmd == "help") then
Settings.OpenToCategory(FI_CONFIG.Pages[4]);
Settings.OpenToCategory(FI_CONFIG.Pages[4]);
elseif (cmd == "options") or (cmd == "config") then
Settings.OpenToCategory(FI_CONFIG.Pages[5]);
Settings.OpenToCategory(FI_CONFIG.Pages[5]);
elseif (cmd == "reset") then
StaticPopup_Show("RESET");
elseif (cmd == "rebuild") then --for ninjas pwnly!!!
if arg then
FI_DB.rebuild( strlower(arg) );
else
FI_DB.rebuild("all");
end
ReloadUI();
elseif (cmd == "debug") then
FI_SV_CONFIG.debug = LIB.toggle(FI_SV_CONFIG.debug);
FI_Message("Debugging output: "..strupper(tostring(FI_SV_CONFIG.debug)));
elseif (cmd == "show") or (cmd == "toggle") then
if arg then
local bar = tonumber(arg);
if FI_SVPC_DATA.Groups[bar] then
FI_Show( FI_SVPC_DATA.Groups[bar]["id"] );
else
FI_Message("Invalid bar number.");
end
else
FI_Show();
end
elseif (cmd == "lock") then
if arg then
local bar = tonumber(arg);
if FI_SVPC_DATA.Groups[bar] then
FI_Lock(bar);
else
FI_Message("Invalid bar number.");
end
else
FI_GlobalLock(false);
end
elseif (cmd == "unlock") then
if arg then
local bar = tonumber(arg);
if FI_SVPC_DATA.Groups[bar] then
FI_Unlock(bar);
else
FI_Message("Invalid bar number.");
end
else
FI_GlobalLock(true);
end
elseif (cmd == "tooltip") then
local opt_msg = "Valid options are: bar, button, currency \nFor example: /farmit tooltip bar";
if arg then
local tip = string.lower(tostring(arg));
if (FI_SV_CONFIG.Tooltips[tip] == nil) then
FI_Message("Unrecognised tooltip type. "..opt_msg);
else
FI_SV_CONFIG.Tooltips[tip] = LIB.toggle(FI_SV_CONFIG.Tooltips[tip]);
FI_Message( tip.." tooltips are now "..LIB.BoolToString(FI_SV_CONFIG.Tooltips[tip],3) );
end
else
FI_Message(opt_msg);
end
elseif (cmd == "scale") then
if arg then
local scale = tonumber(arg);
if val then
--prevent misplaced values from causing trouble
local bar = LIB.round(tonumber(val));
if (bar >= 1) and (bar <= #FI_SVPC_DATA.Groups) then
FI_Scale(scale, FI_SVPC_DATA.Groups[bar]["id"]);
else
FI_Message("Bar number '"..val.."' not found.");
end
else
FI_Scale(scale);
end
end
elseif (cmd == "alpha") then
if arg then
if val then
local bar = tonumber(val);
FI_Alpha( tonumber(arg), FI_SVPC_DATA.Groups[bar]["id"] );
else
FI_Alpha( tonumber(arg) );
end
end
elseif (cmd == "alerts") then
if arg then
FI_Toggle_Alert( strlower(arg) );
else
FI_Alert_Info();
end
elseif (cmd == "currency") then
if arg then
FI_Toggle_Currency( strlower(arg), val );
else
FI_Toggle_Currency();
end
elseif (cmd == "group") then
if arg then
local action = strlower(arg);
if (action == "add") then
FI_Group(action);
elseif (action == "remove") then
local bar;
if val then
-- remove specified bar
bar = tonumber(val);
else
-- automatically remove the last bar that was added
bar = #FI_SVPC_DATA.Groups;
end
-- set popup callback
StaticPopupDialogs["DELETE"].OnAccept = function() FI_Group("remove", FI_SVPC_DATA.Groups[bar]["id"] ); end
-- show dialog
StaticPopup_Show("DELETE", bar);
elseif (action == "list") then
FI_Group(action);
end
end
elseif (cmd == "size") then
if arg then
local bar = tonumber(arg);
if val then
FI_Group("size", FI_SVPC_DATA.Groups[bar]["id"], tonumber(val) );
else
FI_Message("Please specify the number of buttons you want the bar to have.");
end
end
elseif (cmd == "grow") then
if arg then
if val then
local gid = FI_SVPC_DATA.Groups[tonumber(arg)]["id"];
FI_Group("grow", gid, tostring(val));
else
FI_Message("Please choose a direction for the bar to grow: U,D,L,R");
end
end
elseif (cmd == "style") then
if arg then
-- set popup callback
StaticPopupDialogs["STYLE"].OnAccept = function() FI_Style( strlower(arg) ); end
StaticPopup_Show("STYLE");
end
elseif (cmd == "tpl") then
if arg then
FI_Template( strlower(arg), val, val2, val3 );
end
elseif (cmd == "session") then
if arg then
local act = strlower(arg);
local session;
if (act == "start") then
session = FI_SESSION.start();
FI_Message("Farming session started: SID "..session.id..", "..date("%c", session.start) );
elseif (act == "stop") then
session = FI_SESSION.stop();
FI_Message("Farming session stopped: SID "..session.id..", "..date("%c", session.stop) );
elseif (act == "reset") then
FI_SESSION.reset();
FI_Message("Session data cleared.");
else
FI_Message("Valid options for '/farmit session' are: start, stop, reset");
end
else
-- display a "current session info" message
FI_SESSION.info();
end
-- undocumented command (for testing automation) added in v2.17
elseif (cmd == "button") then
if arg then
local bid = tonumber(arg);
if val then
local setting = strlower(val);
if (setting == "bank") then
FI_Toggle_Bank(bid);
elseif (setting == "objective") then
if val2 then
local input = tonumber(val2);
FI_Set_Objective("Buttons", bid, input);
else
FI_Message("Please include a number to set the objective to.");
end
end
else
FI_Message("Please specify a button setting to change. Valid options are: bank, objective");
end
else
FI_Message("Please specify a Button ID. Mouse over any occupied button to see its ID.");
end
else
-- no valid options given, show help prompt
FI_Message("Basic commands:\n"..
"show\n"..
" Toggle display of all FarmIt bars at once.\n"..
" Controls individual bars if followed by a bar number.\n"..
"help\n"..
" Opens the help page.\n"..
"options\n"..
" Shows a full list of configuration commands."
);
end
end