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