class RadialMenuGameController extends inkHUDGameController
{
	private editable var m_containerRef : inkCompoundRef;
	private editable var m_highlightRef : inkWidgetRef;
	private const editable var m_itemListRef : array< inkWidgetRef >;
	private var m_quickSlotsBoard : weak< IBlackboard >;
	private var m_quickSlotsDef : UI_QuickSlotsDataDef;
	private var m_inputAxisCallbackId : CallbackHandle;

	protected event OnInitialize()
	{
		m_quickSlotsDef = GetAllBlackboardDefs().UI_QuickSlotsData;
		m_quickSlotsBoard = GetBlackboardSystem().Get( m_quickSlotsDef );
		m_inputAxisCallbackId = m_quickSlotsBoard.RegisterDelayedListenerFloat( m_quickSlotsDef.UIRadialContextRightStickAngle, this, 'OnRadialAngleChanged' );
		GetRootWidget().SetVisible( false );
	}

	protected event OnUninitialize()
	{
		m_quickSlotsBoard.UnregisterDelayedListener( m_quickSlotsDef.UIRadialContextRightStickAngle, m_inputAxisCallbackId );
	}

	protected event OnRadialAngleChanged( value : Float )
	{
		var i, count : Int32;
		var minAngle : Float;
		var highlightAngle : Float;
		var rootWidget : weak< inkCompoundWidget >;
		var containerPosition : Vector2;
		var containerSize : Vector2;
		var centerPos : Vector2;
		var curItem : inkWidgetRef;
		var curPosition : Vector2;
		var curSize : Vector2;
		var itemPos : Vector2;
		var curAngle : Float;
		var tmpWdg : weak< inkCompoundWidget >;
		var tmpText : inkText;
		highlightAngle = value + 180.0;
		inkWidgetRef.SetRotation( m_highlightRef, highlightAngle );
		count = m_itemListRef.Size();
		minAngle = -1.0;
		rootWidget = ( ( inkCompoundWidget )( GetRootWidget() ) );
		containerSize = rootWidget.GetChildSize( inkCompoundRef.Get( m_containerRef ) );
		containerPosition = rootWidget.GetChildPosition( inkCompoundRef.Get( m_containerRef ) );
		centerPos = Vector2( containerPosition.X + ( containerSize.X / 2.0 ), containerPosition.Y + ( containerSize.Y / 2.0 ) );
		for( i = 0; i < count; i += 1 )
		{
			curItem = m_itemListRef[ i ];
			curPosition = inkCompoundRef.GetChildPosition( m_containerRef, inkWidgetRef.Get( curItem ) );
			curSize = inkCompoundRef.GetChildSize( m_containerRef, inkWidgetRef.Get( curItem ) );
			itemPos = Vector2( curPosition.X + ( curSize.X / 2.0 ), curPosition.Y + ( curSize.Y / 2.0 ) );
			curAngle = Rad2Deg( AtanF( itemPos.X - centerPos.X, itemPos.Y - centerPos.Y ) );
			if( minAngle > curAngle )
			{
				minAngle = curAngle;
			}
			tmpWdg = ( ( inkCompoundWidget )( inkWidgetRef.Get( curItem ) ) );
			tmpText = ( ( inkText )( tmpWdg.GetWidget( 'debug' ) ) );
			tmpText.SetText( ( curAngle + " : " ) + value );
		}
	}

	protected event OnOpenWheelRequest( evt : QuickSlotButtonHoldStartEvent )
	{
		if( evt.dPadItemDirection == EDPadSlot.WeaponsWheel )
		{
			PopulateData();
			SetVisible( true );
		}
	}

	protected event OnCloseWheelRequest( evt : QuickSlotButtonHoldEndEvent )
	{
		if( evt.dPadItemDirection == EDPadSlot.WeaponsWheel )
		{
			ApplySelection();
			SetVisible( false );
		}
	}

	protected function PopulateData() {}

	protected function ApplySelection() {}

	protected function SetVisible( value : Bool )
	{
		GetRootWidget().SetVisible( value );
	}

}

class RadialMenuHelper
{

	public static function IsWeaponsBlocked( target : weak< GameObject > ) : Bool
	{
		return ( StatusEffectSystem.ObjectHasStatusEffectWithTag( target, 'VehicleScene' ) || StatusEffectSystem.ObjectHasStatusEffectWithTag( target, 'NoCombat' ) ) || StatusEffectSystem.ObjectHasStatusEffectWithTag( target, 'FirearmsNoUnequipNoSwitch' );
	}

	public static function IsCombatGadgetsBlocked( target : weak< GameObject > ) : Bool
	{
		return ( StatusEffectSystem.ObjectHasStatusEffectWithTag( target, 'Fists' ) || StatusEffectSystem.ObjectHasStatusEffectWithTag( target, 'Melee' ) ) || StatusEffectSystem.ObjectHasStatusEffectWithTag( target, 'Firearms' );
	}

}

