class WeaponMachineInkGameController extends VendingMachineInkGameController
{
	private var m_buttonRef : weak< WeaponVendorActionWidgetController >;

	protected event OnUpdateStatus( value : Variant )
	{
		m_state = ( ( PaymentStatus )value );
		switch( m_state )
		{
			case PaymentStatus.IN_PROGRESS:
				m_buttonRef.Processing();
			Processing();
			break;
			case PaymentStatus.NO_MONEY:
				m_buttonRef.NoMoney();
			NoMoney();
			break;
			default:
				m_buttonRef.ResetToDefault();
			Refresh( GetOwner().GetDeviceState() );
			break;
		}
	}

	private function Processing()
	{
		inkTextRef.SetLocalizedTextScript( m_priceText, "LocKey#45353" );
		m_rootWidget.SetState( 'Processing' );
	}

	private function NoMoney()
	{
		m_rootWidget.SetState( 'Disabled' );
	}

	public override function UpdateActionWidgets( const widgetsData : ref< array< SActionWidgetPackage > > )
	{
		var widget : inkWidget;
		var action : DispenceItemFromVendor;
		var textParams : inkTextParams;
		if( !( m_buttonRef ) || ( m_buttonRef && !( m_buttonRef.IsProcessing() ) ) )
		{
			HideActionWidgets();
			m_rootWidget.SetState( 'Default' );
			inkHorizontalPanelRef.SetVisible( m_ActionsPanel, true );
			if( widgetsData.Size() > 0 )
			{
				widget = GetActionWidget( widgetsData[ 0 ] );
				action = ( ( DispenceItemFromVendor )( widgetsData[ 0 ].action ) );
				if( action )
				{
					textParams = new inkTextParams;
					textParams.AddNumber( "COST", action.GetPrice() );
					textParams.AddLocalizedString( "ED", "LocKey#884" );
					inkTextRef.SetLocalizedTextScript( m_priceText, "LocKey#45350", textParams );
				}
				if( widget == NULL )
				{
					CreateActionWidgetAsync( inkHorizontalPanelRef.Get( m_ActionsPanel ), widgetsData[ 0 ] );
				}
				else
				{
					InitializeActionWidget( widget, widgetsData[ 0 ] );
				}
			}
		}
	}

	protected event OnActionWidgetSpawned( widget : inkWidget, userData : IScriptable )
	{
		super.OnActionWidgetSpawned( widget, userData );
		m_buttonRef = ( ( WeaponVendorActionWidgetController )( widget.GetController() ) );
	}

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

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

}

