

surface.CreateFont( "coolvetica", 24, 500, true, false, "GModWorldtip" )

local Tips = {}

local TipColor = Color( 250, 250, 200, 255 )

//
// Adds a hint to the queue
//
function AddWorldTip( index, text, length, pos, ent )

	Tips[ index ] = Tips[ index ] or {}
	
	Tips[ index ].dietime 	= CurTime() + length
	Tips[ index ].text 		= text
	Tips[ index ].pos 		= pos
	Tips[ index ].ent 		= ent
	
end


local function DrawWorldTip( tip )

	if ( tip.ent && tip.ent != NULL ) then	
		tip.pos = tip.ent:GetPos()
	end
	
	local alpha = math.Clamp( ((tip.dietime - CurTime()) / 0.1), 0, 1 )
	
	local pos = tip.pos:ToScreen()
	
	local black = Color( 0, 0, 0, 255*alpha )
	local tipcol = Color( TipColor.r, TipColor.g, TipColor.b, 255*alpha )
	
	local x = 0
	local y = 0
	local padding = 10
	local offset = 50
	
	surface.SetFont( "GModWorldtip" )
	local w, h = surface.GetTextSize( tip.text )
	
	x = pos.x - w 
	y = pos.y - h 
	
	x = x - offset
	y = y - offset

	draw.RoundedBox( 8, x-padding-2, y-padding-2, w+padding*2+4, h+padding*2+4, black )
	
	
	local verts = {}
	verts[1] = { x=x+w/1.5-2, y=y+h+2 }
	verts[2] = { x=x+w+2, y=y+h/2-1 }
	verts[3] = { x=pos.x-offset/2+2, y=pos.y-offset/2+2 }
	
	draw.NoTexture()
	surface.SetDrawColor( 0, 0, 0, tipcol.a )
	surface.DrawPoly( verts )
	
	
	draw.RoundedBox( 8, x-padding, y-padding, w+padding*2, h+padding*2, tipcol )
	
	local verts = {}
	verts[1] = { x=x+w/1.5, y=y+h }
	verts[2] = { x=x+w, y=y+h/2 }
	verts[3] = { x=pos.x-offset/2, y=pos.y-offset/2 }
	
	draw.NoTexture()
	surface.SetDrawColor( tipcol.r, tipcol.g, tipcol.b, tipcol.a )
	surface.DrawPoly( verts )
	
	
	draw.DrawText( tip.text, "GModWorldtip", x + w/2, y, black, TEXT_ALIGN_CENTER )

end


function GM:PaintWorldTips()

	for k, v in pairs( Tips ) do
	
		if ( v.dietime < CurTime() ) then
		
			Tips[k] = nil
		
		else
		
			DrawWorldTip( v )		
		
		end
		
	end

end
