Botpack
Class ScrollingMessageTexture

source: e:\games\UnrealTournament\Botpack\Classes\ScrollingMessageTexture.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Info
         |
         +--Botpack.ClientScriptedTexture
            |
            +--Botpack.ScrollingMessageTexture
Direct Known Subclasses:None

class ScrollingMessageTexture
extends Botpack.ClientScriptedTexture


Variables
 Font Font
 color FontColor
 HisMessage, HerMessage
 float LastDrawTime
 string OldText
 int PixelsPerSecond
 PlayerPawn Player
 int Position
 int ScrollWidth
 string ScrollingMessage
 float YPos
 bool bCaps
 bool bResetPosOnTextChange


Function Summary
 
simulated
FindPlayer()
     
/* parameters for ScrollingMessage:

   %p - local player name
   %h - his/her for local player
   %lp - leading player's name
   %lf - leading player's frags
*/
 string Replace(string Text, string Match, string Replacement)



Source Code


00001	class ScrollingMessageTexture expands ClientScriptedTexture;
00002	
00003	var() localized string ScrollingMessage;
00004	var localized string HisMessage, HerMessage;
00005	var() Font Font;
00006	var() color FontColor;
00007	var() bool bCaps;
00008	var() int PixelsPerSecond;
00009	var() int ScrollWidth;
00010	var() float YPos;
00011	var() bool bResetPosOnTextChange;
00012	
00013	var string OldText;
00014	var int Position;
00015	var float LastDrawTime;
00016	var PlayerPawn Player;
00017	
00018	/* parameters for ScrollingMessage:
00019	
00020	   %p - local player name
00021	   %h - his/her for local player
00022	   %lp - leading player's name
00023	   %lf - leading player's frags
00024	*/
00025	
00026	simulated function FindPlayer()
00027	{
00028		local PlayerPawn P;
00029	
00030		foreach AllActors(class'PlayerPawn', P)
00031			if(Viewport(P.Player) != None)
00032				Player = P;
00033	}
00034	
00035	simulated event RenderTexture(ScriptedTexture Tex)
00036	{
00037		local string Text;
00038		local PlayerReplicationInfo Leading, PRI;
00039		local int i;
00040	
00041		if(Player == None)
00042			FindPlayer();
00043	
00044		if(Player == None || Player.PlayerReplicationInfo == None || Player.GameReplicationInfo == None)
00045			return;
00046	
00047		if(LastDrawTime == 0)
00048			Position = Tex.USize;
00049		else
00050			Position -= (Level.TimeSeconds-LastDrawTime) * PixelsPerSecond;
00051	
00052		if(Position < -ScrollWidth)
00053			Position = Tex.USize;
00054	
00055		LastDrawTime = Level.TimeSeconds;
00056	
00057		Text = ScrollingMessage;
00058	
00059		if(Player.bIsFemale)
00060			Text = Replace(Text, "%h", HerMessage);
00061		else
00062			Text = Replace(Text, "%h", HisMessage);
00063		
00064		Text = Replace(Text, "%p", Player.PlayerReplicationInfo.PlayerName);
00065		if(InStr(Text, "%lf") != -1 || InStr(Text, "%lp") != -1)
00066		{
00067			// find the leading player
00068			Leading = None;
00069	
00070			for (i=0; i<32; i++)
00071			{
00072				if (Player.GameReplicationInfo.PRIArray[i] != None)
00073				{
00074					PRI = Player.GameReplicationInfo.PRIArray[i];
00075					if ( !PRI.bIsSpectator && (Leading==None || PRI.Score>Leading.Score) )
00076						Leading = PRI;
00077				}
00078			}
00079			if(Leading == None)
00080				Leading = Player.PlayerReplicationInfo;
00081			Text = Replace(Text, "%lp", Leading.PlayerName);
00082			Text = Replace(Text, "%lf", string(int(Leading.Score)));
00083		}
00084	
00085		if(bCaps)
00086			Text = Caps(Text);
00087	
00088		if(Text != OldText && bResetPosOnTextChange)
00089		{
00090			Position = Tex.USize;
00091			OldText = Text;
00092		}
00093	
00094		Tex.DrawColoredText( Position, YPos, Text, Font, FontColor );
00095	}
00096	
00097	simulated function string Replace(string Text, string Match, string Replacement)
00098	{
00099		local int i;
00100		
00101		i = InStr(Text, Match);	
00102	
00103		if(i != -1)
00104			return Left(Text, i) $ Replacement $ Replace(Mid(Text, i+Len(Match)), Match, Replacement);
00105		else
00106			return Text;
00107	}
00108	
00109	defaultproperties
00110	{
00111	     HisMessage="his"
00112	     HerMessage="her"
00113	     bResetPosOnTextChange=True
00114	}

End Source Code