class HubTimeSkipController extends inkLogicController
{
	private editable var m_gameTimeText : inkTextRef;
	private editable var m_timeSkipText : inkTextRef;
	private editable var m_cantSkipTimeContainer : inkWidgetRef;
	private editable var m_timeSkipButton : inkWidgetRef;
	private var m_gameCtrlRef : weak< gameuiMenuGameController >;
	private var m_timeSystem : weak< TimeSystem >;
	private var m_timeSkipPopupToken : inkGameNotificationToken;
	private var m_cantSkipTimeAnim : inkAnimProxy;
	private var m_gameTimeTextParams : inkTextParams;
	private var m_canSkipTime : Bool;

	public function Init( isEnabled : Bool, timeSystem : weak< TimeSystem >, gameController : weak< gameuiMenuGameController > )
	{
		var buttonController : inkButtonController;
		m_canSkipTime = isEnabled;
		m_timeSystem = timeSystem;
		m_gameCtrlRef = gameController;
		buttonController = ( ( inkButtonController )( inkWidgetRef.GetController( m_timeSkipButton ) ) );
		buttonController.SetEnabled( m_canSkipTime );
		if( m_canSkipTime )
		{
			inkTextRef.SetLocalizedTextScript( m_timeSkipText, "LocKey#15480" );
			MenuItemController.ApplyEnabledLayout( m_timeSkipText, GetRootWidget() );
			buttonController.RegisterToCallback( 'OnRelease', this, 'OnTimeSkipButtonPressed' );
		}
		else
		{
			MenuItemController.ApplyDisabledLayout( m_timeSkipText, GetRootWidget() );
			buttonController.RegisterToCallback( 'OnHoverOver', this, 'OnTimeSkipButtonHoverOver' );
			buttonController.RegisterToCallback( 'OnHoverOut', this, 'OnTimeSkipButtonHoverOut' );
		}
	}

	private function UpdateGameTime()
	{
		GameTimeUtils.UpdateGameTimeText( m_timeSystem, m_gameTimeText, m_gameTimeTextParams );
	}

	protected event OnTimeSkipButtonHoverOver( evt : inkPointerEvent )
	{
		if( !( m_canSkipTime ) )
		{
			inkWidgetRef.SetVisible( m_cantSkipTimeContainer, true );
			if( m_cantSkipTimeAnim )
			{
				m_cantSkipTimeAnim.Stop();
			}
			m_cantSkipTimeAnim = PlayLibraryAnimationOnTargets( 'tooltip_in', SelectWidgets( inkWidgetRef.Get( m_cantSkipTimeContainer ) ) );
		}
	}

	protected event OnTimeSkipButtonHoverOut( evt : inkPointerEvent )
	{
		if( !( m_canSkipTime ) )
		{
			inkWidgetRef.SetVisible( m_cantSkipTimeContainer, false );
		}
	}

	protected event OnTimeSkipButtonPressed( e : inkPointerEvent )
	{
		var data : TimeSkipPopupData;
		if( !( e.IsAction( 'click' ) ) )
		{
			return true;
		}
		SetCursorVisibility( false );
		data = new TimeSkipPopupData;
		data.notificationName = 'base\gameplay\gui\widgets\time_skip\time_skip.inkwidget';
		data.isBlocking = true;
		data.useCursor = true;
		data.queueName = 'modal_popup';
		m_timeSkipPopupToken = m_gameCtrlRef.ShowGameNotification( data );
		m_timeSkipPopupToken.RegisterListener( this, 'OnTimeSkipPopupClosed' );
		PlaySound( 'Button', 'OnPress' );
	}

	protected event OnTimeSkipPopupClosed( data : inkGameNotificationData )
	{
		var timeSkipData : TimeSkipPopupCloseData;
		timeSkipData = ( ( TimeSkipPopupCloseData )( data ) );
		m_timeSkipPopupToken = NULL;
		SetCursorVisibility( true );
		if( timeSkipData.timeChanged )
		{
			UpdateGameTime();
			PlayLibraryAnimation( 'time_changed' );
		}
	}

	private function SetCursorVisibility( visible : Bool )
	{
		var evt : inkMenuLayer_SetCursorVisibility;
		evt = new inkMenuLayer_SetCursorVisibility;
		evt.Init( visible );
		QueueEvent( evt );
	}

}

