--[[This first part is only required because of the turbine bug]]
import "Turbine.UI"
import "Deusdictum.UI.Dragbar"
import "JackdawPlugins.SortPack.OptionPanel"
Plugins["SortPackLoad"].Unload = function( sender, args )
SortButtonData.X,SortButtonData.Y=SortButton:GetPosition()
JackdawPlugins.Patch.Save( Turbine.DataScope.Character, "SortPackButton", SortButtonData )
end
if not pcall(function() import "JackdawPlugins.Patch.Patch" end) then
--Turbine.Shell.WriteLine("Patch not present - default Load and Save used")
JackdawPlugins.Patch={}
function JackdawPlugins.Patch.Load(a,b,c) return Turbine.PluginData.Load(a,b,c) end
function JackdawPlugins.Patch.Save(a,b,c,d) Turbine.PluginData.Save(a,b,c,d) end
end
SortButtonData=JackdawPlugins.Patch.Load( Turbine.DataScope.Character, "SortPackButton")
--[[Here on in is just the normal button code. This could pass pretty much unchanged when the bug is fixed, however, having the button use slash commands is probably a bit over kill, and I would like to put some of the functionality back there instead of having it in the bag]]
--Data for the Button.
if SortButtonData==nil then SortButtonData={} end
if SortButtonData.Scale==nil then SortButtonData.Scale=0.5 end
if SortButtonData.X==nil then SortButtonData.X=100 end
if SortButtonData.Y==nil then SortButtonData.Y=100 end
if SortButtonData.LeftClick==nil then SortButtonData.LeftClick="sort" end
--Create the button.
--Structure is; Window/Quickslot/Icon/Cover
SortButton=Turbine.UI.Window()
SortButton:SetVisible(true)
SortButton.DragBar = Deusdictum.UI.DragBar( SortButton,"Sort")
SortButton.DragBar:SetZOrder(9999)
SortButton:SetPosition(SortButtonData.X,SortButtonData.Y)
SortButton:SetMouseVisible(true)
SortButton.shortcut = Turbine.UI.Lotro.Shortcut();
SortButton.shortcut:SetType(Turbine.UI.Lotro.ShortcutType.Alias);
SortButton.shortcut:SetData("/"..SortButtonData.LeftClick)
SortButton.quickslot=Turbine.UI.Lotro.Quickslot();
SortButton.quickslot:SetParent(SortButton);
SortButton.quickslot:SetShortcut(SortButton.shortcut);
SortButton.quickslot:SetVisible(true);
SortButton.quickslot:SetUseOnRightClick(false)
SortButton.Icon=Turbine.UI.Control()
SortButton.Icon:SetParent(SortButton)
SortButton.Icon:SetVisible(true)
SortButton.Icon:SetSize(32,32)
SortButton.Icon:SetBackground(0x41007ecf)
SortButton.Icon:SetStretchMode(1)
SortButton.Icon:SetMouseVisible(false)
SortButton.Cover=Turbine.UI.Control()
SortButton.Cover:SetParent(SortButton)
SortButton.Cover:SetVisible(false)
SortButton.Cover:SetBackColor(Turbine.UI.Color(0.5,1,1,1))
SortButton.SizeChanged=function()
SortButton.quickslot:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)
SortButton.Icon:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)
SortButton.Cover:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)
end
SortButton:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)
SortButton.DragBar:Refresh()
--When UI is unlocked then make the cover visible.
SortButton.DragEnable=function()
SortButton.Cover:SetVisible(true)
end
SortButton.DragDisable=function()
SortButton.Cover:SetVisible(false)
end
--Cover events - resize the Button.
SortButton.Cover.MouseDown=function(sender,args)
moving=true
end
SortButton.Cover.MouseUp=function(sender,args)
moving=false
end
SortButton.Cover.MouseMove=function(sender,args)
if moving then
local x,y=SortButton.Cover:GetMousePosition()
SortButtonData.Scale=math.max(x,y)/32
if SortButtonData.Scale<0.25 then SortButtonData.Scale=0.25 end
SortButton:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)
SortButton.DragBar:Refresh()
end
end
SortButton.quickslot.MouseDown=function(sender,args)
if ( args.Button == Turbine.UI.MouseButton.Left ) then
Turbine.PluginManager.UnloadScriptState("SortPack")
Turbine.PluginManager.LoadPlugin("SortPack")
else
local contextMenu = Turbine.UI.ContextMenu()
contextMenu.items = contextMenu:GetItems()
local option1 = Turbine.UI.MenuItem("Action on left click..")
local options={
[1] =
{
["Text"] = "Sort the pack",
["Command"] = "sort"
},
[2] =
{
["Text"] = "Open the SortBag",
["Command"] = "openbag"
},
[3] =
{
["Text"] = "Open the Sort Options",
["Command"] = "sortoption"
},
[4] =
{
["Text"] = "Create/Edit custom Categories",
["Command"] = "SortCat"
},
[5] =
{
["Text"] = "Open the Sort Debug window",
["Command"] = "SortDebug"
},
[6] =
{
["Text"] = "Show/Hide Counter",
["Command"] = "SortCounter"
}
}
contextMenu.SubMenuItems = option1:GetItems()
local suboption={}
for i=1,#options do
suboption[i] = Turbine.UI.MenuItem(options[i].Text,true,SortButtonData.LeftClick==options[i].Command)
suboption[i].Click = function ()
SortButtonData.LeftClick=options[i].Command
SortButton.shortcut:SetData("/"..SortButtonData.LeftClick)
SortButton.quickslot:SetShortcut(SortButton.shortcut);
end
contextMenu.SubMenuItems:Add(suboption[i])
end
contextMenu.items:Add(option1)
contextMenu:ShowMenu()
end
end
Turbine.PluginManager.UnloadScriptState("SortPack")
Turbine.PluginManager.LoadPlugin("SortPack")
--This fixes a very odd bug that has crept in - I have no idea what is causing it, but it is most annoying.
--The icon just doesn't seem to scale properly...
SortButton.Icon:SetSize(32*SortButtonData.Scale,32*SortButtonData.Scale)