lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

[/] [trunk/] [JackdawPlugins/] [SortPack/] [Counter.Lua] - Rev 145

Compare with Previous | Blame | View Log

--Adds a small on-screen backpack counter
--No longer tests for accuracy of the count, as this appears to have been fixed.

if Counter==nil then Counter={} end
if Counter.x==nil then Counter.x=100    end
if Counter.y==nil then Counter.y=100    end
if Counter.Scale==nil then Counter.Scale=1 end
if Counter.Show==nil then Counter.Show=true end

--Structure; Window, Cover, Label

Count=Turbine.UI.Window()
        Count:SetVisible(true)
        Count:SetPosition(Counter.x,Counter.y)
        Count:SetMouseVisible(false)
        Count:SetBackColor( Turbine.UI.Color( 0.3,0,0,0.4 ) )

--Initialise bag count
Count.bag=0

for i=1,size do
        local item = backpack:GetItem(i)
        if item~=nil then Count.bag=Count.bag+1 end
end

--Function to set the label text. The hide/show stops an over-writing bug.
function SetLabel()
        Count.label:SetVisible(false)
        if Counter.Remain then
                Count.label:SetText( size-Count.bag )
        else
                Count.label:SetText( Count.bag.."/"..size )
        end
        Count.label:SetVisible(true)
end

--Set the size of the window
function SetCountSize()
        if Counter.Remain then
                Count:SetSize(20*Counter.Scale,14*Counter.Scale)
        else
                Count:SetSize(36*Counter.Scale,14*Counter.Scale)
        end
end

Count.label=Turbine.UI.Label()
        Count.label:SetFont(Turbine.UI.Lotro.Font.TrajanProBold36)
        Count.label:SetMultiline(false)
        Count.label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter )
        Count.label:SetMouseVisible (false)
        Count.label:SetSize(36*36/14,36)
        Count.label:SetParent(Count)
        Count.label:SetStretchMode(1)
        
Count.DragBar = Deusdictum.UI.DragBar( Count,"Count")
Count.DragBar:SetZOrder(9999)

Count.Cover=Turbine.UI.Control()
        Count.Cover:SetParent(Count)
        Count.Cover:SetVisible(false)
        
Count.SizeChanged=function()
        Count.label:SetSize(36*Counter.Scale,14*Counter.Scale)
        Count.Cover:SetSize(Count:GetSize())
        Count.DragBar:Refresh()
        if Counter.Remain then
                Count.label:SetPosition( -8.5*Counter.Scale,0)
        else
                Count.label:SetPosition(0,0)
        end
end
        
--When UI is unlocked then make the cover visible.
        Count.DragEnable=function()
                Count.Cover:SetVisible(true)
        end
        
        Count.DragDisable=function()
                Count.Cover:SetVisible(false)
        end
        
        --Cover events - resize the Button.
        Count.Cover.MouseDown=function(sender,args)
                if ( args.Button == Turbine.UI.MouseButton.Left ) then
                        moving=true
                else
                        Counter.Remain=not(Counter.Remain)
                        if Counter.Remain then
                                Count:SetSize(20*Counter.Scale,14*Counter.Scale)
                        else
                                Count:SetSize(36*Counter.Scale,14*Counter.Scale)
                        end
                        SetLabel()
                end
        end
        
        Count.Cover.MouseUp=function(sender,args)
                moving=false
        end
        
        Count.Cover.MouseMove=function(sender,args)
                        if moving then
                        local x,y=Count.Cover:GetMousePosition()

                        Counter.Scale=y/14
                        if Counter.Scale<1 then Counter.Scale=1 end

                        SetCountSize()
                end
        end

Count.PositionChanged=function()
        Counter.x,Counter.y=Count:GetPosition()
end

--Functions to watch for the addition or subtraction of items.
Count.Add=function(sender,args)
        --Turbine.Shell.WriteLine("Count.Add")
        
        Count.bag=Count.bag+1
        SetLabel()
end

Count.Remove=function(sender,args)
        --Turbine.Shell.WriteLine("Count.Remove")
        Count.bag=Count.bag-1
        SetLabel()
end

Count.Move=function(sender,args)
        --Turbine.Shell.WriteLine("Count.Move")
        
        --I have no faith in this hack but... it is the only way I have found to fix the new turbine behaviour!
        
        local n=0
        for i=1,size do
                local item = backpack:GetItem(i)
                if item~=nil then n=n+1 end
        end
        
        --Turbine.Shell.WriteLine(n.." "..Count.bag)
        
        if Count.bag>n then Count.bag=Count.bag-1 end
        
        SetLabel()
end

AddCallback(backpack, "ItemAdded",              Count.Add)
AddCallback(backpack, "ItemRemoved",    Count.Remove)
AddCallback(backpack, "ItemMoved",              Count.Move)

--Initialise the size, label and back colour.
SetCountSize()
SetLabel()

        --This fixes a very odd bug that has crept in - I have no idea what is causing it, but it is most annoying.
        --The label just doesn't seem to scale properly...
        Count.label:SetSize(36*Counter.Scale,14*Counter.Scale)

Compare with Previous | Blame


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


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