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