//=============================================================================
// ChallengeCTFHUD.
//=============================================================================
class ChallengeCTFHUD expands ChallengeTeamHUD;

// Blue
#exec TEXTURE IMPORT NAME=I_BCapt FILE=TEXTURES\HUD\i_bcapt.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_BDown FILE=TEXTURES\HUD\i_bdown.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_BHome FILE=TEXTURES\HUD\i_bhome.PCX GROUP="Icons" MIPS=OFF

// Red
#exec TEXTURE IMPORT NAME=I_RCapt FILE=TEXTURES\HUD\i_rcapt.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_RDown FILE=TEXTURES\HUD\i_rdown.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_RHome FILE=TEXTURES\HUD\i_rhome.PCX GROUP="Icons" MIPS=OFF

// Yellow
#exec TEXTURE IMPORT NAME=I_YCapt FILE=TEXTURES\HUD\i_ycapt.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_YDown FILE=TEXTURES\HUD\i_ydown.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_YHome FILE=TEXTURES\HUD\i_yhome.PCX GROUP="Icons" MIPS=OFF

// Green
#exec TEXTURE IMPORT NAME=I_GCapt FILE=TEXTURES\HUD\i_gcapt.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_GDown FILE=TEXTURES\HUD\i_gdown.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=I_GHome FILE=TEXTURES\HUD\i_ghome.PCX GROUP="Icons" MIPS=OFF

var bool TakeHome;
var float TakeHomeBlink;

simulated function Tick(float DeltaTime)
{
	Super.Tick(DeltaTime);

	TakeHomeBlink += DeltaTime;
	if (TakeHomeBlink >= 0.5)
	{
		TakeHome = !TakeHome;
		TakeHomeBlink = 0.0;
	}
}

simulated function PostRender( canvas Canvas )
{
	local CTFFlag Flag;
	local int X, Y, i;
	
	Super.PostRender( Canvas );		
	
	if ((PlayerPawn(Owner).bShowMenu) || (PlayerPawn(Owner).bShowScores))
		return;

	X = Canvas.ClipX - 32;
	Y = Canvas.ClipY - 128;
		
	for ( i=0; i<4; i++ )
	{
		Flag = CTFReplicationInfo(PlayerPawn(Owner).GameReplicationInfo).FlagList[i];
		if ( Flag != None )
			switch ( Flag.Team )
			{
				case 0:
					if ( Flag.bHome )
						DrawCTFIcon(Canvas, X, Y, texture'I_RHome');
					else if ( Flag.bHeld )
						DrawCTFIcon(Canvas, X, Y, texture'I_RCapt');
					else
						DrawCTFIcon(Canvas, X, Y, texture'I_RDown');
					break;
				case 1:
					if ( Flag.bHome )
						DrawCTFIcon(Canvas, X, Y, texture'I_BHome');
					else if ( Flag.bHeld )
						DrawCTFIcon(Canvas, X, Y, texture'I_BCapt');
					else
						DrawCTFIcon(Canvas, X, Y, texture'I_BDown');
					break;
				case 2:
					if ( Flag.bHome )
						DrawCTFIcon(Canvas, X, Y, texture'I_YHome');
					else if ( Flag.bHeld )
						DrawCTFIcon(Canvas, X, Y, texture'I_YCapt');
					else
						DrawCTFIcon(Canvas, X, Y, texture'I_YDown');
					break;
				case 3:
					if ( Flag.bHome )
						DrawCTFIcon(Canvas, X, Y, texture'I_GHome');
					else if ( Flag.bHeld )
						DrawCTFIcon(Canvas, X, Y, texture'I_GCapt');
					else
						DrawCTFIcon(Canvas, X, Y, texture'I_GDown');
					break;
			}
		Y -= 32;
	}
	DrawCaptureCounts(Canvas);

	Canvas.DrawColor.R = 255;
	Canvas.DrawColor.G = 255;
	Canvas.DrawColor.B = 0;
	Canvas.bCenter = true;

	for ( i=0; i<4; i++ )
	{
		Flag = CTFReplicationInfo(PlayerPawn(Owner).GameReplicationInfo).FlagList[i];
		if ( (Flag != None) && (Flag.Holder == Owner) && TakeHome )
		{
			Canvas.Font = Font'WhiteFont';
			Canvas.SetPos(4, Canvas.ClipY - 16);
			Canvas.DrawText("You have the flag, take it home!", true);
		}
	}

	Canvas.DrawColor.R = 255;
	Canvas.DrawColor.G = 255;
	Canvas.DrawColor.B = 255;
	Canvas.bCenter = false;
}

simulated function DrawCTFIcon(Canvas Canvas, int X, int Y, texture CTFTexture)
{ 
	Canvas.SetPos(X,Y);
	Canvas.DrawIcon(CTFTexture, 1.0);	
}

simulated function DrawCaptureCounts(Canvas Canvas)
{
	local float XL, YL;
	local CTFReplicationInfo CTFRI;

	foreach AllActors(class'CTFReplicationInfo', CTFRI)
	{
		Canvas.Font = Canvas.LargeFont;
		Canvas.StrLen(CTFRI.Team0Score, XL, YL);
		Canvas.SetPos(Canvas.ClipX - 32 - XL, Canvas.ClipY - 128);
		Canvas.DrawText(CTFRI.Team0Score, false);
		Canvas.StrLen(CTFRI.Team1Score, XL, YL);
		Canvas.SetPos(Canvas.ClipX - 32 - XL, Canvas.ClipY - 160);
		Canvas.DrawText(CTFRI.Team1Score, false);
	}
}

defaultproperties
{
     HudMode=0
}
