lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

[/] [trunk/] [JackdawPlugins/] [SortPack/] [CustomOption.Lua] - Blame information for rev 162

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

Line No. Rev Author Line
1 138 MrJackdaw-1942
--Idea Give the player the ability to re-order the list.
2 MrJackdaw-1942
 
3 MrJackdaw-1942
function ShowCustomOption()
4 146 MrJackdaw-1942
        Height=600
5 MrJackdaw-1942
        Width=600
6 MrJackdaw-1942
        Font=Turbine.UI.Lotro.Font.TrajanPro14
7 138 MrJackdaw-1942
 
8 MrJackdaw-1942
        if CustomOption~=nil then CustomOption.Window:SetVisible(false) CustomOption=nil end
9 MrJackdaw-1942
        if ListOption~=nil then ListOption.Window:SetVisible(false) ListOption=nil end
10 MrJackdaw-1942
 
11 MrJackdaw-1942
        CustomOption={}
12 MrJackdaw-1942
 
13 MrJackdaw-1942
        --Make the window
14 MrJackdaw-1942
        CustomOption.Window = Turbine.UI.Lotro.Window()
15 MrJackdaw-1942
        CustomOption.Window:SetPosition( 100,0 )
16 MrJackdaw-1942
        CustomOption.Window:SetSize(Width,Height)
17 MrJackdaw-1942
 
18 MrJackdaw-1942
        CustomOption.Window:SetText( "Change Custom Categories")
19 MrJackdaw-1942
        CustomOption.Window:SetVisible( true )
20 MrJackdaw-1942
        CustomOption.Window:SetZOrder(1000)
21 MrJackdaw-1942
 
22 MrJackdaw-1942
        CustomOption.Frame={}
23 MrJackdaw-1942
        for i=1,2 do
24 MrJackdaw-1942
                CustomOption.Frame[i]=Frame()
25 MrJackdaw-1942
                CustomOption.Frame[i]:SetParent(CustomOption.Window)
26 MrJackdaw-1942
                CustomOption.Frame[i]:SetSize(Width/2-10,Height-60)
27 MrJackdaw-1942
                CustomOption.Frame[i]:SetTop(40)
28 MrJackdaw-1942
 
29 MrJackdaw-1942
                CustomOption.Frame[i].ScrollBar=Turbine.UI.Lotro.ScrollBar()
30 MrJackdaw-1942
                CustomOption.Frame[i].ScrollBar:SetOrientation( Turbine.UI.Orientation.Vertical )
31 MrJackdaw-1942
 
32 MrJackdaw-1942
                CustomOption.Frame[i].ListBox = Turbine.UI.ListBox()
33 MrJackdaw-1942
                CustomOption.Frame[i].ListBox:SetParent( CustomOption.Frame[i] )
34 MrJackdaw-1942
                CustomOption.Frame[i].ListBox:SetPosition( 10, 2 )
35 MrJackdaw-1942
                CustomOption.Frame[i].ListBox:SetSize( Width/2-20, Height-64)
36 MrJackdaw-1942
                CustomOption.Frame[i].ListBox:SetMaxItemsPerLine(1)
37 MrJackdaw-1942
                CustomOption.Frame[i].ListBox:SetOrientation( Turbine.UI.Orientation.Horizontal )
38 MrJackdaw-1942
                CustomOption.Frame[i].ListBox:SetVerticalScrollBar( CustomOption.Frame[i].ScrollBar )
39 MrJackdaw-1942
                CustomOption.Frame[i].ScrollBar:SetParent(CustomOption.Frame[i])
40 MrJackdaw-1942
                CustomOption.Frame[i].ScrollBar:SetPosition(0,2)
41 MrJackdaw-1942
                CustomOption.Frame[i].ScrollBar:SetHeight(Height-64)
42 MrJackdaw-1942
                CustomOption.Frame[i].ScrollBar:SetWidth(10)
43 MrJackdaw-1942
 
44 MrJackdaw-1942
                CustomOption.Frame[i].MouseEnter=function()
45 MrJackdaw-1942
                        FrameEntered=i
46 MrJackdaw-1942
                end
47 MrJackdaw-1942
        end
48 MrJackdaw-1942
        CustomOption.Frame[1]:SetLeft(10)
49 MrJackdaw-1942
        CustomOption.Frame[2]:SetLeft(Width/2)
50 MrJackdaw-1942
 
51 MrJackdaw-1942
        CustomOption.Resize=Turbine.UI.Control()
52 MrJackdaw-1942
                CustomOption.Resize:SetParent(CustomOption.Window)
53 MrJackdaw-1942
                CustomOption.Resize:SetZOrder(99)
54 MrJackdaw-1942
                CustomOption.Resize:SetSize(Width,10)
55 MrJackdaw-1942
                CustomOption.Resize:SetPosition(0,Height-10)
56 MrJackdaw-1942
 
57 MrJackdaw-1942
                CustomOption.ResizeBack=Turbine.UI.Control()
58 MrJackdaw-1942
                CustomOption.ResizeBack:SetParent(CustomOption.Resize)
59 MrJackdaw-1942
                CustomOption.ResizeBack:SetSize(Width,10)
60 MrJackdaw-1942
                CustomOption.ResizeBack:SetBackColor(Turbine.UI.Color(1,1,1,1))
61 MrJackdaw-1942
                CustomOption.ResizeBack:SetVisible(false)
62 MrJackdaw-1942
                CustomOption.ResizeBack:SetMouseVisible(false)
63 MrJackdaw-1942
 
64 MrJackdaw-1942
                CustomOption.Resize.MouseEnter=function() CustomOption.ResizeBack:SetVisible(true) end
65 MrJackdaw-1942
                CustomOption.Resize.MouseLeave=function() CustomOption.ResizeBack:SetVisible(false)  end
66 MrJackdaw-1942
 
67 MrJackdaw-1942
                CustomOption.Resize.MouseDown=function ()
68 MrJackdaw-1942
                        draggingr=true
69 MrJackdaw-1942
                end
70 MrJackdaw-1942
                CustomOption.Resize.MouseUp=function ()
71 MrJackdaw-1942
                        draggingr=false
72 MrJackdaw-1942
                end
73 MrJackdaw-1942
                CustomOption.Resize.MouseMove=function()
74 MrJackdaw-1942
                        if draggingr then
75 MrJackdaw-1942
                                null,Height=CustomOption.Window:GetMousePosition()      --Change later if I want variable width too.
76 MrJackdaw-1942
                                if Height<300 then Height=300 end
77 MrJackdaw-1942
                                CustomOption.Window:SetSize(Width,Height)
78 MrJackdaw-1942
                                CustomOption.Resize:SetPosition(0,Height-10)
79 MrJackdaw-1942
                                for i=1,2 do
80 MrJackdaw-1942
                                        CustomOption.Frame[i]:SetSize(Width/2-10,Height-60)
81 MrJackdaw-1942
                                        CustomOption.Frame[i].ListBox:SetSize( Width/2-20, Height-64)
82 MrJackdaw-1942
                                        CustomOption.Frame[i].ScrollBar:SetHeight(Height-64)
83 MrJackdaw-1942
                                end
84 MrJackdaw-1942
                                CustomOption.Frame[2]:SetLeft(Width/2)
85 MrJackdaw-1942
                        end
86 MrJackdaw-1942
                end
87 MrJackdaw-1942
 
88 MrJackdaw-1942
        Option=nil Option={}
89 141 MrJackdaw-1942
        CustomLeftList()
90 138 MrJackdaw-1942
 
91 MrJackdaw-1942
        CustomOption.Window.Closed=function()
92 MrJackdaw-1942
                CustomOption=nil
93 MrJackdaw-1942
                DragIcon=nil
94 MrJackdaw-1942
        end
95 MrJackdaw-1942
end
96 MrJackdaw-1942
 
97 141 MrJackdaw-1942
function CustomLeftList()
98 138 MrJackdaw-1942
 
99 MrJackdaw-1942
        CustomOption.Frame[1].ListBox:ClearItems()
100 MrJackdaw-1942
 
101 MrJackdaw-1942
        Option.Categories=nil   Option.Categories={}
102 MrJackdaw-1942
 
103 141 MrJackdaw-1942
        local last=499
104 MrJackdaw-1942
 
105 138 MrJackdaw-1942
        for i=1,1000 do
106 MrJackdaw-1942
                if ItemCategory[i]~=nil then
107 MrJackdaw-1942
                        last=i
108 MrJackdaw-1942
                Option.Categories[i]=Turbine.UI.Control()
109 MrJackdaw-1942
                        Option.Categories[i]:SetSize(Width/2-10,20)
110 MrJackdaw-1942
                Option.Categories[i].Label=Turbine.UI.Label()
111 MrJackdaw-1942
                        Option.Categories[i].Label:SetFont(Font)
112 141 MrJackdaw-1942
                        Option.Categories[i].Label:SetText(i.." "..ItemCategory[i])
113 138 MrJackdaw-1942
                        Option.Categories[i].Label:SetMouseVisible(false)
114 MrJackdaw-1942
                        Option.Categories[i].Label:SetParent(Option.Categories[i])
115 MrJackdaw-1942
                        Option.Categories[i].Label:SetSize(Width/2-10-30,20)
116 MrJackdaw-1942
                        Option.Categories[i].Label:SetMultiline(false)
117 MrJackdaw-1942
 
118 141 MrJackdaw-1942
                        Option.Categories[i].MouseClick=function() CustomLeftList() CustomRightList(i) end
119 138 MrJackdaw-1942
 
120 141 MrJackdaw-1942
                        if i>499 then
121 138 MrJackdaw-1942
                                Option.Categories[i].Icon=Turbine.UI.Control()
122 MrJackdaw-1942
                                Option.Categories[i].Icon:SetParent(Option.Categories[i])
123 MrJackdaw-1942
                                Option.Categories[i].Icon:SetBackground(0x41007e26)
124 MrJackdaw-1942
                                Option.Categories[i].Icon:SetLeft(Width/2-10-30)
125 MrJackdaw-1942
                                Option.Categories[i].Icon:SetSize(16,16)
126 MrJackdaw-1942
                                Option.Categories[i].Icon:SetVisible(true)
127 MrJackdaw-1942
                                Option.Categories[i].Icon.MouseClick=function()
128 MrJackdaw-1942
                                        Turbine.Shell.WriteLine("Deleting Category "..ItemCategory[i])
129 141 MrJackdaw-1942
 
130 MrJackdaw-1942
                                        --Remove from the Groups.
131 MrJackdaw-1942
                                        for k=1,#Groups do
132 MrJackdaw-1942
                                                for l=1,#Groups[k] do
133 MrJackdaw-1942
                                                        if Groups[k][l]==ItemCategory[i] then table.remove(Groups[k],l) end
134 MrJackdaw-1942
                                                end
135 MrJackdaw-1942
                                        end
136 MrJackdaw-1942
 
137 MrJackdaw-1942
                                        --Then delete it.
138 138 MrJackdaw-1942
                                        ItemCategory[i]=nil
139 MrJackdaw-1942
                                        for v in pairs(CustomItem) do
140 MrJackdaw-1942
                                                if CustomItem[v].Cat==i then CustomItem[v]=nil end
141 MrJackdaw-1942
                                        end
142 MrJackdaw-1942
 
143 MrJackdaw-1942
                                        BuildList()
144 141 MrJackdaw-1942
                                        CustomLeftList()
145 138 MrJackdaw-1942
                                        if SortBag~=nil then populatebag() end
146 MrJackdaw-1942
                                end
147 MrJackdaw-1942
                        end
148 MrJackdaw-1942
 
149 MrJackdaw-1942
                        CustomOption.Frame[1].ListBox:AddItem(Option.Categories[i])
150 MrJackdaw-1942
                end
151 MrJackdaw-1942
        end
152 MrJackdaw-1942
 
153 141 MrJackdaw-1942
        if last<500 then last=499 end
154 138 MrJackdaw-1942
 
155 MrJackdaw-1942
        AddCategories=nil AddCategories={}
156 MrJackdaw-1942
                AddCategories=Turbine.UI.Control()
157 MrJackdaw-1942
                AddCategories:SetSize(Width/2-10,20)
158 MrJackdaw-1942
                AddCategories.Icon=Turbine.UI.Control()
159 MrJackdaw-1942
                AddCategories.Icon:SetParent(AddCategories)
160 MrJackdaw-1942
                AddCategories.Icon:SetBackground(0x41007e12)
161 MrJackdaw-1942
                AddCategories.Icon:SetBlendMode( Turbine.UI.BlendMode.Overlay )
162 MrJackdaw-1942
                AddCategories.Icon:SetSize(16,16)
163 MrJackdaw-1942
                AddCategories.Icon:SetMouseVisible(false)
164 MrJackdaw-1942
                AddCategories.Icon:SetOpacity(0.5)
165 MrJackdaw-1942
                AddCategories.TextBox=Turbine.UI.TextBox()
166 MrJackdaw-1942
                AddCategories.TextBox:SetParent(AddCategories)
167 MrJackdaw-1942
                AddCategories.TextBox:SetSize(Width/2-10-32,20)
168 MrJackdaw-1942
                AddCategories.TextBox:SetLeft(16)
169 MrJackdaw-1942
                AddCategories.Apply=Turbine.UI.Control()
170 MrJackdaw-1942
                AddCategories.Apply:SetParent(AddCategories)
171 MrJackdaw-1942
                AddCategories.Apply:SetBackground(0x41007e27)
172 MrJackdaw-1942
                AddCategories.Apply:SetSize(16,16)
173 MrJackdaw-1942
                AddCategories.Apply:SetVisible(false)
174 MrJackdaw-1942
                AddCategories.Apply:SetLeft(Width/2-10-30)
175 MrJackdaw-1942
 
176 MrJackdaw-1942
                AddCategories.Apply.MouseClick=function()
177 MrJackdaw-1942
                        --Add a new Categories
178 MrJackdaw-1942
                        --Step 1: Strip the non-alpha from the name, and make only the first letter uppercase. This is the .Name of the Categories
179 MrJackdaw-1942
                                local str=AddCategories.TextBox:GetText()
180 MrJackdaw-1942
                                local txt=string.gsub(str,"[^%a%s]","")
181 MrJackdaw-1942
                                if str~=txt then Turbine.Shell.WriteLine("Sortpack: Non alphabetical characters have been removed from the name of the new Categories.") end
182 MrJackdaw-1942
                                txt=string.upper(string.sub(txt,1,1))..string.lower(string.sub(txt,2))
183 MrJackdaw-1942
                                if txt==nil or txt=="" then return end
184 MrJackdaw-1942
                        --Step 2: Create a new Category and apply the above!
185 MrJackdaw-1942
                                ItemCategory[last+1]=txt
186 MrJackdaw-1942
                        --Step 3: Refresh the left table.
187 MrJackdaw-1942
                        BuildList()
188 MrJackdaw-1942
                        RepairList()
189 MrJackdaw-1942
                        BuildList()
190 141 MrJackdaw-1942
                        CustomLeftList()
191 138 MrJackdaw-1942
                        if SortBag~=nil then populatebag() end
192 MrJackdaw-1942
                end
193 MrJackdaw-1942
 
194 MrJackdaw-1942
                AddCategories.TextBox.FocusGained=function() AddCategories.Apply:SetVisible(true) end
195 MrJackdaw-1942
                AddCategories.TextBox.FocusLost=function() AddCategories.Apply:SetVisible(false) end
196 MrJackdaw-1942
 
197 MrJackdaw-1942
        CustomOption.Frame[1].ListBox:AddItem(AddCategories)
198 MrJackdaw-1942
end
199 MrJackdaw-1942
 
200 MrJackdaw-1942
 
201 141 MrJackdaw-1942
function CustomRightList(i)
202 138 MrJackdaw-1942
        Option.Categories[i]:SetBackColor(Turbine.UI.Color(1,0,0,0.2))
203 MrJackdaw-1942
        CustomOption.Frame[2].ListBox:ClearItems()
204 MrJackdaw-1942
 
205 MrJackdaw-1942
        Option.Items=nil Option.Items={}
206 MrJackdaw-1942
 
207 MrJackdaw-1942
        for j in orderedPairs(CustomItem) do
208 MrJackdaw-1942
                if CustomItem[j].Cat==i then
209 MrJackdaw-1942
                        Option.Items[j]=Turbine.UI.Label()
210 MrJackdaw-1942
                        Option.Items[j]:SetMultiline(false)
211 MrJackdaw-1942
                        Option.Items[j]:SetSize(Width/2-10,20)
212 MrJackdaw-1942
                        Option.Items[j]:SetFont(Font)
213 MrJackdaw-1942
                        Option.Items[j]:SetText( CustomItem[j].Name)
214 MrJackdaw-1942
 
215 MrJackdaw-1942
                        Option.Items[j].Icon=Turbine.UI.Control()
216 MrJackdaw-1942
                                Option.Items[j].Icon:SetParent(Option.Items[j])
217 MrJackdaw-1942
                                Option.Items[j].Icon:SetBackground(0x41007e26)
218 MrJackdaw-1942
                                Option.Items[j].Icon:SetLeft(Width/2-10-30)
219 MrJackdaw-1942
                                Option.Items[j].Icon:SetSize(16,16)
220 MrJackdaw-1942
                                Option.Items[j].Icon:SetVisible(true)
221 MrJackdaw-1942
                                Option.Items[j].Icon.MouseClick=function()
222 MrJackdaw-1942
                                         CustomItem[j]=nil
223 MrJackdaw-1942
                                        CustomOption.Frame[2].ListBox:RemoveItem(Option.Items[j])
224 MrJackdaw-1942
 
225 MrJackdaw-1942
                                        BuildList()
226 MrJackdaw-1942
                                        if SortBag~=nil then populatebag() end
227 MrJackdaw-1942
                                end
228 MrJackdaw-1942
 
229 MrJackdaw-1942
                        CustomOption.Frame[2].ListBox:AddItem(Option.Items[j])
230 MrJackdaw-1942
                end
231 MrJackdaw-1942
        end
232 MrJackdaw-1942
 
233 MrJackdaw-1942
                local HelpText=Turbine.UI.Label()
234 MrJackdaw-1942
                        HelpText:SetSize(Width/2-30,100)
235 MrJackdaw-1942
                        HelpText:SetFont(Font)
236 MrJackdaw-1942
                        HelpText:SetText( "Drag items here *from your backpack* to add them to the item category; "..ItemCategory[i])
237 MrJackdaw-1942
                        HelpText:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter )
238 MrJackdaw-1942
                        CustomOption.Frame[2].ListBox:AddItem(HelpText)
239 MrJackdaw-1942
 
240 MrJackdaw-1942
 
241 MrJackdaw-1942
        CustomOption.Frame[2].ListBox:SetAllowDrop( true )
242 MrJackdaw-1942
        CustomOption.Frame[2].ListBox.DragDrop = function( sender, args )
243 MrJackdaw-1942
                --This adds the item to that category.
244 MrJackdaw-1942
                --It does this by dropping the shortcut in the last slot  of the backpack and then getting the name from that slot.
245 MrJackdaw-1942
                local shortcut = args.DragDropInfo:GetShortcut();
246 MrJackdaw-1942
                if ( shortcut ~= nil ) then
247 MrJackdaw-1942
 
248 MrJackdaw-1942
                        --There is a time delay in updating the backpack. Using ItemAdded/ItemMoved to watch for the move doesn't work if the item isn't moved. My only choice is to set a time delay instead.
249 MrJackdaw-1942
 
250 MrJackdaw-1942
                        backpack:PerformShortcutDrop( shortcut, size,false)
251 MrJackdaw-1942
 
252 MrJackdaw-1942
                        TempTimer=Turbine.UI.Control()
253 MrJackdaw-1942
 
254 MrJackdaw-1942
                        TempStart= Turbine.Engine.GetGameTime()
255 MrJackdaw-1942
                        TempTimer:SetWantsUpdates(true)
256 MrJackdaw-1942
 
257 MrJackdaw-1942
                        function TempTimer:Update()
258 MrJackdaw-1942
                                local Time = Turbine.Engine.GetGameTime()
259 MrJackdaw-1942
                                local elapsed = Time - TempStart
260 MrJackdaw-1942
 
261 155 MrJackdaw-1942
                                if elapsed>0.4 then
262 138 MrJackdaw-1942
                                        TempTimer:SetWantsUpdates(false)
263 MrJackdaw-1942
 
264 MrJackdaw-1942
                                        local item = backpack:GetItem(size)
265 157 MrJackdaw-1942
                                        local itemInfo=item:GetItemInfo();
266 156 MrJackdaw-1942
                                        local name=itemInfo:GetName()
267 138 MrJackdaw-1942
 
268 MrJackdaw-1942
                                        CustomItem[name]=nil
269 MrJackdaw-1942
                                        CustomItem[name]={}
270 MrJackdaw-1942
                                        CustomItem[name]["Cat"]=i
271 MrJackdaw-1942
                                        CustomItem[name]["Name"]=name
272 MrJackdaw-1942
                                        BuildList()
273 141 MrJackdaw-1942
                                        CustomRightList(i)
274 138 MrJackdaw-1942
                                        if SortBag~=nil then populatebag() end
275 MrJackdaw-1942
                                        TempTimer=nil
276 MrJackdaw-1942
                                end
277 MrJackdaw-1942
                        end
278 MrJackdaw-1942
                end
279 MrJackdaw-1942
        end
280 MrJackdaw-1942
end

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


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