class JukeboxInkGameController extends DeviceInkGameControllerBase
{
	[ category = "Widget Refs" ]
	private editable var m_ActionsPanel : inkHorizontalPanelRef;
	[ category = "Widget Refs" ]
	private editable var m_PriceText : inkTextRef;
	private var m_playButton : weak< PlayPauseActionWidgetController >;
	private var m_nextButton : weak< NextPreviousActionWidgetController >;
	private var m_previousButton : weak< NextPreviousActionWidgetController >;

	protected override function RegisterBlackboardCallbacks( blackboard : IBlackboard )
	{
		super.RegisterBlackboardCallbacks( blackboard );
	}

	public override function UpdateActionWidgets( const widgetsData : ref< array< SActionWidgetPackage > > )
	{
		var i : Int32;
		var price : Int32;
		var action : ScriptableDeviceAction;
		var widget : inkWidget;
		var textParams : inkTextParams;
		HideActionWidgets();
		inkHorizontalPanelRef.SetVisible( m_ActionsPanel, true );
		for( i = 0; i < widgetsData.Size(); i += 1 )
		{
			widget = GetActionWidget( widgetsData[ i ] );
			if( widget == NULL )
			{
				CreateActionWidgetAsync( inkHorizontalPanelRef.Get( m_ActionsPanel ), widgetsData[ i ] );
			}
			else
			{
				InitializeActionWidget( widget, widgetsData[ i ] );
			}
			if( price == 0 )
			{
				action = ( ( ScriptableDeviceAction )( widgetsData[ i ].action ) );
				price = action.GetCost();
			}
		}
		textParams = new inkTextParams;
		textParams.AddNumber( "COST", price );
		textParams.AddLocalizedString( "ED", "LocKey#884" );
		inkTextRef.SetLocalizedTextScript( m_PriceText, "LocKey#45350", textParams );
	}

	protected event OnActionWidgetSpawned( widget : inkWidget, userData : IScriptable )
	{
		var spawnData : AsyncSpawnData;
		var widgetData : SActionWidgetPackage;
		var actionData : ScriptableDeviceAction;
		super.OnActionWidgetSpawned( widget, userData );
		spawnData = ( ( AsyncSpawnData )( userData ) );
		widgetData = ( ( SActionWidgetPackage )spawnData.m_widgetData );
		actionData = ( ( ScriptableDeviceAction )( widgetData.action ) );
		if( ( ( TogglePlay )( actionData ) ) )
		{
			m_playButton = ( ( PlayPauseActionWidgetController )( widget.GetController() ) );
		}
		else if( ( ( NextStation )( actionData ) ) )
		{
			m_nextButton = ( ( NextPreviousActionWidgetController )( widget.GetController() ) );
		}
		else if( ( ( PreviousStation )( actionData ) ) )
		{
			m_previousButton = ( ( NextPreviousActionWidgetController )( widget.GetController() ) );
		}
	}

	protected function Decline()
	{
		PlayLibraryAnimation( 'no_money_root' );
		m_playButton.Decline();
		m_nextButton.Decline();
		m_previousButton.Decline();
	}

	protected override function ExecuteDeviceActions( controller : DeviceActionWidgetControllerBase )
	{
		var executor : weak< GameObject >;
		var actions : array< weak< DeviceAction > >;
		var action : BaseScriptableAction;
		var playAction : TogglePlay;
		var nextAction : NextStation;
		var prevAction : PreviousStation;
		var i : Int32;
		if( controller == NULL )
		{
			return;
		}
		executor = GetPlayer( GetOwner().GetGame() );
		if( controller.CanExecuteAction() )
		{
			actions = controller.GetActions();
		}
		for( i = 0; i < actions.Size(); i += 1 )
		{
			ExecuteAction( actions[ i ], executor );
			controller.FinalizeActionExecution( executor, actions[ i ] );
			action = ( ( BaseScriptableAction )( actions[ i ] ) );
			if( !( action.CanPayCost( executor ) ) )
			{
				Decline();
				continue;
			}
			playAction = ( ( TogglePlay )( actions[ i ] ) );
			if( playAction )
			{
				if( ( ( Bool )playAction.prop.first ) )
				{
					m_nextButton.Reset();
					m_previousButton.Reset();
				}
				else
				{
					m_nextButton.Deactivate();
					m_previousButton.Deactivate();
				}
				continue;
			}
			prevAction = ( ( PreviousStation )( actions[ i ] ) );
			nextAction = ( ( NextStation )( actions[ i ] ) );
			if( prevAction || nextAction )
			{
				m_playButton.TogglePlay( true );
				continue;
			}
		}
	}

	protected override function GetOwner() : Jukebox
	{
		return ( ( Jukebox )( GetOwnerEntity() ) );
	}

	protected override function Refresh( state : EDeviceStatus )
	{
		super.Refresh( state );
		HideActionWidgets();
		RequestActionWidgetsUpdate();
	}

}

