lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

[/] [trunk/] [JackdawPlugins/] [SortPack/] [Button.lua] - Rev 131

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

--[[This first part is only required because of the turbine bug]]

import "Turbine.UI"
import "Deusdictum.UI.Dragbar"

--Unload/load sortpack
Turbine.PluginManager.UnloadScriptState("SortPack")
Turbine.PluginManager.LoadPlugin("SortPack")


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" )

--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

Plugins["SortPackLoad"].Unload = function( sender, args )
                SortButtonData.X,SortButtonData.Y=SortButton:GetPosition()
                JackdawPlugins.Patch.Save( Turbine.DataScope.Character, "SortPackButton", SortButtonData )
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"] = "Open the Sort Debug window",
                                        ["Command"] = "SortDebug"
                                },
                                [5] = 
                                {
                                        ["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

Go to most recent revision | Compare with Previous | Blame


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


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