UMSCredits
Class CreditsHUD

source: e:\games\UnrealTournament\UMSCredits\Classes\CreditsHUD.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.HUD
         |
         +--UMS1_6.MovieHUD
            |
            +--UMSCredits.CreditsHUD
Direct Known Subclasses:None

class CreditsHUD
extends UMS1_6.MovieHUD

//============================================================================= // MovieHUD. // Created by Stephen 'Nemesis' Deaver, Yoda and Hugh Macdonald. //=============================================================================
Variables
 MovieCredits CreditsInfo
           CreditsInfo actor to get our credit info from.
 float GlobalY
           Current Y value - Used for credit scrolling
 float ScreenHeight
           Size of screen - Used for credits.
 float ScrollAmount
           More credits stuff.
 float ScrollingTime
           Also used for credits.
 float TotalLength
           Total length of whole credits sequence.
 bool bCredits
           Are credits running?
 bool bDidScrollInit
           Were the credits already initlialized?


Function Summary
 void InitScroll(Canvas C)
     
// This function sets up the credits for scrolling.
 void PostRender(Canvas C)
 void RunCredits(Canvas C)
     
// Main credits function.
 void StartCredits(MovieCredits CredInfo)
     
// Called by CreditsInfo actor to get the credits rolling.
 void Tick(float DeltaTime)
     
// Scroll the credits up the screen.



Source Code


00001	//=============================================================================
00002	// MovieHUD.
00003	// Created by Stephen 'Nemesis' Deaver, Yoda and Hugh Macdonald.
00004	//=============================================================================
00005	class CreditsHUD expands MovieHUD;
00006	
00007	var() bool bCredits;			// Are credits running?
00008	var float ScreenHeight;			// Size of screen - Used for credits.
00009	var float ScrollingTime;		// Also used for credits.
00010	var float GlobalY;			// Current Y value - Used for credit scrolling
00011	var MovieCredits CreditsInfo;		// CreditsInfo actor to get our credit info from.
00012	var float ScrollAmount;			// More credits stuff.
00013	var float TotalLength;			// Total length of whole credits sequence.
00014	var bool bDidScrollInit;		// Were the credits already initlialized?
00015	
00016	function PostRender(Canvas C)
00017	{    
00018	
00019	    DrawHUDOverlay(C);
00020	
00021	
00022	    // Time to do credits? If so, then initialize them once, then run.
00023	    if(bCredits && CreditsInfo != NONE)
00024	    {
00025			if (!bDidScrollInit)
00026			{
00027				InitScroll(C);
00028				bDidScrollInit = true;
00029			}
00030	        RunCredits(C);
00031	    }
00032	}
00033	
00034	// This function sets up the credits for scrolling.
00035	function InitScroll(Canvas C) {
00036	   
00037		local int CurrentCommand, CurrentSize;
00038		local string CurrentCredit;
00039		local float XL, YL, CurrentGap;
00040		local texture Pic;
00041		local int PicSizeX,PicSizeY;
00042	
00043	    GlobalY = C.ClipY;
00044		ScreenHeight = C.ClipY;
00045		ScrollingTime = CreditsInfo.ScrollingTime;
00046		
00047		// Determine total run length of credits.
00048		for (CurrentCommand=0;CurrentCommand<50;CurrentCommand++) 
00049		{
00050	        	
00051			CurrentCredit = CreditsInfo.GetCreditsScript(CurrentCommand);
00052	
00053		        if(CurrentCredit == "")
00054	        	{
00055		        	break;
00056	        	}
00057	
00058			// Special functions handler. Currently only pics in the credits.
00059			if (Left(CurrentCredit,1) == "#") {
00060		 
00061		                switch(CurrentCredit)
00062	   			{
00063				case "#pic":
00064		        		Pic = CreditsInfo.GetCreditsPic(CreditsInfo.GetCreditsSize(CurrentCommand));
00065	                		PicSizeX = Pic.USize;
00066			        	PicSizeY = Pic.VSize;
00067	        	        	TotalLength += (YL * (CurrentGap+1)) + PicSizeY;
00068					break;
00069		                default:
00070					Log ("Unrecognized function: "$CurrentCredit);
00071				}
00072				continue;
00073			}	
00074		  
00075		        CurrentSize = CreditsInfo.GetCreditsSize(CurrentCommand);
00076	        	SetFontSize(CurrentSize, C);
00077			CurrentGap = CreditsInfo.GetCreditsGap(CurrentCommand);
00078	        	C.StrLen(CurrentCredit, XL, YL);
00079			TotalLength += (YL * (CurrentGap+1));
00080	
00081		}
00082		
00083		// We add the length of the screen to our totallength, because the credits
00084		// need to scroll all the way OFF the screen too.
00085		TotalLength += C.ClipY;
00086	
00087	    // Calculate the amount of pixels we must increment each second.
00088		ScrollAmount = TotalLength / ScrollingTime;
00089	
00090	}
00091	
00092	
00093	// Main credits function.
00094	function RunCredits(Canvas C)
00095	{
00096	
00097	    local int CurrentCommand, CurrentAlign, XStart, CurrentSize, OldY;
00098	    local string CurrentCredit;
00099	    local float CurrentOffset, CreditLen, XL, YL, CurrentGap;
00100	    local vector CurrentColour;
00101	    local texture Pic;
00102	    local int PicSizeX,PicSizeY;
00103	    local color BlackColor;
00104	    C.CurX = C.ClipX/2;
00105	    C.CurY = C.ClipY/2;
00106	   
00107	    // Run through every creditscript.
00108	    for(CurrentCommand=0;CurrentCommand<500;CurrentCommand++)
00109	    {
00110	
00111	        CurrentCredit = CreditsInfo.GetCreditsScript(CurrentCommand);
00112	
00113			// No more credits? Stop execution.
00114			if(CurrentCredit == "")
00115		        break;
00116	
00117			// Setting some local variables for easy use.
00118	        CurrentSize = CreditsInfo.GetCreditsSize(CurrentCommand);
00119	        SetFontSize(CurrentSize, C);
00120	        CurrentAlign = CreditsInfo.GetCreditsAlign(CurrentCommand);
00121	        CurrentOffset = CreditsInfo.GetCreditsOffset(CurrentCommand);
00122			CurrentGap = CreditsInfo.GetCreditsGap(CurrentCommand);
00123	        C.StrLen(CurrentCredit, XL, YL);
00124	        CreditLen = len(CurrentCredit);
00125	
00126			// Special functions handler. Currently, only the #pic command is supported.
00127		
00128			if (Left(CurrentCredit,1) == "#")
00129			{
00130		 
00131				switch(CurrentCredit)
00132	   			{
00133				case "#pic":
00134		    	    	
00135		   		 	Pic = CreditsInfo.GetCreditsPic(CreditsInfo.GetCreditsSize(CurrentCommand));
00136					PicSizeX = Pic.USize;
00137		    		    PicSizeY = Pic.VSize;
00138		    	   	C.DrawColor = CreditsInfo.GetCreditsColor(CurrentCommand);
00139		
00140		    		if (CreditsInfo.GetCreditsColor(CurrentCommand) == BlackColor) 
00141		    		{
00142		    			C.DrawColor = CreditsInfo.MasterColor;
00143		    		}
00144		    	
00145		    		switch (CurrentAlign)
00146	        	    {
00147	        	    case 0:
00148	        	       	C.CurX = (C.ClipX/2) - (PicSizeX/2);
00149		    	    	C.CurX += (C.ClipX/2) * CurrentOffset;
00150	        	       	break;
00151	        	    case 1:
00152	        	       	C.CurX = 0;
00153	        	       	C.CurX += C.ClipX * CurrentOffset;
00154	        	       	break;
00155	        	    case 2:
00156	        	       	C.CurX = C.ClipX - (PicSizeX);
00157	        	       	C.CurX += C.ClipX * CurrentOffset;
00158	        	       	break;
00159	        	    }         
00160		
00161	        	    OldY = C.CurY;
00162		    		C.CurY += GlobalY;
00163		    		C.DrawTile(Pic, PicSizeX, PicSizeY, PicSizeX, PicSizeY, PicSizeX, PicSizeY);
00164	        	    C.CurY = OldY;
00165		    		C.CurY += (YL * (CurrentGap+1)) + PicSizeY;
00166		    		break;
00167		
00168		    	default:
00169					Log ("Unrecognized function: "$CurrentCredit);
00170				}
00171			
00172				continue;
00173			}	
00174	
00175	
00176			// Align the current text to either the center, right, or left of the screen.
00177	    	switch (CurrentAlign)
00178	    	{
00179	    	case 0:
00180	    	    C.CurX = (C.ClipX/2) - (XL)/2;
00181	    	    C.CurX += (C.ClipX/2) * CurrentOffset;
00182	    	    break;
00183	    	case 1:
00184	    	    C.CurX = 0;
00185	    	    C.CurX += C.ClipX * CurrentOffset;
00186	    	    break;
00187	    	case 2:
00188	    	    C.CurX = C.ClipX - (XL);
00189	    	    C.CurX += C.ClipX * CurrentOffset;
00190	    	    break;
00191	    	}
00192			
00193			// If the color of the text is 0,0,0, then we set it to the default master color.
00194	    	C.DrawColor = CreditsInfo.GetCreditsColor(CurrentCommand);
00195			if (CreditsInfo.GetCreditsColor(CurrentCommand) == BlackColor) 
00196			{
00197			    	C.DrawColor = CreditsInfo.MasterColor;
00198			}
00199		
00200			// Draw the text to the screen!
00201			OldY = C.CurY;
00202			C.CurY += GlobalY;
00203			C.DrawTextClipped (CurrentCredit);
00204			C.CurY = OldY;
00205			C.CurY += (YL * (CurrentGap+1));
00206			if (GlobalY < -TotalLength - 10)
00207			{
00208				bCredits = false;
00209			}
00210	    }
00211	}
00212	
00213	// Called by CreditsInfo actor to get the credits rolling.
00214	function StartCredits(MovieCredits CredInfo)
00215	{
00216	    CreditsInfo=CredInfo;
00217	    bCredits=true;
00218	}
00219	
00220	
00221	// Scroll the credits up the screen.
00222	function Tick(float DeltaTime)
00223	{
00224	    if(bCredits)
00225	    {
00226	        GlobalY = GlobalY - (ScrollAmount * DeltaTime);
00227	    }
00228	}
00229	
00230	defaultproperties
00231	{
00232	     ScrollingTime=5.000000
00233	}

End Source Code