1 |
3 |
MrJackdaw-1942 |
function mergetable(table1,list) |
2 |
53 |
MrJackdaw-1942 |
--Appends tables from list on the end of table1 |
3 |
|
MrJackdaw-1942 |
for i=1,#list do |
4 |
|
MrJackdaw-1942 |
table2=list[i] |
5 |
|
MrJackdaw-1942 |
local LenTable1=#table1 |
6 |
|
MrJackdaw-1942 |
for a =LenTable1+1,#table1+#table2 do |
7 |
|
MrJackdaw-1942 |
table1[a]=table2[a-LenTable1] |
8 |
|
MrJackdaw-1942 |
end |
9 |
|
MrJackdaw-1942 |
end |
10 |
100 |
MrJackdaw-1942 |
end |
11 |
|
MrJackdaw-1942 |
|
12 |
|
MrJackdaw-1942 |
|
13 |
|
MrJackdaw-1942 |
--Frame control - Gives a nice border to the window. |
14 |
|
MrJackdaw-1942 |
Frame=class(Turbine.UI.Control) |
15 |
|
MrJackdaw-1942 |
|
16 |
|
MrJackdaw-1942 |
function Frame:Constructor() |
17 |
|
MrJackdaw-1942 |
Turbine.UI.Control.Constructor( self ); |
18 |
|
MrJackdaw-1942 |
self.base=Turbine.UI.Control() |
19 |
|
MrJackdaw-1942 |
self.base:SetBackColor(Turbine.UI.Color(1,1,1,1)) |
20 |
|
MrJackdaw-1942 |
self.base:SetParent(self) |
21 |
|
MrJackdaw-1942 |
self.high=Turbine.UI.Control() |
22 |
|
MrJackdaw-1942 |
self.high:SetBackColor(Turbine.UI.Color(1,0,0,0)) |
23 |
|
MrJackdaw-1942 |
self.high:SetPosition(1,1) |
24 |
|
MrJackdaw-1942 |
self.high:SetParent(self.base) |
25 |
|
MrJackdaw-1942 |
self:SetVisible(true) |
26 |
|
MrJackdaw-1942 |
|
27 |
|
MrJackdaw-1942 |
self.SizeChanged=function() |
28 |
|
MrJackdaw-1942 |
for i=1,#self.SizeChange do |
29 |
|
MrJackdaw-1942 |
self.SizeChange[i]() |
30 |
|
MrJackdaw-1942 |
end |
31 |
|
MrJackdaw-1942 |
end |
32 |
|
MrJackdaw-1942 |
self.SizeChange={} |
33 |
|
MrJackdaw-1942 |
table.insert(self.SizeChange,function() |
34 |
|
MrJackdaw-1942 |
local x,y=self:GetSize() |
35 |
|
MrJackdaw-1942 |
self.base:SetSize(x,y) |
36 |
|
MrJackdaw-1942 |
self.high:SetSize(x-2,y-2) |
37 |
|
MrJackdaw-1942 |
end) |
38 |
|
MrJackdaw-1942 |
end |
39 |
111 |
MrJackdaw-1942 |
|
40 |
112 |
MrJackdaw-1942 |
function weight(i) |
41 |
|
MrJackdaw-1942 |
--Calculate the weight |
42 |
|
MrJackdaw-1942 |
local Weight = 0 |
43 |
128 |
MrJackdaw-1942 |
local Category |
44 |
|
MrJackdaw-1942 |
local Quality |
45 |
|
MrJackdaw-1942 |
local Name |
46 |
112 |
MrJackdaw-1942 |
|
47 |
128 |
MrJackdaw-1942 |
local item = backpack:GetItem(i) |
48 |
|
MrJackdaw-1942 |
|
49 |
112 |
MrJackdaw-1942 |
if item == nil then |
50 |
|
MrJackdaw-1942 |
--Empty slots have no name, quality, category etc |
51 |
|
MrJackdaw-1942 |
Category=0 |
52 |
|
MrJackdaw-1942 |
Quality=0 |
53 |
|
MrJackdaw-1942 |
else |
54 |
|
MrJackdaw-1942 |
Category=item:GetCategory() |
55 |
|
MrJackdaw-1942 |
Quality=item:GetQuality() |
56 |
|
MrJackdaw-1942 |
if Quality==nil then Quality=0 end |
57 |
111 |
MrJackdaw-1942 |
end |
58 |
|
MrJackdaw-1942 |
|
59 |
129 |
MrJackdaw-1942 |
local CategoryText=ItemCategory[Category] |
60 |
112 |
MrJackdaw-1942 |
if CategoryText~=nil then |
61 |
|
MrJackdaw-1942 |
CatWeight=value[CategoryText] --First scan the CategoryText using the value table |
62 |
|
MrJackdaw-1942 |
else |
63 |
|
MrJackdaw-1942 |
--This item has not been given a category number by turbine - it is missing from the category text list. |
64 |
|
MrJackdaw-1942 |
Turbine.Shell.WriteLine("<rgb=#888888>"..item:GetName().." has not been given category text by Turbine. Dammit. It's number is "..Category.." Please inform MrJackdaw!") |
65 |
111 |
MrJackdaw-1942 |
end |
66 |
129 |
MrJackdaw-1942 |
|
67 |
|
MrJackdaw-1942 |
Weight=CatWeight*10+Quality |
68 |
111 |
MrJackdaw-1942 |
|
69 |
112 |
MrJackdaw-1942 |
return Weight |
70 |
|
MrJackdaw-1942 |
end |
71 |
111 |
MrJackdaw-1942 |
|
72 |
112 |
MrJackdaw-1942 |
function strip(str) |
73 |
|
MrJackdaw-1942 |
--Strip numbers first 7 characters to make the sort more logical |
74 |
|
MrJackdaw-1942 |
local left=string.sub(str, 1, 7) |
75 |
|
MrJackdaw-1942 |
local right=string.sub(str, 8) |
76 |
|
MrJackdaw-1942 |
left=string.gsub(left,"[^%a]","") |
77 |
|
MrJackdaw-1942 |
str= left .. right |
78 |
|
MrJackdaw-1942 |
--Strip all spaces now! |
79 |
|
MrJackdaw-1942 |
str=string.gsub(str,"[%s]","") |
80 |
|
MrJackdaw-1942 |
return str |
81 |
|
MrJackdaw-1942 |
end |
82 |
111 |
MrJackdaw-1942 |
|
83 |
112 |
MrJackdaw-1942 |
function analysepack() |
84 |
|
MrJackdaw-1942 |
local VirtPack={} |
85 |
|
MrJackdaw-1942 |
for i=1,size do |
86 |
|
MrJackdaw-1942 |
VirtPack[i]={} |
87 |
|
MrJackdaw-1942 |
VirtPack[i].id=i |
88 |
|
MrJackdaw-1942 |
item = backpack:GetItem(i) |
89 |
|
MrJackdaw-1942 |
if item~=nil then |
90 |
|
MrJackdaw-1942 |
--Data that may be useful... |
91 |
|
MrJackdaw-1942 |
VirtPack[i].Name=item:GetName() |
92 |
|
MrJackdaw-1942 |
VirtPack[i].Group=ItemGroup[ItemCategory[item:GetCategory()]] |
93 |
|
MrJackdaw-1942 |
else |
94 |
|
MrJackdaw-1942 |
VirtPack[i].Name="zEmpty" |
95 |
|
MrJackdaw-1942 |
VirtPack[i].Group=0 |
96 |
|
MrJackdaw-1942 |
end |
97 |
|
MrJackdaw-1942 |
VirtPack[i].Weight=weight(i) |
98 |
111 |
MrJackdaw-1942 |
end |
99 |
112 |
MrJackdaw-1942 |
|
100 |
|
MrJackdaw-1942 |
--Sort VirtPack. If the weight of two items is the same compare the Names, after removing some characters. This way "2 Morale Potions" will get sorted with "Morale Potions" |
101 |
|
MrJackdaw-1942 |
table.sort(VirtPack, function (a,b) |
102 |
|
MrJackdaw-1942 |
if a.Weight == b.Weight then |
103 |
|
MrJackdaw-1942 |
--return a.Name < b.Name |
104 |
|
MrJackdaw-1942 |
if revorder then return strip(a.Name)> strip(b.Name) else return strip(a.Name)< strip(b.Name) end |
105 |
|
MrJackdaw-1942 |
|
106 |
|
MrJackdaw-1942 |
else |
107 |
|
MrJackdaw-1942 |
if revorder then return (a.Weight > b.Weight) else return (a.Weight < b.Weight) end |
108 |
|
MrJackdaw-1942 |
end |
109 |
|
MrJackdaw-1942 |
end) |
110 |
|
MrJackdaw-1942 |
return VirtPack |
111 |
|
MrJackdaw-1942 |
end |