-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultiTalented.lua
335 lines (284 loc) · 9.75 KB
/
MultiTalented.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
--Libraries--
local AceGUI = LibStub("AceGUI-3.0")
--AddOn "Globals"--
local settings
local saved_talents
local DebugMode = false
local version = '0.6.5'
--Function Definitions--
--Wait from http://wowwiki.wikia.com/wiki/USERAPI_wait --
local waitTable = {};
local waitFrame = nil;
local function MultiTalented__wait(delay, func, ...)
if(type(delay)~="number" or type(func)~="function") then
return false;
end
if(waitFrame == nil) then
waitFrame = CreateFrame("Frame","WaitFrame", UIParent);
waitFrame:SetScript("onUpdate",function (self,elapse)
local count = #waitTable;
local i = 1;
while(i<=count) do
local waitRecord = tremove(waitTable,i);
local d = tremove(waitRecord,1);
local f = tremove(waitRecord,1);
local p = tremove(waitRecord,1);
if(d>elapse) then
tinsert(waitTable,i,{d-elapse,f,p});
i = i + 1;
else
count = count - 1;
f(unpack(p));
end
end
end);
end
tinsert(waitTable,{delay,func,{...}});
return true;
end
local function my_print(str)
print("[MultiTalented]: ".. tostring(str))
end
local function CHECK_CURRENT()
current_talents = {}
current_talents["spec"] = GetSpecialization(false, false, 1)
for i = 1, GetMaxTalentTier() do
for j = 1, 3 do
id, name, texture, selected, available, _, _, _, _ = GetTalentInfo(i, j, 1, nil)
if(selected and available) then
current_talents[i] = id
end
end
end
return current_talents
end
local function SAVE_CURRENT(profile_name, profile_type)
if msg == "" then
my_print("Error! you must include a name for this profile!")
else
current_talents = CHECK_CURRENT()
--[[
current_talents["spec"] = GetSpecialization(false, false, 1)
for i = 1, GetMaxTalentTier() do
for j = 1, 3 do
id, name, texture, selected, available, _, _, _, _ = GetTalentInfo(i, j, 1, nil)
if(selected and available) then
current_talents[i] = id
end
end
end
]]--
saved_talents[profile_type][profile_name] = current_talents
my_print("Talents saved as: ".. profile_name)
end
end
local function SET_CURRENT(profile_name, profile_type)
if msg == "" then
my_print("Error! You must include a name for this profile!")
else
if saved_talents[profile_type][profile_name] == nil then
my_print("This profile does not exist")
else
if(GetSpecialization(false, false, 1) ~= saved_talents[profile_type][profile_name]["spec"]) then
SetSpecialization(saved_talents[profile_type][profile_name]["spec"])
MultiTalented__wait(6, SET_CURRENT, profile_name, profile_type)
return
end
for i = 1, GetMaxTalentTier() do
if(saved_talents[profile_type][profile_name][i] ~= nil) then
LearnTalent(saved_talents[profile_type][profile_name][i])
end
end
my_print("Talents set!")
end
end
end
local function REMOVE_PROFILE(profile_name,profile_type)
if msg == "" then
my_print("Error! You must include a name for this profile!")
else
if saved_talents[profile_type][profile_name] == nil then
my_print("Error! This profile doesn't exist!")
else
saved_talents[profile_type][profile_name] = nil
my_print("Profile " .. profile_name .. " has been deleted!")
end
end
end
local function LIST_PROFILES()
my_print("--------Talent Profiles--------")
local keys = {}
for k,_ in pairs(saved_talents) do
if k ~= "exists" then table.insert(keys, k) end
end
table.sort(keys)
for _,v in pairs(keys) do
my_print(v)
end
end
local function DEBUGMODE()
my_print(DebugMode and "Turning Debug Mode off" or "Turning Debug Mode on")
DebugMode = not DebugMode
end
local function MAKE_LIST(scroll, profile_type)
scroll:ReleaseChildren()
local keys = {}
for k,_ in pairs(saved_talents[profile_type]) do
if k ~= "exists" then table.insert(keys, k) end
end
table.sort(keys)
for _,v in pairs(keys) do
local profile_bar = AceGUI:Create("SimpleGroup")
profile_bar:SetLayout("Flow")
profile_bar:SetFullWidth(true)
local icon = AceGUI:Create("Icon")
local profile = AceGUI:Create("Label")
local choose = AceGUI:Create("Button")
local remove = AceGUI:Create("Button")
local save = AceGUI:Create("Button")
save:SetCallback("OnClick", function(widget, call) SAVE_CURRENT(v,profile_type); MAKE_LIST(scroll,profile_type); end)
save:SetText("Overwrite Profile")
profile:SetText(v)
choose:SetText("Select Profile")
choose:SetCallback("OnClick", function(widget, call) SET_CURRENT(v,profile_type); MAKE_LIST(scroll,profile_type) end)
remove:SetText("Remove Profile")
remove:SetCallback("OnClick", function(widget, call) REMOVE_PROFILE(v, profile_type); MAKE_LIST(scroll,profile_type) end)
profile_bar:AddChild(icon)
profile_bar:AddChild(profile)
profile_bar:AddChild(choose)
profile_bar:AddChild(remove)
profile_bar:AddChild(save)
scroll:AddChild(profile_bar)
end
end
local function MAKEWIN(frame, profile_type)
local scroll_pane = AceGUI:Create("InlineGroup")
scroll_pane:SetFullWidth(true)
scroll_pane:SetFullHeight(true)
scroll_pane:SetLayout("Fill")
frame:AddChild(scroll_pane)
local scroll = AceGUI:Create("ScrollFrame")
scroll:SetLayout("List")
--scroll:SetFullHeight(true)
scroll_pane:AddChild(scroll)
local save = AceGUI:Create("Button")
save:SetText("Save Profile")
local new_name = AceGUI:Create("EditBox")
new_name:SetLabel("Profile Name")
local save_bar = AceGUI:Create("SimpleGroup")
save_bar:SetFullWidth(true)
save_bar:SetLayout("Flow")
save:SetCallback("OnClick", function(widget, call) SAVE_CURRENT(new_name:GetText(), profile_type); MAKE_LIST(scroll, profile_type); new_name:SetText("") end)
save_bar:AddChild(new_name)
save_bar:AddChild(save)
frame:AddChild(save_bar, scroll_pane)
MAKE_LIST(scroll, profile_type)
end
local function SelectGroup(container, event, group)
container:ReleaseChildren()
if group == "personal_tab" then
MAKEWIN(container, "personal")
elseif group == "class_tab" then
MAKEWIN(container, "class")
end
end
local function MAKEFRAME(msg, editbox)
if DebugMode then
my_print("Making window")
end
--message((msg == "") and "Hello World" or msg)
local frame = AceGUI:Create("Frame")
frame:SetTitle("MultiTalented")
frame:SetWidth(GetScreenWidth() * .55)
--frame:SetStatusText((msg == "") and "Hello World" or msg)
frame:SetLayout("Fill")
local tabs = AceGUI:Create("TabGroup")
tabs:SetLayout("Flow")
tabs:SetFullWidth(true)
tabs:SetFullHeight(true)
tabs:SetTabs({{text="Personal Profiles", value="personal_tab"}, {text="Class Profiles", value="class_tab"}, --[[{text="Talents",value="talent_tab"}]]})
tabs:SetCallback("OnGroupSelected", SelectGroup)
tabs:SelectTab("personal_tab")
frame:AddChild(tabs)
end
--Load Settings--
local function GEN_SETTINGS()
local frame = CreateFrame("FRAME")
if(frame ~= nil) and DebugMode then
my_print("frame made")
end
frame:RegisterEvent("ADDON_LOADED");
frame:RegisterEvent("PLAYER_LOGOUT");
local function OnEvent(self, event, arg1)
_,class, _ = UnitClass("player")
if event == "ADDON_LOADED" and arg1 == "MultiTalented" then
if DebugMode then my_print("Addon Loaded") end
if MultiTalented_Settings == nil then
if DebugMode then my_print("Making Settings...") end
MultiTalented_Settings = {exists = 1, prev_version = version}
end
if SavedTalents == nil then
if DebugMode then my_print("Making Talent storage...") end
SavedTalents = {exists = 1}
end
if MultiTalented_Settings["exists"] == 1 then
if DebugMode then my_print("Found settings!") end
settings = MultiTalented_Settings
end
if SavedTalents["exists"] == 1 then
if DebugMode then my_print("Found talents!") end
saved_talents = SavedTalents
saved_talents["class"] = MultiTalented_Class_Profiles[class]
if not saved_talents["class"] then saved_talents["class"] = {} end
if settings["prev_version"] ~= version or saved_talents["personal"] == nil then
settings["prev_version"] = version
tmp = {}
for k,v in pairs(saved_talents) do
my_print(k)
if not (k == "personal") and not (k == "exists") and not(k == "class")then
tmp[k] = {}
for k2, v2 in pairs(v) do
--table.insert(SavedTalents["personal"][k], k2, v2)
tmp[k][k2] = v2
end
saved_talents[k] = nil
end
end
saved_talents["personal"] = tmp
saved_talents["class"] = MultiTalented_Class_Profiles[class] or {}
end
end
elseif event == "PLAYER_LOGOUT" then
if DebugMode then my_print("Saving settings") end
MultiTalented_Settings = settings
if DebugMode then my_print("Saving talents") end
SavedTalents = saved_talents
if(not MultiTalented_Class_Profiles[class]) then MultiTalented_Class_Profiles[class] = {} end
for k,v in pairs(saved_talents["class"]) do
MultiTalented_Class_Profiles[class][k] = v
end
end
end
frame:SetScript("OnEvent", OnEvent)
end
--Slash commands--
local function GEN_COMMANDS()
SLASH_MTWIN1 = '/mtalent'
SlashCmdList["MTWIN"] = MAKEFRAME
SLASH_MTDEBUGMODE1 = '/mt_debug'
SlashCmdList["MTMODE"] = DEBUGMODE
SLASH_MTSAVETALENTS1 = '/mt_save'
SlashCmdList["MTSAVETALENTS"] = SAVE_CURRENT
SLASH_MTSETTALENTS1 = '/mt_set'
SlashCmdList["MTSETTALENTS"] = SET_CURRENT
SLASH_MTREMOVEPROFILE1 = '/mt_remove'
SlashCmdList["MTREMOVEPROFILE"] = REMOVE_PROFILE
SLASH_MTLISTPROFILES1 = '/mt_list'
SlashCmdList["MTLISTPROFILES"] = LIST_PROFILES
SLASH_MTVERSION1 = '/mt_version'
SlashCmdList["MTVERSION"] = function() my_print(("Current Version: " .. version)) end
end
--Function Calls--
GEN_SETTINGS()
GEN_COMMANDS()
--Manual testing Area--