lotrointerface.com
Search Downloads

LoTROInterface SVN SortPack

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

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

--To try - add a slash command to the other apartment that reloads this apartment.                                                                                                              Done, then deleted, because of the next point...
--Then, use the "TestBag" command at the bottom to send a message over if the two items don't match.                                            Can this be done without user intervention? I think not
--What about unloading the plugin? If the other plugin was watching for this it could reload on unload.                                                 A plugin can't unload itself.
--How about a compromise? The plugin reloads on the "inventory" key if, and only if, the player is not in combat.               How would it know if the bag was already open? Nope, this won't work either.

--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, Cover, Label

Count=Turbine.UI.Window()
        Count:SetVisible(true)
        Count:SetPosition(Counter.x,Counter.y)
        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

--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. Does not look for "Item Moved"
Count.Add=function()
        --Turbine.Shell.WriteLine("Count.Add")
        Count.bag=Count.bag+1
        SetLabel()
        BagTest()
end

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

--Tests the bag to see if any "ghost" items have happened.
--Not a perfect test, but it should help!
--Only called when an item is added or strange bugs occur...
function BagTest()
        local n=0
        for i=1,size do
                local item = backpack:GetItem(i)
                if item~=nil then n=n+1 end
        end
        if n==Count.bag then
                Count:SetBackColor( Turbine.UI.Color( 0.3,0,0,0.4 ) )
        else
                Count:SetBackColor( Turbine.UI.Color( 0.3,0.5,0,0 ) )
        end
end

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

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

Go to most recent revision | Compare with Previous | Blame


All times are GMT -5. The time now is 03:07 PM.


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