class characterCreationSummaryMenu extends BaseCharacterCreationController
{
	editable var m_backstoryTitle : inkTextRef;
	editable var m_backstoryIcon : inkImageRef;
	editable var m_backstory : inkTextRef;
	editable var m_difficulty : inkTextRef;
	editable var m_attributeBodyValue : inkTextRef;
	editable var m_attributeIntelligenceValue : inkTextRef;
	editable var m_attributeReflexesValue : inkTextRef;
	editable var m_attributeTechnicalAbilityValue : inkTextRef;
	editable var m_attributeCoolValue : inkTextRef;
	editable var m_attributeUnsetValue : inkTextRef;
	editable var m_unsetAttributeWrapper : inkWidgetRef;
	editable var m_expansionInfoWrapper : inkWidgetRef;
	editable var m_previousPageBtn : inkWidgetRef;
	editable var m_glitchBtn : inkWidgetRef;
	private var m_animationProxy : inkAnimProxy;
	private var m_loadingAnimationProxy : inkAnimProxy;
	private var m_loadingFinished : Bool;
	private var m_glitchClicks : Int32;

	protected event OnInitialize()
	{
		super.OnInitialize();
		SetUpLifePath();
		SetUpAttribiutes();
		SetUpDifficulty();
		inkWidgetRef.RegisterToCallback( m_previousPageBtn, 'OnRelease', this, 'OnPreviousButton' );
		inkWidgetRef.RegisterToCallback( m_glitchBtn, 'OnRelease', this, 'OnGlitchButton' );
		inkWidgetRef.SetVisible( m_unsetAttributeWrapper, !( m_characterCustomizationState.IsExpansionStandalone() ) );
		inkWidgetRef.SetVisible( m_expansionInfoWrapper, m_characterCustomizationState.IsExpansionStandalone() );
		m_glitchClicks = 0;
		m_loadingFinished = false;
		OnIntro();
	}

	protected event OnUninitialize()
	{
		super.OnUninitialize();
	}

	protected event OnPreviousButton( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			GameInstance.GetAudioSystem( GetPlayerControlledObject().GetGame() ).Stop( 'ui_main_menu_cc_confirmation_screen_open' );
			this.PriorMenu();
			PlaySound( 'Button', 'OnPress' );
		}
	}

	protected event OnGlitchButton( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			m_glitchClicks += 1;
			if( m_glitchClicks > 2 )
			{
				m_glitchClicks = 0;
				GameInstance.GetAudioSystem( GetPlayerControlledObject().GetGame() ).Play( 'ui_hacking_access_denied' );
				PlayAnim( 'malfunction', , m_loadingAnimationProxy );
			}
		}
	}

	protected event OnButtonRelease( evt : inkPointerEvent )
	{
		if( !( evt.IsHandled() ) )
		{
			if( evt.IsAction( 'one_click_confirm' ) && m_loadingFinished )
			{
				PlaySound( 'Button', 'OnPress' );
				evt.Handle();
				NextMenu();
			}
			if( evt.IsAction( 'back' ) )
			{
				PlaySound( 'Button', 'OnPress' );
				evt.Handle();
				PriorMenu();
			}
			else
			{
				return false;
			}
			evt.Handle();
		}
	}

	public function SetUpDifficulty()
	{
		var difficulty : gameDifficulty;
		difficulty = GameInstance.GetStatsDataSystem( GetPlayerControlledObject().GetGame() ).GetDifficulty();
		switch( difficulty )
		{
			case gameDifficulty.Story:
				inkTextRef.SetText( m_difficulty, "LocKey#52792" );
			break;
			case gameDifficulty.Easy:
				inkTextRef.SetText( m_difficulty, "LocKey#52791" );
			break;
			case gameDifficulty.Hard:
				inkTextRef.SetText( m_difficulty, "LocKey#52790" );
			break;
			case gameDifficulty.VeryHard:
				inkTextRef.SetText( m_difficulty, "LocKey#52789" );
			break;
		}
	}

	public function SetUpLifePath()
	{
		if( m_characterCustomizationState.GetLifePath() == T"LifePaths.Nomad" )
		{
			inkTextRef.SetText( m_backstory, "LocKey#1586" );
			inkTextRef.SetText( m_backstoryTitle, "LocKey#1799" );
			inkImageRef.SetTexturePart( m_backstoryIcon, 'LifepathNomad' );
		}
		else if( m_characterCustomizationState.GetLifePath() == T"LifePaths.StreetKid" )
		{
			inkTextRef.SetText( m_backstory, "LocKey#1587" );
			inkTextRef.SetText( m_backstoryTitle, "LocKey#1801" );
			inkImageRef.SetTexturePart( m_backstoryIcon, 'LifepathStreetKid' );
		}
		else if( m_characterCustomizationState.GetLifePath() == T"LifePaths.Corporate" )
		{
			inkTextRef.SetText( m_backstory, "LocKey#1585" );
			inkTextRef.SetText( m_backstoryTitle, "LocKey#1800" );
			inkImageRef.SetTexturePart( m_backstoryIcon, 'LifepathCorpo' );
		}
	}

	public function SetUpAttribiutes()
	{
		var attributeType : gamedataStatType;
		attributeType = gamedataStatType.Strength;
		inkTextRef.SetText( m_attributeBodyValue, ( ( String )( m_characterCustomizationState.GetAttribute( attributeType ) ) ) );
		attributeType = gamedataStatType.Intelligence;
		inkTextRef.SetText( m_attributeIntelligenceValue, ( ( String )( m_characterCustomizationState.GetAttribute( attributeType ) ) ) );
		attributeType = gamedataStatType.Reflexes;
		inkTextRef.SetText( m_attributeReflexesValue, ( ( String )( m_characterCustomizationState.GetAttribute( attributeType ) ) ) );
		attributeType = gamedataStatType.TechnicalAbility;
		inkTextRef.SetText( m_attributeTechnicalAbilityValue, ( ( String )( m_characterCustomizationState.GetAttribute( attributeType ) ) ) );
		attributeType = gamedataStatType.Cool;
		inkTextRef.SetText( m_attributeCoolValue, ( ( String )( m_characterCustomizationState.GetAttribute( attributeType ) ) ) );
		inkTextRef.SetText( m_attributeUnsetValue, ( ( String )( m_characterCustomizationState.GetAttributePointsAvailable() ) ) );
	}

	protected override function PriorMenu()
	{
		super.PriorMenu();
	}

	protected override function NextMenu()
	{
		if( !( WaitForRunningInstalations() ) )
		{
			PlaySound( 'CharacterCreationConfirmation', 'OnPress' );
			OnOutro();
		}
	}

	private function OnIntro()
	{
		PlayAnim( 'intro', 'OnLoadingComplete', m_loadingAnimationProxy );
		PlayAnim( 'intro_sound', 'OnIntroComplete', m_animationProxy );
	}

	private function OnOutro()
	{
		PlayAnim( 'outro', 'OnOutroComplete', m_animationProxy );
		GameInstance.GetAudioSystem( GetPlayerControlledObject().GetGame() ).Play( 'ui_main_menu_cc_confirmation_screen_close' );
	}

	protected event OnOutroComplete( anim : inkAnimProxy )
	{
		var system : gameuiICharacterCustomizationSystem;
		system = GetCharacterCustomizationSystem();
		system.FinalizeState();
		GetSystemRequestsHandler().StartNewGame( m_characterCustomizationState );
		if( m_characterCustomizationState.IsExpansionStandalone() )
		{
			GetTelemetrySystem().LogPlaythroughEp1();
		}
		GetTelemetrySystem().LogInitialChoiceSetStatege( telemetryInitalChoiceStage.Finished );
		GetTelemetrySystem().LogNewGameStarted();
		super.NextMenu();
	}

	protected event OnIntroComplete( anim : inkAnimProxy )
	{
		GameInstance.GetAudioSystem( GetPlayerControlledObject().GetGame() ).Play( 'ui_main_menu_cc_confirmation_screen_open' );
	}

	protected event OnLoadingComplete( anim : inkAnimProxy )
	{
		m_loadingFinished = true;
	}

	public function PlayAnim( animName : CName, optional callBack : CName, animProxy : inkAnimProxy )
	{
		if( animProxy && animProxy.IsPlaying() )
		{
			animProxy.Stop();
		}
		animProxy = PlayLibraryAnimation( animName );
		if( callBack != '' )
		{
			animProxy.RegisterToCallback( inkanimEventType.OnFinish, this, callBack );
		}
	}

}

