class SubMenuPanelLogicController extends PlayerStatsUIHolder
{
	private editable var m_levelValue : inkTextRef;
	private editable var m_streetCredLabel : inkTextRef;
	private editable var m_currencyValue : inkTextRef;
	private editable var m_weightValue : inkTextRef;
	private editable var m_subMenuLabel : inkTextRef;
	private editable var m_centralLine : inkWidgetRef;
	private editable var m_levelBarProgress : inkWidgetRef;
	private editable var m_levelBarSpacer : inkWidgetRef;
	private editable var m_streetCredBarProgress : inkWidgetRef;
	private editable var m_streetCredBarSpacer : inkWidgetRef;
	private editable var m_menuselectorWidget : inkWidgetRef;
	private editable var m_subMenuselectorWidget : inkWidgetRef;
	private editable var m_topPanel : inkWidgetRef;
	private editable var m_leftHolder : inkWidgetRef;
	private editable var m_rightHolder : inkWidgetRef;
	private editable var m_lineBarsContainer : inkCompoundRef;
	private editable var m_lineWidget : inkCompoundRef;
	private var m_menusList : array< MenuData >;
	private var m_menuSelectorCtrl : weak< hubStaticSelectorController >;
	private var m_subMenuActive : Bool;
	private var m_previousLineBar : weak< inkWidget >;
	private var m_IsSetActive : Bool;
	private var m_selectorMode : Bool;
	private var m_menusData : MenuDataBuilder;
	private var m_curMenuData : MenuData;
	private var m_curSubMenuData : MenuData;
	var m_hubMenuInstanceID : Uint32;

	protected event OnInitialize()
	{
		m_menuSelectorCtrl = ( ( hubStaticSelectorController )( inkWidgetRef.GetController( m_menuselectorWidget ) ) );
		HideName( false );
		SetActive( false );
		inkCompoundRef.RemoveAllChildren( m_lineBarsContainer );
		inkWidgetRef.SetVisible( m_centralLine, true );
	}

	protected event OnUninitialize()
	{
		SetActive( false );
	}

	protected event OnOpenMenuRequest( evt : OpenMenuRequest )
	{
		if( ( evt.m_hubMenuInstanceID > ( ( Uint32 )( 0 ) ) ) && ( evt.m_hubMenuInstanceID != m_hubMenuInstanceID ) )
		{
			return false;
		}
		if( evt.m_menuName != '' )
		{
			m_curMenuData = m_menusData.GetData( evt.m_menuName );
		}
		else
		{
			m_curMenuData = evt.m_eventData;
		}
		inkWidgetRef.SetVisible( m_centralLine, false );
		inkTextRef.SetVisible( m_subMenuLabel, true );
		if( !( evt.m_internal ) )
		{
			m_menuSelectorCtrl.ScrollTo( m_curMenuData );
		}
		HideName( false );
	}

	public function SetHubMenuInstanceID( ID : Uint32 )
	{
		m_hubMenuInstanceID = ID;
	}

	public function SetMenusData( menuData : MenuDataBuilder )
	{
		m_menusData = menuData;
	}

	public function GetActive() : Bool
	{
		return m_IsSetActive;
	}

	public function HideName( val : Bool )
	{
		m_selectorMode = !( val );
		inkWidgetRef.SetVisible( m_menuselectorWidget, !( val ) );
		inkCompoundRef.SetVisible( m_lineWidget, !( val ) );
		inkCompoundRef.SetVisible( m_lineBarsContainer, !( val ) );
	}

	public function SetRepacerMode()
	{
		inkWidgetRef.SetVisible( m_leftHolder, false );
		inkWidgetRef.SetVisible( m_rightHolder, false );
	}

	public function SetActive( isActive : Bool, optional hideSubmenu : Bool )
	{
		m_IsSetActive = isActive;
		inkWidgetRef.SetVisible( m_topPanel, isActive );
		inkWidgetRef.SetVisible( m_subMenuselectorWidget, !( hideSubmenu ) );
		m_subMenuActive = !( hideSubmenu );
		if( isActive )
		{
			RegisterToGlobalInputCallback( 'OnPostOnPress', this, 'OnButtonPressed' );
			RegisterToGlobalInputCallback( 'OnPostOnAxis', this, 'OnButtonPressed' );
			m_menuSelectorCtrl.RegisterToCallback( 'OnSelectionChanged', this, 'OnMenuChanged' );
		}
		else
		{
			UnregisterFromGlobalInputCallback( 'OnPostOnPress', this, 'OnButtonPressed' );
			UnregisterFromGlobalInputCallback( 'OnPostOnAxis', this, 'OnButtonPressed' );
			m_menuSelectorCtrl.UnregisterFromCallback( 'OnSelectionChanged', this, 'OnMenuChanged' );
		}
	}

	protected event OnButtonPressed( evt : inkPointerEvent )
	{
		if( evt.IsHandled() )
		{
			return false;
		}
		if( evt.IsAction( 'prior_menu' ) && m_selectorMode )
		{
			PlaySound( 'TabButton', 'OnPress' );
			PlayRumble( RumbleStrength.SuperLight, RumbleType.Pulse, RumblePosition.Left );
			m_menuSelectorCtrl.Prior();
			evt.Handle();
		}
		else if( evt.IsAction( 'next_menu' ) && m_selectorMode )
		{
			PlaySound( 'TabButton', 'OnPress' );
			PlayRumble( RumbleStrength.SuperLight, RumbleType.Pulse, RumblePosition.Right );
			m_menuSelectorCtrl.Next();
			evt.Handle();
		}
		else
		{
			return false;
		}
	}

	protected event OnMenuChanged( index : Int32, value : String )
	{
		if( m_menusList.Size() <= 0 )
		{
			return false;
		}
		HideName( false );
	}

	public function OpenModsTabExternal( request : CyberwareTabModsRequest )
	{
		var evt : OpenMenuRequest;
		evt = new OpenMenuRequest;
		evt.m_eventData = m_menusData.GetData( ( ( Int32 )( HubMenuItems.Inventory ) ) );
		evt.m_eventData.userData = request.wrapper;
		evt.m_eventData.m_overrideDefaultUserData = true;
		evt.m_isMainMenu = false;
		evt.m_jumpBack = true;
		QueueEvent( evt );
	}

	public function AddMenus( const selectedMenu : ref< MenuData >, const menuDataArray : ref< array< MenuData > >, optional subMenuData : MenuData, optional forceRefreshLines : Bool )
	{
		var i : Int32;
		if( menuDataArray.Size() <= 0 )
		{
			return;
		}
		m_menusList.Clear();
		for( i = 0; i < menuDataArray.Size(); i += 1 )
		{
			if( !( menuDataArray[ i ].disabled ) )
			{
				m_menusList.PushBack( menuDataArray[ i ] );
			}
		}
		m_menuSelectorCtrl.SetupMenu( m_menusList, selectedMenu.identifier );
	}

	public function HandleCharacterLevelUpdated( value : Int32 )
	{
		inkTextRef.SetText( m_levelValue, ( ( String )( value ) ) );
	}

	public function HandleCharacterLevelCurrentXPUpdated( value : Int32, remainingXP : Int32 )
	{
		var percentageValue : Float;
		percentageValue = ( ( Float )( value ) ) / ( ( Float )( ( remainingXP + value ) ) );
		inkWidgetRef.SetSizeCoefficient( m_levelBarProgress, percentageValue );
		inkWidgetRef.SetSizeCoefficient( m_levelBarSpacer, 1.0 - percentageValue );
	}

	public function HandleCharacterStreetCredLevelUpdated( value : Int32 )
	{
		inkTextRef.SetText( m_streetCredLabel, ( ( String )( value ) ) );
	}

	public function HandleCharacterStreetCredPointsUpdated( value : Int32, remainingXP : Int32 )
	{
		var percentageValue : Float;
		percentageValue = ( ( Float )( value ) ) / ( ( Float )( ( remainingXP + value ) ) );
		inkWidgetRef.SetSizeCoefficient( m_streetCredBarProgress, percentageValue );
		inkWidgetRef.SetSizeCoefficient( m_streetCredBarSpacer, 1.0 - percentageValue );
	}

	public function HandlePlayerMaxWeightUpdated( value : Int32, curInventoryWeight : Float )
	{
		inkTextRef.SetText( m_weightValue, ( ( ( String )( ( ( Int32 )( curInventoryWeight ) ) ) ) + "/" ) + ( ( String )( value ) ) );
	}

	public function HandlePlayerWeightUpdated( value : Float, maxWeight : Int32 )
	{
		inkTextRef.SetText( m_weightValue, ( ( ( String )( ( ( Int32 )( value ) ) ) ) + "/" ) + ( ( String )( maxWeight ) ) );
	}

	public override function HandleCharacterCurrencyUpdated( value : Int32 )
	{
		inkTextRef.SetText( m_currencyValue, ( ( String )( value ) ) );
	}

}

class PlayerStatsUIHolder extends inkLogicController
{

	public virtual function HandleCharacterCurrencyUpdated( value : Int32 ) {}
}

