--Data for the Button.
if SortButtonData==nil then
SortButtonData={X=100,Y=100,Scale=0.5}
else
SortButtonData.X,SortButtonData.Y,SortButtonData.Scale,SortButtonData.Hide=SortButtonData[1],SortButtonData[2],SortButtonData[3],SortButtonData[4]
end
SortButton={}
SortButton.Window=Turbine.UI.Window()
SortButton.Window:SetVisible(true)
SortButton.Window.DragBar = Deusdictum.UI.DragBar( SortButton.Window,"Sort")
SortButton.Window:SetPosition(SortButtonData.X,SortButtonData.Y)
SortButton.Window:SetSize(32,32)
SortButton.Window:SetOpacity(1)
SortButton.Window:SetMouseVisible(true)
SortButton.Window:SetBackground(0x41007ecf)
SortButton.Window:SetStretchMode(1)
SortButton.Window:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)
SortButton.Window:SetVisible(not(SortButtonData.Hide))
function SortButton.Window:GetWidth()
return 32*SortButtonData.Scale
end
function SortButton.Window:GetHeight()
return 32*SortButtonData.Scale
end
function SortButton.Window:GetSize()
return 32*SortButtonData.Scale ,32*SortButtonData.Scale
end
SortButton.Window.DragBar:Refresh()
SortButton.Window.MouseDown=function(sender,args)
if SortButton.Window.DragBar:IsVisible() then
moving=true
else
if ( args.Button == Turbine.UI.MouseButton.Left ) then
if SB.LeftClick~="bag" then
Sort()
else
if SortBag:IsVisible() then SortBag:Close() else openbag() end
end
else
--Context menu
local contextMenu = Turbine.UI.ContextMenu()
contextMenu.items = contextMenu:GetItems()
local option1 = Turbine.UI.MenuItem("On left click..")
contextMenu.SubMenuItems = option1:GetItems()
local suboption1={}
suboption1[1] = Turbine.UI.MenuItem("Sort the pack",true,SB.LeftClick~="bag")
suboption1[1].Click = function () SB.LeftClick="sort" end
contextMenu.SubMenuItems:Add(suboption1[1])
suboption1[2] = Turbine.UI.MenuItem("Open the SortBag",true,SB.LeftClick=="bag")
suboption1[2].Click = function () SB.LeftClick="bag" end
contextMenu.SubMenuItems:Add(suboption1[2])
local txt
if SB.LeftClick~="bag" then txt="Open the SortBag" else txt="Sort the backpack" end
local option2=Turbine.UI.MenuItem(txt,true)
option2.Click = function () if SB.LeftClick=="bag" then Sort() else openbag() end end
local option3=Turbine.UI.MenuItem("Override default bags",true,SB.override)
option3.Click = function () SB.override=not(SB.override) SBOverride() end
local option4=Turbine.UI.MenuItem("Open the sort order panel",true)
option4.Click = function () import"JackdawPlugins.SortPack.ListOption" ShowListOption() end
local option5 = Turbine.UI.MenuItem("Select SortBag label font;")
contextMenu.SubMenuItems = option5:GetItems()
local suboption5={}
local font={}
j=1
for i in pairs(Turbine.UI.Lotro.Font) do
font[j]=i
j=j+1
end
table.sort(font, function (a,b)
return (a < b)
end)
for i=1,#font do
suboption5[i] = Turbine.UI.MenuItem(font[i],true,font[i]==SB.font)
suboption5[i].Click = function ()
SB.font=font[i]
SB.fontsize=string.sub(SB.font,-2)
if SB.fontsize=="ed" then SB.fontsize=13 else SB.fontsize=tonumber(SB.fontsize) end
if SortBag:IsVisible() then openbag() end
end
contextMenu.SubMenuItems:Add(suboption5[i])
end
contextMenu.items:Add(option1)
contextMenu.items:Add(option5)
contextMenu.items:Add(option3)
contextMenu.items:Add(option2)
contextMenu.items:Add(option4)
--Experimental functions attempt to fix the lost item bug
if Experiment~=nil then
local option6=Turbine.UI.MenuItem("Experiment",true)
option6.Click = function () Experiment() end
contextMenu.items:Add(option6)
end
contextMenu:ShowMenu()
end
end
end
SortButton.Window.MouseUp=function(sender,args)
moving=false
end
SortButton.Window.MouseMove=function(sender,args)
if moving then
local x,y=SortButton.Window:GetMousePosition()
SortButtonData.Scale=math.max(x,y)/32
if SortButtonData.Scale<0.25 then SortButtonData.Scale=0.25 end
SortButton.Window:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)
SortButton.Window.DragBar:Refresh()
end
end