class NumericDisplayController extends ScriptableDeviceComponent
{

	public const override function GetPS() : NumericDisplayControllerPS
	{
		return ( ( NumericDisplayControllerPS )( GetBasePS() ) );
	}

}

class NumericDisplayControllerPS extends ScriptableDeviceComponentPS
{
	private instanceeditable var m_numberToDisplay : Int32;
	private instanceeditable var m_targetNumber : Int32;
	default m_targetNumber = 0;

	public export quest const function GetCurrentNumber() : Int32
	{
		return m_numberToDisplay;
	}

	public export quest const function TargetReached() : Bool
	{
		return m_numberToDisplay == m_targetNumber;
	}

	protected override function GetInkWidgetTweakDBID( const context : ref< GetActionsContext > ) : TweakDBID
	{
		return T"DevicesUIDefinitions.q302_NumericDisplayWidget";
	}

	public const override function GetBlackboardDef() : NumericDisplayBlackboardDef
	{
		return GetAllBlackboardDefs().NumericDisplay;
	}

	public override function GetQuestActions( out actions : array< DeviceAction >, const context : ref< GetActionsContext > )
	{
		super.GetQuestActions( actions, context );
		actions.PushBack( ActionQuestIncreaseNumber() );
		actions.PushBack( ActionQuestDecreaseNumber() );
		actions.PushBack( ActionQuestIdle() );
	}

	public function ActionQuestIncreaseNumber() : QuestIncreaseNumber
	{
		var action : QuestIncreaseNumber;
		action = new QuestIncreaseNumber;
		action.clearanceLevel = DefaultActionsParametersHolder.GetQuestClearance();
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		return action;
	}

	public function ActionQuestDecreaseNumber() : QuestDecreaseNumber
	{
		var action : QuestDecreaseNumber;
		action = new QuestDecreaseNumber;
		action.clearanceLevel = DefaultActionsParametersHolder.GetQuestClearance();
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		return action;
	}

	public function ActionQuestIdle() : QuestIdle
	{
		var action : QuestIdle;
		action = new QuestIdle;
		action.clearanceLevel = DefaultActionsParametersHolder.GetQuestClearance();
		action.SetUp( this );
		action.SetProperties();
		action.AddDeviceName( m_deviceName );
		return action;
	}

	protected override function GameAttached()
	{
		super.GameAttached();
		SendNumberToUIBlackboard();
		SendDirectionToUIBlackboard( 0 );
	}

	public export function OnQuestIncreaseNumber( evt : QuestIncreaseNumber ) : EntityNotificationType
	{
		m_numberToDisplay += 1;
		SendNumberToUIBlackboard();
		SendDirectionToUIBlackboard( 1 );
		RefreshUI( GetBlackboard() );
		UseNotifier( evt );
		return EntityNotificationType.SendPSChangedEventToEntity;
	}

	public export function OnQuestDecreaseNumber( evt : QuestDecreaseNumber ) : EntityNotificationType
	{
		m_numberToDisplay -= 1;
		SendNumberToUIBlackboard();
		SendDirectionToUIBlackboard( -1 );
		RefreshUI( GetBlackboard() );
		UseNotifier( evt );
		return EntityNotificationType.SendPSChangedEventToEntity;
	}

	public export function OnQuestIdle( evt : QuestIdle ) : EntityNotificationType
	{
		SendDirectionToUIBlackboard( 0 );
		RefreshUI( GetBlackboard() );
		UseNotifier( evt );
		return EntityNotificationType.SendPSChangedEventToEntity;
	}

	protected function SendNumberToUIBlackboard()
	{
		GetBlackboard().SetInt( GetBlackboardDef().CurrentNumber, GetCurrentNumber(), true );
	}

	protected function SendDirectionToUIBlackboard( direction : Int32 )
	{
		GetBlackboard().SetInt( GetBlackboardDef().Direction, direction, true );
	}

}

