XIII
Class HudMessage

source: C:\XIII\XIII\Classes\HudMessage.uc
Core.Object
   |
   +--Engine.Actor
      |
      +--Engine.Info
         |
         +--XIII.HudMessage
Direct Known Subclasses:None

class HudMessage
extends Engine.Info

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 color DrawColor
 float EndOfLife
 float LifeTime
 Class Message
 HUDLocalizedMessage MyMessage
 HudMessage NextHudMsg
 Object OptionalObject
 HudMessage PrevHudMsg
 PlayerReplicationInfo RelatedPRI
 string StringMessage
 int Switch
 XL, YL
           compute memorize these vars only for the first HudMsg
 float YP
 bool bCenter
 bool bDrawing
 bool bIsSpecial
           If true, don't erase (increase lifetime indefinetly until player access info menu)
 float fXSize
 int index
 int numLines


Function Summary
 void ActualizeIndex()
     
//____________________________________________________________________
 void DestroyFirstMessage()
     
//____________________________________________________________________
 
simulated
DrawMsg(Canvas C)
     
//____________________________________________________________________
 void ProcessMessage(Canvas C)
     
//____________________________________________________________________
 void RemoveMe()
     
//____________________________________________________________________



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class HudMessage extends Info
00005	  NotPlaceable;
00006	
00007	var HudMessage NextHudMsg;
00008	var HudMessage PrevHudMsg;
00009	var int index;
00010	const MAXDISPLAYEDMESSAGES = 7;
00011	
00012	struct HUDLocalizedMessage
00013	{
00014	    var Class<LocalMessage> Message;
00015	    var int Switch;
00016	    var PlayerReplicationInfo RelatedPRI;
00017	    var Object OptionalObject;
00018	    var float EndOfLife;
00019	    var float LifeTime;
00020	    var bool bDrawing;
00021	    var int numLines;
00022	    var string StringMessage;
00023	    var color DrawColor;
00024	    var bool bCenter;
00025	    var float fXSize;
00026	};
00027	
00028	var HUDLocalizedMessage MyMessage;
00029	var float YP;
00030	var float XL, YL;       // compute memorize these vars only for the first HudMsg
00031	
00032	var bool bIsSpecial;    // If true, don't erase (increase lifetime indefinetly until player access info menu)
00033	
00034	CONST DBMSG=false;
00035	
00036	//____________________________________________________________________
00037	simulated function SetUpLocalizedMessage( class<LocalMessage> Message, optional int Switch, optional PlayerReplicationInfo RelatedPRI_1, optional PlayerReplicationInfo RelatedPRI_2, optional Object OptionalObject, optional string CriticalString )
00038	{
00039	    if ( CriticalString == "" )
00040	    {
00041	      CriticalString = Message.Static.GetString(Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject);
00042	    }
00043	    if ( DBMSG ) Log("MESSAGE SetUpLocalizedMessage CriticalString '"$CriticalString$"'");
00044	
00045	    if ( CriticalString == "" )
00046	    {
00047	      RemoveMe();
00048	      return;
00049	    }
00050	
00051	    bIsSpecial = Message.Default.bIsSpecial;
00052	    MyMessage.Message = Message;
00053	    if ( Class<Pickup>(OptionalObject) == none )
00054	      MyMessage.Switch = 0;
00055	    else
00056	      MyMessage.Switch = switch;
00057	    MyMessage.RelatedPRI = RelatedPRI_1;
00058	    MyMessage.OptionalObject = OptionalObject;
00059	    if ( MessageTrigger(OptionalObject) != none )
00060	    {
00061	      MyMessage.EndOfLife = MessageTrigger(OptionalObject).fMessageDuration + Level.TimeSeconds;
00062	      MyMessage.LifeTime = MessageTrigger(OptionalObject).fMessageDuration;
00063	    }
00064	    else
00065	    {
00066	      MyMessage.EndOfLife = Message.Default.Lifetime + Level.TimeSeconds;
00067	      MyMessage.LifeTime = Message.Default.Lifetime;
00068	    }
00069	    if ( MyMessage.Switch > 0 )
00070	    {
00071	      MyMessage.LifeTime += 2.5;
00072	      MyMessage.EndOfLife += 2.5;
00073	    }
00074	
00075	    MyMessage.bDrawing = true;
00076	    MyMessage.NumLines = 0; // should be initialized first time we draw the string
00077	    MyMessage.StringMessage = CriticalString;
00078	    if ( MyMessage.Switch == 0 )
00079	      MyMessage.DrawColor = Message.Static.GetColor(Switch, RelatedPRI_1, RelatedPRI_2);
00080	    else // New Weapon Notify
00081	//      MyMessage.DrawColor = class'Canvas'.static.MakeColor(160,220,233,255);
00082	      MyMessage.DrawColor = class'Canvas'.static.MakeColor(65,186,212,255);
00083	    MyMessage.bCenter = Message.default.bCenter;
00084	    MyMessage.fXSize = 0; // should be initialized first time we draw the string
00085	
00086	    if ( PrevHudMsg != none )
00087	      index = PrevHudMsg.index + 1;
00088	    else
00089	      index = 0;
00090	
00091	    if ( DBMSG ) log("     OK index="$index@"'"$CriticalString$"' Switch"@Switch);
00092	    if ( index >= MAXDISPLAYEDMESSAGES )
00093	      PrevHudMsg.DestroyFirstMessage();
00094	}
00095	
00096	//____________________________________________________________________
00097	simulated function AddLocalizedMessage( class<LocalMessage> Message, optional int Switch, optional PlayerReplicationInfo RelatedPRI_1, optional PlayerReplicationInfo RelatedPRI_2, optional Object OptionalObject, optional string CriticalString )
00098	{
00099	    if ( DBMSG ) Log("MESSAGE "$self$" AddLocalizedMessage index="$index$" NextHudMsg="$NextHudMsg);
00100	
00101	    if ( Message.default.bIsSpecial && bIsSpecial )
00102	      return; // don't draw 2 special messages.
00103	
00104	    if ( NextHudMsg == none )
00105	    {
00106	      NextHudMsg = Spawn(class'HudMessage',Owner);
00107	      NextHudMsg.PrevHudMsg = self;
00108	      NextHudMsg.SetUpLocalizedMessage( Message, Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject, CriticalString );
00109	    }
00110	    else
00111	      NextHudMsg.AddLocalizedMessage( Message, Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject, CriticalString );
00112	}
00113	
00114	//____________________________________________________________________
00115	function ProcessMessage(Canvas C)
00116	{
00117	    Local int i; // Index of the processed space
00118	    local int j; // number of lines
00119	    local int k; // index of the starting current strine
00120	    local string SubString, NewCriticalString, NewCriticalCurrentString;
00121	    local float XT,XT2,YT;
00122	    local bool bNotFirstTime;
00123	    local string LeftString;
00124	
00125	    MyMessage.fXSize = C.ClipX * (1.0 - XIIIBaseHUD(Owner).RightMargin - XIIIBaseHUD(Owner).LeftMargin) / 3;
00126	
00127	    if ( DBMSG ) Log("MESSAGE ProcessMessage, Len="$MyMessage.fXSize$" string="$MyMessage.StringMessage);
00128	    j = 1;
00129	
00130	    XIIIBaseHUD(Owner).UseMsgFont(C);
00131	    C.SpaceX=0;
00132	
00133	    SubString = MyMessage.StringMessage;
00134	    NewCriticalString = "";
00135	    NewCriticalcurrentString = "";
00136	    i = InStr(SubString, " ");
00137	    if ( DBMSG ) Log("    NewCriticalCurrentString='"$NewCriticalCurrentString$"' SHOULD BE ''");
00138	    While ( i >= 0 )
00139	    {
00140	      LeftString = Left(SubString, i);
00141	      if ( DBMSG ) Log("      pass I="$i$" adding '"$NewCriticalCurrentString$"' with '"$LeftString$"'");
00142	      NewCriticalCurrentString = NewCriticalCurrentString$LeftString;
00143	      C.StrLen(NewCriticalCurrentString, XT2, YT);
00144	      if ( DBMSG ) Log("      NewCriticalCurrentString='"$NewCriticalCurrentString$"' Len="$XT2);
00145	      if ( (XT2 >= MyMessage.fXSize) || (XT2 == XT) )
00146	      {
00147	        NewCriticalString = NewCriticalString$"#N"$LeftString;
00148	        NewCriticalcurrentString = LeftString$" ";
00149	        j++;
00150	      }
00151	      else
00152	      {
00153	        if ( bNotFirstTime )
00154	          NewCriticalString = NewCriticalString$" "$LeftString;
00155	        else
00156	          NewCriticalString = LeftString;
00157	        NewCriticalcurrentString = NewCriticalcurrentString$" ";
00158	      }
00159	      bNotFirstTime=true;
00160	      XT = XT2;
00161	      SubString = right(SubString, len(SubString) - i - 1);
00162	      if ( DBMSG ) Log("    NewCriticalString='"$NewCriticalString$"' SubString='"$SubString$"'");
00163	      i = InStr(SubString, " ");
00164	    }
00165	    // Last Word
00166	    if ( DBMSG ) Log("  Processing Last Word,  NewCriticalCurrentString='"$NewCriticalCurrentString$"' SubString='"$SubString$"'");
00167	    NewCriticalCurrentString = NewCriticalCurrentString$SubString;
00168	    C.StrLen(NewCriticalCurrentString, XT2, YT);
00169	    if ( DBMSG ) Log("  NewCriticalCurrentString='"$NewCriticalCurrentString$"' Len="$XT2);
00170	    if ( (XT2 >= MyMessage.fXSize) || (XT == XT2) )
00171	    {
00172	      NewCriticalString = NewCriticalString$"#N"$SubString;
00173	      j++;
00174	    }
00175	    else
00176	    {
00177	      if ( bNotFirstTime )
00178	        NewCriticalString = NewCriticalString$" "$SubString;
00179	      else
00180	        NewCriticalString = SubString;
00181	    }
00182	    if ( DBMSG ) Log("  NewCriticalString='"$NewCriticalString$"'");
00183	
00184	    MyMessage.NumLines = j;
00185	    MyMessage.StringMessage = NewCriticalString;
00186	}
00187	
00188	//____________________________________________________________________
00189	simulated function DrawMsg(Canvas C)
00190	{
00191	    local float XP;
00192	    local float fAlpha, XT, YT;
00193	    Local int i,j;
00194	    local string OutString, SubString;
00195	    local int XCoords, YCoords;
00196	
00197	    if ( MyMessage.NumLines == 0 )
00198	      ProcessMessage(C);
00199	
00200	    if ( PrevHudMsg != none )
00201	      YP = PrevHudMsg.YP;
00202	    else
00203	      YP = XIIIBaseHUD(Owner).YP;
00204	
00205	    // Only compute char len/wid fro the first HudMsg
00206	    if ( PrevHudMsg == none )
00207	      C.StrLen("A",XL,YL);
00208	    else
00209	    {
00210	      XL = PrevHudMsg.XL;
00211	      YL = PrevHudMsg.YL;
00212	    }
00213	
00214	    YP -= ( (YL+2)*MyMessage.NumLines);
00215	    XP = XIIIBaseHUD(Owner).XP - 4;
00216	
00217	    if ( bIsSpecial )
00218	      fAlpha = 1.0;
00219	    else
00220	      fAlpha = fMax(0.0, fMin(0.25, MyMessage.EndOfLife - Level.TimeSeconds) * 4.0);
00221	
00222	    if ( (MyMessage.Switch != 0) || (PrevHudMsg == none) ) // fade w/ dropping
00223	      YP += ( (YL+2)*MyMessage.NumLines) * (1.0 - fAlpha);
00224	
00225	    if (fAlpha > 0.01)
00226	    {
00227	      C.bTextShadow = true;
00228	      C.DrawColor = MyMessage.DrawColor;
00229	      C.DrawColor.A = C.DrawColor.A * fAlpha;
00230	      if ( MyMessage.NumLines == 1 )
00231	      {
00232	        C.StrLen(MyMessage.StringMessage, XT, YT);
00233	        C.SetPos(XP-XT,YP);
00234	        C.DrawText(MyMessage.StringMessage);
00235	      }
00236	      else
00237	      {
00238	        j = 0;
00239	        SubString = MyMessage.StringMessage;
00240	        i = InStr(SubString, "#N");
00241	        while ( i >= 0 )
00242	        {
00243	          OutString = Left(SubString, i);
00244	          C.StrLen(OutString, XT, YT);
00245	          C.SetPos(XP-XT,YP+j*(YT+2));
00246	          C.DrawText(OutString);
00247	          j ++;
00248	          SubString = right(SubString, Len(SubString)-i-2);
00249	          i = InStr(SubString, "#N");
00250	        }
00251	        C.StrLen(SubString, XT, YT);
00252	        C.SetPos(XP-XT,YP+j*(YT+2));
00253	        C.DrawText(SubString);
00254	      }
00255	      if ( MyMessage.Switch != 0 )
00256	      { // Draw weapon icon according to switch
00257	    		YCoords = MyMessage.Switch / 4;
00258	    		XCoords = MyMessage.Switch - YCoords * 4;
00259	        C.DrawColor = MyMessage.DrawColor * 0.5;
00260	        C.DrawColor.A = C.DrawColor.A * fAlpha * 0.7;
00261	        C.SetPos(XP - 64*XIIIBaseHud(Owner).fDrawScale, YP - 32*XIIIBaseHud(Owner).fDrawScale);
00262	        C.DrawTile(XIIIBaseHud(Owner).WhiteTex, 64*XIIIBaseHud(Owner).fDrawScale,32*XIIIBaseHud(Owner).fDrawScale, 0, 0, XIIIBaseHud(Owner).WhiteTex.USize, XIIIBaseHud(Owner).WhiteTex.VSize);
00263	        C.bUseBorder = true;
00264	        C.DrawColor = XIIIBaseHud(Owner).WhiteColor;
00265	        C.DrawColor.A = C.DrawColor.A * fAlpha;
00266	    		C.BorderColor = C.DrawColor;
00267	        C.SetPos(XP - 64*XIIIBaseHud(Owner).fDrawScale, YP - 32*XIIIBaseHud(Owner).fDrawScale);
00268	        C.DrawTile(XIIIBaseHud(Owner).HudWIcons, 64*XIIIBaseHud(Owner).fDrawScale, 32*XIIIBaseHud(Owner).fDrawScale, 64*XCoords, 32*YCoords, 64, 32);
00269	        C.bUseBorder = false;
00270	        YP -= 32*XIIIBaseHud(Owner).fDrawScale;
00271	      }
00272	    }
00273	    else
00274	      fAlpha = 0.0;
00275	
00276	    if ( NextHudMsg != none )
00277	      NextHudMsg.DrawMsg(C);
00278	    else
00279	      XIIIBaseHUD(Owner).YP = YP;
00280	
00281	    if ( fAlpha == 0.0 )
00282	      ReMoveMe();
00283	
00284	}
00285	
00286	//____________________________________________________________________
00287	function RemoveMe()
00288	{
00289	    if (PrevHudMsg == none)
00290	    {
00291	      if (NextHudMsg != none)
00292	      {
00293	        XIIIBaseHUD(Owner).HudMsg = NextHudMsg;
00294	        NextHudMsg.PrevHudMsg = none;
00295	        XIIIBaseHUD(Owner).HudMsg.ActualizeIndex();
00296	      }
00297	      else
00298	        XIIIBaseHUD(Owner).HudMsg = none;
00299	    }
00300	    else
00301	    {
00302	      PrevHudMsg.NextHudMsg = NextHudMsg;
00303	      if ( NextHudMsg != none )
00304	        NextHudMsg.PrevHudMsg = PrevHudMsg;
00305	      PrevHudMsg.ActualizeIndex();
00306	    }
00307	    Destroy();
00308	}
00309	
00310	//____________________________________________________________________
00311	function DestroyFirstMessage()
00312	{
00313	    if ( (index == 0) || (PrevHudMsg == none) )
00314	    {
00315	      index = -1;
00316	      NextHudMsg.ActualizeIndex();
00317	      RemoveMe();
00318	    }
00319	    else
00320	      PrevHudMsg.DestroyFirstMessage();
00321	}
00322	
00323	//____________________________________________________________________
00324	function ActualizeIndex()
00325	{
00326	    if ( PrevHudMsg != none )
00327	      Index = PrevHudMsg.index + 1;
00328	    else
00329	      Index = 0;
00330	    if ( NextHudMsg != none )
00331	      NextHudMsg.ActualizeIndex();
00332	}
00333	
00334	
00335	
00336	defaultproperties
00337	{
00338	}

End Source Code