lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

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

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

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


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