class CharacterCreationPersistantElements extends inkLogicController
{
	private editable var m_headerHolder : inkCompoundRef;
	private editable var m_LBBtn : inkWidgetRef;
	private editable var m_RBBtn : inkWidgetRef;
	private editable var m_fluffHolderRight : inkCompoundRef;
	private editable var m_fluffHolderDown : inkCompoundRef;
	private editable var m_fluffHolderLeft : inkCompoundRef;
	private editable var m_fluffText1 : inkTextRef;
	private editable var m_fluffTextRight : inkTextRef;
	private editable var m_fluffTextDown : inkTextRef;
	private editable var m_fluffTextLeft : inkTextRef;
	private var m_headers : array< weak< CharacterCreationTopBarHeader > >;
	private var m_selectedHeader : weak< CharacterCreationTopBarHeader >;
	const var c_fluffMaxX : Float;
	default c_fluffMaxX = 1800;
	const var c_fluffMinY : Float;
	default c_fluffMinY = 300;
	const var c_fluffMaxY : Float;
	default c_fluffMaxY = 2000;

	protected event OnInitialize()
	{
		var currLogic : weak< CharacterCreationTopBarHeader >;
		var i : Int32;
		CreateHeader( "UI-Cyberpunk-Fullscreen-CharacterCreation-Life_Path", 'icon_backstory' );
		CreateHeader( "UI-Cyberpunk-Fullscreen-CharacterCreation-Body", 'icon_body' );
		CreateHeader( "UI-Cyberpunk-Fullscreen-CharacterCreation-Appearance", 'icon_appearence' );
		CreateHeader( "UI-Cyberpunk-Fullscreen-CharacterCreation-Attributes", 'icon_stats' );
		for( i = 0; i < m_headers.Size(); i += 1 )
		{
			currLogic = ( ( CharacterCreationTopBarHeader )( m_headers[ i ] ) );
			currLogic.m_root.SetState( 'Unselected' );
		}
		RegisterToCallback( 'OnChangeToHeader_00', this, 'OnChangeToHeader_00' );
		RegisterToGlobalInputCallback( 'OnPostOnAxis', this, 'OnAxisInput' );
		RegisterToGlobalInputCallback( 'OnPostOnRelative', this, 'OnRelativeInput' );
		PlaySound( 'GameMenu', 'OnOpen' );
	}

	protected event OnUninitialize()
	{
		UnregisterFromGlobalInputCallback( 'OnPostOnAxis', this, 'OnAxisInput' );
		UnregisterFromCallback( 'OnChangeToHeader_00', this, 'OnChangeToHeader_00' );
		UnregisterFromGlobalInputCallback( 'OnPostOnRelative', this, 'OnRelativeInput' );
		PlaySound( 'GameMenu', 'OnClose' );
	}

	public function ChangeSelectedHeader( selectedIndex : Int32 )
	{
		var currLogic : weak< CharacterCreationTopBarHeader >;
		inkWidgetRef.SetVisible( m_LBBtn, true );
		inkWidgetRef.SetVisible( m_RBBtn, true );
		if( m_selectedHeader )
		{
			m_selectedHeader.Unselect();
		}
		if( m_headers[ selectedIndex ] )
		{
			currLogic = ( ( CharacterCreationTopBarHeader )( m_headers[ selectedIndex ] ) );
			m_selectedHeader = currLogic;
			m_selectedHeader.Select();
		}
	}

	public function ChangeNavigationButtonVisibility( previousBtnAvailable : Bool, nextBtnAvailable : Bool )
	{
		inkWidgetRef.SetVisible( m_LBBtn, previousBtnAvailable );
		inkWidgetRef.SetVisible( m_RBBtn, nextBtnAvailable );
	}

	public function CreateHeader( const label : ref< String >, icon : CName )
	{
		var currButton : inkWidget;
		var currLogic : weak< CharacterCreationTopBarHeader >;
		currButton = ( ( inkWidget )( SpawnFromLocal( inkCompoundRef.Get( m_headerHolder ), 'top_bar_header' ) ) );
		currLogic = ( ( CharacterCreationTopBarHeader )( currButton.GetController() ) );
		currLogic.SetData( label, icon );
		m_headers.PushBack( currLogic );
	}

	protected event OnChangeToHeader_00( e : weak< inkWidget > )
	{
		ChangeSelectedHeader( 0 );
	}

	protected event OnAxisInput( e : inkPointerEvent )
	{
		SetFluff( e );
	}

	protected event OnRelativeInput( e : inkPointerEvent )
	{
		SetFluff( e );
	}

	public function SetFluff( e : inkPointerEvent )
	{
		var value : Vector2;
		var clampedValueX : Float;
		var clampedValueY : Float;
		var inkMarginFluffRight : inkMargin;
		var inkMarginFluffLeft : inkMargin;
		value = e.GetScreenSpacePosition();
		clampedValueX = ClampF( value.X, 0.0, c_fluffMaxX );
		clampedValueY = ClampF( value.Y, c_fluffMinY, c_fluffMaxY );
		inkCompoundRef.SetMargin( m_fluffHolderDown, inkMargin( clampedValueX, 0.0, 0.0, 0.0 ) );
		inkMarginFluffRight = inkCompoundRef.GetMargin( m_fluffHolderRight );
		inkMarginFluffLeft = inkCompoundRef.GetMargin( m_fluffHolderLeft );
		inkCompoundRef.SetMargin( m_fluffHolderRight, inkMargin( 0.0, clampedValueY, inkMarginFluffRight.right, 0.0 ) );
		inkCompoundRef.SetMargin( m_fluffHolderLeft, inkMargin( inkMarginFluffLeft.left, clampedValueY, 0.0, 0.0 ) );
		inkTextRef.SetText( m_fluffText1, ( ( ( ( ( "OB " + ( ( String )( value.X ) ) ) + " " ) + ( ( String )( value.X ) ) ) + " " ) + ( ( String )( value.X ) ) ) + " CP" );
		inkTextRef.SetText( m_fluffTextRight, ( ( String )( ( ( Int32 )( value.Y ) ) ) ) );
		inkTextRef.SetText( m_fluffTextDown, ( ( String )( ( ( Int32 )( value.X ) ) ) ) );
		inkTextRef.SetText( m_fluffTextLeft, ( ( String )( ( ( Int32 )( value.Y ) ) ) ) );
	}

}

class CharacterCreationTopBarHeader extends inkButtonController
{
	private editable var m_icon : inkImageRef;
	private editable var m_label : inkTextRef;
	var m_root : weak< inkWidget >;
	private var m_animationProxy : inkAnimProxy;

	protected event OnInitialize()
	{
		m_root = GetRootWidget();
	}

	protected event OnUninitialize() {}

	public function SetData( const label : ref< String >, icon : CName )
	{
		inkImageRef.SetTexturePart( m_icon, icon );
		inkTextRef.SetText( m_label, label );
	}

	public function Select()
	{
		PlayAnim( 'Select' );
	}

	public function Unselect()
	{
		PlayAnim( 'Unselect' );
	}

	public function PlayAnim( animName : CName )
	{
		if( m_animationProxy && m_animationProxy.IsPlaying() )
		{
			m_animationProxy.Stop();
		}
		m_animationProxy = PlayLibraryAnimation( animName );
	}

}

