XIII
Class HudMPMessage

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

class HudMPMessage
extends Engine.Info

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

End Source Code