--Adds a small on-screen backpack counter
--Add to button
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, Label, Icon.
Count=Turbine.UI.Window()
Count:SetVisible(true)
Count:SetPosition(Counter.x,Counter.y)
Count:SetSize(35,14)
Count:SetMouseVisible(false)
--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
Count.label=Turbine.UI.Label()
Count.label:SetBackColor( Turbine.UI.Color( 0.3,0,0,0.4 ) )
Count.label:SetFont(Turbine.UI.Lotro.Font.TrajanProBold36)
Count.label:SetMultiline(false)
Count.label:SetTextAlignment( Turbine.UI.ContentAlignment.MiddleCenter )
if Counter.Remain then
Count.label:SetText( size-Count.bag )
else
Count.label:SetText( Count.bag.."/"..size )
end
Count.label:SetMouseVisible (false)
Count.label:SetSize(35*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(35*Counter.Scale,14*Counter.Scale)
Count.Cover:SetSize(35*Counter.Scale,14*Counter.Scale)
end
Count:SetSize(35*Counter.Scale,14*Counter.Scale)
Count.DragBar:Refresh()
--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.label:SetText( size-Count.bag )
else
Count.label:SetText( Count.bag.."/"..size )
end
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=x/35
if Counter.Scale<1 then Counter.Scale=1 end
Count:SetSize(35*Counter.Scale,14*Counter.Scale)
Count.DragBar:Refresh()
end
end
Count.PositionChanged=function()
Counter.x,Counter.y=Count:GetPosition()
end
Count.Add=function()
Count.bag=Count.bag+1
if Counter.Remain then
Count.label:SetText( size-Count.bag )
else
Count.label:SetText( Count.bag.."/"..size )
end
end
Count.Remove=function()
Count.bag=Count.bag-1
if Counter.Remain then
Count.label:SetText( size-Count.bag )
else
Count.label:SetText( Count.bag.."/"..size )
end
end
AddCallback(backpack, "ItemAdded", Count.Add)
AddCallback(backpack, "ItemRemoved", Count.Remove)