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