This repository was archived by the owner on Jan 24, 2020. It is now read-only.
forked from laytya/AdvancedTradeSkillWindow-vanilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathatsw_customsorting.lua
More file actions
executable file
·369 lines (350 loc) · 17 KB
/
atsw_customsorting.lua
File metadata and controls
executable file
·369 lines (350 loc) · 17 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
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
360
361
362
363
364
365
366
367
368
369
-- custom sorting options script file
atsw_customsorting={};
atsw_customheaders={};
atsw_uncategorized={};
atsw_opencategory=0;
function ATSWCS_OnLoad(self)
if(atsw_customsorting[UnitName("player")]==nil) then
atsw_customsorting[UnitName("player")]={};
end
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]==nil) then
atsw_customsorting[UnitName("player")][atsw_selectedskill]={};
end
if(atsw_customheaders[UnitName("player")]==nil) then
atsw_customheaders[UnitName("player")]={};
end
if(atsw_customheaders[UnitName("player")][atsw_selectedskill]==nil) then
atsw_customheaders[UnitName("player")][atsw_selectedskill]={};
end
FauxScrollFrame_SetOffset(ATSWCSUListScrollFrame, 0);
FauxScrollFrame_SetOffset(ATSWCSSListScrollFrame, 0);
ATSWCS_UpdateUncategorizedList();
ATSWCS_UpdateSkillList();
end
function ATSWCS_OnHide(self)
end
function ATSWCSFrame_OnEvent(self)
end
function ATSWCS_HideWindow()
HideUIPanel(ATSWCSFrame);
end
function ATSWCS_Update()
ATSWCS_UpdateSkillList();
end
function ATSWCS_UpdateSkillList()
if(atsw_customsorting[UnitName("player")]==nil) then
atsw_customsorting[UnitName("player")]={};
end
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]==nil) then
atsw_customsorting[UnitName("player")][atsw_selectedskill]={};
end
if(atsw_customheaders[UnitName("player")]==nil) then
atsw_customheaders[UnitName("player")]={};
end
if(atsw_customheaders[UnitName("player")][atsw_selectedskill]==nil) then
atsw_customheaders[UnitName("player")][atsw_selectedskill]={};
end
local totalcount=table.getn(atsw_uncategorized);
local offset=FauxScrollFrame_GetOffset(ATSWCSUListScrollFrame);
for i=1,23,1 do
local skillbutton=getglobal("ATSWCSSkill"..i);
if(atsw_uncategorized[offset+i]) then
skillbutton:SetText(atsw_uncategorized[offset+i].name);
skillbutton:Show();
skillbutton.skillname=atsw_uncategorized[offset+i].name;
local color=ATSWTypeColor[atsw_uncategorized[offset+i].type];
if(color) then
ATSW_SetTextColor(skillbutton, color.r, color.g, color.b, 1, "GameFontNormalSmall");
end
else
skillbutton:Hide();
end
end
offset=FauxScrollFrame_GetOffset(ATSWCSSListScrollFrame);
local header=1;
local skill=0;
local i=1-offset;
repeat
local skillbutton=nil;
local skillframe=nil;
if(i>=1 and i<=17) then
skillbutton=getglobal("ATSWCSCSkill"..i.."SkillButton");
skillframe=getglobal("ATSWCSCSkill"..i);
end
if(atsw_customheaders[UnitName("player")][atsw_selectedskill][header] and skill==0) then
if(i>=1 and i<=17) then
skillbutton:SetText(atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name);
ATSW_SetTextColor(skillbutton, ATSWTypeColor.header.r, ATSWTypeColor.header.g, ATSWTypeColor.header.b);
skillframe.skillname=atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name;
skillbutton:GetParent().btype="header";
end
if(header==atsw_opencategory) then
if(i>=1 and i<=17) then skillbutton:SetNormalTexture("Interface\\Buttons\\UI-MinusButton-Up"); end
skill=1;
else
if(i>=1 and i<=17) then skillbutton:SetNormalTexture("Interface\\Buttons\\UI-PlusButton-Up"); end
header=header+1;
end
if(i>=1 and i<=17) then
getglobal("ATSWCSCSkill"..i.."SkillButtonHighlight"):SetTexture("Interface\\Buttons\\UI-PlusButton-Hilight");
skillbutton:UnlockHighlight();
skillframe:Show();
skillbutton:Show();
getglobal("ATSWCSCSkill"..i.."MoveUp"):Show();
getglobal("ATSWCSCSkill"..i.."MoveDown"):Show();
getglobal("ATSWCSCSkill"..i.."Delete"):Show();
end
elseif(atsw_opencategory==header) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill] and atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name]) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name][skill]) then
if(i>=1 and i<=17) then
skillbutton:SetText(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name][skill].name);
skillframe.skillname=atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name][skill].name;
skillbutton:SetTextColor(ATSWTypeColor[atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name][skill].type].r, ATSWTypeColor[atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name][skill].type].g, ATSWTypeColor[atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][header].name][skill].type].b);
skillframe:Show();
skillbutton:Show();
skillbutton:SetNormalTexture("");
getglobal("ATSWCSCSkill"..i.."MoveUp"):Show();
getglobal("ATSWCSCSkill"..i.."MoveDown"):Show();
getglobal("ATSWCSCSkill"..i.."Delete"):Show();
getglobal("ATSWCSCSkill"..i.."SkillButtonHighlight"):SetTexture("");
skillbutton:GetParent().btype="recipe";
end
skill=skill+1;
else
if(skill==1) then
if(i>=1 and i<=17) then
skillbutton:SetText(ATSWCS_NOTHINGINCATEGORY);
skillframe.skillname=ATSWCS_NOTHINGINCATEGORY;
skillbutton:SetTextColor(0.6, 0.6, 0.6, 1, "GameFontNormalSmall");
skillframe:Show();
skillbutton:Show();
skillbutton:SetNormalTexture("");
getglobal("ATSWCSCSkill"..i.."SkillButtonHighlight"):SetTexture("");
getglobal("ATSWCSCSkill"..i.."MoveUp"):Hide();
getglobal("ATSWCSCSkill"..i.."MoveDown"):Hide();
getglobal("ATSWCSCSkill"..i.."Delete"):Hide();
end
else
i=i-1;
end
skill=0;
header=header+1;
end
else
if(skill==1) then
if(i>=1 and i<=17) then
skillbutton:SetText(ATSWCS_NOTHINGINCATEGORY);
skillframe.skillname=ATSWCS_NOTHINGINCATEGORY;
ATSW_SetTextColor(skillbutton, 0.6, 0.6, 0.6);
skillframe:Show();
skillbutton:Show();
skillbutton:SetNormalTexture("");
getglobal("ATSWCSCSkill"..i.."SkillButtonHighlight"):SetTexture("");
getglobal("ATSWCSCSkill"..i.."MoveUp"):Hide();
getglobal("ATSWCSCSkill"..i.."MoveDown"):Hide();
getglobal("ATSWCSCSkill"..i.."Delete"):Hide();
end
else
i=i-1;
end
skill=0;
header=header+1;
end
else
if(i>=1 and i<=17) then
skillbutton:Show();
skillframe:Hide();
skillframe.skillname=nil;
end
end
i=i+1;
until(i>17);
local totalcount2=0;
if(atsw_customheaders[UnitName("player")][atsw_selectedskill]) then
totalcount2=totalcount2+table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]);
if(atsw_opencategory~=0) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][atsw_opencategory].name]) then
totalcount2=totalcount2+table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][atsw_opencategory].name]);
else
totalcount2=totalcount2+1;
end
end
end
FauxScrollFrame_Update(ATSWCSUListScrollFrame, totalcount, 23, 16);
FauxScrollFrame_Update(ATSWCSSListScrollFrame, totalcount2, 17, 16);
ATSW_CreateSkillListing();
ATSWFrame_Update();
end
function ATSWCS_UpdateUncategorizedList()
atsw_uncategorized={};
for i=1,table.getn(atsw_tradeskilllist),1 do
if(ATSWCS_CheckIfCategorized(atsw_tradeskilllist[i].name)==false) then
table.insert(atsw_uncategorized,{name=atsw_tradeskilllist[i].name, type=atsw_tradeskilllist[i].type});
end
end
table.sort(atsw_uncategorized,ATSWCS_SortUncategorizedList);
end
function ATSWCS_SortUncategorizedList(i,j)
return string.lower(i.name) < string.lower(j.name);
end
function ATSWCS_CheckIfCategorized(skillName)
if(atsw_customsorting[UnitName("player")]) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]) then
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]) then
for k=1,table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k].name==skillName) then
return true;
end
end
end
end
end
end
return false;
end
function ATSWCS_AddCategory(categoryName)
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name==categoryName) then return; end
end
table.insert(atsw_customheaders[UnitName("player")][atsw_selectedskill],{name=categoryName, expanded=false});
ATSWCS_UpdateSkillList();
end
function ATSWCS_MoveUp(skillName)
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name==skillName) then
if(i>1) then
local buffer=atsw_customheaders[UnitName("player")][atsw_selectedskill][i-1];
atsw_customheaders[UnitName("player")][atsw_selectedskill][i-1]=atsw_customheaders[UnitName("player")][atsw_selectedskill][i];
atsw_customheaders[UnitName("player")][atsw_selectedskill][i]=buffer;
break;
end
end
end
if(atsw_customsorting[UnitName("player")]) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]) then
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]) then
for k=1,table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k].name==skillName) then
if(k>1) then
local buffer=atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k-1];
atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k-1]=atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k]
atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k]=buffer;
break;
end
end
end
end
end
end
end
ATSWCS_UpdateSkillList();
end
function ATSWCS_MoveDown(skillName)
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name==skillName) then
if(i<table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill])) then
local buffer=atsw_customheaders[UnitName("player")][atsw_selectedskill][i+1];
atsw_customheaders[UnitName("player")][atsw_selectedskill][i+1]=atsw_customheaders[UnitName("player")][atsw_selectedskill][i];
atsw_customheaders[UnitName("player")][atsw_selectedskill][i]=buffer;
break;
end
end
end
if(atsw_customsorting[UnitName("player")]) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]) then
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]) then
for k=1,table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k].name==skillName) then
if(k<table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name])) then
local buffer=atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k+1];
atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k+1]=atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k]
atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k]=buffer;
break;
end
end
end
end
end
end
end
ATSWCS_UpdateSkillList();
end
function ATSWCS_Delete(skillName,onlySkill)
if(self:GetParent().btype=="header" and onlySkill==nil) then
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name==skillName) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]) then
for j=table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]),1,-1 do
ATSWCS_Delete(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][j].name,true);
end
end
table.remove(atsw_customheaders[UnitName("player")][atsw_selectedskill],i);
if(atsw_opencategory==i) then atsw_opencategory=0; end
end
end
end
if(atsw_customsorting[UnitName("player")]) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]) then
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]) then
for k=1,table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k].name==skillName) then
table.remove(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name],k);
break;
end
end
end
end
end
end
ATSWCS_UpdateUncategorizedList();
ATSWCS_UpdateSkillList();
end
function ATSWCSCSkillButton_OnClick(self,skillName)
if(self:GetParent().btype=="header") then
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name==skillName) then
if(atsw_opencategory==i) then
atsw_opencategory=0;
else
atsw_opencategory=i;
end
ATSWCS_UpdateUncategorizedList();
ATSWCS_UpdateSkillList();
return;
end
end
end
if(atsw_customsorting[UnitName("player")]) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]) then
for i=1,table.getn(atsw_customheaders[UnitName("player")][atsw_selectedskill]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]) then
for k=1,table.getn(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name]),1 do
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name][k].name==skillName) then
table.remove(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][i].name],k);
break;
end
end
end
end
end
end
ATSWCS_UpdateUncategorizedList();
ATSWCS_UpdateSkillList();
end
function ATSWCSSkillButton_OnClick(self,skillName)
if(atsw_opencategory==0) then return; end
for i=1,table.getn(atsw_uncategorized),1 do
if(atsw_uncategorized[i].name==skillName) then
if(atsw_customsorting[UnitName("player")][atsw_selectedskill]==nil) then atsw_customsorting[UnitName("player")][atsw_selectedskill]={}; end
if(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][atsw_opencategory].name]==nil) then atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][atsw_opencategory].name]={}; end
table.insert(atsw_customsorting[UnitName("player")][atsw_selectedskill][atsw_customheaders[UnitName("player")][atsw_selectedskill][atsw_opencategory].name],{name=skillName,type=atsw_uncategorized[i].type});
end
end
ATSWCS_UpdateUncategorizedList();
ATSWCS_UpdateSkillList();
end