class DifficultySelectionMenu extends BaseCharacterCreationController
{
	editable var m_difficultyTitle : inkTextRef;
	editable var m_textureTop : inkImageRef;
	editable var m_textureBottom : inkImageRef;
	private editable var m_hoverAnimation : CName;
	editable var m_difficulty0 : inkWidgetRef;
	editable var m_difficulty1 : inkWidgetRef;
	editable var m_difficulty2 : inkWidgetRef;
	editable var m_difficulty3 : inkWidgetRef;
	private var m_animationProxy : inkAnimProxy;
	private var m_lastShownPart : CName;
	private var m_lastAtlas : ResRef;
	default m_lastAtlas = R"base\gameplay\gui\fullscreen\main_menu\difficulty_level.inkatlas";
	private var m_translationAnimationCtrl : weak< inkTextReplaceController >;
	private var m_localizedText : String;
	private const var c_atlas1 : ResRef;
	default c_atlas1 = R"base\gameplay\gui\fullscreen\main_menu\difficulty_level.inkatlas";
	private const var c_atlas2 : ResRef;
	default c_atlas2 = R"base\gameplay\gui\fullscreen\main_menu\difficulty_level1.inkatlas";
	private var m_isInputLocked : Bool;
	default m_isInputLocked = false;

	protected event OnInitialize()
	{
		super.OnInitialize();
		RegisterToCallback( 'OnPress', this, 'OnPress' );
		inkWidgetRef.RegisterToCallback( m_difficulty0, 'OnHoverOver', this, 'OnHoverOverDifficulty0' );
		inkWidgetRef.RegisterToCallback( m_difficulty1, 'OnHoverOver', this, 'OnHoverOverDifficulty1' );
		inkWidgetRef.RegisterToCallback( m_difficulty2, 'OnHoverOver', this, 'OnHoverOverDifficulty2' );
		inkWidgetRef.RegisterToCallback( m_difficulty3, 'OnHoverOver', this, 'OnHoverOverDifficulty3' );
		GetTelemetrySystem().LogInitialChoiceSetStatege( telemetryInitalChoiceStage.Difficulty );
		OnIntro();
	}

	protected event OnUninitialize()
	{
		super.OnUninitialize();
		UnregisterFromCallback( 'OnPress', this, 'OnPress' );
	}

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

	protected event OnHoverOverDifficulty0( e : inkPointerEvent )
	{
		TextureTransition( c_atlas1, 'story' );
		m_localizedText = GetLocalizedText( "LocKey#54124" );
		PlayTranslationAnimation();
	}

	protected event OnHoverOverDifficulty1( e : inkPointerEvent )
	{
		TextureTransition( c_atlas1, 'fight' );
		m_localizedText = GetLocalizedText( "LocKey#54125" );
		PlayTranslationAnimation();
	}

	protected event OnHoverOverDifficulty2( e : inkPointerEvent )
	{
		TextureTransition( c_atlas2, 'hard' );
		m_localizedText = GetLocalizedText( "LocKey#54126" );
		PlayTranslationAnimation();
	}

	protected event OnHoverOverDifficulty3( e : inkPointerEvent )
	{
		TextureTransition( c_atlas2, 'deathmarch' );
		m_localizedText = GetLocalizedText( "LocKey#54127" );
		PlayTranslationAnimation();
	}

	private function PlayTranslationAnimation()
	{
		m_translationAnimationCtrl.SetBaseText( "..." );
		m_translationAnimationCtrl = ( ( inkTextReplaceController )( inkTextRef.GetController( m_difficultyTitle ) ) );
		m_translationAnimationCtrl.SetTargetText( m_localizedText );
		m_translationAnimationCtrl.PlaySetAnimation();
	}

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

	protected event OnPress( e : inkPointerEvent )
	{
		var target : weak< inkWidget >;
		target = e.GetTarget();
		if( e.IsAction( 'click' ) && !( m_isInputLocked ) )
		{
			PlaySound( 'Button', 'OnPress' );
			switch( target )
			{
				case inkWidgetRef.Get( m_difficulty0 ):
					GameInstance.GetStatsDataSystem( GetPlayerControlledObject().GetGame() ).SetDifficulty( gameDifficulty.Story );
				GetTelemetrySystem().LogInitialChoiceDifficultySelected( gameDifficulty.Story );
				inkImageRef.SetVisible( m_textureBottom, false );
				NextMenu();
				break;
				case inkWidgetRef.Get( m_difficulty1 ):
					GameInstance.GetStatsDataSystem( GetPlayerControlledObject().GetGame() ).SetDifficulty( gameDifficulty.Easy );
				GetTelemetrySystem().LogInitialChoiceDifficultySelected( gameDifficulty.Easy );
				inkImageRef.SetVisible( m_textureBottom, false );
				NextMenu();
				break;
				case inkWidgetRef.Get( m_difficulty2 ):
					GameInstance.GetStatsDataSystem( GetPlayerControlledObject().GetGame() ).SetDifficulty( gameDifficulty.Hard );
				GetTelemetrySystem().LogInitialChoiceDifficultySelected( gameDifficulty.Hard );
				inkImageRef.SetVisible( m_textureBottom, false );
				NextMenu();
				break;
				case inkWidgetRef.Get( m_difficulty3 ):
					GameInstance.GetStatsDataSystem( GetPlayerControlledObject().GetGame() ).SetDifficulty( gameDifficulty.VeryHard );
				GetTelemetrySystem().LogInitialChoiceDifficultySelected( gameDifficulty.VeryHard );
				inkImageRef.SetVisible( m_textureBottom, false );
				NextMenu();
				break;
			}
		}
	}

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

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

	private function OnIntro()
	{
		PlayAnim( 'intro', '' );
	}

	private function OnOutro()
	{
		PlayAnim( 'outro', 'OnOutroComplete' );
	}

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

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

}

