lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

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

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

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

All times are GMT -5. The time now is 05:57 PM.


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