epsilonScript.Messages = {};

-- Hide default hud.
function GM:HUDShouldDraw( name )
	local nodraw = { "CHudHealth", "CHudBattery" };  -- "CHudAmmo", "CHudSecondaryAmmo"
	
	for k, v in pairs( nodraw ) do
		if ( name == v ) then return false end;
	end;
	
	return true;
end;

function GM:HUDDrawTargetID() return false; end;
function GM:DrawDeathNotice( x, y ) return false; end;

-- Intro function.
local StartTime = CurTime();
local IntroFade = 255;
local IntroBlackFade = 255;
local function DrawIntro()
	if ( LocalPlayer().DoneIntro ) then return end;
	
	draw.RoundedBox( 0, 0, 0, ScrW(), ScrH(), Color( 0, 0, 0, IntroBlackFade ) );
	
	draw.DrawTextGlowing( "epsilonScript\nScheme: '" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "'", "IntroFont", ScrW() / 2, ScrH() * .1, Color( 255, 255, 255, 255 - IntroFade ), 1, nil, 6, Color( 255, 255, 255, 255 - IntroFade ) );
	draw.DrawText( "epsilonScript\nScheme: '" .. epsilonScript.Config:Get( "ActiveScheme" ) .. "'", "IntroFont", ScrW() / 2, ScrH() * .1, Color( 0, 0, 0, 255 - IntroFade ), 1 );
	
	if ( CurTime() - StartTime > 1 ) then
		IntroFade = math.Clamp( IntroFade - 80 * FrameTime(), 0, 255 );
	end;
	
	if ( CurTime() - StartTime > 10 ) then
		IntroBlackFade = math.Clamp( IntroBlackFade - 60 * FrameTime(), 0, 255 );
	end;
end;

local function DrawNotify()
	local x = ScrW() - 46;
	local y = 15;
	
	-- Fucken mess.............. ;(
	for k, v in pairs( epsilonScript.Messages ) do
		if ( v.Time + 10 > CurTime() ) then
			local alpha = math.Clamp( ( ( v.Time + 10 ) - CurTime() ) * 255, 0, 255 );
			
			surface.SetFont( "MenuFont2" );
			v.w, v.h = surface.GetTextSize( v.Text );
			
			draw.SimpleTextOutlined( v.Text, "MenuFont2", x - ( v.w / 2 ) + 32, y, Color( 255, 255, 255, alpha ), 1, 1, 2, Color( 0, 0, 0, alpha ) );
			y = y + v.h
		end;
	end;
	
	for k, v in pairs( epsilonScript.Messages ) do
		if ( v.Time + 10 > CurTime() ) then
			return;
		end;
	end;
	
	epsilonScript.Messages = {};
end;

local Doors = {};
local LastDoorUpdate = 0;
usermessage.Hook( "UpdateDoor", function( um )
	local Entity = um:ReadEntity();
	local Name = um:ReadString();
	
	Doors[ Entity ] = { [ "Name" ] = Name };
end );

-- Draw the hud and shit.
local MoneyFade = 0
function GM:HUDPaint()
	self.BaseClass:HUDPaint();
	
	-- Draw the intro.
	DrawIntro();
	
	-- Draw the notify.
	DrawNotify();
	
	if ( !LocalPlayer().DoneIntro ) then return end;
	
	if ( LocalPlayer():Alive() ) then
		local tr = LocalPlayer():EyeTrace( 90 );
		
		if ( LocalPlayer():Armor() <= 0 ) then
		--	if ( LocalPlayer():GetMoney() != nil ) then
		--		draw.SimpleTextOutlined( epsilonScript.Config:Get( "Currency" ) .. LocalPlayer():GetMoney(), "TargetID", 100, 70, Colour_White, 1, 1, 2, Colour_Black );
		--	end;
			
			draw.DrawBar( 10, ScrH() - 20, 200, LocalPlayer():Health() / 100, 12, Color( 205, 50, 50, 255 ), Color( 205, 90, 90, 255 ) );
		else
		--	if ( LocalPlayer():GetMoney() != nil ) then
			--	draw.SimpleTextOutlined( epsilonScript.Config:Get( "Currency" ) .. LocalPlayer():GetMoney(), "TargetID", 100, 70, Colour_White, 1, 1, 2, Colour_Black );
			--end;
			
			draw.DrawBar( 10, ScrH() - 35, 200, LocalPlayer():Health() / 100, 12, Color( 205, 50, 50, 255 ), Color( 205, 90, 90, 255 ) );
		end;
		
		if ( LocalPlayer():Armor() > 0 ) then
			draw.DrawBar( 10, ScrH() - 20, 200, LocalPlayer():Armor() / 100, 12, Color( 50, 50, 250, 255 ), Color( 90, 90, 250, 255 ) );
		end;
		
		if ( tr.Entity:IsValid() ) then
			if ( tr.Entity:IsDoor() ) then
				
				if ( LastDoorUpdate < CurTime() ) then
					LocalPlayer():ConCommand( "eps_updatedoorinfo " .. tr.Entity:EntIndex() );
					LastDoorUpdate = CurTime() + .7;
				end;
				
				if ( Doors[ tr.Entity ] ) then
					if ( tr.Entity:GetClass() == "func_door_rotating" ) then
						draw.SimpleTextOutlined( Doors[ tr.Entity ].Name, "TargetFont", ScrW() / 2, ScrH() / 2 - 30, Colour_Black, 1, 1, 1, Colour_White );
					else
						local ScrPos = ( tr.Entity:EyePos() + Vector( 0, 0, 5 ) - tr.Entity:GetAngles():Right() * 25 ):ToScreen();
						draw.SimpleTextOutlined( Doors[ tr.Entity ].Name, "TargetFont", ScrPos.x, ScrPos.y, Colour_Black, 1, 1, 1, Colour_White );
					end;
				end;
			elseif ( tr.Entity:GetClass() == "eps_item" ) then
				local ScrPos = tr.Entity:EyePos():ToScreen();
				draw.SimpleTextOutlined( tr.Entity:GetNWString( "Name" ), "MenuFont2", ScrPos.x, ScrPos.y, Colour_White, 1, 1, 1, Colour_Black );
			elseif ( tr.Entity:IsPlayer() ) then
				local TargetPos = ( tr.Entity:EyePos() + Vector( 0, 0, 11 ) ):ToScreen();
				local x, y = TargetPos.x, TargetPos.y;
				draw.DrawText( tr.Entity:Name(), "TargetID", x, y - 16, team.GetColor( tr.Entity:Team() ), 1 );
				draw.DrawText( tr.Entity:Title(), "TargetID", x, y, Colour_White, 1 );
			end;
		end;
	end;
end;