--Idea Give the player the ability to re-order the list.
function ShowCustomOption()
Height=600
Width=600
Font=Turbine.UI.Lotro.Font.TrajanPro14
if CustomOption~=nil then CustomOption.Window:SetVisible(false) CustomOption=nil end
if ListOption~=nil then ListOption.Window:SetVisible(false) ListOption=nil end
CustomOption={}
--Make the window
CustomOption.Window = Turbine.UI.Lotro.Window()
CustomOption.Window:SetPosition( 100,0 )
CustomOption.Window:SetSize(Width,Height)
CustomOption.Window:SetText( "Change Custom Categories")
CustomOption.Window:SetVisible( true )
CustomOption.Window:SetZOrder(1000)
CustomOption.Frame={}
for i=1,2 do
CustomOption.Frame[i]=Frame()
CustomOption.Frame[i]:SetParent(CustomOption.Window)
CustomOption.Frame[i]:SetSize(Width/2-10,Height-60)
CustomOption.Frame[i]:SetTop(40)
CustomOption.Frame[i].ScrollBar=Turbine.UI.Lotro.ScrollBar()
CustomOption.Frame[i].ScrollBar:SetOrientation( Turbine.UI.Orientation.Vertical )
CustomOption.Frame[i].ListBox = Turbine.UI.ListBox()
CustomOption.Frame[i].ListBox:SetParent( CustomOption.Frame[i] )
CustomOption.Frame[i].ListBox:SetPosition( 10, 2 )
CustomOption.Frame[i].ListBox:SetSize( Width/2-20, Height-64)
CustomOption.Frame[i].ListBox:SetMaxItemsPerLine(1)
CustomOption.Frame[i].ListBox:SetOrientation( Turbine.UI.Orientation.Horizontal )
CustomOption.Frame[i].ListBox:SetVerticalScrollBar( CustomOption.Frame[i].ScrollBar )
CustomOption.Frame[i].ScrollBar:SetParent(CustomOption.Frame[i])
CustomOption.Frame[i].ScrollBar:SetPosition(0,2)
CustomOption.Frame[i].ScrollBar:SetHeight(Height-64)
CustomOption.Frame[i].ScrollBar:SetWidth(10)
CustomOption.Frame[i].MouseEnter=function()
FrameEntered=i
end
end
CustomOption.Frame[1]:SetLeft(10)
CustomOption.Frame[2]:SetLeft(Width/2)
CustomOption.Resize=Turbine.UI.Control()
CustomOption.Resize:SetParent(CustomOption.Window)
CustomOption.Resize:SetZOrder(99)
CustomOption.Resize:SetSize(Width,10)
CustomOption.Resize:SetPosition(0,Height-10)
CustomOption.ResizeBack=Turbine.UI.Control()
CustomOption.ResizeBack:SetParent(CustomOption.Resize)
CustomOption.ResizeBack:SetSize(Width,10)
CustomOption.ResizeBack:SetBackColor(Turbine.UI.Color(1,1,1,1))
CustomOption.ResizeBack:SetVisible(false)
CustomOption.ResizeBack:SetMouseVisible(false)
CustomOption.Resize.MouseEnter=function() CustomOption.ResizeBack:SetVisible(true) end
CustomOption.Resize.MouseLeave=function() CustomOption.ResizeBack:SetVisible(false) end
CustomOption.Resize.MouseDown=function ()
draggingr=true
end
CustomOption.Resize.MouseUp=function ()
draggingr=false
end
CustomOption.Resize.MouseMove=function()
if draggingr then
null,Height=CustomOption.Window:GetMousePosition() --Change later if I want variable width too.
if Height<300 then Height=300 end
CustomOption.Window:SetSize(Width,Height)
CustomOption.Resize:SetPosition(0,Height-10)
for i=1,2 do
CustomOption.Frame[i]:SetSize(Width/2-10,Height-60)
CustomOption.Frame[i].ListBox:SetSize( Width/2-20, Height-64)
CustomOption.Frame[i].ScrollBar:SetHeight(Height-64)
end
CustomOption.Frame[2]:SetLeft(Width/2)
end
end
Option=nil Option={}
CustomLeftList()
CustomOption.Window.Closed=function()
CustomOption=nil
DragIcon=nil
end
end
function CustomLeftList()
CustomOption.Frame[1].ListBox:ClearItems()
Option.Categories=nil Option.Categories={}
local last=499
for i=1,1000 do
if ItemCategory[i]~=nil then
last=i
Option.Categories[i]=Turbine.UI.Control()
Option.Categories[i]:SetSize(Width/2-10,20)
Option.Categories[i].Label=Turbine.UI.Label()
Option.Categories[i].Label:SetFont(Font)
Option.Categories[i].Label:SetText(i.." "..ItemCategory[i])
Option.Categories[i].Label:SetMouseVisible(false)
Option.Categories[i].Label:SetParent(Option.Categories[i])
Option.Categories[i].Label:SetSize(Width/2-10-30,20)
Option.Categories[i].Label:SetMultiline(false)
Option.Categories[i].MouseClick=function() CustomLeftList() CustomRightList(i) end
if i>499 then
Option.Categories[i].Icon=Turbine.UI.Control()
Option.Categories[i].Icon:SetParent(Option.Categories[i])
Option.Categories[i].Icon:SetBackground(0x41007e26)
Option.Categories[i].Icon:SetLeft(Width/2-10-30)
Option.Categories[i].Icon:SetSize(16,16)
Option.Categories[i].Icon:SetVisible(true)
Option.Categories[i].Icon.MouseClick=function()
Turbine.Shell.WriteLine("Deleting Category "..ItemCategory[i])
--Remove from the Groups.
for k=1,#Groups do
for l=1,#Groups[k] do
if Groups[k][l]==ItemCategory[i] then table.remove(Groups[k],l) end
end
end
--Then delete it.
ItemCategory[i]=nil
for v in pairs(CustomItem) do
if CustomItem[v].Cat==i then CustomItem[v]=nil end
end
BuildList()
CustomLeftList()
if SortBag~=nil then populatebag() end
end
end
CustomOption.Frame[1].ListBox:AddItem(Option.Categories[i])
end
end
if last<500 then last=499 end
AddCategories=nil AddCategories={}
AddCategories=Turbine.UI.Control()
AddCategories:SetSize(Width/2-10,20)
AddCategories.Icon=Turbine.UI.Control()
AddCategories.Icon:SetParent(AddCategories)
AddCategories.Icon:SetBackground(0x41007e12)
AddCategories.Icon:SetBlendMode( Turbine.UI.BlendMode.Overlay )
AddCategories.Icon:SetSize(16,16)
AddCategories.Icon:SetMouseVisible(false)
AddCategories.Icon:SetOpacity(0.5)
AddCategories.TextBox=Turbine.UI.TextBox()
AddCategories.TextBox:SetParent(AddCategories)
AddCategories.TextBox:SetSize(Width/2-10-32,20)
AddCategories.TextBox:SetLeft(16)
AddCategories.Apply=Turbine.UI.Control()
AddCategories.Apply:SetParent(AddCategories)
AddCategories.Apply:SetBackground(0x41007e27)
AddCategories.Apply:SetSize(16,16)
AddCategories.Apply:SetVisible(false)
AddCategories.Apply:SetLeft(Width/2-10-30)
AddCategories.Apply.MouseClick=function()
--Add a new Categories
--Step 1: Strip the non-alpha from the name, and make only the first letter uppercase. This is the .Name of the Categories
local str=AddCategories.TextBox:GetText()
local txt=string.gsub(str,"[^%a%s]","")
if str~=txt then Turbine.Shell.WriteLine("Sortpack: Non alphabetical characters have been removed from the name of the new Categories.") end
txt=string.upper(string.sub(txt,1,1))..string.lower(string.sub(txt,2))
if txt==nil or txt=="" then return end
--Step 2: Create a new Category and apply the above!
ItemCategory[last+1]=txt
--Step 3: Refresh the left table.
BuildList()
RepairList()
BuildList()
CustomLeftList()
if SortBag~=nil then populatebag() end
end
AddCategories.TextBox.FocusGained=function() AddCategories.Apply:SetVisible(true) end
AddCategories.TextBox.FocusLost=function() AddCategories.Apply:SetVisible(false) end
CustomOption.Frame[1].ListBox:AddItem(AddCategories)
end
function CustomRightList(i)
Option.Categories[i]:SetBackColor(Turbine.UI.Color(1,0,0,0.2))
CustomOption.Frame[2].ListBox:ClearItems()
Option.Items=nil Option.Items={}
for j in orderedPairs(CustomItem) do
if CustomItem[j].Cat==i then
Option.Items[j]=Turbine.UI.Label()
Option.Items[j]:SetMultiline(false)
Option.Items[j]:SetSize(Width/2-10,20)
Option.Items[j]:SetFont(Font)
Option.Items[j]:SetText( CustomItem[j].Name)
Option.Items[j].Icon=Turbine.UI.Control()
Option.Items[j].Icon:SetParent(Option.Items[j])
Option.Items[j].Icon:SetBackground(0x41007e26)
Option.Items[j].Icon:SetLeft(Width/2-10-30)
Option.Items[j].Icon:SetSize(16,16)
Option.Items[j].Icon:SetVisible(true)
Option.Items[j].Icon.MouseClick=function()
CustomItem[j]=nil
CustomOption.Frame[2].ListBox:RemoveItem(Option.Items[j])
BuildList()
if SortBag~=nil then populatebag() end
end
CustomOption.Frame[2].ListBox:AddItem(Option.Items[j])
end
end
local HelpText=Turbine.UI.Label()
HelpText:SetSize(Width/2-30,100)
HelpText:SetFont(Font)
HelpText:SetText( "Drag items here *from your backpack* to add them to the item category; "..ItemCategory[i])
HelpText:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter )
CustomOption.Frame[2].ListBox:AddItem(HelpText)
CustomOption.Frame[2].ListBox:SetAllowDrop( true )
CustomOption.Frame[2].ListBox.DragDrop = function( sender, args )
--This adds the item to that category.
--It does this by dropping the shortcut in the last slot of the backpack and then getting the name from that slot.
local shortcut = args.DragDropInfo:GetShortcut();
if ( shortcut ~= nil ) then
--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.
backpack:PerformShortcutDrop( shortcut, size,false)
TempTimer=Turbine.UI.Control()
TempStart= Turbine.Engine.GetGameTime()
TempTimer:SetWantsUpdates(true)
function TempTimer:Update()
local Time = Turbine.Engine.GetGameTime()
local elapsed = Time - TempStart
if elapsed>0.2 then
TempTimer:SetWantsUpdates(false)
local item = backpack:GetItem(size)
local name=item:GetName()
CustomItem[name]=nil
CustomItem[name]={}
CustomItem[name]["Cat"]=i
CustomItem[name]["Name"]=name
BuildList()
CustomRightList(i)
if SortBag~=nil then populatebag() end
TempTimer=nil
end
end
end
end
end