--Idea Give the player the ability to re-order the list.
function ShowListOption()
Height=600
Width=600
Font=Turbine.UI.Lotro.Font.TrajanPro16
if CustomOption~=nil then CustomOption.Window:SetVisible(false) CustomOption=nil end
if ListOption~=nil then ListOption.Window:SetVisible(false) ListOption=nil end
ListOption={}
--Make the window
ListOption.Window = Turbine.UI.Lotro.Window()
ListOption.Window:SetPosition( 100,0 )
ListOption.Window:SetSize(Width,Height)
ListOption.Window:SetText( "Change Sort Order")
ListOption.Window:SetVisible( true )
ListOption.Window:SetZOrder(1000)
ListOption.Frame={}
for i=1,2 do
ListOption.Frame[i]=Frame()
ListOption.Frame[i]:SetParent(ListOption.Window)
ListOption.Frame[i]:SetSize(Width/2-10,Height-60)
ListOption.Frame[i]:SetTop(40)
ListOption.Frame[i].ScrollBar=Turbine.UI.Lotro.ScrollBar()
ListOption.Frame[i].ScrollBar:SetOrientation( Turbine.UI.Orientation.Vertical )
ListOption.Frame[i].ListBox = Turbine.UI.ListBox()
ListOption.Frame[i].ListBox:SetParent( ListOption.Frame[i] )
ListOption.Frame[i].ListBox:SetPosition( 10, 2 )
ListOption.Frame[i].ListBox:SetSize( Width/2-20, Height-64)
ListOption.Frame[i].ListBox:SetMaxItemsPerLine(1)
ListOption.Frame[i].ListBox:SetOrientation( Turbine.UI.Orientation.Horizontal )
ListOption.Frame[i].ListBox:SetVerticalScrollBar( ListOption.Frame[i].ScrollBar )
ListOption.Frame[i].ScrollBar:SetParent(ListOption.Frame[i])
ListOption.Frame[i].ScrollBar:SetPosition(0,2)
ListOption.Frame[i].ScrollBar:SetHeight(Height-64)
ListOption.Frame[i].ScrollBar:SetWidth(10)
ListOption.Frame[i].MouseEnter=function()
FrameEntered=i
end
end
ListOption.Frame[1]:SetLeft(10)
ListOption.Frame[2]:SetLeft(Width/2)
ListOption.Resize=Turbine.UI.Control()
ListOption.Resize:SetParent(ListOption.Window)
ListOption.Resize:SetZOrder(99)
ListOption.Resize:SetSize(Width,10)
ListOption.Resize:SetPosition(0,Height-10)
ListOption.ResizeBack=Turbine.UI.Control()
ListOption.ResizeBack:SetParent(ListOption.Resize)
ListOption.ResizeBack:SetSize(Width,10)
ListOption.ResizeBack:SetBackColor(Turbine.UI.Color(1,1,1,1))
ListOption.ResizeBack:SetVisible(false)
ListOption.ResizeBack:SetMouseVisible(false)
ListOption.Resize.MouseEnter=function() ListOption.ResizeBack:SetVisible(true) end
ListOption.Resize.MouseLeave=function() ListOption.ResizeBack:SetVisible(false) end
ListOption.Resize.MouseDown=function ()
draggingr=true
end
ListOption.Resize.MouseUp=function ()
draggingr=false
end
ListOption.Resize.MouseMove=function()
if draggingr then
null,Height=ListOption.Window:GetMousePosition() --Change later if I want variable width too.
if Height<300 then Height=300 end
ListOption.Window:SetSize(Width,Height)
ListOption.Resize:SetPosition(0,Height-10)
for i=1,2 do
ListOption.Frame[i]:SetSize(Width/2-10,Height-60)
ListOption.Frame[i].ListBox:SetSize( Width/2-20, Height-64)
ListOption.Frame[i].ScrollBar:SetHeight(Height-64)
end
ListOption.Frame[2]:SetLeft(Width/2)
end
end
Option=nil Option={}
LeftList()
DragIcon={}
DragIcon=Turbine.UI.Control()
DragIcon.Window=Turbine.UI.Window()
DragIcon.Window:SetVisible(false)
DragIcon.Window:SetSize(150,12)
DragIcon.Window:SetOpacity(0.8)
DragIcon.Window:SetMouseVisible(false)
DragIcon.Icon=Turbine.UI.Control()
DragIcon.Icon:SetParent(DragIcon.Window)
DragIcon.Icon:SetSize(32,32)
DragIcon.Icon:SetBackground(0x41007ecf)
DragIcon.Icon:SetStretchMode(1)
DragIcon.Icon:SetSize(12,12)
DragIcon.Icon:SetMouseVisible(false)
DragIcon.Label=Turbine.UI.Label()
DragIcon.Label:SetParent(DragIcon.Window)
DragIcon.Label:SetPosition(12,0)
DragIcon.Label:SetSize(140,12)
DragIcon.Label:SetText("label!")
DragIcon.Label:SetMouseVisible(false)
function DragIcon:Update()
local x,y=Turbine.UI.Display.GetMousePosition()
DragIcon.Window:SetPosition(x+10,y)
DragIcon.Window:SetZOrder(9999)
end
ListOption.Window.Closed=function()
ListOption=nil
DragIcon=nil
end
end
function LeftList()
ListOption.Frame[1].ListBox:ClearItems()
Option.Groups=nil Option.Groups={}
for i=1,#Groups do-- in pairs(Groups) do
Option.Groups[i]=Turbine.UI.Control()
Option.Groups[i]:SetSize(Width/2-10,20)
Option.Groups[i].Label=Turbine.UI.Label()
Option.Groups[i].Label:SetFont(Font)
Option.Groups[i].Label:SetText(Groups[i].Name)
Option.Groups[i].Label:SetMouseVisible(false)
Option.Groups[i].Label:SetParent(Option.Groups[i])
Option.Groups[i].Label:SetSize(Width/2-10-30,20)
Option.Groups[i].Icon=Turbine.UI.Control()
Option.Groups[i].Icon:SetParent(Option.Groups[i])
Option.Groups[i].Icon:SetBackground(0x41007e26)
Option.Groups[i].Icon:SetLeft(Width/2-10-30)
Option.Groups[i].Icon:SetSize(16,16)
Option.Groups[i].Icon:SetVisible(#Groups[i]==0)
Option.Groups[i].Icon.MouseClick=function()
Turbine.Shell.WriteLine("Deleting group "..Groups[i].Name)
table.remove(Groups,i)
BuildList()
LeftList()
end
ListOption.Frame[1].ListBox:AddItem(Option.Groups[i])
--Dragging event for group i
--The Drag events do not seem to be firing for these controls so... Replace this when they are fixed.
Option.Groups[i].MouseDown=function(sender,args)
ldragging=i
ldraggedout=nil --Needed to detect just a "click" instead of a drag.
ldraggedin=nil
DragIcon.Window:SetVisible(true)
DragIcon.Label:SetText(Groups[i].Name)
DragIcon:SetWantsUpdates(true)
end
Option.Groups[i].MouseLeave=function(sender,args)
ldraggedout=true
end
Option.Groups[i].MouseEnter=function(sender,args)
ldraggedin=i
ldraggedout=false
end
Option.Groups[i].MouseUp=function(sender,args)
DragIcon.Window:SetVisible(false)
DragIcon:SetWantsUpdates(false)
--if ldraggedout then return end
if ldragging==nil then return end
if ldraggedout==nil then
--Not dragged, just clicked.
RightList(i)
end
if ldraggedin~=nil then
if FrameEntered==1 then
--Left to left drag - changing group order
--Dragging has taken place! Long range insert
RightList(ldragging)
local temp=Groups[ldragging]
table.remove(Groups,ldragging)
table.insert(Groups,ldraggedin,temp)
BuildList()
end
end
ldragging=nil
ldraggedout=nil
ldraggedin=nil
ldragfromgroup=nil
LeftList()
end
end
AddGroup=nil AddGroup={}
AddGroup=Turbine.UI.Control()
AddGroup:SetSize(Width/2-10,20)
AddGroup.Icon=Turbine.UI.Control()
AddGroup.Icon:SetParent(AddGroup)
AddGroup.Icon:SetBackground(0x41007e12)
AddGroup.Icon:SetBlendMode( Turbine.UI.BlendMode.Overlay )
AddGroup.Icon:SetSize(16,16)
AddGroup.Icon:SetMouseVisible(false)
AddGroup.Icon:SetOpacity(0.5)
AddGroup.TextBox=Turbine.UI.TextBox()
AddGroup.TextBox:SetParent(AddGroup)
AddGroup.TextBox:SetSize(Width/2-10-32,20)
AddGroup.TextBox:SetLeft(16)
AddGroup.Apply=Turbine.UI.Control()
AddGroup.Apply:SetParent(AddGroup)
AddGroup.Apply:SetBackground(0x41007e27)
AddGroup.Apply:SetSize(16,16)
AddGroup.Apply:SetVisible(false)
AddGroup.Apply:SetLeft(Width/2-10-30)
AddGroup.Apply.MouseClick=function()
--Add a new group
--Step 1: Strip the non-alpha from the name, and make only the first letter uppercase. This is the .Name of the group
local str=AddGroup.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 group.") 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 group and apply the above!
Groups[#Groups+1]={}
Groups[#Groups].Name=txt
--Step 3: Refresh the left table.
BuildList()
LeftList()
end
AddGroup.TextBox.FocusGained=function() AddGroup.Apply:SetVisible(true) end
AddGroup.TextBox.FocusLost=function() AddGroup.Apply:SetVisible(false) end
ListOption.Frame[1].ListBox:AddItem(AddGroup)
if SortBag~=nil then populatebag() end
end
function RightList(i)
ListOption.Frame[2].ListBox:ClearItems()
Option.Items=nil Option.Items={}
for j=1,#Groups[i] do
Option.Items[j]=Turbine.UI.Label()
Option.Items[j]:SetSize(Width/2-10,20)
Option.Items[j]:SetFont(Font)
Option.Items[j]:SetText(Groups[i][j])
ListOption.Frame[2].ListBox:AddItem(Option.Items[j])
--Dragging event for item i,j
--The Drag events do not seem to be firing for these controls so... Replace this when they are fixed.
Option.Items[j].MouseDown=function(sender,args)
rdragging=j
rdragfromgroup=i
rdraggedout=nil
rdraggedin=nil
DragIcon.Window:SetVisible(true)
DragIcon.Label:SetText(Groups[i][j])
DragIcon:SetWantsUpdates(true)
end
Option.Items[j].MouseLeave=function(sender,args)
rdraggedout=true
end
Option.Items[j].MouseEnter=function(sender,args)
rdraggedin=j
rdraggedout=false
end
Option.Items[j].MouseUp=function(sender,args)
DragIcon.Window:SetVisible(false)
DragIcon:SetWantsUpdates(false)
if FrameEntered==2 then
--Right to right drag performed
if rdraggedout then return end
if rdragging==nil then return end
if rdraggedout==nil then
--Not dragged out ;Do nothing!
end
if rdraggedin~=nil then
--Dragging has taken place! Long range insert. Note: only accepts drags from right to right.
local temp=Groups[i][rdragging]
table.remove(Groups[i],rdragging)
table.insert(Groups[i],rdraggedin,temp)
BuildList()
end
else
--If we land here we have done a right-to-left drag.
local temp=Groups[rdragfromgroup][rdragging]
table.remove(Groups[rdragfromgroup],rdragging)
table.insert(Groups[ldraggedin],temp)
BuildList()
end
rdragging=nil
rdraggedout=nil
rdraggedin=nil
rdragfromgroup=nil
RightList(i)
LeftList()
end
end
end