struct SSoundData
{
	editable var widgetAudioName : CName;
	default widgetAudioName = 'Button';
	editable var onPressKey : CName;
	editable var onReleaseKey : CName;
	editable var onHoverOverKey : CName;
	editable var onHoverOutKey : CName;
}

class DeviceButtonLogicControllerBase extends inkButtonController
{
	[ category = "Widget Refs" ]
	protected editable var m_targetWidgetRef : inkWidgetRef;
	[ category = "Widget Refs" ]
	protected editable var m_displayNameWidget : inkTextRef;
	[ category = "Widget Refs" ]
	protected editable var m_iconWidget : inkImageRef;
	[ category = "Widget Refs" ]
	protected editable var m_toggleSwitchWidget : inkImageRef;
	[ category = "Widget Refs" ]
	protected editable var m_sizeProviderWidget : inkWidgetRef;
	[ category = "Widget Refs" ]
	protected editable var m_selectionMarkerWidget : inkWidgetRef;
	[ category = "Animations" ]
	protected editable inlined var m_onReleaseAnimations : WidgetAnimationManager;
	[ category = "Animations" ]
	protected editable inlined var m_onPressAnimations : WidgetAnimationManager;
	[ category = "Animations" ]
	protected editable inlined var m_onHoverOverAnimations : WidgetAnimationManager;
	[ category = "Animations" ]
	protected editable inlined var m_onHoverOutAnimations : WidgetAnimationManager;
	[ category = "Style Overrides" ]
	protected editable var m_defaultStyle : ResRef;
	[ category = "Style Overrides" ]
	protected editable var m_selectionStyle : ResRef;
	protected editable var m_soundData : SSoundData;
	protected var m_isInitialized : Bool;
	protected var m_targetWidget : weak< inkWidget >;
	protected var m_isSelected : Bool;

	protected event OnInitialize()
	{
		if( inkWidgetRef.Get( m_targetWidgetRef ) == NULL )
		{
			m_targetWidget = GetRootWidget();
		}
		else
		{
			m_targetWidget = inkWidgetRef.Get( m_targetWidgetRef );
		}
		RegisterBaseInputCallbacks();
		ResolveSelection();
	}

	public function IsInitialized() : Bool
	{
		return m_isInitialized;
	}

	protected virtual function ResolveWidgetState( state : EWidgetState ) {}

	public function SetButtonSize( x : Float, y : Float )
	{
		inkWidgetRef.SetSize( m_sizeProviderWidget, x, y );
	}

	public virtual function ToggleSelection( isSelected : Bool )
	{
		SetSelected( isSelected );
		UpdateButtonState( true );
		ResolveSelection();
	}

	public virtual function ResolveSelection()
	{
		if( GetSelected() )
		{
			inkWidgetRef.SetVisible( m_selectionMarkerWidget, true );
			if( ResRef.IsValid( m_selectionStyle ) )
			{
				m_targetWidget.SetStyle( m_selectionStyle );
			}
		}
		else
		{
			inkWidgetRef.SetVisible( m_selectionMarkerWidget, false );
			if( ResRef.IsValid( m_defaultStyle ) )
			{
				m_targetWidget.SetStyle( m_defaultStyle );
			}
		}
	}

	public virtual function RegisterBaseInputCallbacks()
	{
		m_targetWidget.RegisterToCallback( 'OnHoverOver', this, 'OnHoverOver' );
		m_targetWidget.RegisterToCallback( 'OnHoverOut', this, 'OnHoverOut' );
		m_targetWidget.RegisterToCallback( 'OnPress', this, 'OnPress' );
		m_targetWidget.RegisterToCallback( 'OnRelease', this, 'OnRelease' );
	}

	protected event OnHoverOver( e : inkPointerEvent )
	{
		TriggerOnHoverOverAnimations();
	}

	protected event OnHoverOut( e : inkPointerEvent )
	{
		TriggerOnHoverOutAnimations();
	}

	protected event OnPress( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			TriggerOnPressAnimations();
		}
	}

	protected event OnRelease( e : inkPointerEvent )
	{
		if( e.IsAction( 'click' ) )
		{
			TriggerOnReleaseAnimations();
		}
	}

	private function TriggerOnHoverOutAnimations()
	{
		if( m_onHoverOutAnimations != NULL )
		{
			m_onHoverOutAnimations.TriggerAnimations( this );
		}
	}

	private function TriggerOnHoverOverAnimations()
	{
		if( m_onHoverOverAnimations != NULL )
		{
			m_onHoverOverAnimations.TriggerAnimations( this );
		}
	}

	private function TriggerOnPressAnimations()
	{
		if( m_onPressAnimations != NULL )
		{
			m_onPressAnimations.TriggerAnimations( this );
		}
	}

	private function TriggerOnReleaseAnimations()
	{
		if( m_onReleaseAnimations != NULL )
		{
			m_onReleaseAnimations.TriggerAnimations( this );
		}
	}

	public function RegisterAudioCallbacks( gameController : inkGameController )
	{
		m_targetWidget.RegisterToCallback( 'OnHoverOver', gameController, 'OnButtonHoverOver' );
		m_targetWidget.RegisterToCallback( 'OnHoverOut', gameController, 'OnButtonHoverOut' );
		m_targetWidget.RegisterToCallback( 'OnPress', gameController, 'OnButtonPress' );
	}

	public function GetWidgetAudioName() : CName
	{
		return m_soundData.widgetAudioName;
	}

	public function GetOnPressKeySfxName() : CName
	{
		return m_soundData.onPressKey;
	}

	public function GetOnReleaseKeySfxName() : CName
	{
		return m_soundData.onReleaseKey;
	}

	public function GetOnHoverOverKeySfxName() : CName
	{
		return m_soundData.onHoverOverKey;
	}

	public function GetOnHoverOutKeySfxName() : CName
	{
		return m_soundData.onHoverOutKey;
	}

	public function ATUI_GetButtonDisplayText() : String
	{
		return inkTextRef.GetText( m_displayNameWidget );
	}

}

