lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

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

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

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

All times are GMT -5. The time now is 06:07 PM.


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