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 |
134 |
MrJackdaw-1942 |
|
65 |
|
MrJackdaw-1942 |
--** |
66 |
|
MrJackdaw-1942 |
--Added a few lines so each warning is only recieved once per load - of course as the plugin is sometimes reloaded this could be frequent, but hopefully not too frequent. |
67 |
|
MrJackdaw-1942 |
if warned==nil then |
68 |
|
MrJackdaw-1942 |
warned={} |
69 |
|
MrJackdaw-1942 |
end |
70 |
|
MrJackdaw-1942 |
if warned.Category==nil then |
71 |
|
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!") |
72 |
|
MrJackdaw-1942 |
warned.Category=true |
73 |
|
MrJackdaw-1942 |
end |
74 |
|
MrJackdaw-1942 |
--** |
75 |
111 |
MrJackdaw-1942 |
end |
76 |
129 |
MrJackdaw-1942 |
|
77 |
|
MrJackdaw-1942 |
Weight=CatWeight*10+Quality |
78 |
132 |
MrJackdaw-1942 |
|
79 |
|
MrJackdaw-1942 |
if item == nil then Weight=99999 end |
80 |
111 |
MrJackdaw-1942 |
|
81 |
112 |
MrJackdaw-1942 |
return Weight |
82 |
|
MrJackdaw-1942 |
end |
83 |
111 |
MrJackdaw-1942 |
|
84 |
112 |
MrJackdaw-1942 |
function strip(str) |
85 |
|
MrJackdaw-1942 |
--Strip numbers first 7 characters to make the sort more logical |
86 |
|
MrJackdaw-1942 |
local left=string.sub(str, 1, 7) |
87 |
|
MrJackdaw-1942 |
local right=string.sub(str, 8) |
88 |
|
MrJackdaw-1942 |
left=string.gsub(left,"[^%a]","") |
89 |
|
MrJackdaw-1942 |
str= left .. right |
90 |
|
MrJackdaw-1942 |
--Strip all spaces now! |
91 |
|
MrJackdaw-1942 |
str=string.gsub(str,"[%s]","") |
92 |
|
MrJackdaw-1942 |
return str |
93 |
|
MrJackdaw-1942 |
end |
94 |
111 |
MrJackdaw-1942 |
|
95 |
112 |
MrJackdaw-1942 |
function analysepack() |
96 |
|
MrJackdaw-1942 |
local VirtPack={} |
97 |
|
MrJackdaw-1942 |
for i=1,size do |
98 |
|
MrJackdaw-1942 |
VirtPack[i]={} |
99 |
|
MrJackdaw-1942 |
VirtPack[i].id=i |
100 |
|
MrJackdaw-1942 |
item = backpack:GetItem(i) |
101 |
|
MrJackdaw-1942 |
if item~=nil then |
102 |
|
MrJackdaw-1942 |
--Data that may be useful... |
103 |
|
MrJackdaw-1942 |
VirtPack[i].Name=item:GetName() |
104 |
|
MrJackdaw-1942 |
VirtPack[i].Group=ItemGroup[ItemCategory[item:GetCategory()]] |
105 |
|
MrJackdaw-1942 |
else |
106 |
|
MrJackdaw-1942 |
VirtPack[i].Name="zEmpty" |
107 |
|
MrJackdaw-1942 |
VirtPack[i].Group=0 |
108 |
|
MrJackdaw-1942 |
end |
109 |
|
MrJackdaw-1942 |
VirtPack[i].Weight=weight(i) |
110 |
134 |
MrJackdaw-1942 |
if VirtPack[i].Group==nil then VirtPack[i].Group=0 end |
111 |
111 |
MrJackdaw-1942 |
end |
112 |
112 |
MrJackdaw-1942 |
|
113 |
|
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" |
114 |
|
MrJackdaw-1942 |
table.sort(VirtPack, function (a,b) |
115 |
|
MrJackdaw-1942 |
if a.Weight == b.Weight then |
116 |
|
MrJackdaw-1942 |
--return a.Name < b.Name |
117 |
|
MrJackdaw-1942 |
if revorder then return strip(a.Name)> strip(b.Name) else return strip(a.Name)< strip(b.Name) end |
118 |
|
MrJackdaw-1942 |
else |
119 |
|
MrJackdaw-1942 |
if revorder then return (a.Weight > b.Weight) else return (a.Weight < b.Weight) end |
120 |
|
MrJackdaw-1942 |
end |
121 |
|
MrJackdaw-1942 |
end) |
122 |
|
MrJackdaw-1942 |
return VirtPack |
123 |
131 |
MrJackdaw-1942 |
end |
124 |
|
MrJackdaw-1942 |
|
125 |
|
MrJackdaw-1942 |
--Callback handler due to Pengoros... Many thanks! |
126 |
|
MrJackdaw-1942 |
function AddCallback(object, event, callback) |
127 |
|
MrJackdaw-1942 |
if (object[event] == nil) then |
128 |
|
MrJackdaw-1942 |
object[event] = callback; |
129 |
|
MrJackdaw-1942 |
else |
130 |
|
MrJackdaw-1942 |
if (type(object[event]) == "table") then |
131 |
|
MrJackdaw-1942 |
table.insert(object[event], callback); |
132 |
|
MrJackdaw-1942 |
else |
133 |
|
MrJackdaw-1942 |
object[event] = {object[event], callback}; |
134 |
|
MrJackdaw-1942 |
end |
135 |
|
MrJackdaw-1942 |
end |
136 |
|
MrJackdaw-1942 |
return callback; |
137 |
|
MrJackdaw-1942 |
end |
138 |
|
MrJackdaw-1942 |
|
139 |
|
MrJackdaw-1942 |
-- safely remove a callback without clobbering any extras |
140 |
|
MrJackdaw-1942 |
function RemoveCallback(object, event, callback) |
141 |
|
MrJackdaw-1942 |
if (object[event] == callback) then |
142 |
|
MrJackdaw-1942 |
object[event] = nil; |
143 |
|
MrJackdaw-1942 |
else |
144 |
|
MrJackdaw-1942 |
if (type(object[event]) == "table") then |
145 |
|
MrJackdaw-1942 |
local size = table.getn(object[event]); |
146 |
|
MrJackdaw-1942 |
for i = 1, size do |
147 |
|
MrJackdaw-1942 |
if (object[event][i] == callback) then |
148 |
|
MrJackdaw-1942 |
table.remove(object[event], i); |
149 |
|
MrJackdaw-1942 |
break; |
150 |
|
MrJackdaw-1942 |
end |
151 |
|
MrJackdaw-1942 |
end |
152 |
|
MrJackdaw-1942 |
end |
153 |
|
MrJackdaw-1942 |
end |
154 |
112 |
MrJackdaw-1942 |
end |