XIII
Class HudCartoonFocus

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

class HudCartoonFocus
extends Engine.Info

//----------------------------------------------------------- // //-----------------------------------------------------------
Variables
 color BorderColor
           target Width & Height of 'outline' (in fact half w/h)
 int CWndAppearFX
 CWndX, CWndY
           coords of 'outline'
 StartOfLife, EndOfLife
 color FilterColor
           coords of 'outline'
 Material FilterTexture
           coords of 'outline'
 FocusWidth, FocusHeight
           target Width & Height of 'outline' (in fact half w/h)
 float HighLight
           coords of 'outline'
 Actor MyFocus
 HudCartoonFocus NextHudFoc
 OMsgWidth, OMsgH
           witdh of the message, Height of one line
 OMsgX, OMsgY
           position of message
 array OverlayMsg
           message to display in overlay
 HudCartoonFocus PrevHudFoc
 XP2, YP2
           coords of 'outline'
 bool bCartoonFocusDanger
           position of message
 bool bEnableCWnd
           coords of 'outline'
 bool bModeInfini
           coords of 'outline'
 bool bUseVignette
           coords of 'outline'
 float zoomCameraDistance
           position of message
 float zoomCameraFOV
           position of message
 bool zoomFocus
           position of message

States
ZoomToStandardCWnd, AppearZoom

Function Summary
 
simulated
AddCartoonFocus(Actor Focus, int AppearFX, bool bUseVignette, float Duration, bool zoom, float zoomFOV, float zoomDist, bool bDanger)
     
//____________________________________________________________________
 
simulated
DrawWnd(Canvas C)
     
//____________________________________________________________________
 void RemoveMe()
     
//____________________________________________________________________
 
simulated
SetUpCartoonFocus(Actor Focus, int AppearFX, bool bVignette, float Duration, bool zoom, float zoomFOV, float zoomDist, bool bDanger)
     
//____________________________________________________________________


State ZoomToStandardCWnd Function Summary


State AppearZoom Function Summary



Source Code


00001	//-----------------------------------------------------------
00002	//
00003	//-----------------------------------------------------------
00004	class HudCartoonFocus extends Info
00005	  NotPlaceable;
00006	
00007	var HudCartoonFocus NextHudFoc;
00008	var HudCartoonFocus PrevHudFoc;
00009	
00010	var actor MyFocus;
00011	
00012	// vars for appearance sfx
00013	var float StartOfLife, EndOfLife;
00014	var int CWndAppearFX;
00015	var float FocusWidth, FocusHeight;  // target Width & Height of 'outline' (in fact half w/h)
00016	var color BorderColor;
00017	var float XP1, YP1, XP2, YP2;       // coords of 'outline'
00018	
00019	var color FilterColor;
00020	var float HighLight;
00021	var Material FilterTexture;
00022	var int CWndX, CWndY;
00023	var bool bEnableCWnd;
00024	var bool bUseVignette;
00025	var bool bModeInfini;
00026	
00027	// vars for overlay text
00028	var array<string> OverlayMsg;       // message to display in overlay
00029	var float OMsgWidth, OMsgH;         // witdh of the message, Height of one line
00030	var float OMsgX, OMsgY;             // position of message
00031	
00032	var bool zoomFocus;
00033	var float zoomCameraDistance;
00034	var float zoomCameraFOV;
00035	
00036	var bool bCartoonFocusDanger;
00037	
00038	CONST TRANSITDELAY=0.35;            // transition delay for appearance SFXs
00039	
00040	//____________________________________________________________________
00041	simulated function DrawWnd(Canvas C);
00042	
00043	//____________________________________________________________________
00044	simulated function SetUpCartoonFocus(Actor Focus, int AppearFX, bool bVignette, float Duration, bool zoom, float zoomFOV, float zoomDist, bool bDanger)
00045	{
00046	    MyFocus = Focus;
00047	    FocusWidth = fMax(Focus.CollisionRadius, 30);
00048	    FocusHeight = fMax(Focus.COllisionHeight, 30);
00049	    StartOfLife = Level.TimeSeconds;
00050	    if (Duration < 0)
00051	    {
00052	      // cas de focus longs desactivables par event
00053	      EndOfLife = StartOfLife;
00054	      bModeInfini = true;
00055	      XIIIBaseHUD(Owner).tCartoonFocus[XIIIBaseHUD(Owner).eNbHudCartoonFocus] = self;
00056	      XIIIBaseHUD(Owner).eNbHudCartoonFocus ++;
00057	    }
00058	    else
00059	    {
00060	      EndOfLife = StartOfLife + Duration;
00061	    }
00062	    CWndAppearFX = AppearFX;
00063	    bUseVignette = bVignette;
00064	    zoomFocus = zoom;
00065	    zoomCameraFOV = zoomFOV;
00066	    zoomCameraDistance = zoomDist;
00067	    bCartoonFocusDanger = bDanger;
00068	    switch ( CWndAppearFX )
00069	    {
00070	      Case 0:
00071	        GotoState('AppearZoom');
00072	        break;
00073	      Case 1:
00074	        GotoState('AppearZoom');
00075	        break;
00076	    }
00077	}
00078	
00079	//____________________________________________________________________
00080	simulated function AddCartoonFocus(Actor Focus, int AppearFX, bool bUseVignette, float Duration, bool zoom, float zoomFOV, float zoomDist, bool bDanger)
00081	{
00082	    if ( NextHudFoc == none )
00083	    {
00084	      NextHudFoc = Spawn(class'HudCartoonFocus',Owner);
00085	      NextHudFoc.PrevHudFoc = self;
00086	      NextHudFoc.SetUpCartoonFocus(Focus, AppearFX, bUseVignette, Duration, zoom, zoomFOV, zoomDist, bDanger);
00087	    }
00088	    else
00089	    {
00090	      NextHudFoc.AddCartoonFocus(Focus, AppearFX, bUseVignette, Duration, zoom, zoomFOV, zoomDist, bDanger);
00091	    }
00092	}
00093	
00094	//____________________________________________________________________
00095	function RemoveMe()
00096	{
00097	    if ( bEnableCWnd && bUseVignette )
00098	      XIIIBaseHUD(Owner).CWndMat.FreeRect(CWndX, CWndY, FocusWidth*2, FocusHeight*2);
00099	
00100	    if (PrevHudFoc == none)
00101	    {
00102	      if (NextHudFoc != none)
00103	      {
00104	        XIIIBaseHUD(Owner).HudFoc = NextHudFoc;
00105	        NextHudFoc.PrevHudFoc = none;
00106	      }
00107	      else
00108	      XIIIBaseHUD(Owner).HudFoc = none;
00109	    }
00110	    else
00111	    {
00112	      PrevHudFoc.NextHudFoc = NextHudFoc;
00113	      if ( NextHudFoc != none )
00114	        NextHudFoc.PrevHudFoc = PrevHudFoc;
00115	    }
00116	    Destroy();
00117	}
00118	
00119	//____________________________________________________________________
00120	state AppearZoom
00121	{
00122	    simulated function BeginState()
00123	    {
00124	      Disable('tick');
00125	    }
00126	
00127	    simulated function DrawWnd(Canvas C)
00128	    {
00129	      local vector campos;
00130	      local int x1,y1,x2,y2;
00131	      local eDrawType DT_mem;
00132	      Local Vector vFocusLoc;
00133	      local float fVarSize;
00134	      local float XL, YL; // realtime length & width of icon
00135	      local float fAlpha; // from 0.f to 1.f, 1 = transition ended
00136	      local actor A;
00137	      local vector HitLoc, HitNorm;
00138	      local material HitMat;
00139	
00140	      if ( MyFocus == none )
00141	      {
00142	        RemoveMe();
00143	        Return;
00144	      }
00145	//      Log("Angle="$normal(MyFocus.Location - (XIIIBaseHUD(Owner).PawnOwner.Location + XIIIBaseHUD(Owner).PawnOwner.EyePosition())) dot vector(XIIIBaseHUD(Owner).XIIIPlayerOwner.rotation));
00146	      if ( normal(MyFocus.Location - (XIIIBaseHUD(Owner).PawnOwner.Location + XIIIBaseHUD(Owner).PawnOwner.EyePosition())) dot vector(XIIIBaseHUD(Owner).XIIIPlayerOwner.rotation) < 0.707 )
00147	      {
00148	        if (NextHudFoc != none)
00149	          NextHudFoc.DrawWnd(C);
00150	        if (( Level.TimeSeconds > EndOfLife ) && !bModeInfini )
00151	          RemoveMe();
00152	        return;
00153	      }
00154	      A = Trace(HitLoc, HitNorm, MyFocus.Location, XIIIBaseHUD(Owner).PawnOwner.Location, true, vect(0,0,0), HitMat, TRACETYPE_DiscardIfCanSeeThrough);
00155	      if ( (A != none) && (A != MyFocus) )
00156	      {
00157	        if (NextHudFoc != none)
00158	          NextHudFoc.DrawWnd(C);
00159	        if (( Level.TimeSeconds > EndOfLife ) && !bModeInfini )
00160	          RemoveMe();
00161	        return;
00162	      }
00163	
00164	      vFocusLoc = XIIIBaseHUD(Owner).XIIIPlayerOwner.Player.Console.WorldToScreen(MyFocus.Location);
00165	      C.Style = ERenderStyle.STY_Alpha;
00166	      fVarSize = 100.0
00167	        / vSize(MyFocus.Location - ( XIIIBaseHUD(Owner).PawnOwner.Location + XIIIBaseHUD(Owner).PawnOwner.EyePosition()))
00168	        / Tan(XIIIBaseHUD(Owner).XIIIPlayerOwner.FOVAngle);
00169	
00170	      fAlpha = (Level.TimeSeconds - StartOfLife) / TRANSITDELAY;
00171	      XL = FocusWidth * fVarSize;
00172	      YL = FocusHeight * fVarSize;
00173	      if ( fAlpha <= 0.97 )
00174	      {
00175	        XP1 = int(C.ClipX * XIIIBaseHUD(Owner).LeftMargin * ( 1.0 - fAlpha ) + fAlpha * (vFocusLoc.X - XL));
00176	        XP2 = int(C.ClipX * (1.0 - XIIIBaseHUD(Owner).RightMargin) * ( 1.0 - fAlpha ) + fAlpha * (vFocusLoc.X + XL));
00177	        YP1 = int(C.ClipY * XIIIBaseHUD(Owner).UpMargin * ( 1.0 - fAlpha ) + fAlpha * (vFocusLoc.Y - YL));
00178	        YP2 = int(C.ClipY * (1.0 - XIIIBaseHUD(Owner).DownMargin) * ( 1.0 - fAlpha ) + fAlpha * (vFocusLoc.Y + YL));
00179	      }
00180	      else
00181	      {
00182	        XP1 = int(vFocusLoc.X - XL);
00183	        XP2 = int(vFocusLoc.X + XL);
00184	        YP1 = int(vFocusLoc.Y - YL);
00185	        YP2 = int(vFocusLoc.Y + YL);
00186	      }
00187	/*
00188	      // white border
00189	      C.DrawColor = C.Static.MakeColor(255,255,255,255);
00190	      // Above
00191	      C.SetPos(XP1 - 8, YP1 - 8);
00192	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1) + 16, 8);
00193	      // Left
00194	      C.SetPos(XP1 - 8, YP1 - 8);
00195	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, 8, (YP2 - YP1) + 16);
00196	      // Under
00197	      C.SetPos(XP1 - 8, YP2);
00198	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1) + 16, 8);
00199	      // Right
00200	      C.SetPos(XP2, YP1 - 8);
00201	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, 8, (YP2 - YP1) + 16);
00202	*/
00203	
00204	      C.DrawColor = C.Static.MakeColor(0,0,0,0);
00205	      C.BorderColor = C.Static.MakeColor(0,0,0,255);
00206	      C.bUseBorder = true;
00207	      // outer outline
00208	      if ( bCartoonFocusDanger )
00209	      {
00210	        C.SetPos(XP1 - 1, YP1 - 1);
00211	        C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1)+2, (YP2 - YP1)+2);
00212	      }
00213	      else
00214	      {
00215	        C.SetPos(XP1 - 2, YP1 - 2);
00216	        C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1)+4, (YP2 - YP1)+4);
00217	      }
00218	      // inner outline
00219	      C.SetPos(XP1, YP1);
00220	      if ( bCartoonFocusDanger )
00221	        C.BorderColor = C.Static.MakeColor(190,66,24,255);
00222	      else
00223	        C.BorderColor = C.Static.MakeColor(255,255,255,255);
00224	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1), (YP2 - YP1));
00225	      C.bUseBorder = false;
00226	
00227	      if ( fAlpha > 0.97 )
00228	      {
00229	        if ( !bUseVignette )
00230	        {
00231	          bEnableCWnd = true;
00232	        }
00233	        else
00234	        {
00235	          if ( !bEnableCWnd )
00236	          {
00237	            XIIIBaseHUD(Owner).CWndMat.AllocRect( FocusWidth*2, FocusHeight*2, CWndX, CWndY );
00238	            Log(self$"Call to AllocRect size="$FocusWidth*2$"x"$FocusHeight*2$" result pos="$CWndX$","$CWndY);
00239	          }
00240	          if ( (CWndX < 0) || (CWndY < 0) )
00241	          {
00242	            if ( !bModeInfini )
00243	              RemoveMe();
00244	            return;
00245	          }
00246	          else
00247	            bEnableCWnd = true;
00248	        }
00249	        Enable('tick');
00250	      }
00251	      if (NextHudFoc != none)
00252	        NextHudFoc.DrawWnd(C);
00253	      if (( Level.TimeSeconds > EndOfLife ) && !bModeInfini )
00254	        RemoveMe();
00255	    }
00256	
00257	    simulated function Tick(float DeltaT)
00258	    { // Because Update(...) CAN'T be called while in postrender
00259	      if ( bEnableCWnd )
00260	      {
00261	        if ( bUseVignette )
00262	          XIIIBaseHUD(Owner).CWndMat.Update( CWndX, CWndY, FocusWidth*2, FocusHeight*2, MyFocus.Location + fMax(MyFocus.CollisionRadius, MyFocus.CollisionHeight) / 17.0 * 100.0 * normal(XIIIBaseHUD(Owner).PawnOwner.Location - MyFocus.Location), rotator(MyFocus.Location - XIIIBaseHUD(Owner).PawnOwner.Location), 20, FilterColor, HighLight, FilterTexture );
00263	        GotoState('ZoomToStandardCWnd');
00264	      }
00265	    }
00266	}
00267	
00268	//____________________________________________________________________
00269	state ZoomToStandardCWnd
00270	{
00271	    simulated function DrawWnd(Canvas C)
00272	    {
00273	      local vector campos;
00274	      local int x1,y1,x2,y2;
00275	      local eDrawType DT_mem;
00276	      Local Vector vFocusLoc;
00277	      local float XL, YL; // realtime length & width of icon
00278	      local float fAlpha; // from 0.f to 1.f, 1 = transition ended
00279	      local actor A;
00280	      local vector HitLoc, HitNorm;
00281	      local material HitMat;
00282	
00283	//      Log("Angle="$normal(MyFocus.Location - (XIIIBaseHUD(Owner).PawnOwner.Location + XIIIBaseHUD(Owner).PawnOwner.EyePosition())) dot vector(XIIIBaseHUD(Owner).XIIIPlayerOwner.rotation));
00284	      if ( normal(MyFocus.Location - (XIIIBaseHUD(Owner).PawnOwner.Location+XIIIBaseHUD(Owner).PawnOwner.EyePosition())) dot vector(XIIIBaseHUD(Owner).XIIIPlayerOwner.rotation) < 0.707 )
00285	      {
00286	        if (NextHudFoc != none)
00287	          NextHudFoc.DrawWnd(C);
00288	        if (( Level.TimeSeconds > EndOfLife ) && !bModeInfini )
00289	          RemoveMe();
00290	        return;
00291	      }
00292	      A = Trace(HitLoc, HitNorm, MyFocus.Location, XIIIBaseHUD(Owner).PawnOwner.Location, true, vect(0,0,0), HitMat, TRACETYPE_DiscardIfCanSeeThrough);
00293	      if ( (A != none) && (A != MyFocus) )
00294	      {
00295	        if (NextHudFoc != none)
00296	          NextHudFoc.DrawWnd(C);
00297	        if (( Level.TimeSeconds > EndOfLife ) && !bModeInfini )
00298	          RemoveMe();
00299	        return;
00300	      }
00301	
00302	      if ( ( vSize(MyFocus.Location - XIIIBaseHUD(Owner).PawnOwner.Location) < 300 ) && !bModeInfini )
00303	      {
00304	        if (NextHudFoc != none)
00305	          NextHudFoc.DrawWnd(C);
00306	        RemoveMe();
00307	        return;
00308	      }
00309	
00310	      if ( (Pawn(MyFocus) != none) && Pawn(Myfocus).bIsDead && (Pawn(MyFocus).Inventory == none) )
00311	      { // ELR why focusing on a dead pawn w/out inventory ?
00312	        if (NextHudFoc != none)
00313	          NextHudFoc.DrawWnd(C);
00314	        RemoveMe();
00315	        return;
00316	      }
00317	
00318	      vFocusLoc = XIIIBaseHUD(Owner).XIIIPlayerOwner.Player.Console.WorldToScreen(MyFocus.Location);
00319	      C.Style = ERenderStyle.STY_Alpha;
00320	
00321	      fAlpha = (Level.TimeSeconds - StartOfLife - TRANSITDELAY) / TRANSITDELAY;
00322	      XL = FocusWidth;
00323	      YL = FocusHeight;
00324	      XP1 = int(vFocusLoc.X - XL);
00325	      XP2 = int(vFocusLoc.X + XL);
00326	      YP1 = int(vFocusLoc.Y - YL);
00327	      YP2 = int(vFocusLoc.Y + YL);
00328	      // white border
00329	/*
00330	      C.DrawColor = C.Static.MakeColor(255,255,255,255);
00331	      // Above
00332	      C.SetPos(XP1 - 8, YP1 - 8);
00333	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1) + 16, 8);
00334	      // Left
00335	      C.SetPos(XP1 - 8, YP1 - 8);
00336	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, 8, (YP2 - YP1) + 16);
00337	      // Under
00338	      C.SetPos(XP1 - 8, YP2);
00339	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1) + 16, 8);
00340	      // Right
00341	      C.SetPos(XP2, YP1 - 8);
00342	      C.DrawRect(XIIIBaseHUD(Owner).FondDlg, 8, (YP2 - YP1) + 16);
00343	*/
00344	
00345	      if ( bUseVignette )
00346	      {
00347	        C.DrawColor = C.Static.MakeColor(0,0,0,0);
00348	        C.BorderColor = C.Static.MakeColor(0,0,0,255);
00349	        C.bUseBorder = true;
00350	        // outer outline
00351	        if ( bCartoonFocusDanger )
00352	        {
00353	          C.SetPos(XP1 - 1, YP1 - 1);
00354	          C.DrawRect(XIIIBaseHUD(Owner).FondDlg, FocusWidth*2+2, FocusHeight*2+2);
00355	        }
00356	        else
00357	        {
00358	          C.SetPos(XP1 - 2, YP1 - 2);
00359	          C.DrawRect(XIIIBaseHUD(Owner).FondDlg, FocusWidth*2+4, FocusHeight*2+4);
00360	        }
00361	        // inner outline
00362	        C.SetPos(XP1, YP1);
00363	        C.DrawColor = C.Static.MakeColor(255,255,255,255);
00364	        if ( bCartoonFocusDanger )
00365	          C.BorderColor = C.Static.MakeColor(190,66,24,255);
00366	        else
00367	          C.BorderColor = C.Static.MakeColor(255,255,255,255);
00368	//        C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1), (YP2 - YP1));
00369	//        Log("bUseVignette CWndX="$CWndX@"CWndY="$CWndY@FocusWidth*2$"x"@FocusHeight*2);
00370	        C.DrawTile(XIIIBaseHUD(Owner).CWndMat, FocusWidth*2, FocusHeight*2, CWndX, CWndY, FocusWidth*2, FocusHeight*2);
00371	        C.bUseBorder = false;
00372	      }
00373	      else
00374	      {
00375	        C.DrawColor = C.Static.MakeColor(0,0,0,0);
00376	        C.BorderColor = C.Static.MakeColor(0,0,0,255);
00377	        C.bUseBorder = true;
00378	        // outer outline
00379	        if ( bCartoonFocusDanger )
00380	        {
00381	          C.SetPos(XP1 - 1, YP1 - 1);
00382	          C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1)+2, (YP2 - YP1)+2);
00383	        }
00384	        else
00385	        {
00386	          C.SetPos(XP1 - 2, YP1 - 2);
00387	          C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1)+4, (YP2 - YP1)+4);
00388	}
00389	        // inner outline
00390	        C.SetPos(XP1, YP1);
00391	        if ( bCartoonFocusDanger )
00392	          C.BorderColor = C.Static.MakeColor(190,66,24,255);
00393	        else
00394	          C.BorderColor = C.Static.MakeColor(255,255,255,255);
00395	        C.DrawRect(XIIIBaseHUD(Owner).FondDlg, (XP2 - XP1), (YP2 - YP1));
00396	        C.bUseBorder = false;
00397	      }
00398	
00399	      if ( (zoomFocus && (Level.Game != none) && (Level.Game.DetailLevel > 1)) && !(XIIIBaseHUD(Owner).XIIIPlayerOwner.bRenderPortal))
00400	      {
00401	        if (!XIIIPlayerPawn(XIIIBaseHUD(Owner).XIIIPlayerOwner.Pawn).bIsSniper)
00402	        {
00403	          if (!(XP2<0 || XP1>C.ClipX || YP2<0 || YP1>C.ClipY))
00404	          {
00405	            campos = myFocus.location - zoomCameraDistance*normal(MyFocus.location-XIIIBaseHUD(Owner).XIIIPlayerOwner.location) + vect(0,0,20);
00406	            x1 = XP1;
00407	            y1 = YP1;
00408	            x2 = XP2;
00409	            y2 = YP2;
00410	            if (XP1<0) x1=0;
00411	            if (YP1<0) y1=0;
00412	            if (XP2>C.ClipX) x2=C.ClipX;
00413	            if (YP2>C.ClipY) y2=C.ClipY;
00414	            C.SetPos(x1, y1);
00415	            DT_mem = DrawType;
00416	            SetDrawType(DT_none);
00417	            XIIIBaseHUD(Owner).XIIIPlayerOwner.bRenderPortal = true;
00418	            C.DrawPortal(x1,y1,(x2-x1),(y2-y1),XIIIBaseHUD(Owner).XIIIPlayerOwner,campos,rotator(MyFocus.location-campos), zoomCameraFOV);
00419	            XIIIBaseHUD(Owner).XIIIPlayerOwner.bRenderPortal = false;
00420	            SetDrawType(DT_mem);
00421	          }
00422	        }
00423	      }
00424	
00425	      if (NextHudFoc != none)
00426	        NextHudFoc.DrawWnd(C);
00427	      if (( Level.TimeSeconds > EndOfLife ) && !bModeInfini )
00428	        ReMoveMe();
00429	    }
00430	}
00431	
00432	
00433	
00434	defaultproperties
00435	{
00436	     BorderColor=(B=255,G=255,R=255,A=255)
00437	     FilterColor=(B=255,G=255,R=255)
00438	     zoomCameraDistance=200.000000
00439	     zoomCameraFOV=50.000000
00440	}

End Source Code