import class HoldIndicatorGameController extends inkGameController
{

	protected event OnInitialize()
	{
		RegisterToCallback( 'OnHoldProgress', this, 'OnHoldProgress' );
		RegisterToCallback( 'OnHoldStart', this, 'OnHoldStart' );
		RegisterToCallback( 'OnHoldFinish', this, 'OnHoldFinish' );
		RegisterToCallback( 'OnHoldStop', this, 'OnHoldStop' );
		if( IsNoInputIconsModeEnabled() )
		{
			GetRootWidget().SetVisible( false );
		}
	}

	protected event OnHoldProgress( value : Float )
	{
		HoldProgress( value );
	}

	protected event OnHoldStart()
	{
		HoldStart();
	}

	protected event OnHoldFinish()
	{
		HoldFinish();
	}

	protected event OnHoldStop()
	{
		HoldStop();
	}

	protected virtual function HoldProgress( value : Float ) {}

	protected virtual function HoldStart() {}

	protected virtual function HoldFinish() {}

	protected virtual function HoldStop() {}
}

class GamepadHoldIndicatorGameController extends HoldIndicatorGameController
{
	private editable var m_image : inkImageRef;
	private editable var m_partName : String;
	default m_partName = "icon_circle_anim_";
	private var m_progress : Int32;
	private var m_animProxy : inkAnimProxy;

	protected override function HoldProgress( value : Float )
	{
		super.HoldProgress( value );
		SetProgress( ( ( Int32 )( value * 100.0 ) ) );
	}

	protected override function HoldStart()
	{
		if( IsNoInputIconsModeEnabled() )
		{
			return;
		}
		inkImageRef.SetVisible( m_image, true );
		if( m_animProxy )
		{
			m_animProxy.Stop();
		}
		m_animProxy = PlayLibraryAnimation( 'hold' );
	}

	protected override function HoldFinish()
	{
		StopAnimation();
	}

	protected override function HoldStop()
	{
		StopAnimation();
	}

	private function SetProgress( value : Int32 )
	{
		var partName : CName;
		value = Clamp( value, 0, 99 );
		if( m_progress != value )
		{
			m_progress = value;
			partName = StringToName( m_partName + IntToString( m_progress ) );
			inkImageRef.SetTexturePart( m_image, partName );
		}
	}

	private function StopAnimation()
	{
		if( m_animProxy )
		{
			m_animProxy.Stop();
			m_animProxy = NULL;
		}
		inkImageRef.SetVisible( m_image, false );
	}

}

class KeyboardHoldIndicatorGameController extends HoldIndicatorGameController
{
	private editable var m_progress : inkImageRef;

	protected override function HoldProgress( value : Float )
	{
		inkImageRef.SetScale( m_progress, Vector2( 1.0, value ) );
	}

	protected override function HoldStart()
	{
		inkImageRef.SetVisible( m_progress, true );
	}

	protected override function HoldFinish()
	{
		inkImageRef.SetVisible( m_progress, false );
	}

	protected override function HoldStop()
	{
		inkImageRef.SetVisible( m_progress, false );
	}

}

