lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

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

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  "JackdawPlugins.SortPack.JContextMenu"
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.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.Window:GetPosition()
                JackdawPlugins.Patch.Save( Turbine.DataScope.Character, "SortPackButton", SortButtonData )
end

--[[After here, it is standard code. When the bug is fixed roll the above into the Load.Lua]]

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))
        SortButton.Window:SetZOrder(0)
                
        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 SortButtonData.LeftClick~="bag" then
                                        Sort()
                                else
                                        if SortBag:IsVisible() then SortBag:Close() else        openbag() end
                                end
                        else]]
                                        
                                context=JContextMenu()
                                context:SetVisible(true)
                        --      if SortButtonData.LeftClick=="sort" then
                                        context:AddItem(JClabel("Show backpack","/openbag"))
                                --      context:AddItem(JClabel("Left click; Open SortBag","/sorttoggle"))
                        --      end
                        --      if SortButtonData.LeftClick=="bag" then
                                        context:AddItem(JClabel("Sort the backpack","/sort"))
                                --      context:AddItem(JClabel("Left Click; Sort backpack","/sorttoggle"))
                                --end

                                context:AddItem(JClabel("Show sort options","/sortoption"))
                        
                                --[[
                                --Context menu - old style. Restore this when the time comes.
                                --A lot of this is moved to bag.lua
                                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)
                                                                
                                contextMenu:ShowMenu()]]
                        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
        

Go to most recent revision | Compare with Previous | Blame


All times are GMT -5. The time now is 08:39 AM.


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