123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- class CTObjectFollower extends ScriptedWidgetEventHandler
- {
- protected Widget m_FollowerRoot;
- protected Widget m_FollowerButton;
-
- protected vector m_Position;
- protected vector m_Orientation;
- protected EntityAI m_FollowedObject;
-
- protected float m_MaxFade;
- protected float m_MinFade;
-
- protected CameraToolsMenu m_Menu;
-
- void ~CTObjectFollower()
- {
- DestroyFollowedObject();
- delete m_FollowerRoot;
- }
-
- void CreateFollowedObject( string type )
- {
- m_FollowedObject = EntityAI.Cast( GetGame().CreateObject( type, m_Position, true ) );
- SetPosition( m_Position );
- SetRotation( m_Orientation );
- }
-
- void DestroyFollowedObject()
- {
- if( m_FollowedObject )
- {
- GetGame().ObjectDelete( m_FollowedObject );
- }
- }
-
- void Update( float timeslice )
- {
- UpdatePos();
- }
-
- EntityAI GetObj()
- {
- return m_FollowedObject;
- }
-
- void SetPosition( vector position )
- {
- m_Position = position;
- if( m_FollowedObject )
- {
- m_FollowedObject.SetPosition( position );
- m_Position = m_FollowedObject.GetPosition();
- }
- UpdatePos();
- }
-
- void SetRotation( vector dir )
- {
- m_Orientation = dir;
- PlayerBase player = PlayerBase.Cast( m_FollowedObject );
- if( player )
- {
- player.SetOrientation( m_Orientation );
- }
- UpdatePos();
- }
-
- vector GetPosition()
- {
- if( m_FollowedObject && m_FollowedObject.GetPosition() != m_Position )
- {
- SetPosition( m_FollowedObject.GetPosition() );
- }
- return m_Position;
- }
-
- vector GetRotation()
- {
- if( m_FollowedObject )
- {
- return m_FollowedObject.GetOrientation();
- }
- return "0 0 0";
- }
-
- /*! \brief Function updating the position of the tracker widget.
- *
- * Currently tracks using GetScreenPos() on the position of the player.
- */
- void UpdatePos()
- {
- vector relativePos;
-
- relativePos = GetGame().GetScreenPosRelative( GetPosition() );
-
- if( relativePos[0] >= 1 || relativePos[0] == 0 || relativePos[1] >= 1 || relativePos[1] == 0 )
- {
- m_FollowerRoot.Show( false );
- return;
- }
- else if( relativePos[2] < 0 )
- {
- m_FollowerRoot.Show( false );
- return;
- }
- else
- {
- m_FollowerRoot.Show( true );
- }
-
- float x, y;
- m_FollowerRoot.GetSize( x, y );
-
- m_FollowerRoot.SetPos( relativePos[0], relativePos[1] );
- }
-
- void Show()
- {
- m_FollowerRoot.Show( true );
- }
-
- void Hide()
- {
- m_FollowerRoot.Show( false );
- }
-
- void Fade( bool fade )
- {
- if( fade )
- {
- m_FollowerRoot.SetAlpha( m_MinFade );
- }
- else
- {
- m_FollowerRoot.SetAlpha( m_MaxFade );
- }
- }
-
- override bool OnClick( Widget w, int x, int y, int button )
- {
- return false;
- }
-
- override bool OnDoubleClick( Widget w, int x, int y, int button )
- {
- return false;
- }
-
- override bool OnMouseButtonDown( Widget w, int x, int y, int button )
- {
- if( w == m_FollowerButton && button == MouseState.LEFT )
- {
- if( m_Menu )
- {
- m_Menu.SelectActor( CTActor.Cast( this ) );
- }
- return true;
- }
- return false;
- }
-
- override bool OnMouseButtonUp( Widget w, int x, int y, int button )
- {
- if( w == m_FollowerButton && button == MouseState.LEFT )
- {
- if( m_Menu )
- {
- m_Menu.SelectActor( null );
- }
- return true;
- }
- return false;
- }
- }
|