lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

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

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


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