lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

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

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

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

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


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