import class HUDCyberwareInfoGameController extends inkHUDGameController
{
	editable var m_activatePopupAnimName : CName;
	default m_activatePopupAnimName = 'cw_reactivated_popup';
	editable var m_deactivatePopupAnimName : CName;
	default m_deactivatePopupAnimName = 'cw_deactivated_popup';
	editable var m_activateAnimName : CName;
	default m_activateAnimName = 'hud_addon_outro';
	editable var m_deactivateAnimName : CName;
	default m_deactivateAnimName = 'hud_addon_intro';
	editable var m_fact : CName;
	default m_fact = 'q306_cyberware_deactivated';
	editable var m_hudElement : inkWidgetRef;
	var m_isCyberwareDeactivated : Bool;
	var m_popupAnimProxy : inkAnimProxy;
	var m_animProxy : inkAnimProxy;

	public import function ListenToFact( fact : CName );

	protected event OnInitialize()
	{
		m_isCyberwareDeactivated = GetFact( GetGame(), m_fact ) > 0;
		inkWidgetRef.SetOpacity( m_hudElement, ( ( m_isCyberwareDeactivated ) ? ( 1.0 ) : ( 0.0 ) ) );
		ListenToFact( m_fact );
	}

	protected event OnFactChanged( fact : CName, value : Int32 )
	{
		var isCyberwareDeactivated : Bool;
		if( m_fact == fact )
		{
			isCyberwareDeactivated = value > 0;
			if( m_isCyberwareDeactivated != isCyberwareDeactivated )
			{
				m_isCyberwareDeactivated = isCyberwareDeactivated;
				StopPopupAnim();
				StopAnim();
				m_popupAnimProxy = PlayLibraryAnimation( ( ( m_isCyberwareDeactivated ) ? ( m_deactivatePopupAnimName ) : ( m_activatePopupAnimName ) ) );
				m_popupAnimProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnPopupAnimationFinished' );
			}
		}
	}

	protected event OnPopupAnimationFinished( proxy : inkAnimProxy )
	{
		StopPopupAnim();
		StopAnim();
		m_animProxy = PlayLibraryAnimation( ( ( m_isCyberwareDeactivated ) ? ( m_deactivateAnimName ) : ( m_activateAnimName ) ) );
		m_popupAnimProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnAnimationFinished' );
	}

	protected event OnAnimationFinished( proxy : inkAnimProxy )
	{
		StopPopupAnim();
		StopAnim();
		inkWidgetRef.SetOpacity( m_hudElement, ( ( m_isCyberwareDeactivated ) ? ( 1.0 ) : ( 0.0 ) ) );
	}

	public function StopPopupAnim()
	{
		if( m_popupAnimProxy )
		{
			m_popupAnimProxy.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnPopupAnimationFinished' );
			m_popupAnimProxy.GotoEndAndStop();
			m_popupAnimProxy = NULL;
		}
	}

	public function StopAnim()
	{
		if( m_animProxy )
		{
			m_animProxy.UnregisterFromCallback( inkanimEventType.OnFinish, this, 'OnPopupAnimationFinished' );
			m_animProxy.GotoEndAndStop();
			m_animProxy = NULL;
		}
	}

	public function GetGame() : GameInstance
	{
		var gameInstance : GameInstance;
		var gameObject : GameObject;
		gameObject = ( ( GameObject )( GetPlayerControlledObject() ) );
		if( gameObject )
		{
			gameInstance = gameObject.GetGame();
		}
		return gameInstance;
	}

}

