class ExpansionNewGame extends BaseCharacterCreationController
{
	editable var m_newGameDescription : inkTextRef;
	editable var m_textureTop : inkImageRef;
	editable var m_textureBottom : inkImageRef;
	editable var m_creditsBaseTexture : inkImageRef;
	editable var m_creditsExpansionTexture : inkImageRef;
	editable var m_creditsBase : inkWidgetRef;
	editable var m_creditsExpansion : inkWidgetRef;
	editable var m_creditsHoverFrameLeft : inkWidgetRef;
	editable var m_creditsHoverFrameRight : inkWidgetRef;
	private editable var m_introAnimation : CName;
	private editable var m_outroAnimation : CName;
	private editable var m_hoverAnimation : CName;
	private var m_animationProxy : inkAnimProxy;
	private var translationAnimationCtrl : weak< inkTextReplaceController >;
	private var localizedText : String;
	private var m_lastShownPart : CName;
	[ category = "Buttons" ]
	private editable var m_baseGameButton : inkWidgetRef;
	[ category = "Buttons" ]
	private editable var m_standaloneButton : inkWidgetRef;
	private var m_isInputLocked : Bool;
	default m_isInputLocked = false;

	protected event OnInitialize()
	{
		GetCharacterCustomizationSystem().InitializeState();
		super.OnInitialize();
		inkWidgetRef.RegisterToCallback( m_baseGameButton, 'OnHoverOver', this, 'OnHoverOverBaseGame' );
		inkWidgetRef.RegisterToCallback( m_baseGameButton, 'OnPress', this, 'OnPressBaseGame' );
		inkWidgetRef.RegisterToCallback( m_standaloneButton, 'OnHoverOver', this, 'OnHoverOverExpansion' );
		inkWidgetRef.RegisterToCallback( m_standaloneButton, 'OnPress', this, 'OnPressExpansion' );
		inkWidgetRef.RegisterToCallback( m_creditsBase, 'OnHoverOver', this, 'OnHoverOverBaseCredits' );
		inkWidgetRef.RegisterToCallback( m_creditsBase, 'OnHoverOut', this, 'OnHoverOutBaseCredits' );
		inkWidgetRef.RegisterToCallback( m_creditsBase, 'OnPress', this, 'OnCredits' );
		inkWidgetRef.RegisterToCallback( m_creditsExpansion, 'OnHoverOver', this, 'OnHoverOverExpansionCredits' );
		inkWidgetRef.RegisterToCallback( m_creditsExpansion, 'OnHoverOut', this, 'OnHoverOutExpansionCredits' );
		inkWidgetRef.RegisterToCallback( m_creditsExpansion, 'OnPress', this, 'OnCreditsEp1' );
		OnIntro();
	}

	protected event OnCreditsEp1( evt : inkPointerEvent )
	{
		if( evt.IsAction( 'click' ) )
		{
			m_eventDispatcher.SpawnEvent( 'OnSwitchToCreditsEp1' );
		}
	}

	protected event OnCredits( evt : inkPointerEvent )
	{
		if( evt.IsAction( 'click' ) )
		{
			m_eventDispatcher.SpawnEvent( 'OnSwitchToCredits' );
		}
	}

	protected event OnUninitialize()
	{
		super.OnUninitialize();
		inkWidgetRef.UnregisterFromCallback( m_baseGameButton, 'OnHoverOver', this, 'OnHoverOverBaseGame' );
		inkWidgetRef.UnregisterFromCallback( m_baseGameButton, 'OnPress', this, 'OnPressBaseGame' );
		inkWidgetRef.UnregisterFromCallback( m_standaloneButton, 'OnHoverOver', this, 'OnHoverOverExpansion' );
		inkWidgetRef.UnregisterFromCallback( m_standaloneButton, 'OnPress', this, 'OnPressExpansion' );
		inkWidgetRef.UnregisterFromCallback( m_creditsBase, 'OnHoverOver', this, 'OnHoverOverBaseCredits' );
		inkWidgetRef.UnregisterFromCallback( m_creditsBase, 'OnHoverOut', this, 'OnHoverOutBaseCredits' );
		inkWidgetRef.UnregisterFromCallback( m_creditsBase, 'OnPress', this, 'OnPressBaseCredits' );
		inkWidgetRef.UnregisterFromCallback( m_creditsExpansion, 'OnHoverOver', this, 'OnHoverOverExpansionCredits' );
		inkWidgetRef.UnregisterFromCallback( m_creditsExpansion, 'OnHoverOut', this, 'OnHoverOutExpansionCredits' );
		inkWidgetRef.UnregisterFromCallback( m_creditsExpansion, 'OnPress', this, 'OnPressExpansionCredits' );
	}

	protected event OnPressBaseGame( evt : inkPointerEvent )
	{
		if( evt.IsAction( 'click' ) && !( m_isInputLocked ) )
		{
			m_characterCustomizationState.SetIsExpansionStandalone( false );
			PlaySound( 'Button', 'OnPress' );
			NextMenu();
		}
	}

	protected event OnPressExpansion( evt : inkPointerEvent )
	{
		if( evt.IsAction( 'click' ) && !( m_isInputLocked ) )
		{
			m_characterCustomizationState.SetIsExpansionStandalone( true );
			PlaySound( 'Button', 'OnPress' );
			NextMenu();
		}
	}

	private function TextureTransition( part : CName )
	{
		if( m_lastShownPart != part )
		{
			m_lastShownPart = part;
			inkImageRef.SetTexturePart( m_textureBottom, inkImageRef.GetTexturePart( m_textureTop ) );
			inkImageRef.SetOpacity( m_textureTop, 0.0 );
			inkImageRef.SetTexturePart( m_textureTop, part );
			PlayLibraryAnimation( 'hoverAnimation' );
		}
	}

	protected event OnHoverOverBaseCredits( e : inkPointerEvent )
	{
		inkWidgetRef.SetVisible( m_creditsHoverFrameLeft, true );
		inkImageRef.Get( m_creditsBaseTexture ).SetEffectEnabled( inkEffectType.Glitch, 'Glitch_0', true );
		PlayLibraryAnimation( 'hoverBaseCredits' );
	}

	protected event OnHoverOutBaseCredits( e : inkPointerEvent )
	{
		inkWidgetRef.SetVisible( m_creditsHoverFrameLeft, false );
		inkImageRef.Get( m_creditsBaseTexture ).SetEffectEnabled( inkEffectType.Glitch, 'Glitch_0', false );
		PlayLibraryAnimation( 'hoverOutBaseCredits' );
	}

	protected event OnHoverOverExpansionCredits( e : inkPointerEvent )
	{
		inkWidgetRef.SetVisible( m_creditsHoverFrameRight, true );
		inkImageRef.Get( m_creditsExpansionTexture ).SetEffectEnabled( inkEffectType.Glitch, 'Glitch_0', true );
		PlayLibraryAnimation( 'hoverExpansionCredits' );
	}

	protected event OnHoverOutExpansionCredits( e : inkPointerEvent )
	{
		inkWidgetRef.SetVisible( m_creditsHoverFrameRight, false );
		inkImageRef.Get( m_creditsExpansionTexture ).SetEffectEnabled( inkEffectType.Glitch, 'Glitch_0', false );
		PlayLibraryAnimation( 'hoverOutExpansionCredits' );
	}

	protected event OnHoverOverBaseGame( e : inkPointerEvent )
	{
		TextureTransition( 'flow_base_game' );
		localizedText = GetLocalizedText( "LocKey#93618" );
		translationAnimationCtrl.SetBaseText( "..." );
		translationAnimationCtrl = ( ( inkTextReplaceController )( inkTextRef.GetController( m_newGameDescription ) ) );
		translationAnimationCtrl.SetTargetText( localizedText );
		translationAnimationCtrl.PlaySetAnimation();
	}

	protected event OnHoverOverExpansion( e : inkPointerEvent )
	{
		TextureTransition( 'flow_ep' );
		localizedText = GetLocalizedText( "LocKey#93620" );
		translationAnimationCtrl.SetBaseText( "..." );
		translationAnimationCtrl = ( ( inkTextReplaceController )( inkTextRef.GetController( m_newGameDescription ) ) );
		translationAnimationCtrl.SetTargetText( localizedText );
		translationAnimationCtrl.PlaySetAnimation();
	}

	protected override function PriorMenu()
	{
		GetTelemetrySystem().LogInitialChoiceSetStatege( telemetryInitalChoiceStage.None );
		GetCharacterCustomizationSystem().ClearState();
		super.PriorMenu();
	}

	protected override function NextMenu()
	{
		m_isInputLocked = true;
		OnOutro();
	}

	private function OnIntro()
	{
		PlayAnim( m_introAnimation, 'OnIntroComplete' );
		PlaySound( 'CharacterCreationConfirmationAnimation', 'OnOpen' );
	}

	private function OnOutro()
	{
		var animOptions : inkAnimOptions;
		animOptions.playReversed = false;
		PlayAnim( m_outroAnimation, 'OnOutroComplete', animOptions );
	}

	protected event OnOutroComplete( anim : inkAnimProxy )
	{
		super.NextMenu();
	}

	protected event OnIntroComplete( anim : inkAnimProxy )
	{
		inkWidgetRef.SetInteractive( m_creditsBase, true );
		inkWidgetRef.SetInteractive( m_creditsExpansion, true );
		inkWidgetRef.SetInteractive( m_baseGameButton, true );
		inkWidgetRef.SetInteractive( m_standaloneButton, true );
	}

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

}

