class sampleStyleManagerGameController extends inkGameController
{
	editable var m_stylePath1 : ResRef;
	editable var m_stylePath2 : ResRef;
	editable var m_content : inkWidgetRef;

	protected event OnInitialize()
	{
		GetController( inkWidgetPath.Build( 'stateContainer', 'state1Button' ) ).RegisterToCallback( 'OnRelease', this, 'OnState1' );
		GetController( inkWidgetPath.Build( 'stateContainer', 'state2Button' ) ).RegisterToCallback( 'OnRelease', this, 'OnState2' );
		GetController( inkWidgetPath.Build( 'stateContainer', 'state3Button' ) ).RegisterToCallback( 'OnRelease', this, 'OnState3' );
		GetController( inkWidgetPath.Build( 'styleContainer', 'style1Button' ) ).RegisterToCallback( 'OnRelease', this, 'OnStyle1' );
		GetController( inkWidgetPath.Build( 'styleContainer', 'style2Button' ) ).RegisterToCallback( 'OnRelease', this, 'OnStyle2' );
	}

	protected event OnState1( e : inkPointerEvent )
	{
		inkWidgetRef.SetState( m_content, 'Default' );
	}

	protected event OnState2( e : inkPointerEvent )
	{
		inkWidgetRef.SetState( m_content, 'Green' );
	}

	protected event OnState3( e : inkPointerEvent )
	{
		inkWidgetRef.SetState( m_content, 'Blue' );
	}

	protected event OnStyle1( e : inkPointerEvent )
	{
		inkWidgetRef.SetStyle( m_content, m_stylePath1 );
	}

	protected event OnStyle2( e : inkPointerEvent )
	{
		inkWidgetRef.SetStyle( m_content, m_stylePath2 );
	}

}

class sampleUIPathAndReferenceGameController extends inkGameController
{
	editable var m_textWidget : inkTextRef;
	editable var m_imageWidgetPath : inkWidgetPath;
	private var m_imageWidget : weak< inkImage >;
	private var m_panelWidget : weak< inkBasePanel >;

	protected event OnInitialize()
	{
		if( inkTextRef.IsValid( m_textWidget ) )
		{
			inkTextRef.SetText( m_textWidget, "Hello World!" );
		}
		m_imageWidget = ( ( inkImage )( GetWidget( m_imageWidgetPath ) ) );
		m_panelWidget = ( ( inkBasePanel )( GetWidget( inkWidgetPath.Build( 'container', 'pane;' ) ) ) );
	}

}

class sampleUIStatusWidgetLogicController extends inkLogicController
{
	editable var enableStateColor : Color;
	editable var disableStateColor : Color;
	private var m_textWidget : weak< inkText >;
	private var m_iconWidget : weak< inkRectangle >;

	protected event OnInitialize()
	{
		m_textWidget = ( ( inkText )( GetWidget( 'statusText' ) ) );
		m_iconWidget = ( ( inkRectangle )( GetWidget( 'statusIcon' ) ) );
		SetStatus( false );
	}

	public function SetStatus( on : Bool )
	{
		var statusText : String;
		var statusColor : Color;
		if( on )
		{
			statusText = "ON";
			statusColor = enableStateColor;
		}
		else
		{
			statusText = "OFF";
			statusColor = disableStateColor;
		}
		m_textWidget.SetText( statusText );
		m_iconWidget.SetTintColor( statusColor );
	}

}

class sampleUIInteractionWidgetLogicController extends inkLogicController
{
	editable var enableStateColor : Color;
	editable var disableStateColor : Color;
	private var m_textWidget : weak< inkText >;

	protected event OnInitialize()
	{
		m_textWidget = ( ( inkText )( GetWidget( 'valueText' ) ) );
	}

	public function SetIsInteracting( interacting : Bool )
	{
		var displayText : String;
		var displayColor : Color;
		if( interacting )
		{
			displayText = "Yes";
			displayColor = enableStateColor;
		}
		else
		{
			displayText = "No";
			displayColor = disableStateColor;
		}
		m_textWidget.SetText( displayText );
		m_textWidget.SetTintColor( displayColor );
	}

}

class sampleStylesGameController extends inkGameController
{
	private var m_stateText : weak< inkText >;
	private var m_button1Controller : weak< inkButtonController >;
	private var m_button2Controller : weak< inkButtonController >;

	protected event OnInitialize()
	{
		m_stateText = ( ( inkText )( GetWidget( 'StateTransitionText' ) ) );
		m_button1Controller = ( ( inkButtonController )( GetController( 'Button1' ) ) );
		m_button1Controller.RegisterToCallback( 'OnButtonStateChanged', this, 'OnButton1StateChanged' );
		m_button2Controller = ( ( inkButtonController )( GetController( 'Button2' ) ) );
		m_button2Controller.RegisterToCallback( 'OnRelease', this, 'OnButton2Pressed' );
	}

	protected event OnButton1StateChanged( controller : weak< inkButtonController >, oldState : inkEButtonState, newState : inkEButtonState )
	{
		m_stateText.SetText( ( ButtonStateToString( oldState ) + " >> " ) + ButtonStateToString( newState ) );
	}

	protected event OnButton2Pressed( e : inkPointerEvent )
	{
		var isEnabled : Bool;
		if( e.IsAction( 'click' ) )
		{
			isEnabled = m_button1Controller.GetEnabled();
			m_button1Controller.SetEnabled( !( isEnabled ) );
		}
	}

	private function ButtonStateToString( state : inkEButtonState ) : String
	{
		switch( state )
		{
			case inkEButtonState.Normal:
				return "Normal";
			case inkEButtonState.Press:
				return "Press";
			case inkEButtonState.Hover:
				return "Hover";
			case inkEButtonState.Disabled:
				return "Disabled";
		}
		return "";
	}

}

class sampleScreenProjectionGameController extends inkProjectedHUDGameController
{
	private var m_OnTargetHitCallback : CallbackHandle;

	protected event OnInitialize()
	{
		var blackboardSystem : BlackboardSystem;
		var blackboard : IBlackboard;
		blackboardSystem = GetBlackboardSystem();
		blackboard = blackboardSystem.Get( GetAllBlackboardDefs().UI_ActiveWeaponData );
		m_OnTargetHitCallback = blackboard.RegisterListenerVariant( GetAllBlackboardDefs().UI_ActiveWeaponData.TargetHitEvent, this, 'OnTargetHit' );
	}

	protected event OnTargetHit( value : Variant )
	{
		var targetHitData : gameTargetHitEvent;
		var targetController : weak< sampleScreenProjectionLogicController >;
		var screenProjectionData : inkScreenProjectionData;
		var projection : inkScreenProjection;
		targetHitData = ( ( gameTargetHitEvent )value );
		targetController = ( ( sampleScreenProjectionLogicController )( SpawnFromLocal( GetRootWidget(), 'Target' ).GetController() ) );
		screenProjectionData.entity = targetHitData.target;
		screenProjectionData.slotComponentName = 'Item_Attachment_Slot';
		screenProjectionData.slotName = 'Head';
		screenProjectionData.fixedWorldOffset = Vector4( 0.0, 0.0, 0.5, 0.0 );
		screenProjectionData.userData = targetController;
		projection = RegisterScreenProjection( screenProjectionData );
		targetController.SetProjection( projection );
		targetController.RegisterToCallback( 'OnReadyToRemove', this, 'OnRemoveTarget' );
	}

	protected event OnScreenProjectionUpdate( projections : gameuiScreenProjectionsData )
	{
		var i, count : Int32;
		var projection : inkScreenProjection;
		var controller : sampleScreenProjectionLogicController;
		count = projections.data.Size();
		for( i = 0; i < count; i += 1 )
		{
			projection = projections.data[ i ];
			controller = ( ( sampleScreenProjectionLogicController )( projection.GetUserData() ) );
			controller.UpdatewidgetPosition( projection );
		}
	}

	protected event OnRemoveTarget( targetWidget : weak< inkWidget > )
	{
		var rootWidget : weak< inkCompoundWidget >;
		var targetController : sampleScreenProjectionLogicController;
		targetController = ( ( sampleScreenProjectionLogicController )( targetWidget.GetController() ) );
		UnregisterScreenProjection( targetController.GetProjection() );
		rootWidget = ( ( inkCompoundWidget )( GetRootWidget() ) );
		rootWidget.RemoveChild( targetWidget );
	}

}

class sampleScreenProjectionLogicController extends inkLogicController
{
	private var m_widgetPos : weak< inkText >;
	private var m_worldPos : weak< inkText >;
	private var m_projection : inkScreenProjection;

	protected event OnInitialize()
	{
		GetRootWidget().SetAnchorPoint( Vector2( 0.5, 0.5 ) );
		m_widgetPos = ( ( inkText )( GetWidget( 'widgetPos' ) ) );
		m_worldPos = ( ( inkText )( GetWidget( 'worldPos' ) ) );
		PlayAnimation();
	}

	public function GetProjection() : inkScreenProjection
	{
		return m_projection;
	}

	public function SetProjection( projection : inkScreenProjection )
	{
		m_projection = projection;
	}

	public function UpdatewidgetPosition( projection : inkScreenProjection )
	{
		var rootWidget : weak< inkWidget >;
		var gameEntity : GameEntity;
		var widgetPosition : Vector2;
		var worldPosition : Vector4;
		var margin : inkMargin;
		rootWidget = GetRootWidget();
		gameEntity = ( ( GameEntity )( projection.GetEntity() ) );
		widgetPosition = projection.currentPosition;
		worldPosition = gameEntity.GetWorldPosition() + projection.GetFixedWorldOffset();
		margin.left = widgetPosition.X;
		margin.top = widgetPosition.Y;
		rootWidget.SetMargin( margin );
		m_widgetPos.SetText( ( ( ( "Screen: (" + widgetPosition.X ) + "," ) + widgetPosition.Y ) + ")" );
		m_worldPos.SetText( ( ( ( ( ( "World: (" + worldPosition.X ) + "," ) + worldPosition.Y ) + "," ) + worldPosition.Z ) + ")" );
		rootWidget.SetVisible( projection.IsInScreen() );
	}

	private function PlayAnimation()
	{
		var anim : inkAnimDef;
		var animProxy : inkAnimProxy;
		var alphaInterpolator : inkAnimTransparency;
		anim = new inkAnimDef;
		alphaInterpolator = new inkAnimTransparency;
		alphaInterpolator.SetStartTransparency( 1.0 );
		alphaInterpolator.SetEndTransparency( 0.0 );
		alphaInterpolator.SetDuration( 3.0 );
		alphaInterpolator.SetType( inkanimInterpolationType.Linear );
		alphaInterpolator.SetMode( inkanimInterpolationMode.EasyIn );
		anim.AddInterpolator( alphaInterpolator );
		animProxy = GetRootWidget().PlayAnimation( anim );
		animProxy.RegisterToCallback( inkanimEventType.OnFinish, this, 'OnAnimFinished' );
	}

	protected event OnAnimFinished( proxy : inkAnimProxy )
	{
		CallCustomCallback( 'OnReadyToRemove' );
	}

}

