class CarRadioGameController extends inkHUDGameController
{
	private editable var m_radioStationName : inkTextRef;
	private editable var m_songName : inkTextRef;
	private var m_root : weak< inkWidget >;
	private var m_stateChangesBlackboardId : CallbackHandle;
	private var m_songNameChangeBlackboardId : CallbackHandle;
	private var m_blackboard : weak< IBlackboard >;
	private var m_animationProxy : inkAnimProxy;

	protected event OnInitialize()
	{
		m_blackboard = GetBlackboardSystem().Get( GetAllBlackboardDefs().Vehicle );
		m_stateChangesBlackboardId = m_blackboard.RegisterListenerBool( GetAllBlackboardDefs().Vehicle.VehRadioState, this, 'OnRadioChange' );
		m_songNameChangeBlackboardId = m_blackboard.RegisterListenerName( GetAllBlackboardDefs().Vehicle.VehRadioStationName, this, 'OnSongChange' );
		m_root = GetRootWidget();
		m_root.SetVisible( false );
	}

	protected event OnUninitialize()
	{
		m_blackboard.UnregisterListenerBool( GetAllBlackboardDefs().Vehicle.VehRadioState, m_stateChangesBlackboardId );
		m_blackboard.UnregisterListenerName( GetAllBlackboardDefs().Vehicle.VehRadioStationName, m_songNameChangeBlackboardId );
	}

	protected event OnRadioChange( value : Bool )
	{
		if( value )
		{
			PlayIntroAnimation();
		}
	}

	protected event OnSongChange( value : CName )
	{
		inkTextRef.SetText( m_songName, GetLocalizedText( "UI-Cyberpunk-HUD-Radio-NowPlaying" ) + ( ( String )( value ) ) );
	}

	private function PlayIntroAnimation()
	{
		m_root.SetVisible( true );
		m_animationProxy = PlayLibraryAnimation( 'intro' );
		m_animationProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnOutroAnimFinished' );
	}

	protected event OnOutroAnimFinished( anim : inkAnimProxy )
	{
		m_root.SetVisible( false );
	}

}

