//=============================================================================
// ChallengeTeamHUD
//=============================================================================
class ChallengeTeamHUD expands ChallengeHUD;

#exec TEXTURE IMPORT NAME=BlueSkull FILE=..\UNREALSHARE\TEXTURES\HUD\i_skullb.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=GreenSkull FILE=..\UNREALSHARE\TEXTURES\HUD\i_skullg.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=RedSkull FILE=..\UNREALSHARE\TEXTURES\HUD\i_skullr.PCX GROUP="Icons" MIPS=OFF
#exec TEXTURE IMPORT NAME=YellowSkull FILE=..\UNREALSHARE\TEXTURES\HUD\i_skully.PCX GROUP="Icons" MIPS=OFF

var localized string[32] IdentifyAssault;
var localized string[32] ChatChannel;
var localized string[32] TeamChannel;

simulated function DrawFragCount(Canvas Canvas, int X, int Y)
{
	local texture SkullTexture;

	SkullTexture = texture'IconSkull';

	if ( Pawn(Owner).PlayerReplicationInfo.TeamName ~= "red" )
		SkullTexture = texture'RedSkull';
	else if ( Pawn(Owner).PlayerReplicationInfo.TeamName ~= "blue" )
		SkullTexture = texture'BlueSkull';
	else if ( Pawn(Owner).PlayerReplicationInfo.TeamName ~= "green" )
		SkullTexture = texture'GreenSkull';
	else if ( Pawn(Owner).PlayerReplicationInfo.TeamName ~= "gold" )
		SkullTexture = texture'YellowSkull';

	DrawSkull(Canvas, X, Y, SkullTexture);
}

function DrawSkull(Canvas Canvas, int X, int Y, texture SkullTexture)
{ 
	Canvas.SetPos(X,Y);
	Canvas.DrawIcon(SkullTexture, 1.0);	
	Canvas.CurX -= 19;
	Canvas.CurY += 23;
	Canvas.Font = Font'TinyWhiteFont';	
	if (Pawn(Owner).PlayerReplicationInfo.Score<100) Canvas.CurX+=6;
	if (Pawn(Owner).PlayerReplicationInfo.Score<10) Canvas.CurX+=6;	
	if (Pawn(Owner).PlayerReplicationInfo.Score<0) Canvas.CurX-=6;
	Canvas.DrawText(int(Pawn(Owner).PlayerReplicationInfo.Score),False);
}

simulated function bool DisplayMessages( canvas Canvas )
{
	local string[255] TypingPrompt;
	local float XL, YL, XOffset;
	local int I, J, CriticalCount;
	local int ExtraSpace;
	local float PickupColor;
	local string[128] ShortMessages[4], ShortNames[4], ShortZones[4], ShortCallsigns[4], ChannelName;
	local name ShortTypes[4];
	local byte ShortTeams[4];
	local console Console;
	local inventory Inv;

	Console = PlayerPawn(Owner).Player.Console;

	Canvas.Font = HUDFont;

	if (!Console.Viewport.Actor.bShowMenu)
		DrawTypingPrompt( Canvas, Console );

	if ( Console.TextLines > 0 && (!Console.Viewport.Actor.bShowMenu || Console.Viewport.Actor.bShowScores) )
	{
		if ( Console.GetMsgType(Console.TopLine) == 'Pickup' ) {
			Canvas.bCenter = true;
			Canvas.Style = 3;
			PickupColor = 255 * ( square(Console.GetMsgTick(Console.TopLine)) / (3.0 * Console.GetMsgTick(Console.TopLine)) );
			Canvas.DrawColor.r = PickupColor;
			Canvas.DrawColor.g = PickupColor;
			Canvas.DrawColor.b = PickupColor;
			Canvas.SetPos(4, Console.FrameY - 44);
			Canvas.DrawText( Console.GetMsgText(Console.TopLine), true );
			Canvas.bCenter = false;
			Canvas.Style = 1;
			J = Console.TopLine - 1;
		} else if ( Console.GetMsgType(Console.TopLine) == 'CriticalEvent') {
			Canvas.DrawColor.r = 0;
			Canvas.DrawColor.g = 128;
			Canvas.DrawColor.b = 255;
			Canvas.bCenter = true;
			Canvas.SetPos(0, Console.FrameY/2 - 32);
			Canvas.DrawText( Console.GetMsgText(Console.TopLine), true );
			Canvas.bCenter = false;
			J = Console.TopLine - 1;
		} else {
			J = Console.TopLine;
		}
		I = 0;
		while ((I < 4) && (J >= 0))
		{
			if ((Console.GetMsgText(J) != "") && (Console.GetMsgTick(J) > 0.0))
			{
				if ((Console.GetMsgType(J) == 'Event') || (Console.GetMsgType(J) == 'DeathMessage'))
				{
					ShortTypes[I] = Console.GetMsgType(J);
					ShortNames[I] = "";
					ShortTeams[I] = 255;
					ShortMessages[I] = Console.GetMsgText(J);
					I++;
				} else if ((Console.GetMsgType(J) == 'Say') || (Console.GetMsgType(J) == 'TeamSay')) {
					ShortTypes[I] = Console.GetMsgType(J);
					ShortTeams[I] = Console.GetMsgTeam(J);
					ShortCallsigns[I] = Class'ChallengeOrdersMenu'.static.GetCallSigns(Console.GetMsgTeamID(J));
					ShortNames[I] = Console.GetMsgPlayer(J);
					ShortZones[I] = Console.GetMsgZone(J);
					ShortMessages[I] = Console.GetMsgText(J);
					I++;
				}
			}
			J--;
		}
		J = 0;
		Canvas.Font = HUDFont;
		for ( I = 0; I < 4; I++ )
		{
			XOffset = 0;

			if ((HUDMode == 0) || (HUDMode == 1))
				for( Inv=Owner.Inventory; Inv!=None; Inv=Inv.Inventory ) 
					if (Inv.bIsAnArmor) 
						XOffset += 32;

			if (HUDMode == 0)
				for( Inv=Owner.Inventory; Inv!=None; Inv=Inv.Inventory )
					if (Inv.bIsAnArmor)
					{
						XOffset += 3 * 16;
						break;
					}		

			if (ShortMessages[3 - I] != "")
			{
				if ((ShortTypes[3 - I] != 'Say') && (ShortTypes[3 - I] != 'TeamSay'))
				{
					if (ShortTypes[3 - I] == 'DeathMessage')
					{
						Canvas.DrawColor.r = 200;
						Canvas.DrawColor.g = 0;
						Canvas.DrawColor.b = 0;	
						Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
						Canvas.StrLen( ShortMessages[3 - I], XL, YL );
						Canvas.DrawText( ShortMessages[3 - I], false );
					} else {
						Canvas.DrawColor.r = 200;
						Canvas.DrawColor.g = 200;
						Canvas.DrawColor.b = 200;	
						Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
						Canvas.StrLen( ShortMessages[3 - I], XL, YL );
						Canvas.DrawText( ShortMessages[3 - I], false );
					}
				} else {
					if (ShortTypes[3 - I] == 'TeamSay')
						ChannelName = TeamChannel;
					else
						ChannelName = ChatChannel;

					// Sample:
					// (CHAT) [Leader] GreenMarine: This is a test.
					// (TEAM) [Leader] GreenMarine (Under Red Base): This is a test.

					switch (ShortTeams[3 - I])
					{
						case 0:
							Canvas.DrawColor.r = 0;
							Canvas.DrawColor.g = 255;
							Canvas.DrawColor.b = 0;	
							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( ChannelName, XL, YL );
							XOffset += XL;
							Canvas.DrawText( ChannelName, false );

							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( "["$ShortCallsigns[3-I]$"] ", XL, YL );
							XOffset += XL;
							Canvas.DrawText( "["$ShortCallsigns[3-I]$"] ", false );

							Canvas.DrawColor.r = 255;
							Canvas.DrawColor.g = 0;
							Canvas.DrawColor.b = 0;
							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( ShortNames[3 - I], XL, YL );
							XOffset += XL;
							Canvas.DrawText( ShortNames[3 - I], false );

							if (ChannelName == TeamChannel)
							{
								Canvas.DrawColor.r = 0;
								Canvas.DrawColor.g = 255;
								Canvas.DrawColor.b = 0;
								Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
								Canvas.StrLen( " ("$ShortZones[3 - I]$")", XL, YL );
								XOffset += XL;
								Canvas.DrawText( " ("$ShortZones[3 - I]$")", false );
							}

							Canvas.DrawColor.r = 0;
							Canvas.DrawColor.g = 160;
							Canvas.DrawColor.b = 0;	
							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( ShortMessages[3 - I], XL, YL );
							Canvas.DrawText( ": "$ShortMessages[3 - I], false );
							break;
						case 1:
							Canvas.DrawColor.r = 0;
							Canvas.DrawColor.g = 255;
							Canvas.DrawColor.b = 0;	
							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( ChannelName, XL, YL );
							XOffset += XL;
							Canvas.DrawText( ChannelName, false );

							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( "["$ShortCallsigns[3-I]$"]", XL, YL );
							XOffset += XL;
							Canvas.DrawText( "["$ShortCallsigns[3-I]$"]", false );

							Canvas.DrawColor.r = 0;
							Canvas.DrawColor.g = 128;
							Canvas.DrawColor.b = 255;	
							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( ShortNames[3 - I], XL, YL );
							XOffset += XL;
							Canvas.DrawText( ShortNames[3 - I], false );

							if (ChannelName == TeamChannel)
							{
								Canvas.DrawColor.r = 0;
								Canvas.DrawColor.g = 255;
								Canvas.DrawColor.b = 0;
								Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
								Canvas.StrLen( " ("$ShortZones[3 - I]$")", XL, YL );
								XOffset += XL;
								Canvas.DrawText( " ("$ShortZones[3 - I]$")", false );
							}

							Canvas.DrawColor.r = 0;
							Canvas.DrawColor.g = 160;
							Canvas.DrawColor.b = 0;	
							Canvas.SetPos(4 + XOffset, 2 + (10 * J) + (10 * ExtraSpace));
							Canvas.StrLen( ShortMessages[3 - I], XL, YL );
							Canvas.DrawText( ": "$ShortMessages[3 - I], false );
							break;
					}
				}
				if ( YL == 18.0 )
					ExtraSpace++;
				J++;
			}
		}
	}		

	Canvas.DrawColor.r = 255;
	Canvas.DrawColor.g = 255;
	Canvas.DrawColor.b = 255;

	return true;
}

simulated function bool TraceIdentify(canvas Canvas)
{
	local float XL, YL, XOffset;
	local actor Other;
	local vector HitLocation, HitNormal, X, Y, Z, StartTrace, EndTrace;

	StartTrace = Owner.Location;
	StartTrace.Z += Pawn(Owner).BaseEyeHeight;

	EndTrace = StartTrace + vector(Pawn(Owner).ViewRotation) * 1000.0;

	Other = Trace(HitLocation, HitNormal, EndTrace, StartTrace, true);

	if ((Pawn(Other) != None) && 
	    ((Pawn(Other).bIsPlayer) || (Pawn(Other).IsA('FortStandard'))) )
	{
		IdentifyTarget = Pawn(Other);
		IdentifyFadeTime = 3.0;
	}

	if ( IdentifyFadeTime == 0.0 )
		return false;

	if (IdentifyTarget == None)
		return false;

	if ( IdentifyTarget.IsA('FortStandard') )
	{
		Canvas.Font = HUDFont;
		Canvas.DrawColor.R = 255 * (IdentifyFadeTime / 3.0);
		Canvas.DrawColor.G = 0;
		Canvas.DrawColor.B = 0;

		XOffset = 0.0;
		Canvas.StrLen(IdentifyAssault, XL, YL);
		XOffset = Canvas.ClipX/2 - XL/2;
		Canvas.SetPos(XOffset, Canvas.ClipY - 74);
		Canvas.DrawText(IdentifyAssault);

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

	if ( (!IdentifyTarget.bIsPlayer) || (IdentifyTarget.bHidden) ||
		 (IdentifyTarget.PlayerReplicationInfo == None) )
		return false;

	return true;
}

simulated function DrawIdentifyInfo(canvas Canvas, float PosX, float PosY)
{
	local float XL, YL, XOffset;
	local string[128] Callsign;

	if (!TraceIdentify(Canvas))
		return;

	Canvas.Font = HUDFont;
	Canvas.Style = 3;

	XOffset = 0.0;
	Canvas.StrLen(IdentifyName$": "$IdentifyTarget.PlayerReplicationInfo.PlayerName, XL, YL);
	XOffset = Canvas.ClipX/2 - XL/2;
	Canvas.SetPos(XOffset, Canvas.ClipY - 74);

	if(IdentifyTarget.PlayerReplicationInfo.PlayerName != "")
	{
		if (IdentifyTarget.PlayerReplicationInfo.Team == 0)
			SetTeam0Color2(Canvas);
		else
			SetTeam1Color2(Canvas);

		Canvas.StrLen(IdentifyName$": ", XL, YL);
		XOffset += XL;
		Canvas.DrawText(IdentifyName$": ");
		Canvas.SetPos(XOffset, Canvas.ClipY - 74);

		if (IdentifyTarget.PlayerReplicationInfo.Team == 0)
			SetTeam0Color1(Canvas);
		else
			SetTeam1Color1(Canvas);

		Canvas.StrLen(IdentifyTarget.PlayerReplicationInfo.PlayerName, XL, YL);
		Canvas.DrawText(IdentifyTarget.PlayerReplicationInfo.PlayerName);
	}

	XOffset = 0.0;
	Callsign = Class'ChallengeOrdersMenu'.static.GetCallSigns(IdentifyTarget.PlayerReplicationInfo.TeamID);
	Canvas.StrLen(IdentifyCallsign$": "$Callsign, XL, YL);
	XOffset = Canvas.ClipX/2 - XL/2;
	Canvas.SetPos(XOffset, Canvas.ClipY - 64);

	if(Callsign != "")
	{
		if (IdentifyTarget.PlayerReplicationInfo.Team == 0)
			SetTeam0Color2(Canvas);
		else
			SetTeam1Color2(Canvas);

		Canvas.StrLen(IdentifyCallsign$": ", XL, YL);
		XOffset += XL;
		Canvas.DrawText(IdentifyCallsign$": ");
		Canvas.SetPos(XOffset, Canvas.ClipY - 64);

		if (IdentifyTarget.PlayerReplicationInfo.Team == 0)
			SetTeam0Color1(Canvas);
		else
			SetTeam1Color1(Canvas);

		Canvas.StrLen(Callsign, XL, YL);
		Canvas.DrawText(Callsign);
	}

	XOffset = 0.0;
	Canvas.StrLen(IdentifyHealth$": "$IdentifyTarget.Health, XL, YL);
	XOffset = Canvas.ClipX/2 - XL/2;
	Canvas.SetPos(XOffset, Canvas.ClipY - 54);

	if(Pawn(Owner).PlayerReplicationInfo.Team == IdentifyTarget.PlayerReplicationInfo.Team)
	{
		if (IdentifyTarget.PlayerReplicationInfo.Team == 0)
			SetTeam0Color2(Canvas);
		else
			SetTeam1Color2(Canvas);

		Canvas.StrLen(IdentifyHealth$": ", XL, YL);
		XOffset += XL;
		Canvas.DrawText(IdentifyHealth$": ");
		Canvas.SetPos(XOffset, Canvas.ClipY - 54);

		if (IdentifyTarget.PlayerReplicationInfo.Team == 0)
			SetTeam0Color1(Canvas);
		else
			SetTeam1Color1(Canvas);

		Canvas.StrLen(IdentifyTarget.Health, XL, YL);
		Canvas.DrawText(IdentifyTarget.Health);
	}

	Canvas.Style = 1;
	Canvas.DrawColor.R = 255;
	Canvas.DrawColor.G = 255;
	Canvas.DrawColor.B = 255;
}

defaultproperties
{
	 IdentifyAssault=" !! Assault Target !! "
	 ChatChannel="(CHAT) "
	 TeamChannel="(TEAM) "
}
