
class BRUTScoreBoard extends TournamentScoreBoard;

//Tile imports
#exec TEXTURE IMPORT NAME=SBHeader FILE=Textures\SBHeader.bmp Group=HUD MIPS=ON
#exec TEXTURE IMPORT NAME=VictoryTile FILE=Textures\VictoryTile.bmp Group=HUD MIPS=ON

//Custom fonts
#exec OBJ LOAD FILE=Textures\UTBRFonts.utx PACKAGE=BRUT

var localized string VictoryGoal;
var color BRYellow, BRRed;

//Added to plug in the scoreboard header
function ShowScores(canvas Canvas)
{
   local PlayerReplicationInfo PRI;
   local int PlayerCount, i;
   local float XL, YL, Scale;
   local float YOffset, YStart;
   local font CanvasFont;

   Canvas.Style = ERenderStyle.STY_Normal;

   Canvas.SetPos(0, 0);
   DrawHeader(Canvas);

   for (i=0; i<ArrayCount(Ordered); i++)
      Ordered[i] = None;
   for (i=0; i<32; i++)
   {
      if (PlayerPawn(Owner).GameReplicationInfo.PRIArray[i] != None)
      {
         PRI = PlayerPawn(Owner).GameReplicationInfo.PRIArray[i];
         if (!PRI.bIsSpectator || PRI.bWaitingPlayer)
         {
            Ordered[PlayerCount] = PRI;
            PlayerCount++;
            if (PlayerCount == ArrayCount(Ordered))
               break;
         }
      }
   }
   SortScores(PlayerCount);
    
   CanvasFont = Canvas.Font;
   Canvas.Font = MyFonts.GetBigFont(Canvas.ClipX);
   Canvas.SetPos(0, 200.0/768.0 * Canvas.ClipY);
   Canvas.StrLen("TEST", XL, YL);
   YStart = Canvas.CurY;
   YOffset = YStart;
   if (PlayerCount > 15)
      PlayerCount = FMin(PlayerCount, (Canvas.ClipY - YStart)/YL - 1);

   Canvas.SetPos(0, 0);
   for (I=0; I<PlayerCount; I++)
   {
      YOffset = YStart + I * YL;
      DrawNameAndPing(Canvas, Ordered[I], 0, YOffset, false);
   }
   Canvas.DrawColor = WhiteColor;
   Canvas.Font = CanvasFont;

   if (!Level.bLowRes)
   {
      Canvas.Font = MyFonts.GetSmallFont(Canvas.ClipX);
      DrawTrailer(Canvas);
   }
   Canvas.DrawColor = WhiteColor;
   Canvas.Font = CanvasFont;

	//added
   DrawF2background(Canvas);
}

function DrawNameAndPing(Canvas Canvas, PlayerReplicationInfo PRI, float XOffset, float YOffset, bool bCompressed)
{
   local float XL, YL, XL2;
   local Font CanvasFont;

   if (PRI.bAdmin)
      Canvas.DrawColor = WhiteColor;
	else
      Canvas.DrawColor = BRYellow;

   Canvas.SetPos((Canvas.ClipX / 6) * 1.5, YOffset * 1.3); //added some padding (1.3) because of custom font size

	if (PRI.Score < 1)
	{
   	Canvas.Font = Font'BPtypewriteStrikethrough';
   	Canvas.DrawColor = BRRed;
   }
   else
   	Canvas.Font = Font'BPtypewrite';
   
   if (!PRI.bIsABot) //show players/bots/admin in the scoreboard
   {
   	if (PRI.bAdmin)
   		Canvas.DrawText(PRI.PlayerName@ "(ADMIN)", False);
   	else
   		Canvas.DrawText(PRI.PlayerName, False);
   }
   else
   	Canvas.DrawText(PRI.PlayerName @ "(bot)", False);

   Canvas.StrLen("0000", XL, YL);
	Canvas.Font = Font'BPtypewrite';
   if (PRI.Score < 1)
   {
   	Canvas.DrawColor = BRRed;
     	Canvas.StrLen(int(PRI.Score), XL2, YL);
    	Canvas.SetPos((Canvas.ClipX / 9) * 6 + XL/2 - XL2, YOffset * 1.3);
    	Canvas.DrawText("DEAD");
   }
   else
   {
      Canvas.DrawColor = BRYellow;
    	Canvas.StrLen(int(PRI.Score), XL2, YL);
    	Canvas.SetPos((Canvas.ClipX / 9) * 6 + XL/2 - XL2, YOffset * 1.3);
    	Canvas.DrawText("ALIVE");
   }
}

simulated function DrawF2background(Canvas Canvas)
{
   local float XL, YL, DrawScale;

	Canvas.Style = ERenderStyle.STY_Translucent;

	XL = Canvas.ClipX * 0.5;
	YL = Canvas.ClipY * 0.07;

	if (Canvas.ClipX < 1024)
		DrawScale = Canvas.ClipX / 1024;
	else
		DrawScale = 1;

	Canvas.SetPos(XL - (DrawScale * 512) , YL - (DrawScale * 256));
	Canvas.DrawTile(Texture'SBHeader', DrawScale * 1024, DrawScale * 512, 0, 0,1024,512);

   XL = Canvas.ClipX * 0.5;
	YL = Canvas.ClipY * 0.8;
	if (Canvas.ClipX < 1024)
		DrawScale = Canvas.ClipX / 1024;
	else
		DrawScale = 0.6;

	Canvas.SetPos(XL - (DrawScale * 512) , YL - (DrawScale * 256));
}

function DrawHeader(canvas Canvas)
{
	//Removed the game ended comments, it was crowding the scoreboard
}

function DrawVictoryConditions(Canvas Canvas)
{
	//draw function unused so it's nulled out
}

function DrawTrailer(canvas Canvas)
{
   local int Hours, Minutes, Seconds;
   local float XL, YL;
   local PlayerPawn PlayerOwner;

   Canvas.bCenter = true;
   Canvas.StrLen("Test", XL, YL);
   Canvas.DrawColor = WhiteColor;
   PlayerOwner = PlayerPawn(Owner);
   Canvas.SetPos(0, Canvas.ClipY - 2 * YL);
   if ((Level.NetMode == NM_Standalone) && Level.Game.IsA('DeathMatchPlus'))
   {
      if (DeathMatchPlus(Level.Game).bRatedGame)
         Canvas.DrawText(DeathMatchPlus(Level.Game).RatedGameLadderObj.SkillText@PlayerOwner.GameReplicationInfo.GameName@MapTitle@MapTitleQuote$Level.Title$MapTitleQuote, true);
      else if (DeathMatchPlus(Level.Game).bNoviceMode)
         Canvas.DrawText(class'ChallengeBotInfo'.default.Skills[Level.Game.Difficulty]@PlayerOwner.GameReplicationInfo.GameName@MapTitle@MapTitleQuote$Level.Title$MapTitleQuote, true);
      else
         Canvas.DrawText(class'ChallengeBotInfo'.default.Skills[Level.Game.Difficulty + 4]@PlayerOwner.GameReplicationInfo.GameName@MapTitle@MapTitleQuote$Level.Title$MapTitleQuote, true);
   }
   else
      Canvas.DrawText(PlayerOwner.GameReplicationInfo.GameName@MapTitle@Level.Title, true);

   Canvas.SetPos(0, Canvas.ClipY - YL);
   if (bTimeDown || (PlayerOwner.GameReplicationInfo.RemainingTime > 0))
   {
      bTimeDown = true;
      if (PlayerOwner.GameReplicationInfo.RemainingTime <= 0)
         Canvas.DrawText(RemainingTime@"00:00", true);
      else
      {
         Minutes = PlayerOwner.GameReplicationInfo.RemainingTime/60;
         Seconds = PlayerOwner.GameReplicationInfo.RemainingTime % 60;
         Canvas.DrawText(RemainingTime@TwoDigitString(Minutes)$":"$TwoDigitString(Seconds), true);
      }
   }
   else
   {
      Seconds = PlayerOwner.GameReplicationInfo.ElapsedTime;
      Minutes = Seconds / 60;
      Hours   = Minutes / 60;
      Seconds = Seconds - (Minutes * 60);
      Minutes = Minutes - (Hours * 60);
      Canvas.DrawText(ElapsedTime@TwoDigitString(Hours)$":"$TwoDigitString(Minutes)$":"$TwoDigitString(Seconds), true);
   }

   if (PlayerOwner.GameReplicationInfo.GameEndedComments != "")
   {
   	DrawVictoryTile(Canvas);
      Canvas.bCenter = true;
      Canvas.StrLen("Test", XL, YL);
      Canvas.SetPos(0, Canvas.ClipY - Min(YL*6, Canvas.ClipY * 0.1));
      Canvas.DrawColor = GreenColor;
      if (Level.NetMode == NM_Standalone)
         Canvas.DrawText(Ended@Continue, true);
      else
         Canvas.DrawText(Ended, true);
   }
   else if ((PlayerOwner != None) && (PlayerOwner.Health <= 0))
   {
      Canvas.bCenter = true;
      Canvas.StrLen("Test", XL, YL);
      Canvas.SetPos(0, Canvas.ClipY - Min(YL*6, Canvas.ClipY * 0.1));
      Canvas.DrawColor = GreenColor;
      Canvas.DrawText(Restart, true);
   }
   Canvas.bCenter = false;
}

simulated function DrawVictoryTile(Canvas Canvas)
{
   local float XL, YL, DrawScale;

	Canvas.Style = ERenderStyle.STY_Translucent;

	XL = Canvas.ClipX * 0.5;
	YL = Canvas.ClipY * 0.7;

	if (Canvas.ClipX < 1024)
		DrawScale = Canvas.ClipX / 1024;
	else
		DrawScale = 1;

	Canvas.SetPos(XL - (DrawScale * 256) , YL - (DrawScale * 64));
	Canvas.DrawTile(Texture'VictoryTile', DrawScale * 512, DrawScale * 128, 0, 0,512,128);

   XL = Canvas.ClipX * 0.5;
	YL = Canvas.ClipY * 0.8;
	if (Canvas.ClipX < 1024)
		DrawScale = Canvas.ClipX / 1024;
	else
		DrawScale = 0.6;

	Canvas.SetPos(XL - (DrawScale * 256) , YL - (DrawScale * 64));
}

defaultproperties
{
   BRYellow=(R=231,G=206,B=52,A=0),
	BRRed=(R=216,G=26,B=26,A=0),
   VictoryGoal="Be the last one alive!"
   FragsString="Status"
}