lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

[/] [trunk/] [JackdawPlugins/] [SortPack/] [functions.LUA] - Blame information for rev 119

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
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 111 MrJackdaw-1942
 
44 112 MrJackdaw-1942
        item = backpack:GetItem(i)
45 MrJackdaw-1942
 
46 MrJackdaw-1942
        if item == nil then
47 MrJackdaw-1942
                --Empty slots have no name, quality, category etc
48 MrJackdaw-1942
                Category=0
49 MrJackdaw-1942
                Quality=0
50 MrJackdaw-1942
        else
51 MrJackdaw-1942
                Category=item:GetCategory()
52 MrJackdaw-1942
                Quality=item:GetQuality()
53 MrJackdaw-1942
                if Quality==nil then Quality=0 end
54 111 MrJackdaw-1942
        end
55 MrJackdaw-1942
 
56 112 MrJackdaw-1942
                CategoryText=ItemCategory[Category]
57 MrJackdaw-1942
                if CategoryText~=nil then
58 MrJackdaw-1942
                        CatWeight=value[CategoryText]           --First scan the CategoryText using the value table
59 MrJackdaw-1942
                else
60 MrJackdaw-1942
                        --This item has not been given a category number by turbine - it is missing from the category text list.
61 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!")
62 111 MrJackdaw-1942
                end
63 112 MrJackdaw-1942
 
64 MrJackdaw-1942
                QualWeight=Quality
65 111 MrJackdaw-1942
 
66 112 MrJackdaw-1942
                Weight=CatWeight*100+QualWeight
67 MrJackdaw-1942
 
68 MrJackdaw-1942
                if item==nil then Weight = 99999 end
69 MrJackdaw-1942
 
70 MrJackdaw-1942
        return Weight
71 MrJackdaw-1942
end
72 111 MrJackdaw-1942
 
73 112 MrJackdaw-1942
function strip(str)
74 MrJackdaw-1942
        --Strip numbers first 7 characters to make the sort more logical
75 MrJackdaw-1942
        local left=string.sub(str, 1, 7)
76 MrJackdaw-1942
        local right=string.sub(str, 8)
77 MrJackdaw-1942
        left=string.gsub(left,"[^%a]","")
78 MrJackdaw-1942
        str= left .. right
79 MrJackdaw-1942
        --Strip all spaces now!
80 MrJackdaw-1942
        str=string.gsub(str,"[%s]","")
81 MrJackdaw-1942
        return str
82 MrJackdaw-1942
end
83 111 MrJackdaw-1942
 
84 112 MrJackdaw-1942
function analysepack()
85 MrJackdaw-1942
        local VirtPack={}
86 MrJackdaw-1942
                for i=1,size do
87 MrJackdaw-1942
                        VirtPack[i]={}
88 MrJackdaw-1942
                        VirtPack[i].id=i
89 MrJackdaw-1942
                        item = backpack:GetItem(i)
90 MrJackdaw-1942
                        if item~=nil then
91 MrJackdaw-1942
                                --Data that may be useful...
92 MrJackdaw-1942
                                VirtPack[i].Name=item:GetName()
93 MrJackdaw-1942
                                VirtPack[i].Group=ItemGroup[ItemCategory[item:GetCategory()]]
94 MrJackdaw-1942
                        else
95 MrJackdaw-1942
                                VirtPack[i].Name="zEmpty"
96 MrJackdaw-1942
                                VirtPack[i].Group=0
97 MrJackdaw-1942
                        end
98 MrJackdaw-1942
                        VirtPack[i].Weight=weight(i)
99 111 MrJackdaw-1942
                end
100 112 MrJackdaw-1942
 
101 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"
102 MrJackdaw-1942
                table.sort(VirtPack, function (a,b)
103 MrJackdaw-1942
                        if a.Weight == b.Weight then
104 MrJackdaw-1942
                                --return a.Name < b.Name
105 MrJackdaw-1942
                                if revorder then return strip(a.Name)> strip(b.Name) else return strip(a.Name)< strip(b.Name) end
106 MrJackdaw-1942
 
107 MrJackdaw-1942
                        else
108 MrJackdaw-1942
                                if revorder then return (a.Weight > b.Weight) else return (a.Weight < b.Weight) end
109 MrJackdaw-1942
                        end
110 MrJackdaw-1942
                 end)
111 MrJackdaw-1942
        return VirtPack
112 MrJackdaw-1942
end

All times are GMT -5. The time now is 06:42 PM.


Our Network
EQInterface | EQ2Interface | Minion | WoWInterface | ESOUI | LoTROInterface | MMOUI | Swtorui