lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

[/] [trunk/] [JackdawPlugins/] [SortPack/] [Bag.lua] - Blame information for rev 155

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

Line No. Rev Author Line
1 148 MrJackdaw-1942
--Needs a tidy!
2 119 MrJackdaw-1942
--Check the bag datais valid.
3 127 MrJackdaw-1942
if SB==nil then SB={} end
4 148 MrJackdaw-1942
if SB.x==nil then                               SB.x=100                                                end     --}
5 MrJackdaw-1942
if      SB.y==nil then                          SB.y=100                                                end     --}Position
6 MrJackdaw-1942
if      SB.icx==nil then                        SB.icx=4                                                end     --]
7 MrJackdaw-1942
if      SB.icy==nil then                        SB.icy=3                                                end     --]Size, in icons
8 MrJackdaw-1942
if      SB.override==nil then   SB.override=false                       end     --Override default bags?
9 MrJackdaw-1942
if      SB.labelwidth==nil then         SB.labelwidth=80                        end     --Width of the text label for the group.
10 MrJackdaw-1942
if      SB.font==nil then                       SB.font="TrajanPro14"   end     --Label font
11 MrJackdaw-1942
if      SB.ShowItem==nil then   SB.ShowItem=true                        end     --un-hide a group when an item is looted in it?
12 119 MrJackdaw-1942
 
13 148 MrJackdaw-1942
 
14 127 MrJackdaw-1942
--font size
15 MrJackdaw-1942
SB.fontsize=string.sub(SB.font,-2)
16 MrJackdaw-1942
if SB.fontsize=="ed" then SB.fontsize=13-1 else SB.fontsize=tonumber(SB.fontsize)-1 end
17 104 MrJackdaw-1942
 
18 119 MrJackdaw-1942
--Frame padding
19 124 MrJackdaw-1942
pad={top=30,side=15,bottom=10}
20 105 MrJackdaw-1942
 
21 119 MrJackdaw-1942
--Calculate width and maximum height for the bag.
22 111 MrJackdaw-1942
SB.width=SB.labelwidth+36*SB.icx+2*pad.side
23 119 MrJackdaw-1942
SB.maxheight=Turbine.UI.Display.GetHeight()
24 105 MrJackdaw-1942
 
25 119 MrJackdaw-1942
--Functions
26 MrJackdaw-1942
        --Set the sizes of all the areas of the bag.
27 MrJackdaw-1942
        function SortBagSetSize()
28 151 MrJackdaw-1942
                SortBag.ListBox:SetSize( SB.labelwidth+SB.icx*36, SortBag:GetHeight()-(pad.top+pad.bottom)+1)
29 119 MrJackdaw-1942
                SortBag.ScrollBar:SetPosition(SB.labelwidth+SB.icx*36+10,pad.top+5)
30 MrJackdaw-1942
                SortBag.ScrollBar:SetHeight(SortBag:GetHeight()-(pad.top+pad.bottom)-10)
31 125 MrJackdaw-1942
                SortBag.Resize:SetPosition(SB.width-10,pad.top+10)
32 MrJackdaw-1942
                SortBag.Resize:SetSize(10,SortBag:GetHeight()-2*pad.top-10)
33 119 MrJackdaw-1942
                SortBag.ResizeBack:SetSize(10,SortBag:GetHeight()-pad.top-pad.bottom)
34 151 MrJackdaw-1942
                Search.label:SetSize(SB.labelwidth,SB.fontsize)
35 119 MrJackdaw-1942
        end
36 MrJackdaw-1942
 
37 MrJackdaw-1942
        --Adjust the sizes of the GroupBoxes.
38 MrJackdaw-1942
        function SetGroupBoxSize()
39 138 MrJackdaw-1942
                if GroupBox==nil then return end
40 119 MrJackdaw-1942
                local height=0
41 MrJackdaw-1942
                for j=0,#Groups do
42 MrJackdaw-1942
                        --Adjust GroupBox Widths
43 MrJackdaw-1942
                        GroupBox[j]:SetMaxItemsPerLine(SB.icx)
44 MrJackdaw-1942
                        GroupBox[j]:SetWidth(SB.icx*36)
45 MrJackdaw-1942
 
46 MrJackdaw-1942
                        --Hide the slot, or adjust its height
47 MrJackdaw-1942
                        if Groups[j].hide then
48 MrJackdaw-1942
                                GroupBox[j]:SetHeight(0)
49 MrJackdaw-1942
                                GroupBox[j].label:SetBackColor(Turbine.UI.Color( 1,0.4,0,0 ))
50 MrJackdaw-1942
                        else
51 MrJackdaw-1942
                                GroupBox[j]:SetHeight( math.ceil(GroupBox[j]:GetItemCount()/SB.icx)*36)
52 MrJackdaw-1942
                                GroupBox[j].label:SetBackColor(Turbine.UI.Color( 1,0,0,0.4 ))
53 MrJackdaw-1942
                        end
54 MrJackdaw-1942
 
55 MrJackdaw-1942
                        --Adjust Label Width,Height
56 MrJackdaw-1942
                        GroupBox[j].label:SetWidth(SB.labelwidth)
57 MrJackdaw-1942
                        if GroupBox[j]:GetItemCount()>0 then
58 MrJackdaw-1942
                                GroupBox[j].label:SetHeight(SB.fontsize)
59 MrJackdaw-1942
                        else
60 MrJackdaw-1942
                                GroupBox[j].label:SetHeight(0)
61 MrJackdaw-1942
                        end
62 MrJackdaw-1942
 
63 MrJackdaw-1942
                        --Add to the height variable
64 MrJackdaw-1942
                        height=height+math.max(GroupBox[j]:GetHeight(),GroupBox[j].label:GetHeight())
65 132 MrJackdaw-1942
 
66 119 MrJackdaw-1942
                end
67 132 MrJackdaw-1942
                if height>SB.maxheight-(pad.top+pad.bottom) then height=SB.maxheight-(pad.top+pad.bottom) end
68 MrJackdaw-1942
 
69 151 MrJackdaw-1942
                --Resize the window to fit the new height NOTE: The SB.fontsize is to accomodate the "search" box
70 MrJackdaw-1942
                        SortBag:SetHeight(height+pad.top+pad.bottom+SB.fontsize)
71 119 MrJackdaw-1942
 
72 MrJackdaw-1942
                        --Change the title to show how many empty slots are left
73 MrJackdaw-1942
                        SortBag:SetText(GroupBox[0]:GetItemCount().." empty slots left")
74 MrJackdaw-1942
        end
75 151 MrJackdaw-1942
 
76 MrJackdaw-1942
--Search function now added to the bag!
77 MrJackdaw-1942
        Search={}
78 105 MrJackdaw-1942
 
79 151 MrJackdaw-1942
        Search.label=Turbine.UI.Label()
80 MrJackdaw-1942
                Search.label:SetBackColor( Turbine.UI.Color( 1,0.1,0.1,0.1 ) )
81 MrJackdaw-1942
                Search.label:SetMultiline(true)
82 MrJackdaw-1942
                Search.label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter )
83 MrJackdaw-1942
                Search.label:SetMouseVisible (true)
84 MrJackdaw-1942
                Search.label:SetSize(SB.labelwidth,SB.fontsize)
85 155 MrJackdaw-1942
                Search.label.MouseDown=function()
86 MrJackdaw-1942
                        Search.Textbox:SetText("")
87 MrJackdaw-1942
                        SearchBag()
88 MrJackdaw-1942
                end
89 151 MrJackdaw-1942
 
90 MrJackdaw-1942
        Search.Textbox=Turbine.UI.TextBox()
91 MrJackdaw-1942
                Search.Textbox:SetSize(200,SB.fontsize)
92 MrJackdaw-1942
 
93 155 MrJackdaw-1942
 
94 151 MrJackdaw-1942
                --When focus is gained turn updating on so that the plugin will scan the text entered.
95 MrJackdaw-1942
                Search.Textbox.FocusGained=function()
96 MrJackdaw-1942
                        Search.Textbox:SetWantsUpdates(true)
97 MrJackdaw-1942
                        SearchString=Search.Textbox:GetText()
98 MrJackdaw-1942
                end
99 MrJackdaw-1942
                Search.Textbox.FocusLost=function()
100 MrJackdaw-1942
                        Search.Textbox:SetWantsUpdates(false)
101 MrJackdaw-1942
                end
102 MrJackdaw-1942
                Search.Textbox.Update = function()
103 MrJackdaw-1942
                        SearchBag()
104 MrJackdaw-1942
                end
105 MrJackdaw-1942
 
106 MrJackdaw-1942
        function SearchBag()
107 MrJackdaw-1942
                if SearchString ~= Search.Textbox:GetText() then
108 MrJackdaw-1942
                        SearchString = Search.Textbox:GetText()
109 MrJackdaw-1942
                        --remove odd characters
110 MrJackdaw-1942
                        txt1=string.lower(SearchString)
111 MrJackdaw-1942
                        for i=1,size do
112 MrJackdaw-1942
                                local item = backpack:GetItem(i)
113 MrJackdaw-1942
                                if item~=nil then
114 MrJackdaw-1942
                                        local txt2=string.lower(item:GetName())
115 MrJackdaw-1942
                                        if string.find(txt2,txt1) then
116 MrJackdaw-1942
                                                BackpackSlots[i]:SetVisible(true)
117 MrJackdaw-1942
                                        else
118 MrJackdaw-1942
                                                BackpackSlots[i]:SetVisible(false)
119 MrJackdaw-1942
                                        end
120 MrJackdaw-1942
                                end
121 MrJackdaw-1942
                        end
122 MrJackdaw-1942
                end
123 MrJackdaw-1942
        end
124 MrJackdaw-1942
 
125 119 MrJackdaw-1942
        --populate the bag.
126 MrJackdaw-1942
        function populatebag()
127 MrJackdaw-1942
                SortBag.ListBox:ClearItems()
128 151 MrJackdaw-1942
 
129 MrJackdaw-1942
                --Add the search section. Fonts applied here too.
130 MrJackdaw-1942
                SortBag.ListBox:AddItem(Search.label)
131 MrJackdaw-1942
                SortBag.ListBox:AddItem(Search.Textbox)
132 MrJackdaw-1942
 
133 MrJackdaw-1942
                Search.Textbox:SetFont(Turbine.UI.Lotro.Font[SB.font])
134 MrJackdaw-1942
                Search.label:SetFont(Turbine.UI.Lotro.Font[SB.font])
135 MrJackdaw-1942
                Search.label:SetText( "Search" )
136 MrJackdaw-1942
 
137 MrJackdaw-1942
 
138 119 MrJackdaw-1942
                GroupBox={}
139 MrJackdaw-1942
                BackpackSlots=nil
140 MrJackdaw-1942
                BackpackSlots={}
141 MrJackdaw-1942
 
142 124 MrJackdaw-1942
                --Check for font size errors
143 MrJackdaw-1942
                if SB.labelwidth<SB.fontsize then SB.labelwidth=SB.fontsize end
144 MrJackdaw-1942
 
145 119 MrJackdaw-1942
                --Build VirtPack
146 MrJackdaw-1942
 
147 151 MrJackdaw-1942
                VirtPack=analysepack()
148 119 MrJackdaw-1942
 
149 MrJackdaw-1942
                ---Build a box for this group of items. Box 0 is for empty slots.
150 MrJackdaw-1942
                for i=0,#Groups do
151 MrJackdaw-1942
                        GroupBox[i] = Turbine.UI.ListBox()
152 MrJackdaw-1942
                        GroupBox[i]:SetOrientation( Turbine.UI.Orientation.Horizontal )
153 MrJackdaw-1942
 
154 MrJackdaw-1942
                        GroupBox[i]:SetAllowDrop( true )
155 MrJackdaw-1942
                        GroupBox[i].DragDrop = function( sender, args )
156 MrJackdaw-1942
                                --Empty slots allow drag-drop. Hopefully!
157 MrJackdaw-1942
                                local shortcut = args.DragDropInfo:GetShortcut();
158 MrJackdaw-1942
 
159 MrJackdaw-1942
                                if ( shortcut ~= nil ) then
160 MrJackdaw-1942
                                        local item = GroupBox[i]:GetItemAt( args.X, args.Y );
161 143 MrJackdaw-1942
                                        local index
162 MrJackdaw-1942
                                        if item==nil then index=1 else index= item.id end
163 119 MrJackdaw-1942
 
164 MrJackdaw-1942
                                        backpack:PerformShortcutDrop( shortcut, index, Turbine.UI.Control.IsShiftKeyDown() )
165 MrJackdaw-1942
                                end
166 MrJackdaw-1942
                        end
167 MrJackdaw-1942
                end
168 MrJackdaw-1942
 
169 MrJackdaw-1942
                --Build the backpack Slots.
170 MrJackdaw-1942
                for i=1,size do
171 148 MrJackdaw-1942
                        item = backpack:GetItem(i)
172 MrJackdaw-1942
                        if item~=nil then AddCallback(item, "QuantityChanged",  BagQuantityChanged) end
173 119 MrJackdaw-1942
                        BackpackSlots[i]=Turbine.UI.Lotro.ItemControl( item )
174 MrJackdaw-1942
                        BackpackSlots[i].id=i --so it can be passed for item swopping.
175 MrJackdaw-1942
                        BackpackSlots[i]:SetBackground( "JackdawPlugins/SortPack/Back.tga" )
176 MrJackdaw-1942
                        BackpackSlots[i]:SetBlendMode( Turbine.UI.BlendMode.Overlay )
177 MrJackdaw-1942
                end
178 MrJackdaw-1942
 
179 MrJackdaw-1942
                --Move the items into the boxes
180 MrJackdaw-1942
                for i=1,#VirtPack do
181 134 MrJackdaw-1942
                        --if i<10 then Turbine.Shell.WriteLine(VirtPack[i].id) end --Re-enable if the "not sorting correctly" bug rears its head again.
182 119 MrJackdaw-1942
                        BackpackSlots[VirtPack[i].id].Group=VirtPack[i].Group
183 MrJackdaw-1942
                        GroupBox[VirtPack[i].Group]:AddItem(BackpackSlots[VirtPack[i].id])
184 MrJackdaw-1942
                end
185 MrJackdaw-1942
 
186 MrJackdaw-1942
                --Add the groups to the backpack
187 MrJackdaw-1942
                for j=0,#Groups do
188 MrJackdaw-1942
                        --Build a label
189 MrJackdaw-1942
                        GroupBox[j].label=Turbine.UI.Label()
190 MrJackdaw-1942
                                GroupBox[j].label:SetBackColor( Turbine.UI.Color( 1,0,0,0.4 ) )
191 MrJackdaw-1942
                                GroupBox[j].label:SetFont(Turbine.UI.Lotro.Font[SB.font])
192 124 MrJackdaw-1942
                                GroupBox[j].label:SetMultiline(true)
193 119 MrJackdaw-1942
                                GroupBox[j].label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter )
194 MrJackdaw-1942
                                GroupBox[j].label:SetText( Groups[j].Name )
195 MrJackdaw-1942
                                GroupBox[j].label:SetMouseVisible (true)
196 MrJackdaw-1942
                                GroupBox[j].label:SetSize(SB.labelwidth,0)--Initially of height 0
197 132 MrJackdaw-1942
                                GroupBox[j].label.label=true
198 MrJackdaw-1942
 
199 119 MrJackdaw-1942
                        if j~=0 then
200 MrJackdaw-1942
                                --Add the label and GroupBox, but not for empty slots
201 MrJackdaw-1942
                                SortBag.ListBox:AddItem(GroupBox[j].label)
202 MrJackdaw-1942
                                SortBag.ListBox:AddItem(GroupBox[j])
203 MrJackdaw-1942
                        end
204 148 MrJackdaw-1942
 
205 MrJackdaw-1942
                        --Click events for the labels.
206 147 MrJackdaw-1942
                        GroupBox[j].label.MouseClick=function(sender,args)
207 MrJackdaw-1942
                                if ( args.Button == Turbine.UI.MouseButton.Left ) then
208 148 MrJackdaw-1942
                                        --Left Clicking the label collapses this group
209 147 MrJackdaw-1942
                                        Groups[j].hide=not(Groups[j].hide)
210 MrJackdaw-1942
                                else
211 148 MrJackdaw-1942
                                        --Right clicking either collapses all groups, if this one is shown, or opens all groups if not.
212 MrJackdaw-1942
                                                Groups[j].hide=not(Groups[j].hide)
213 147 MrJackdaw-1942
                                        for i=0,#Groups do
214 148 MrJackdaw-1942
                                                Groups[i].hide=Groups[j].hide
215 147 MrJackdaw-1942
                                        end
216 MrJackdaw-1942
                                end
217 119 MrJackdaw-1942
                                SetGroupBoxSize()
218 MrJackdaw-1942
                        end
219 MrJackdaw-1942
                end
220 MrJackdaw-1942
                        --Empty Slots group added last.
221 MrJackdaw-1942
                        SortBag.ListBox:AddItem(GroupBox[0].label)
222 MrJackdaw-1942
                        SortBag.ListBox:AddItem(GroupBox[0])
223 MrJackdaw-1942
 
224 MrJackdaw-1942
                --Function refresh the heights of the group boxes
225 MrJackdaw-1942
                SetGroupBoxSize()
226 131 MrJackdaw-1942
        end
227 MrJackdaw-1942
 
228 MrJackdaw-1942
        --Show the backpack
229 151 MrJackdaw-1942
        function openbag()
230 MrJackdaw-1942
                --Clear out any previous search
231 MrJackdaw-1942
                Search.Textbox:SetText("")
232 MrJackdaw-1942
                SearchString=""
233 MrJackdaw-1942
                for i=1,size do BackpackSlots[i]:SetVisible(true) end
234 MrJackdaw-1942
                --Show the bag!
235 131 MrJackdaw-1942
                SortBag:SetVisible(true)
236 MrJackdaw-1942
        end
237 MrJackdaw-1942
 
238 MrJackdaw-1942
        --Events here replace the default bags with this one.
239 MrJackdaw-1942
        function SBOverride()
240 MrJackdaw-1942
 
241 MrJackdaw-1942
                if SB.override then SortBag:SetWantsKeyEvents( true );
242 119 MrJackdaw-1942
 
243 131 MrJackdaw-1942
                        SortBag.KeyDown = function( sender, args )
244 MrJackdaw-1942
                                if ( args.Action == Turbine.UI.Lotro.Action.Escape ) then
245 MrJackdaw-1942
                                        SortBag:Close()
246 MrJackdaw-1942
                                end
247 MrJackdaw-1942
 
248 MrJackdaw-1942
                                if ( args.Action == Turbine.UI.Lotro.Action.ToggleBags or
249 MrJackdaw-1942
                                         args.Action == Turbine.UI.Lotro.Action.ToggleBag1 or
250 MrJackdaw-1942
                                         args.Action == Turbine.UI.Lotro.Action.ToggleBag2 or
251 MrJackdaw-1942
                                         args.Action == Turbine.UI.Lotro.Action.ToggleBag3 or
252 MrJackdaw-1942
                                         args.Action == Turbine.UI.Lotro.Action.ToggleBag4 or
253 MrJackdaw-1942
                                         args.Action == Turbine.UI.Lotro.Action.ToggleBag5 )
254 MrJackdaw-1942
                                then
255 MrJackdaw-1942
                                        if SortBag:IsVisible() then
256 MrJackdaw-1942
                                                SortBag:Close()
257 MrJackdaw-1942
                                        else
258 MrJackdaw-1942
                                                openbag()
259 MrJackdaw-1942
                                        end
260 MrJackdaw-1942
                                end
261 MrJackdaw-1942
                        end
262 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack1, false )
263 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack2, false )
264 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack3, false )
265 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack4, false )
266 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack5, false )
267 MrJackdaw-1942
                else
268 MrJackdaw-1942
                        SortBag:SetWantsKeyEvents( false )
269 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack1, true )
270 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack2, true )
271 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack3, true )
272 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack4, true )
273 MrJackdaw-1942
                        Turbine.UI.Lotro.LotroUI.SetEnabled( Turbine.UI.Lotro.LotroUIElement.Backpack5, true )
274 MrJackdaw-1942
                end
275 MrJackdaw-1942
        end
276 MrJackdaw-1942
 
277 MrJackdaw-1942
        --Next three items update the bag if items are added or removed.
278 MrJackdaw-1942
 
279 MrJackdaw-1942
 
280 MrJackdaw-1942
                BagAdd=function( sender, args )
281 142 MrJackdaw-1942
                        --Turbine.Shell.WriteLine("BagAdd "..args.Index..args.Item:GetName())
282 119 MrJackdaw-1942
                        --args.Index    = Bag slot
283 MrJackdaw-1942
                        --args.Item             = Item object
284 MrJackdaw-1942
 
285 MrJackdaw-1942
                        --Remove the slot from the group it is in.
286 MrJackdaw-1942
 
287 MrJackdaw-1942
                        for i=0,#Groups do
288 MrJackdaw-1942
                                if GroupBox[i]:ContainsItem(BackpackSlots[args.Index]) then GroupBox[i]:RemoveItem(BackpackSlots[args.Index]) end
289 MrJackdaw-1942
                        end
290 147 MrJackdaw-1942
 
291 119 MrJackdaw-1942
                        --Determine which group it belongs to
292 137 MrJackdaw-1942
                        local destination=ItemGroup[ItemCategory[args.Item:GetCat()]]
293 147 MrJackdaw-1942
 
294 134 MrJackdaw-1942
                        if destination==nil then destination=0 end
295 147 MrJackdaw-1942
 
296 119 MrJackdaw-1942
                        --Insert the item in that group
297 MrJackdaw-1942
                        BackpackSlots[args.Index]:SetItem(args.Item)
298 MrJackdaw-1942
                        BackpackSlots[args.Index].Group=destination
299 MrJackdaw-1942
 
300 MrJackdaw-1942
                        GroupBox[destination]:InsertItem(position,BackpackSlots[args.Index])
301 MrJackdaw-1942
 
302 134 MrJackdaw-1942
                        if destination~=0 then
303 MrJackdaw-1942
                                --Remove every item from that groupbox one at a time and resort them.
304 MrJackdaw-1942
                                local temp={}
305 MrJackdaw-1942
                                --cycle through the elements checking for weights
306 MrJackdaw-1942
                                for i=GroupBox[destination]:GetItemCount(),1,-1 do
307 MrJackdaw-1942
                                        temp[i]=GroupBox[destination]:GetItem(i)
308 MrJackdaw-1942
                                        temp[i].Weight=weight(temp[i].id)
309 MrJackdaw-1942
                                        temp[i].Name=GroupBox[destination]:GetItem(i):GetItem():GetName()
310 MrJackdaw-1942
                                end
311 MrJackdaw-1942
 
312 MrJackdaw-1942
                                --Remove all the items
313 MrJackdaw-1942
                                GroupBox[destination]:ClearItems()
314 MrJackdaw-1942
 
315 MrJackdaw-1942
                                --Sort the items according to weight (ignoring alpha. I am happy with this compromise)
316 MrJackdaw-1942
                                table.sort(temp, function (a,b)
317 MrJackdaw-1942
                                        if a.Weight == b.Weight then
318 MrJackdaw-1942
                                                --return a.Name < b.Name
319 MrJackdaw-1942
                                                --return strip(a.Name)< strip(b.Name)
320 MrJackdaw-1942
                                                if revorder then return strip(a.Name)> strip(b.Name) else return strip(a.Name)< strip(b.Name) end
321 MrJackdaw-1942
                                        else
322 MrJackdaw-1942
                                                if revorder then return (a.Weight > b.Weight) else return (a.Weight < b.Weight) end
323 MrJackdaw-1942
                                        end
324 MrJackdaw-1942
                                 end)
325 MrJackdaw-1942
 
326 MrJackdaw-1942
                                --Put the items in the group
327 MrJackdaw-1942
                                for i=1,#temp do
328 MrJackdaw-1942
                                        GroupBox[destination]:AddItem(temp[i])
329 MrJackdaw-1942
                                end
330 119 MrJackdaw-1942
                        end
331 132 MrJackdaw-1942
 
332 119 MrJackdaw-1942
                        --Refresh heights
333 MrJackdaw-1942
                        SetGroupBoxSize()
334 148 MrJackdaw-1942
 
335 MrJackdaw-1942
                        --Add the quantity changed event
336 MrJackdaw-1942
                        AddCallback(args.Item, "QuantityChanged",       BagQuantityChanged)
337 MrJackdaw-1942
                        unhide(args.Item)
338 119 MrJackdaw-1942
                end
339 131 MrJackdaw-1942
 
340 MrJackdaw-1942
                BagRemove=function( sender, args )
341 142 MrJackdaw-1942
                        --Turbine.Shell.WriteLine("BagRemove "..args.Index)
342 121 MrJackdaw-1942
                        --Note: this is sometimes called when looting *and no item is removed* causing the "empty slot" bug. Annoying, and not my fault!
343 MrJackdaw-1942
 
344 119 MrJackdaw-1942
                        --Also called if a stack is merged.
345 MrJackdaw-1942
                        --args.Index    = Bag slot
346 148 MrJackdaw-1942
 
347 MrJackdaw-1942
                        --Remove the quantity changed callback
348 MrJackdaw-1942
                        item = backpack:GetItem(args.Index)
349 MrJackdaw-1942
                        RemoveCallback(item, "QuantityChanged",         BagQuantityChanged)
350 119 MrJackdaw-1942
 
351 MrJackdaw-1942
                        --Remove item from group
352 MrJackdaw-1942
                        GroupBox[BackpackSlots[args.Index].Group]:RemoveItem(BackpackSlots[args.Index])
353 MrJackdaw-1942
                        --Make the item for that slot nil
354 MrJackdaw-1942
                        BackpackSlots[args.Index]:SetItem(nil)
355 MrJackdaw-1942
                        BackpackSlots[args.Index].Group=0
356 MrJackdaw-1942
                        --Add it to empty slots.
357 MrJackdaw-1942
                        GroupBox[0]:AddItem(BackpackSlots[args.Index])
358 MrJackdaw-1942
 
359 MrJackdaw-1942
                        --Refesh Heights
360 MrJackdaw-1942
                        SetGroupBoxSize()
361 MrJackdaw-1942
                end
362 MrJackdaw-1942
 
363 131 MrJackdaw-1942
                BagMove=function( sender, args )
364 142 MrJackdaw-1942
                        --15/12/11 This has changed completely! The notes below are now false.
365 147 MrJackdaw-1942
 
366 142 MrJackdaw-1942
                        --Turbine.Shell.WriteLine("BagMove Old Index"..args.OldIndex.." New Index "..args.NewIndex)
367 119 MrJackdaw-1942
                        --[[
368 MrJackdaw-1942
                        1) If an item has just been moved to an empty slot then just this fires.
369 MrJackdaw-1942
                        2) If an item has been swopped with another; Say A in slot n1 with B in slot n2
370 MrJackdaw-1942
                                        ItemRemoved fires on slot n1
371 MrJackdaw-1942
                                        ItemMoved fires with B from n2 to n1
372 MrJackdaw-1942
                                        ItemAdded fires on slot n2 with item A
373 MrJackdaw-1942
 
374 132 MrJackdaw-1942
                        Essentially, item A (the moved item) gets held "in hand" making the target slot empty.
375 MrJackdaw-1942
 
376 MrJackdaw-1942
                        Recently I have come to the belief that it is this that causes the bug, and not ItemRemoved.
377 MrJackdaw-1942
                        ]]
378 119 MrJackdaw-1942
 
379 MrJackdaw-1942
                        --args.Item             =Item object of the item that has been moved.
380 MrJackdaw-1942
                        --args.NewIndex =Target Slot
381 MrJackdaw-1942
                        --args.OldIndex =Destination Slot
382 MrJackdaw-1942
 
383 MrJackdaw-1942
                        BackpackSlots[args.NewIndex],BackpackSlots[args.OldIndex]=BackpackSlots[args.OldIndex],BackpackSlots[args.NewIndex]
384 132 MrJackdaw-1942
 
385 MrJackdaw-1942
                        --Refresh heights
386 MrJackdaw-1942
                        SetGroupBoxSize()
387 MrJackdaw-1942
 
388 119 MrJackdaw-1942
                end
389 MrJackdaw-1942
 
390 148 MrJackdaw-1942
                BagQuantityChanged=function(sender,args)
391 MrJackdaw-1942
                        unhide(sender)
392 MrJackdaw-1942
                end
393 MrJackdaw-1942
 
394 MrJackdaw-1942
        function unhide(item)
395 MrJackdaw-1942
                if not(SB.ShowItem) then return end
396 MrJackdaw-1942
                local destination=ItemGroup[ItemCategory[item:GetCat()]]
397 MrJackdaw-1942
                --Turbine.Shell.WriteLine(item:GetName().." "..destination.." "..Groups[destination].Name)
398 MrJackdaw-1942
 
399 MrJackdaw-1942
                if destination==nil then destination=0 end
400 MrJackdaw-1942
 
401 MrJackdaw-1942
                --Un-Hide this group
402 MrJackdaw-1942
                if Groups[destination].hide then
403 MrJackdaw-1942
                        Groups[destination].hide=false
404 MrJackdaw-1942
                        SetGroupBoxSize()
405 MrJackdaw-1942
                end
406 MrJackdaw-1942
        end
407 MrJackdaw-1942
 
408 MrJackdaw-1942
        AddCallback(backpack, "ItemAdded",                      BagAdd)
409 MrJackdaw-1942
        AddCallback(backpack, "ItemRemoved",            BagRemove)
410 MrJackdaw-1942
        AddCallback(backpack, "ItemMoved",                      BagMove)
411 119 MrJackdaw-1942
 
412 MrJackdaw-1942
--Main Structure; Create the window to hold the backpack slots and populate it.
413 MrJackdaw-1942
 
414 111 MrJackdaw-1942
SortBag = Turbine.UI.Lotro.Window()
415 MrJackdaw-1942
        SortBag:SetPosition( SB.x,SB.y )
416 146 MrJackdaw-1942
        SortBag:SetText("SortBag")
417 104 MrJackdaw-1942
 
418 MrJackdaw-1942
SortBag.ListBox = Turbine.UI.ListBox()
419 111 MrJackdaw-1942
        SortBag.ListBox:SetParent( SortBag )
420 104 MrJackdaw-1942
        SortBag.ListBox:SetPosition( pad.side, pad.top )
421 105 MrJackdaw-1942
        SortBag.ListBox:SetMaxItemsPerLine(2)
422 104 MrJackdaw-1942
        SortBag.ListBox:SetOrientation( Turbine.UI.Orientation.Horizontal )
423 MrJackdaw-1942
 
424 105 MrJackdaw-1942
        SortBag.ScrollBar=Turbine.UI.Lotro.ScrollBar()
425 MrJackdaw-1942
                SortBag.ScrollBar:SetOrientation( Turbine.UI.Orientation.Vertical )
426 MrJackdaw-1942
                SortBag.ListBox:SetVerticalScrollBar( SortBag.ScrollBar )
427 111 MrJackdaw-1942
                SortBag.ScrollBar:SetParent(SortBag)
428 105 MrJackdaw-1942
                SortBag.ScrollBar:SetPosition(SB.labelwidth+SB.icx*36+10,pad.top+5)
429 MrJackdaw-1942
                SortBag.ScrollBar:SetWidth(10)
430 MrJackdaw-1942
 
431 114 MrJackdaw-1942
        --Remove this control when Turbine fix the backpack bug. again.
432 MrJackdaw-1942
        SortBag.Control=Turbine.UI.Control()
433 MrJackdaw-1942
                SortBag.Control:SetParent(SortBag)
434 MrJackdaw-1942
                SortBag.Control:SetMouseVisible(true)
435 MrJackdaw-1942
                SortBag.Control:SetBackground(0x41007e26)
436 MrJackdaw-1942
                SortBag.Control:SetSize(16,16)
437 MrJackdaw-1942
                SortBag.Control:SetPosition(pad.side-15,pad.top-15)
438 MrJackdaw-1942
 
439 MrJackdaw-1942
        SortBag.Control.MouseClick=function()
440 MrJackdaw-1942
                --This was, originally, in Button.lua. And is better there imho.
441 MrJackdaw-1942
                local contextMenu = Turbine.UI.ContextMenu()
442 150 MrJackdaw-1942
                contextMenu.items = contextMenu:GetItems()
443 151 MrJackdaw-1942
 
444 MrJackdaw-1942
                local option2=Turbine.UI.MenuItem("Re-stack the items - WARNING! EXPERIMENTAL!",true)
445 MrJackdaw-1942
                        option2.Click = function () import "JackdawPlugins.SortPack.Stack"      Turbine.Shell.WriteLine("<rgb=#888888>Starting stack")  Stack() end
446 114 MrJackdaw-1942
 
447 150 MrJackdaw-1942
                local option3=Turbine.UI.MenuItem("Override default bags",true,SB.override)
448 MrJackdaw-1942
                        option3.Click = function () SB.override=not(SB.override) SBOverride() end
449 MrJackdaw-1942
 
450 MrJackdaw-1942
                local option4=Turbine.UI.MenuItem("Open the sort order panel",true)
451 MrJackdaw-1942
                        option4.Click = function () import"JackdawPlugins.SortPack.ListOption" ShowListOption() end
452 MrJackdaw-1942
 
453 MrJackdaw-1942
                local option6=Turbine.UI.MenuItem("Create/Edit custom Categories",true)
454 MrJackdaw-1942
                        option6.Click = function () import"JackdawPlugins.SortPack.CustomOption" ShowCustomOption() end
455 MrJackdaw-1942
 
456 MrJackdaw-1942
                local option7=Turbine.UI.MenuItem("Show a group on item gain.",true,SB.ShowItem)
457 MrJackdaw-1942
                        option7.Click = function () SB.ShowItem=not(SB.ShowItem) end
458 MrJackdaw-1942
 
459 MrJackdaw-1942
                local option5 = Turbine.UI.MenuItem("Select SortBag label font;")
460 MrJackdaw-1942
                        contextMenu.SubMenuItems = option5:GetItems()
461 MrJackdaw-1942
                        local suboption5={}
462 MrJackdaw-1942
                        local font={}
463 MrJackdaw-1942
                        j=1
464 MrJackdaw-1942
                        for i in pairs(Turbine.UI.Lotro.Font) do
465 MrJackdaw-1942
                                font[j]=i
466 MrJackdaw-1942
                                j=j+1
467 MrJackdaw-1942
                        end
468 MrJackdaw-1942
                        table.sort(font, function (a,b)
469 MrJackdaw-1942
                                        return (a < b)
470 MrJackdaw-1942
                         end)
471 MrJackdaw-1942
                         for i=1,#font do
472 MrJackdaw-1942
                                suboption5[i] = Turbine.UI.MenuItem(font[i],true,font[i]==SB.font)
473 MrJackdaw-1942
                                suboption5[i].Click = function ()
474 MrJackdaw-1942
                                        SB.font=font[i]
475 MrJackdaw-1942
                                        SB.fontsize=string.sub(SB.font,-2)
476 MrJackdaw-1942
                                        if SB.fontsize=="ed" then SB.fontsize=13-1 else SB.fontsize=tonumber(SB.fontsize)-1 end
477 MrJackdaw-1942
                                        populatebag()
478 MrJackdaw-1942
                                end
479 114 MrJackdaw-1942
 
480 150 MrJackdaw-1942
                                contextMenu.SubMenuItems:Add(suboption5[i])
481 114 MrJackdaw-1942
                        end
482 150 MrJackdaw-1942
 
483 151 MrJackdaw-1942
                contextMenu.items:Add(option2)
484 150 MrJackdaw-1942
                contextMenu.items:Add(option5)
485 MrJackdaw-1942
                contextMenu.items:Add(option3)
486 MrJackdaw-1942
                contextMenu.items:Add(option7)
487 MrJackdaw-1942
                contextMenu.items:Add(option4)
488 MrJackdaw-1942
                contextMenu.items:Add(option6)
489 MrJackdaw-1942
 
490 MrJackdaw-1942
                contextMenu:ShowMenu()
491 MrJackdaw-1942
        end
492 114 MrJackdaw-1942
 
493 104 MrJackdaw-1942
        SortBag.Resize=Turbine.UI.Control()
494 111 MrJackdaw-1942
                SortBag.Resize:SetParent(SortBag)
495 104 MrJackdaw-1942
                SortBag.Resize:SetZOrder(99)
496 MrJackdaw-1942
 
497 MrJackdaw-1942
                SortBag.ResizeBack=Turbine.UI.Control()
498 MrJackdaw-1942
                SortBag.ResizeBack:SetParent(SortBag.Resize)
499 111 MrJackdaw-1942
                SortBag.ResizeBack:SetBackColor(Turbine.UI.Color(0.7,0.3,0.3,1))
500 104 MrJackdaw-1942
                SortBag.ResizeBack:SetVisible(false)
501 MrJackdaw-1942
                SortBag.ResizeBack:SetMouseVisible(false)
502 MrJackdaw-1942
 
503 MrJackdaw-1942
                SortBag.Resize.MouseEnter=function() SortBag.ResizeBack:SetVisible(true) end
504 MrJackdaw-1942
                SortBag.Resize.MouseLeave=function() SortBag.ResizeBack:SetVisible(false)  end
505 MrJackdaw-1942
 
506 MrJackdaw-1942
                SortBag.Resize.MouseDown=function ()
507 MrJackdaw-1942
                        draggingr=true
508 MrJackdaw-1942
                end
509 MrJackdaw-1942
                SortBag.Resize.MouseUp=function ()
510 MrJackdaw-1942
                        draggingr=false
511 MrJackdaw-1942
                end
512 105 MrJackdaw-1942
                SortBag.Resize.MouseMove=function(sender,args)
513 104 MrJackdaw-1942
                        if draggingr then
514 105 MrJackdaw-1942
                                local oldwidth=SB.width
515 151 MrJackdaw-1942
                                SB.width,dummy=SortBag:GetMousePosition()
516 111 MrJackdaw-1942
 
517 105 MrJackdaw-1942
                                if SortBag:IsAltKeyDown() then
518 MrJackdaw-1942
                                        SB.labelwidth=SB.width-oldwidth+SB.labelwidth
519 124 MrJackdaw-1942
                                        if SB.labelwidth<SB.fontsize then SB.labelwidth=SB.fontsize end
520 105 MrJackdaw-1942
                                else
521 MrJackdaw-1942
                                        SB.icx=math.floor((SB.width-2*pad.side-SB.labelwidth)/36)
522 111 MrJackdaw-1942
                                        SB.icy=math.floor((SB.maxheight-(pad.top+pad.bottom))/36)
523 104 MrJackdaw-1942
                                        if SB.icx<3 then SB.icx=3 end
524 MrJackdaw-1942
                                        if SB.icy<1 then SB.icy=1 end
525 105 MrJackdaw-1942
                                end
526 MrJackdaw-1942
                                        SB.width=36*SB.icx+2*pad.side+SB.labelwidth
527 111 MrJackdaw-1942
                                        SortBag:SetSize(SB.width,SB.maxheight)
528 104 MrJackdaw-1942
                        end
529 111 MrJackdaw-1942
                end
530 104 MrJackdaw-1942
 
531 121 MrJackdaw-1942
SortBag.SizeChanged=function()
532 130 MrJackdaw-1942
        SortBagSetSize()
533 MrJackdaw-1942
        SetGroupBoxSize()
534 MrJackdaw-1942
 
535 MrJackdaw-1942
        --Now, if the size of the bag would take the bottom of the bag off the screen, then re-position it.
536 MrJackdaw-1942
        local x,y=SortBag:GetPosition()
537 MrJackdaw-1942
        if y+SortBag:GetHeight()>SB.maxheight then y=SB.maxheight-SortBag:GetHeight() end
538 MrJackdaw-1942
        SortBag:SetPosition(x,y)
539 111 MrJackdaw-1942
end
540 MrJackdaw-1942
 
541 121 MrJackdaw-1942
SortBag:SetSize(SB.width,SB.maxheight)
542 111 MrJackdaw-1942
 
543 MrJackdaw-1942
SortBag.PositionChanged=function()
544 MrJackdaw-1942
        local x,y=SortBag:GetPosition()
545 MrJackdaw-1942
                if x<0 then x=0 end
546 MrJackdaw-1942
                if y<0 then y=0 end
547 MrJackdaw-1942
                SortBag:SetPosition(x,y)
548 MrJackdaw-1942
                SB.x,SB.y=x,y
549 MrJackdaw-1942
end
550 110 MrJackdaw-1942
 
551 119 MrJackdaw-1942
populatebag()
552 110 MrJackdaw-1942
 
553 114 MrJackdaw-1942
SBOverride()

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


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