class ButtonHints extends inkLogicController
{
	editable var m_horizontalHolder : inkCompoundRef;

	protected event OnInitialize()
	{
		inkCompoundRef.RemoveAllChildren( m_horizontalHolder );
	}

	public function AddButtonHint( icon : EInputKey, const label : ref< String > ) {}

	public function AddButtonHint( action : CName, label : CName, holdInteraction : Bool )
	{
		AddButtonHint( action, ( ( "[" + GetLocalizedText( "LocKey#565" ) ) + "] " ) + GetLocalizedTextByKey( label ) );
	}

	public function AddButtonHint( action : CName, label : CName )
	{
		AddButtonHint( action, GetLocalizedTextByKey( label ) );
	}

	public function AddButtonHint( action : CName, const label : ref< String > )
	{
		var newWidget : weak< inkWidget >;
		var buttonHint : weak< ButtonHintListItem >;
		buttonHint = CheckForPreExisting( action );
		if( buttonHint != NULL )
		{
			buttonHint.SetData( action, label );
		}
		else
		{
			newWidget = ( ( inkWidget )( SpawnFromLocal( inkCompoundRef.Get( m_horizontalHolder ), 'ButtonHintListItem' ) ) );
			buttonHint = ( ( ButtonHintListItem )( newWidget.GetController() ) );
			buttonHint.SetData( action, label );
		}
	}

	public function AddCharacterRoatateButtonHint()
	{
		SpawnFromLocal( inkCompoundRef.Get( m_horizontalHolder ), 'ButtonHintRotation' );
	}

	public function RemoveButtonHint( action : CName )
	{
		var widgetToDelete : weak< inkWidget >;
		widgetToDelete = RemoveItem( action );
		inkCompoundRef.RemoveChild( m_horizontalHolder, widgetToDelete );
	}

	public function ClearButtonHints()
	{
		inkCompoundRef.RemoveAllChildren( m_horizontalHolder );
	}

	public function RemoveItem( action : CName ) : weak< inkWidget >
	{
		var widget : weak< inkWidget >;
		var ctrl : weak< ButtonHintListItem >;
		var i, count : Int32;
		count = inkCompoundRef.GetNumChildren( m_horizontalHolder );
		for( i = 0; i < count; i += 1 )
		{
			widget = inkCompoundRef.GetWidgetByIndex( m_horizontalHolder, i );
			ctrl = ( ( ButtonHintListItem )( widget.GetController() ) );
			if( ctrl.CheckAction( action ) )
			{
				return widget;
			}
		}
		return NULL;
	}

	public function Hide()
	{
		inkCompoundRef.SetVisible( m_horizontalHolder, false );
	}

	public function Show()
	{
		inkCompoundRef.SetVisible( m_horizontalHolder, true );
	}

	public function IsVisible() : Bool
	{
		return inkCompoundRef.IsVisible( m_horizontalHolder );
	}

	private function CheckForPreExisting( action : CName ) : weak< ButtonHintListItem >
	{
		var widget : weak< inkWidget >;
		var ctrl : weak< ButtonHintListItem >;
		var i, count : Int32;
		count = inkCompoundRef.GetNumChildren( m_horizontalHolder );
		for( i = 0; i < count; i += 1 )
		{
			widget = inkCompoundRef.GetWidgetByIndex( m_horizontalHolder, i );
			ctrl = ( ( ButtonHintListItem )( widget.GetController() ) );
			if( ctrl.CheckAction( action ) )
			{
				return ctrl;
			}
		}
		return NULL;
	}

}

class ButtonHintListItem extends inkLogicController
{
	private editable var m_inputDisplay : inkWidgetRef;
	private editable var m_label : inkTextRef;
	private var m_buttonHint : weak< inkInputDisplayController >;
	private var m_actionName : CName;

	protected event OnInitialize()
	{
		m_buttonHint = ( ( inkInputDisplayController )( inkWidgetRef.GetController( m_inputDisplay ) ) );
	}

	public function CheckAction( action : CName ) : Bool
	{
		return m_actionName == action;
	}

	public function SetData( action : CName, const label : ref< String > )
	{
		m_actionName = action;
		inkTextRef.SetText( m_label, label );
		m_buttonHint.SetInputAction( m_actionName );
	}

	public function SetData( icon : EInputKey, const label : ref< String > ) {}
}

