enum EGenericNotificationPriority
{
	Default = 0,
	Low = 1,
	Medium = 2,
	Height = 3,
}

import class GenericNotificationViewData extends IScriptable
{
	import var title : String;
	import var text : String;
	import var soundEvent : CName;
	import var soundAction : CName;
	var action : GenericNotificationBaseAction;

	public virtual function CanMerge( data : GenericNotificationViewData ) : Bool
	{
		return false;
	}

	public virtual function OnRemoveNotification( data : IScriptable ) : Bool
	{
		return false;
	}

	public export virtual function GetPriority() : Int32
	{
		return ( ( Int32 )( EGenericNotificationPriority.Default ) );
	}

}

class GenericNotificationController extends gameuiGenericNotificationReceiverGameController
{
	protected editable var m_titleRef : inkTextRef;
	protected editable var m_textRef : inkTextRef;
	protected editable var m_actionLabelRef : inkTextRef;
	protected editable var m_actionRef : inkWidgetRef;
	protected var m_paused : Bool;
	protected var m_blockAction : Bool;
	private var translationAnimationCtrl : weak< inkTextReplaceController >;
	private var m_data : GenericNotificationViewData;
	private var m_player : weak< GameObject >;
	private var m_isInteractive : Bool;
	protected var m_customInputActionName : CName;

	protected event OnInitialize()
	{
		m_player = GetPlayerControlledObject();
		RegisterToCallback( 'OnNotificationPaused', this, 'OnNotificationPaused' );
		RegisterToCallback( 'OnNotificationResumed', this, 'OnNotificationResumed' );
	}

	protected event OnUninitialize()
	{
		UnregisterFromCallback( 'OnNotificationPaused', this, 'OnNotificationPaused' );
		UnregisterFromCallback( 'OnNotificationResumed', this, 'OnNotificationResumed' );
		if( m_isInteractive )
		{
			GetPlayerControlledObject().UnregisterInputListener( this );
		}
	}

	protected event OnNotificationPaused()
	{
		m_paused = true;
	}

	protected event OnNotificationResumed()
	{
		m_paused = false;
	}

	public override function SetNotificationData( notificationData : GenericNotificationViewData )
	{
		m_data = ( ( GenericNotificationViewData )( notificationData ) );
		if( m_data.action != NULL )
		{
			inkWidgetRef.SetVisible( m_actionRef, true );
			inkTextRef.SetText( m_actionLabelRef, m_data.action.GetLabel() );
			m_isInteractive = true;
			GetPlayerControlledObject().RegisterInputListener( this, GetInputActionName() );
		}
		else
		{
			inkWidgetRef.SetVisible( m_actionRef, false );
			m_isInteractive = false;
		}
		if( inkTextRef.IsValid( m_titleRef ) )
		{
			inkTextRef.SetText( m_titleRef, m_data.title );
		}
		if( inkTextRef.IsValid( m_textRef ) )
		{
			translationAnimationCtrl = ( ( inkTextReplaceController )( inkTextRef.GetController( m_textRef ) ) );
			if( translationAnimationCtrl )
			{
				translationAnimationCtrl.SetTargetText( m_data.text );
				translationAnimationCtrl.PlaySetAnimation();
			}
			else
			{
				inkTextRef.SetText( m_textRef, m_data.text );
			}
		}
		if( m_data.soundEvent != '' && m_data.soundAction != '' )
		{
			PlaySound( m_data.soundEvent, m_data.soundAction );
		}
	}

	protected event OnAction( action : ListenerAction, consumer : ListenerActionConsumer )
	{
		if( m_paused || m_blockAction )
		{
			return 0;
		}
		if( ListenerAction.GetType( action ) == gameinputActionType.BUTTON_RELEASED )
		{
			if( m_data.action.Execute( m_data ) )
			{
				OnActionTriggered();
			}
		}
	}

	private function GetInputActionName() : CName
	{
		return ( ( m_customInputActionName != '' ) ? ( m_customInputActionName ) : ( 'NotificationOpen' ) );
	}

	private virtual function OnActionTriggered() {}
}

