XIII
Class HudObjectifMessage

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

class HudObjectifMessage
extends Engine.Info

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 float CharCount
           special display for main objective
 color DrawColor
 float EndOfLife
 float LifeTime
 Class Message
 HUDLocalizedMessage MyMessage
 HudObjectifMessage NextHudMsg
 Object OptionalObject
 HudObjectifMessage PrevHudMsg
 PlayerReplicationInfo RelatedPRI
 float StartOfLife
 string StringMessage
 int Switch
 Texture ValidatedTex
 Texture WhiteTex
 XL, YL
 bool bCenter
 bool bDrawing
 bool bIsHudCartoonFX
           special display for main objective
 float fXSize
 int index
 int numLines


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



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class HudObjectifMessage extends Info
00005	  NotPlaceable;
00006	
00007	var HudObjectifMessage NextHudMsg;
00008	var HudObjectifMessage PrevHudMsg;
00009	var int index;
00010	var texture WhiteTex;
00011	var texture ValidatedTex;
00012	
00013	struct HUDLocalizedMessage
00014	{
00015	    var Class<LocalMessage> Message;
00016	    var int Switch;
00017	    var PlayerReplicationInfo RelatedPRI;
00018	    var Object OptionalObject;
00019	    var float EndOfLife;
00020	    var float StartOfLife;
00021	    var float LifeTime;
00022	    var bool bDrawing;
00023	    var int numLines;
00024	    var string StringMessage;
00025	    var color DrawColor;
00026	    var bool bCenter;
00027	    var float fXSize;
00028	};
00029	
00030	var HUDLocalizedMessage MyMessage;
00031	var float YP, XL, YL;
00032	var float CharCount;                        // special display for main objective
00033	
00034	//var bool bIsSpecial; // If true, don't erase (increase lifetime indefinetly until player access info menu)
00035	var bool bIsHudCartoonFX;
00036	
00037	CONST DBMSG=false;
00038	CONST MAXDISPLAYEDMESSAGES = 7;
00039	
00040	// new method using auto-line cut
00041	//____________________________________________________________________
00042	simulated function SetUpLocalizedMessage( class<LocalMessage> Message, optional int Switch, optional PlayerReplicationInfo RelatedPRI_1, optional PlayerReplicationInfo RelatedPRI_2, optional Object OptionalObject, optional string CriticalString )
00043	{
00044	    if ( CriticalString == "" )
00045	      CriticalString = Message.Static.GetString(Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject);
00046	
00047	    if ( DBMSG ) Log(" SetUpLocalizedMessage"@switch@CriticalString);
00048	    if ( CriticalString == "" )
00049	      RemoveMe();
00050	
00051	//    bIsSpecial = Message.Default.bIsSpecial;
00052	    MyMessage.Message = Message;
00053	    MyMessage.Switch = switch;
00054	    MyMessage.RelatedPRI = RelatedPRI_1;
00055	    MyMessage.OptionalObject = OptionalObject;
00056	    MyMessage.StartOfLife = Level.TimeSeconds;
00057	    if ( MessageTrigger(OptionalObject) != none )
00058	    {
00059	      MyMessage.EndOfLife = MessageTrigger(OptionalObject).fMessageDuration + Level.TimeSeconds;
00060	      MyMessage.LifeTime = MessageTrigger(OptionalObject).fMessageDuration;
00061	    }
00062	    else
00063	    {
00064	      MyMessage.EndOfLife = Message.Default.Lifetime + Level.TimeSeconds;
00065	      MyMessage.LifeTime = Message.Default.Lifetime;
00066	      if ( (Switch >= 8) && (PrevHudMsg != none) ) // delay 1 second before display
00067	        MyMessage.EndOfLife += 1.0;
00068	    }
00069	    MyMessage.bDrawing = true;
00070	    MyMessage.NumLines = 0; // should be initialized first time we draw the string
00071	    MyMessage.StringMessage = CriticalString;
00072	    MyMessage.DrawColor = Message.Static.GetColor(Switch, RelatedPRI_1, RelatedPRI_2);
00073	    MyMessage.bCenter = Message.default.bCenter;
00074	    MyMessage.fXSize = 0; // should be initialized first time we draw the string
00075	
00076	    if ( PrevHudMsg != none )
00077	      index = PrevHudMsg.index + 1;
00078	    else
00079	      index = 0;
00080	
00081	    if ( DBMSG ) log("MESSAGE index="$index@"'"$CriticalString$"'");
00082	    if ( index >= MAXDISPLAYEDMESSAGES )
00083	      PrevHudMsg.DestroyFirstMessage();
00084	
00085	    bIsHudCartoonFX = true;
00086	
00087	    if ( DBMSG ) Log("MESSAGE "$self$" SetUpLocalizedMessage index="$index);
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'HudObjectifMessage',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 string
00114	    local string SubString, NewCriticalString, NewCriticalCurrentString;
00115	    local float XT,XT2,YT;
00116	    local bool bNotFirstTime;
00117	    local string LeftString;
00118	
00119	    C.StrLen("A",XL,YL);
00120	
00121	    MyMessage.fXSize = C.ClipX * (1.0 - XIIIBaseHUD(Owner).RightMargin - XIIIBaseHUD(Owner).LeftMargin);
00122	    MyMessage.fXSize *= 0.7;
00123	
00124	    j = 1;
00125	
00126	    SubString = MyMessage.StringMessage;
00127	    NewCriticalString = "";
00128	    NewCriticalcurrentString = "";
00129	    i = InStr(SubString, " ");
00130	    //if ( DBMSG ) Log("NewCriticalCurrentString='"$NewCriticalCurrentString$"' SHOULD BE ''");
00131	    While ( i >= 0 )
00132	    {
00133	      LeftString = Left(SubString, i);
00134	      //if ( DBMSG ) Log("pass I="$i$" adding '"$NewCriticalCurrentString$"' with '"$LeftString$"'");
00135	      NewCriticalCurrentString = NewCriticalCurrentString$LeftString;
00136	      C.StrLen(NewCriticalCurrentString, XT2, YT);
00137	      if ( DBMSG ) Log("NewCriticalCurrentString='"$NewCriticalCurrentString$"' Len="$XT2);
00138	      if ( (XT2 >= MyMessage.fXSize) || (XT2 == XT) )
00139	      {
00140	        NewCriticalString = NewCriticalString$"#N"$LeftString;
00141	        NewCriticalcurrentString = LeftString$" ";
00142	        j++;
00143	      }
00144	      else
00145	      {
00146	        if ( bNotFirstTime )
00147	          NewCriticalString = NewCriticalString$" "$LeftString;
00148	        else
00149	          NewCriticalString = LeftString;
00150	        NewCriticalcurrentString = NewCriticalcurrentString$" ";
00151	      }
00152	      bNotFirstTime=true;
00153	      XT = XT2;
00154	      SubString = right(SubString, len(SubString) - i - 1);
00155	      //if ( DBMSG ) Log("  NewCriticalString='"$NewCriticalString$"' SubString='"$SubString$"'");
00156	      i = InStr(SubString, " ");
00157	    }
00158	    // Last Word
00159	    //if ( DBMSG ) Log("Processing Last Word,  NewCriticalCurrentString='"$NewCriticalCurrentString$"' SubString='"$SubString$"'");
00160	    NewCriticalCurrentString = NewCriticalCurrentString$SubString;
00161	    C.StrLen(NewCriticalCurrentString, XT2, YT);
00162	    //if ( DBMSG ) Log("NewCriticalCurrentString='"$NewCriticalCurrentString$"' Len="$XT2);
00163	    if ( (XT2 >= MyMessage.fXSize) || (XT == XT2) )
00164	    {
00165	      NewCriticalString = NewCriticalString$"#N"$SubString;
00166	      j++;
00167	    }
00168	    else
00169	    {
00170	      if ( bNotFirstTime )
00171	        NewCriticalString = NewCriticalString$" "$SubString;
00172	      else
00173	        NewCriticalString = SubString;
00174	    }
00175	    if ( DBMSG ) Log("  NewCriticalString='"$NewCriticalString$"'");
00176	
00177	    MyMessage.NumLines = j;
00178	    MyMessage.StringMessage = NewCriticalString;
00179	}
00180	
00181	//____________________________________________________________________
00182	simulated function DrawHudCartoonSFXMsg(Canvas C)
00183	{
00184	    local float XP, TmpH;
00185	    local float XT, YT;
00186	    Local int i,j;
00187	    local string OutString, SubString;
00188	    local bool bSkip;
00189	    local int NbChars;
00190	    local float fAlpha;
00191	
00192	    if ( MyMessage.Switch >= 8 )
00193	    { // delay display
00194	      if ( MyMessage.EndOfLife - Level.TimeSeconds > MyMessage.LifeTime )
00195	        return;
00196	      MyMessage.Switch -= 8;
00197	    }
00198	    if ( CharCount == 0.0 )
00199	    {
00200	      MyMessage.StartOfLife = Level.TimeSeconds;
00201	      CharCount = 0.01;
00202	    }
00203	    else
00204	      CharCount = Level.TimeSeconds - MyMessage.StartOfLife;
00205	    NbChars = int(charcount*50.0);
00206	    if ( DBMSG ) Log("CharCount = "$NbChars); // 5 characters by second ?
00207	
00208	    if ( PrevHudMsg != none )
00209	      YP = PrevHudMsg.YP + 8;
00210	    else if ( NextHudMsg != none )
00211	      YP = C.ClipY/2.0 + 80 - NextHudMsg.MyMessage.NumLines*YL;
00212	    else
00213	      YP = C.ClipY/2.0 + 80;
00214	    XP = ( C.ClipX - MyMessage.fXSize )/2.0 - 4;
00215	
00216	    if ( XIIIBaseHUD(Owner).HudCartoonSFX ) // extend life only if SFX still active
00217	    {
00218	      fAlpha = 1.0;
00219	      MyMessage.EndOfLife = MyMessage.Lifetime + Level.TimeSeconds;
00220	    }
00221	    else
00222	    {
00223	      fAlpha = fMin(0.25, MyMessage.EndOfLife - Level.TimeSeconds) * 4.0;
00224	      fAlpha = fMin(0.5882, fAlpha);
00225	    }
00226	
00227	    if ( fAlpha > 0.1 )
00228	    {
00229	      C.Style = ERenderStyle.STY_Alpha;
00230	      // Background
00231	      // White background for all
00232	      C.DrawColor = C.Static.MakeColor(255,255,255);
00233	      C.DrawColor.A = 255*fAlpha;
00234	      C.bUseBorder = false;
00235	      C.SetPos(XP - 6,YP - 6);
00236	      C.DrawRect(WhiteTex, MyMessage.fXSize + 8 + 12 , MyMessage.NumLines*YL + 8 + 12);
00237	
00238	//      Log("MSG Display switch="$MyMessage.Switch);
00239	      // then background for message w/ black border
00240	      if ( MyMessage.switch == 2 ) // antigoal
00241	        C.DrawColor = C.Static.MakeColor(255,150,0,180*fAlpha);
00242	      else  if ( MyMessage.switch == -1 ) // Help Msg
00243	        C.DrawColor = C.static.MakeColor(65,186,212,180*fAlpha);
00244	      else
00245	        C.DrawColor = C.Static.MakeColor(0,0,0,30);
00246	      C.BorderColor= C.Static.MakeColor(0,0,0);
00247	      C.BorderColor.A = 255;
00248	      C.bUseBorder = true;
00249	      C.SetPos(XP,YP);
00250	      C.DrawRect(WhiteTex, MyMessage.fXSize + 8 , MyMessage.NumLines*YL + 8);
00251	      C.bUseBorder = false;
00252	
00253	      // Text
00254	      C.DrawColor= C.Static.MakeColor(0,0,0, 255*fAlpha);
00255	      C.bTextShadow = true;
00256	      j = 0;
00257	      SubString = MyMessage.StringMessage;
00258	      i = InStr(SubString, "#N");
00259	      while ( i >= 0 )
00260	      {
00261	        OutString = Left(SubString, i);
00262	        C.StrLen(OutString, XT, YT);
00263	        if ( Len(OutString) > NbChars )
00264	        {
00265	          bSkip = true;
00266	          OutString = left(OutString, NbChars);
00267	        }
00268	        C.SetPos(XP + (MyMessage.fXSize + 8 - XT)/2.0 + 2, YP + 4 + j*YT);
00269	        C.DrawText(OutString);
00270	        if ( MyMessage.Switch == 1 ) // objective complete
00271	        {
00272	//          Log("MSG Display text for completed");
00273	          C.SetPos(XP + (MyMessage.fXSize + 8 - XT)/2.0 + 2, YP + 4 + j*YT + YT*0.52);
00274	          C.StrLen(OutString, XT, YT);
00275	          C.DrawRect(WhiteTex, XT , 2);
00276	        }
00277	        j ++;
00278	        if ( bSkip )
00279	          i = -1;
00280	        else
00281	        {
00282	          NbChars -= Len(OutString);
00283	          SubString = right(SubString, Len(SubString)-i-2);
00284	          i = InStr(SubString, "#N");
00285	        }
00286	      }
00287	      C.StrLen(SubString, XT, YT);
00288	      if ( !bSkip )
00289	      {
00290	        if (Len(SubString) > NbChars)
00291	        {
00292	          bSkip = true;
00293	          SubString = left(SubString, NbChars);
00294	        }
00295	        C.SetPos(XP + (MyMessage.fXSize + 8 - XT)/2.0 + 2, YP + 4 + j*YT);
00296	        C.DrawText(SubString);
00297	        if ( MyMessage.Switch == 1 ) // objective complete
00298	        {
00299	//          Log("MSG Display text for completed");
00300	          C.SetPos(XP + (MyMessage.fXSize + 8 - XT)/2.0 + 2, YP + 4 + j*YT + YT*0.52);
00301	          C.StrLen(SubString, XT, YT);
00302	          C.DrawRect(WhiteTex, XT , 2);
00303	        }
00304	      }
00305	    }
00306	    else
00307	      fAlpha = 0;
00308	
00309	    YP += YL*MyMessage.NumLines + 12;
00310	
00311	    if ( !bSkip && (NextHudMsg != none) )
00312	    {
00313	      if ( bIsHudCartoonFX )
00314	        NextHudMsg.bIsHudCartoonFX = true;
00315	      NextHudMsg.DrawMsg(C);
00316	    }
00317	    else
00318	      XIIIBaseHUD(Owner).YP = YP;
00319	
00320	    if ( MyMessage.EndOfLife < Level.TimeSeconds )
00321	      ReMoveMe();
00322	
00323	    C.SpaceX = 0;
00324	}
00325	
00326	//____________________________________________________________________
00327	simulated function DrawMsg(Canvas C)
00328	{
00329	    local float XP, TmpH;
00330	    local float fAlpha, XT, YT, MXT;
00331	    Local int i,j;
00332	    local string OutString, SubString;
00333	
00334	    C.SpaceX = 1;
00335	    XIIIBaseHUD(Owner).UseMsgFont(C);
00336	
00337	    if ( MyMessage.NumLines == 0 )
00338	      ProcessMessage(C);
00339	
00340	    if ( MyMessage.Switch == -1 ) // Help message
00341	    {
00342	      if ( ((PrevHudMsg != none) && (PrevHudMsg.MyMessage.Switch != -1)) || ((NextHudMsg != none) && (NextHudMsg.MyMessage.Switch != -1)) )
00343	      { // Delay Help Message (MessageTriggers) until no objectives drawn
00344	        MyMessage.EndOfLife = MyMessage.Lifetime + Level.TimeSeconds;
00345	        if ( NextHudMsg != none )
00346	        {
00347	          if ( PrevHudMsg != none )
00348	            YP = PrevHudMsg.YP + 8;
00349	          else if ( NextHudMsg != none )
00350	            YP = C.ClipY/2.0 + 80 - NextHudMsg.MyMessage.NumLines*YL;
00351	          else
00352	            YP = C.ClipY/2.0 + 80;
00353	          NextHudMsg.DrawMsg(C);
00354	        }
00355	        return;
00356	      }
00357	    }
00358	    if( XIIIBaseHUD(Owner).HudCartoonSFX || bIsHudCartoonFX )
00359	    {
00360	      bIsHudCartoonFX = true;
00361	      DrawHudCartoonSFXMsg(C);
00362	      return;
00363	    }
00364	}
00365	
00366	//____________________________________________________________________
00367	function RemoveMe()
00368	{
00369	    if (PrevHudMsg == none)
00370	    {
00371	      if (NextHudMsg != none)
00372	      {
00373	        XIIIBaseHUD(Owner).HudObjMsg = NextHudMsg;
00374	        NextHudMsg.PrevHudMsg = none;
00375	      }
00376	      else
00377	        XIIIBaseHUD(Owner).HudObjMsg = none;
00378	    }
00379	    else
00380	    {
00381	      PrevHudMsg.NextHudMsg = NextHudMsg;
00382	      if ( NextHudMsg != none )
00383	        NextHudMsg.PrevHudMsg = PrevHudMsg;
00384	    }
00385	    Destroy();
00386	}
00387	
00388	//____________________________________________________________________
00389	function DestroyFirstMessage()
00390	{
00391	    if ( (index == 0) || (PrevHudMsg == none) )
00392	    {
00393	      index = -1;
00394	      NextHudMsg.ActualizeIndex();
00395	      RemoveMe();
00396	    }
00397	    else
00398	      PrevHudMsg.DestroyFirstMessage();
00399	}
00400	
00401	//____________________________________________________________________
00402	function ActualizeIndex()
00403	{
00404	    if ( PrevHudMsg != none )
00405	      Index = PrevHudMsg.index + 1;
00406	    if ( NextHudMsg != none )
00407	      NextHudMsg.ActualizeIndex();
00408	}
00409	
00410	
00411	
00412	defaultproperties
00413	{
00414	     WhiteTex=Texture'XIIIMenu.HUD.blanc'
00415	     ValidatedTex=Texture'XIIIMenu.HUD.Valid'
00416	}

End Source Code