function mergetable(table1,list)
--Appends tables from list on the end of table1
for i=1,#list do
table2=list[i]
local LenTable1=#table1
for a =LenTable1+1,#table1+#table2 do
table1[a]=table2[a-LenTable1]
end
end
end
--Frame control - Gives a nice border to the window.
Frame=class(Turbine.UI.Control)
function Frame:Constructor()
Turbine.UI.Control.Constructor( self );
self.base=Turbine.UI.Control()
self.base:SetBackColor(Turbine.UI.Color(1,1,1,1))
self.base:SetParent(self)
self.high=Turbine.UI.Control()
self.high:SetBackColor(Turbine.UI.Color(1,0,0,0))
self.high:SetPosition(1,1)
self.high:SetParent(self.base)
self:SetVisible(true)
self.SizeChanged=function()
for i=1,#self.SizeChange do
self.SizeChange[i]()
end
end
self.SizeChange={}
table.insert(self.SizeChange,function()
local x,y=self:GetSize()
self.base:SetSize(x,y)
self.high:SetSize(x-2,y-2)
end)
end
function weight(i)
--Calculate the weight
local Weight = 0
local Category
local Quality
local Name
local item = backpack:GetItem(i)
if item == nil then
--Empty slots have no name, quality, category etc
Category=0
Quality=0
else
Category=item:GetCategory()
Quality=item:GetQuality()
if Quality==nil then Quality=0 end
end
local CategoryText=ItemCategory[Category]
if CategoryText~=nil then
CatWeight=value[CategoryText] --First scan the CategoryText using the value table
else
--This item has not been given a category number by turbine - it is missing from the category text list.
Turbine.Shell.WriteLine("<rgb=#888888>"..item:GetName().." has not been given category text by Turbine. Dammit. It's number is "..Category.." Please inform MrJackdaw!")
end
Weight=CatWeight*10+Quality
return Weight
end
function strip(str)
--Strip numbers first 7 characters to make the sort more logical
local left=string.sub(str, 1, 7)
local right=string.sub(str, 8)
left=string.gsub(left,"[^%a]","")
str= left .. right
--Strip all spaces now!
str=string.gsub(str,"[%s]","")
return str
end
function analysepack()
local VirtPack={}
for i=1,size do
VirtPack[i]={}
VirtPack[i].id=i
item = backpack:GetItem(i)
if item~=nil then
--Data that may be useful...
VirtPack[i].Name=item:GetName()
VirtPack[i].Group=ItemGroup[ItemCategory[item:GetCategory()]]
else
VirtPack[i].Name="zEmpty"
VirtPack[i].Group=0
end
VirtPack[i].Weight=weight(i)
end
--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"
table.sort(VirtPack, function (a,b)
if a.Weight == b.Weight then
--return a.Name < b.Name
if revorder then return strip(a.Name)> strip(b.Name) else return strip(a.Name)< strip(b.Name) end
else
if revorder then return (a.Weight > b.Weight) else return (a.Weight < b.Weight) end
end
end)
return VirtPack
end