import class DeathMenuGameController extends gameuiMenuItemListGameController
{
	private editable var m_buttonHintsManagerRef : inkWidgetRef;
	private var m_buttonHintsController : weak< ButtonHints >;
	private var m_animIntro : inkAnimProxy;
	private var m_axisInputReceived : Bool;
	default m_axisInputReceived = false;
	private var m_dpadInputReceived : Bool;
	default m_dpadInputReceived = false;

	protected event OnInitialize()
	{
		super.OnInitialize();
		m_buttonHintsController = ( ( ButtonHints )( SpawnFromExternal( inkWidgetRef.Get( m_buttonHintsManagerRef ), R"base\gameplay\gui\common\buttonhints.inkwidget", 'Root' ).GetController() ) );
		m_buttonHintsController.AddButtonHint( 'select', GetLocalizedText( "UI-UserActions-Select" ) );
		m_menuListController.GetRootWidget().RegisterToCallback( 'OnRelease', this, 'OnListRelease' );
		m_menuListController.GetRootWidget().RegisterToCallback( 'OnRepeat', this, 'OnListRelease' );
		RegisterToGlobalInputCallback( 'OnPostOnRelease', this, 'OnGlobalRelease' );
		PlaySound( 'DeathMenu', 'OnOpen' );
	}

	protected event OnUninitialize()
	{
		m_menuListController.GetRootWidget().UnregisterFromCallback( 'OnRelease', this, 'OnListRelease' );
		m_menuListController.GetRootWidget().UnregisterFromCallback( 'OnRepeat', this, 'OnListRelease' );
		UnregisterFromGlobalInputCallback( 'OnPostOnRelease', this, 'OnGlobalRelease' );
		PlaySound( 'DeathMenu', 'OnClose' );
		super.OnUninitialize();
	}

	protected event OnSetUserData( userData : IScriptable )
	{
		var deathMenuData : DeathMenuUserData;
		deathMenuData = ( ( DeathMenuUserData )( userData ) );
		if( deathMenuData && deathMenuData.m_playInitAnimation )
		{
			m_animIntro = PlayLibraryAnimation( 'intro' );
			m_animIntro.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnIntroFinished' );
		}
	}

	private override function ShouldAllowExitGameMenuItem() : Bool
	{
		return false;
	}

	private override function PopulateMenuItemList()
	{
		if( GetSystemRequestsHandler().HasLastCheckpoint() )
		{
			AddMenuItem( GetLocalizedText( "UI-ScriptExports-LoadLastSavegame" ), PauseMenuAction.QuickLoad );
		}
		AddMenuItem( GetLocalizedText( "UI-ScriptExports-LoadGame0" ), 'OnSwitchToLoadGame' );
		AddMenuItem( GetLocalizedText( "UI-Labels-Settings" ), 'OnSwitchToSettings' );
		AddMenuItem( GetLocalizedText( "UI-Labels-ExitToMenu" ), PauseMenuAction.ExitToMainMenu );
		m_menuListController.Refresh();
	}

	protected event OnIntroFinished( proxy : inkAnimProxy )
	{
		var widgetToSnap : weak< inkWidget >;
		var index : Int32;
		index = -1;
		if( !( m_axisInputReceived ) )
		{
			if( !( m_dpadInputReceived ) )
			{
				widgetToSnap = inkCompoundRef.GetWidgetByIndex( m_menuList, 0 );
			}
			else
			{
				index = m_menuListController.GetSelectedIndex();
				widgetToSnap = ( ( ( index > -1 ) && ( index < m_menuListController.Size() ) ) ? ( m_menuListController.GetItemAt( index ) ) : ( inkCompoundRef.GetWidgetByIndex( m_menuList, 0 ) ) );
			}
			SetCursorOverWidget( widgetToSnap, ( ( index > -1 ) ? ( 0.1 ) : ( 0.0 ) ) );
		}
	}

	protected override function HandleMenuItemActivate( data : PauseMenuListItemData ) : Bool
	{
		if( super.HandleMenuItemActivate( data ) )
		{
			return false;
		}
		switch( data.action )
		{
			case PauseMenuAction.QuickLoad:
				GameInstance.GetTelemetrySystem( GetPlayerControlledObject().GetGame() ).LogLastCheckpointLoaded();
			GetSystemRequestsHandler().LoadLastCheckpoint( true );
			return true;
			break;
		}
		return false;
	}

	protected event OnListRelease( e : inkPointerEvent )
	{
		if( e.IsHandled() )
		{
			return false;
		}
		m_menuListController.HandleInput( e, this );
	}

	protected event OnGlobalRelease( e : inkPointerEvent )
	{
		if( ( ( e.IsAction( 'navigate_up' ) || e.IsAction( 'navigate_left' ) ) || e.IsAction( 'navigate_down' ) ) || e.IsAction( 'navigate_right' ) )
		{
			m_dpadInputReceived = true;
		}
	}

}

