XIII
Class HudDialog

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

class HudDialog
extends Engine.Info

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 color DrawColor
 float EndOfLife
 float LifeTime
 Class Message
 HUDLocalizedMessage MyMessage
 Texture NoiseTex
           texture for above display
 Object OptionalObject
 Pawn SpeakingPawn
           the pawn that speak this sentence
 string StringMessage
 int Switch
 TextColor, WarnColor
           Because we may change them upon character speaking
 XL, YL
 float YP
 bool bSpecialBackGround
           Special display for HF/HP/Unlocalized voices
 float fXSize
 int numLines


Function Summary
 
simulated
DrawDlg(Canvas C)
     
//____________________________________________________________________
 
simulated
DrawDlg(Canvas C)
     
//____________________________________________________________________
 void ProcessMessage(Canvas C)
     
//____________________________________________________________________
 void RemoveMe()
     
//____________________________________________________________________



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class HudDialog extends Info
00005	  NotPlaceable;
00006	
00007	struct HUDLocalizedMessage
00008	{
00009	    var Class<LocalMessage> Message;
00010	    var int Switch;
00011	    var Object OptionalObject;
00012	    var float EndOfLife;
00013	    var float LifeTime;
00014	    var int numLines;
00015	    var string StringMessage;
00016	    var color DrawColor;
00017	    var float fXSize;
00018	};
00019	
00020	var HUDLocalizedMessage MyMessage;
00021	var float YP;
00022	
00023	// Optimization, global vars to comput only once
00024	var float XL, YL;
00025	var Pawn SpeakingPawn;                // the pawn that speak this sentence
00026	//var float NameXL, NameYL;
00027	
00028	var color BackGrndColor, TextColor, WarnColor;   // Because we may change them upon character speaking
00029	
00030	var bool bSpecialBackGround;          // Special display for HF/HP/Unlocalized voices
00031	var Texture NoiseTex;                 // texture for above display
00032	
00033	//____________________________________________________________________
00034	simulated function SetUpLocalizedMessage( class<LocalMessage> Message, optional int Switch, optional PlayerReplicationInfo RelatedPRI_1, optional PlayerReplicationInfo RelatedPRI_2, optional Object OptionalObject, optional string CriticalString )
00035	{
00036	    if ( CriticalString == "" )
00037	      CriticalString = Message.Static.GetString(Switch, RelatedPRI_1, RelatedPRI_2, OptionalObject);
00038	
00039	    if ( CriticalString == "" )
00040	      RemoveMe();
00041	
00042	    MyMessage.Message = Message;
00043	    MyMessage.Switch = Switch;
00044	    MyMessage.OptionalObject = OptionalObject;
00045	    MyMessage.EndOfLife = Message.Default.Lifetime + Level.TimeSeconds;
00046	    MyMessage.LifeTime = Message.Default.Lifetime;
00047	    MyMessage.NumLines = 0; // should be initialized first time we draw the string
00048	    MyMessage.StringMessage = CriticalString;
00049	    MyMessage.DrawColor = Message.Static.GetColor(Switch, RelatedPRI_1, RelatedPRI_2);
00050	    MyMessage.fXSize = 0; // should be initialized first time we draw the string
00051	}
00052	
00053	//____________________________________________________________________
00054	FUNCTION ProcessMessage(Canvas C)
00055	{
00056	    local int i; // Index of the processed space
00057	    local int linesCounter; // number of lines
00058	    local string SubString, NewCriticalString, NewCriticalCurrentString;
00059	    local float XT,XT2,YT;
00060	    local string LeftString;
00061	
00062	    // Max message width
00063	    MyMessage.fXSize = C.ClipX * (1.0 - XIIIBaseHUD(Owner).RightMargin - XIIIBaseHUD(Owner).LeftMargin) - 80*C.ClipX/640.0;
00064	
00065	    linesCounter = 1;
00066	    SubString = MyMessage.StringMessage;
00067	    NewCriticalString = "";
00068	    NewCriticalcurrentString = "";
00069	    i = InStr(SubString, " ");
00070	
00071	    while ( i >= 0 )
00072	    {
00073	      LeftString = Left(SubString, i);
00074	      NewCriticalCurrentString = NewCriticalCurrentString$LeftString;
00075	      C.StrLen(NewCriticalCurrentString, XT2, YT);
00076	
00077	      if ( (XT2 >= MyMessage.fXSize-20) || (XT2 == XT) )
00078	      {
00079	        NewCriticalString = NewCriticalString$"#N"$LeftString;
00080	        NewCriticalcurrentString = LeftString$" ";
00081	        linesCounter++;
00082	      }
00083	      else
00084	      {
00085	        NewCriticalString = NewCriticalString@LeftString;
00086	        NewCriticalcurrentString = NewCriticalcurrentString$" ";
00087	      }
00088	      XT = XT2;
00089	      SubString = Mid (SubString,i+1); //right(SubString, len(SubString) - i - 1);
00090	
00091	      i = InStr(SubString, " ");
00092	    }
00093	// Last Word
00094	
00095	    NewCriticalCurrentString = NewCriticalCurrentString$SubString;
00096	    C.StrLen(NewCriticalCurrentString, XT2, YT);
00097	
00098	    if ( (XT2 >= MyMessage.fXSize-20) || (XT == XT2) )
00099	    {
00100	      NewCriticalString = NewCriticalString$"#N"$SubString;
00101	      linesCounter++;
00102	    }
00103	    else
00104	    {
00105	      NewCriticalString = NewCriticalString@SubString;
00106	    }
00107	
00108	    MyMessage.NumLines = LinesCounter;
00109	    MyMessage.StringMessage = NewCriticalString;
00110	    if ( MyMessage.NumLines == 1 )
00111	    { // Only one line, change FXSize
00112	//      C.StrLen(MyMessage.StringMessage, XT, YT);
00113	      MyMessage.fXSize = fMin(XT2 + YT, MyMessage.fXSize);
00114	    }
00115	
00116	    // this can be done to optimize only if the UseDialogFont() can't change the font upon res change
00117	    C.StrLen("A",XL,YL);
00118	    SpeakingPawn = Pawn(MyMessage.OptionalObject);
00119	//    if ( SpeakingPawn != none )
00120	//      C.StrLen(XIIIPawn(SpeakingPawn).PawnName, NameXL, NameYL);
00121	
00122	    switch ( MyMessage.Switch )
00123	    {
00124	      Case 2:
00125	        bSpecialBackGround = true;
00126	      Case 0:
00127	        BackGrndColor = default.BackGrndColor;
00128	        TextColor = MyMessage.DrawColor;
00129	        break;
00130	      Case 1:
00131	        BackGrndColor = MyMessage.DrawColor;
00132	        TextColor = default.BackGrndColor;
00133	        break;
00134	      Case 3:
00135	        BackGrndColor = WarnColor;
00136	        TextColor = MyMessage.DrawColor;
00137	        break;
00138	      Case 4: // XIIIDialogMessages, spoken by XIII
00139	      Case 5:
00140	        BackGrndColor = MyMessage.DrawColor;
00141	        TextColor = default.BackGrndColor;
00142	        break;
00143	      Default:
00144	        BackGrndColor = default.BackGrndColor;
00145	        TextColor = MyMessage.DrawColor;
00146	        break;
00147	    }
00148	}
00149	
00150	/* // ELR Old way using text scrolling / Line limitation (unoptimized)
00151	//____________________________________________________________________
00152	simulated FUNCTION DrawDlg(Canvas C)
00153	{
00154	    local float XP;
00155	    local float XL, YL, fAlpha, XT, YT, NameXL, NameYL;
00156	    local int i,j;
00157	    local string OutString, SubString;
00158	    local pawn SpeakingPawn;
00159	    local float dSAT;
00160	    local float dSTAB;
00161	    local float dist;
00162	    local float offset;
00163	    local int NumVisibleLines;
00164	    local int OldClipX,OldClipY,OldOriginX,OldOriginY;
00165	    const MaxVisibleLines=5;
00166	    local vector vT, vT2;
00167	    local bool bMemSmooth;
00168	
00169	    C.SpaceX=0;
00170	    if ( MyMessage.NumLines == 0 )
00171	      ProcessMessage(C);
00172	
00173	    if (MyMessage.NumLines>MaxVisibleLines)
00174	      NumVisibleLines=MaxVisibleLines;
00175	    else
00176	      NumVisibleLines=MyMessage.NumLines;
00177	
00178	    C.StrLen("A",XL,YL);
00179	
00180	    YP = XIIIBaseHUD(Owner).UpMargin * C.ClipY;
00181	    XP = XIIIBaseHUD(Owner).LeftMargin * C.ClipX;
00182	
00183	// iKi : visual RollOff
00184	    SpeakingPawn=Pawn(MyMessage.OptionalObject);
00185	    if (SpeakingPawn!=none)
00186	    {
00187	      dSAT=SpeakingPawn.VoicesSaturationDistance;
00188	      dSTAB=SpeakingPawn.VoicesStabilisationDistance;
00189	      dist=VSize(SpeakingPawn.Location-XIIIGameInfo(Level.Game).MapInfo.XIIIPawn.Location);
00190	
00191	//      if (dist<dSAT)
00192	//        fAlpha=1.0;
00193	//      else
00194	//        if (dist>dSTAB)
00195	//          fAlpha=0.0;
00196	//        else
00197	//          fAlpha= (dist-dSTAB)/(dSAT-dSTAB);
00198	        fAlpha=1.0;
00199	    }
00200	    else
00201	      fAlpha=1.0;
00202	// iKi : END
00203	
00204	    fAlpha *= fMin(0.25, MyMessage.EndOfLife - Level.TimeSeconds) * 4.0;
00205	
00206	    if (fAlpha > 0.01)
00207	    {
00208	      C.SetPos(XP-3,YP-3);
00209	      C.Style = ERenderStyle.STY_Alpha;
00210	      C.SetDrawColor(220,220,220,255);
00211	      C.BorderColor = C.Static.makecolor(0,0,0,255);
00212	      C.bUseBorder = true;
00213	//      C.bDialogWindow = true;
00214	      C.DrawTile(XIIIBaseHUD(Owner).FondDlg, MyMessage.fXSize ,YL*NumVisibleLines+6, 0, 0, XIIIBaseHUD(Owner).FondDlg.USize, XIIIBaseHUD(Owner).FondDlg.VSize);
00215	      C.bUseBorder = false;
00216	//      C.bDialogWindow = false;
00217	
00218	      if ( ( SpeakingPawn != none ) && (Level.TimeSeconds < SpeakingPawn.LastRenderTime + 0.1) )
00219	//      if ( (SpeakingPawn != none) && FastTrace(SpeakingPawn.Location, XIIIGameInfo(Level.Game).MapInfo.XIIIPawn.EyePosition()) )
00220	      {
00221	        vT = XIIIBaseHUD(Owner).XIIIPlayerOwner.Player.Console.WorldToScreen(SpeakingPawn.Location);
00222	        vT2.Y = YP-3+YL*NumVisibleLines+2;
00223	
00224	        if ( vT.X < ( C.ClipX*XIIIBaseHUD(Owner).LeftMargin ) )
00225	          vT2.x = C.ClipX*XIIIBaseHUD(Owner).LeftMargin;
00226	        else if ( vT.X > C.ClipX*XIIIBaseHUD(Owner).LeftMargin + MyMessage.fXSize -XIIIBaseHUD(Owner).FlechDlg.USize )
00227	          vT2.x = C.ClipX*XIIIBaseHUD(Owner).LeftMargin + MyMessage.fXSize -XIIIBaseHUD(Owner).FlechDlg.USize;
00228	        else
00229	          vT2.x = vT.x;
00230	
00231	
00232	        // Display PawnName
00233	        C.StrLen(XIIIPawn(SpeakingPawn).PawnName,NameXL,NameYL);
00234	        C.Style = ERenderStyle.STY_Normal;
00235	        C.SetPos(XP, YP-NameYL);
00236	        C.SetDrawColor(220,220,220,255);
00237	        C.bUseBorder = true;
00238	        C.DrawTile(XIIIBaseHUD(Owner).FondDlg, NameXL+8, NameYL, 0, 0, XIIIBaseHUD(Owner).FondDlg.USize, XIIIBaseHUD(Owner).FondDlg.VSize);
00239	        C.bUseBorder = false;
00240	        C.SetPos(XP+4, YP-NameYL);
00241	        C.SetDrawColor(0,0,0,255);
00242	        C.DrawText(XIIIPawn(SpeakingPawn).PawnName);
00243	        // Display comic arrow
00244	        C.SetPos(vT2.x, vT2.y);
00245	        C.Style = ERenderStyle.STY_Alpha;
00246	        C.SetDrawColor(220,220,220,255);
00247	        bMemSmooth = C.bNoSmooth;
00248	        C.bNoSmooth = true;
00249	
00250	        if ( C.CurX > MyMessage.fXSize/2.0 )
00251	//        if ( C.CurX > C.ClipX/2.0 )
00252	          C.DrawTile(XIIIBaseHUD(Owner).FlechDlg, XIIIBaseHUD(Owner).FlechDlg.USize ,XIIIBaseHUD(Owner).FlechDlg.VSize, 0, 0, -XIIIBaseHUD(Owner).FlechDlg.USize, XIIIBaseHUD(Owner).FlechDlg.VSize);
00253	        else
00254	          C.DrawTile(XIIIBaseHUD(Owner).FlechDlg, XIIIBaseHUD(Owner).FlechDlg.USize ,XIIIBaseHUD(Owner).FlechDlg.VSize, 0, 0, XIIIBaseHUD(Owner).FlechDlg.USize, XIIIBaseHUD(Owner).FlechDlg.VSize);
00255	        C.bNoSmooth = bMemSmooth;
00256	      }
00257	
00258	      C.Style = ERenderStyle.STY_Alpha;
00259	
00260	      j = 0;
00261	      SubString = MyMessage.StringMessage;
00262	      OldOriginX=C.OrgX;
00263	      OldOriginY=C.OrgY;
00264	      OldClipX=C.ClipX;
00265	      OldClipY=C.ClipY;
00266	
00267	      C.SetOrigin(XP,YP);
00268	      C.SetClip(C.ClipX,YL*NumVisibleLines);
00269	
00270	      if (MyMessage.NumLines>NumVisibleLines)
00271	      {
00272	        offset=(1-(MyMessage.EndOfLife - Level.TimeSeconds)/MyMessage.LifeTime);
00273	        if (offset<0.15)
00274	          offset=0;
00275	        else
00276	          if (offset>0.80)
00277	            offset=YL*(MyMessage.NumLines-NumVisibleLines);
00278	          else
00279	            offset=YL*(MyMessage.NumLines-NumVisibleLines)*(offset-0.15)/0.65;
00280	//            offset=YL*(MyMessage.NumLines-NumVisibleLines)*(1-(MyMessage.EndOfLife - Level.TimeSeconds)/MyMessage.LifeTime);
00281	      }
00282	      else
00283	        offset=0;
00284	      do
00285	      {
00286	        i = InStr(SubString, "#N");
00287	        if (i>0)
00288	          OutString = Left(SubString, i);
00289	        else
00290	          OutString = SubString;
00291	
00292	        C.StrLen(OutString, NameXL, NameYL);
00293	        C.SetPos((MyMessage.fXSize-10.0)/2.0 - NameXL/2.0, j*YL - offset );
00294	        C.DrawColor = MyMessage.DrawColor * 0.15;
00295	        C.DrawColor.A = C.DrawColor.A * fAlpha;
00296	        C.DrawTextClipped(OutString);
00297	
00298	        j ++;
00299	        SubString = right(SubString, Len(SubString)-i-2);
00300	      } until ( i < 0 );
00301	
00302	      C.SetOrigin(OldOriginX,OldOriginY);
00303	      C.SetClip(OldClipX,OldClipY);
00304	    }
00305	    else
00306	      fAlpha = 0.0;
00307	
00308	//    if ( fAlpha == 0.0 ) // ELR can't use anymore with fadeout because must be able to start dialog and approch later (don't remove it if it's not really finished)
00309	    if ( (MyMessage.EndOfLife <= Level.TimeSeconds)  )
00310	      ReMoveMe();
00311	}
00312	*/
00313	
00314	//____________________________________________________________________
00315	simulated function DrawDlg(Canvas C)
00316	{
00317	    local float XP;
00318	    local float fAlpha;
00319	    local int i,j;
00320	    local string OutString, SubString;
00321	    local vector vT, vT2;
00322	    local bool bMemSmooth;
00323	    local bool bMirrorDlgArrow;
00324	
00325	    C.SpaceX = 0;
00326	    XIIIBaseHUD(Owner).UseDialogFont(C);
00327	    if ( MyMessage.NumLines == 0 )
00328	      ProcessMessage(C);
00329	
00330	    YP = XIIIBaseHUD(Owner).UpMargin * C.ClipY;
00331	    XP = XIIIBaseHUD(Owner).LeftMargin * C.ClipX + 80*C.ClipX/640.0;
00332	
00333	    fAlpha = fMin(0.25, MyMessage.EndOfLife - Level.TimeSeconds) * 4.0;
00334	
00335	    if (fAlpha > 0.01)
00336	    {
00337	      C.Style = ERenderStyle.STY_Alpha;
00338	      C.SetPos(XP-5,YP-5);
00339	      C.DrawColor = TextColor;
00340	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, MyMessage.fXSize + 4 ,YL*MyMessage.NumLines+6 + 4);
00341	      C.SetPos(XP-3,YP-3);
00342	      C.DrawColor = BackGrndColor;
00343	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, MyMessage.fXSize ,YL*MyMessage.NumLines+6);
00344	      if ( bSpecialBackGround )
00345	      { // Draw special background there
00346	        C.SetPos(XP-3,YP-3);
00347	        C.DrawColor = BackGrndColor;
00348	        C.DrawColor.A = 130;
00349	        C.DrawTile(NoiseTex, MyMessage.fXSize ,YL*MyMessage.NumLines+6,0,0,NoiseTex.USize*(Frand()+2),NoiseTex.VSize*(Frand()+2));
00350	      }
00351	
00352	      if ( SpeakingPawn != none )
00353	      {
00354	
00355	/* Activate to enable pawn name display
00356	        if ( SpeakingPawn.PawnName != "" )
00357	        { // Display Name
00358	          C.SetPos(XP-2, YP-NameYL-2);
00359	          C.DrawColor = TextColor;
00360	          C.DrawRect(XIIIBaseHUD(Owner).FondDlg, NameXL+8 + 4, NameYL + 4);
00361	          C.SetPos(XP, YP-NameYL);
00362	          C.DrawColor = BackGrndColor;
00363	          C.DrawRect(XIIIBaseHUD(Owner).FondDlg, NameXL+8, NameYL);
00364	          C.SetPos(XP+4, YP-NameYL);
00365	          C.DrawColor = TextColor;
00366	          C.DrawText(SpeakingPawn.PawnName);
00367	        }
00368	*/
00369	
00370	        if ((SpeakingPawn.Location-XIIIBaseHUD(Owner).PlayerOwner.Pawn.Location) dot vector(XIIIBaseHUD(Owner).PlayerOwner.Rotation) > 0.707)
00371	        { // Display comic arrow
00372	          vT = XIIIBaseHUD(Owner).PlayerOwner.Player.Console.WorldToScreen(SpeakingPawn.Location);
00373	          if ( vT != vect(0,0,0) )
00374	          {
00375	            vT2.Y = YP-3+YL*MyMessage.NumLines+2;
00376	            if ( vT.x < XP )
00377	              vT2.x = XP;
00378	            else if ( vT.X > (XP + MyMessage.fXSize - XIIIBaseHUD(Owner).FlechDlg.USize) )
00379	            {
00380	              vT2.x = XP + MyMessage.fXSize - XIIIBaseHUD(Owner).FlechDlg.USize;
00381	              bMirrorDlgArrow = true;
00382	            }
00383	            else
00384	              vT2.x = vT.x;
00385	
00386	            C.SetPos(vT2.x, vT2.y);
00387	            C.DrawColor = BackGrndColor;
00388	            bMemSmooth = C.bNoSmooth;
00389	            C.bNoSmooth = true;
00390	            if ( bMirrorDlgArrow )
00391	              C.DrawTile(XIIIBaseHUD(Owner).FlechDlg, XIIIBaseHUD(Owner).FlechDlg.USize, XIIIBaseHUD(Owner).FlechDlg.VSize, 0, 0, XIIIBaseHUD(Owner).FlechDlg.USize, XIIIBaseHUD(Owner).FlechDlg.VSize);
00392	            else
00393	              C.DrawTile(XIIIBaseHUD(Owner).FlechDlg, XIIIBaseHUD(Owner).FlechDlg.USize, XIIIBaseHUD(Owner).FlechDlg.VSize, 0, 0, -XIIIBaseHUD(Owner).FlechDlg.USize, XIIIBaseHUD(Owner).FlechDlg.VSize);
00394	            C.bNoSmooth = bMemSmooth;
00395	          }
00396	        }
00397	      }
00398	
00399	      C.DrawColor = TextColor;
00400	      C.DrawColor.A = C.DrawColor.A * fAlpha;
00401	      C.bTextShadow = false;
00402	      j = 0;
00403	      SubString = MyMessage.StringMessage;
00404	      do
00405	      {
00406	        i = InStr(SubString, "#N");
00407	        if (i>0)
00408	          OutString = Left(SubString, i);
00409	        else
00410	          OutString = SubString;
00411	
00412	        C.SetPos(XP + 2, YP + j*YL + 1);
00413	        C.DrawText(OutString);
00414	        j ++;
00415	        SubString = right(SubString, Len(SubString)-i-2);
00416	      }
00417	      until ( i < 0 );
00418	    }
00419	    else
00420	      fAlpha = 0.0;
00421	
00422	    if ( (MyMessage.EndOfLife <= Level.TimeSeconds)  )
00423	      ReMoveMe();
00424	}
00425	
00426	//____________________________________________________________________
00427	function RemoveMe()
00428	{
00429	    XIIIBaseHUD(Owner).HudDlg = none;
00430	    Destroy();
00431	}
00432	
00433	
00434	
00435	defaultproperties
00436	{
00437	     BackGrndColor=(B=220,G=220,R=220,A=255)
00438	     WarnColor=(B=20,G=150,R=255,A=255)
00439	     NoiseTex=Texture'XIIICine.Bruit'
00440	}

End Source Code