class DeviceMappinsContainer extends IScriptable
{
	mutable instanceeditable var m_mappins : array< SDeviceMappinData >;
	instanceeditable var m_newNewFocusMappin : SDeviceMappinData;
	instanceeditable var m_useNewFocusMappin : Bool;
	private var m_offsetValue : Float;
	default m_offsetValue = 0.2f;

	public function Initialize()
	{
		var mappin : SDeviceMappinData;
		mappin.mappinType = T"Mappins.DeviceMappinDefinition";
		mappin.enabled = false;
		mappin.active = false;
		mappin.range = 35.0;
		if( !( HasMappin( gamedataMappinVariant.NetrunnerVariant ) ) )
		{
			mappin.mappinVariant = gamedataMappinVariant.NetrunnerVariant;
			m_mappins.PushBack( mappin );
		}
		if( !( HasMappin( gamedataMappinVariant.NetrunnerAccessPointVariant ) ) )
		{
			mappin.mappinVariant = gamedataMappinVariant.NetrunnerAccessPointVariant;
			m_mappins.PushBack( mappin );
		}
		if( !( HasMappin( gamedataMappinVariant.TechieVariant ) ) )
		{
			mappin.mappinVariant = gamedataMappinVariant.TechieVariant;
			m_mappins.PushBack( mappin );
		}
		if( !( HasMappin( gamedataMappinVariant.SoloVariant ) ) )
		{
			mappin.mappinVariant = gamedataMappinVariant.SoloVariant;
			m_mappins.PushBack( mappin );
		}
		if( m_useNewFocusMappin )
		{
			mappin.mappinVariant = m_newNewFocusMappin.mappinVariant;
			mappin.enabled = true;
			m_mappins.PushBack( mappin );
		}
	}

	public function HasNewFocusMappin() : Bool
	{
		return m_useNewFocusMappin;
	}

	private function EvaluatePositions( owner : GameObject )
	{
		var currentOffset : Vector4;
		var currentPos : Vector4;
		var rootPos : Vector4;
		var offsetValue : Float;
		var transform : WorldTransform;
		var i : Int32;
		var direction : Int32;
		direction = 0;
		rootPos = owner.GetPlaystyleMappinLocalPos();
		WorldTransform.SetPosition( transform, owner.GetWorldPosition() );
		WorldTransform.SetOrientation( transform, owner.GetWorldOrientation() );
		for( i = 0; i < m_mappins.Size(); i += 1 )
		{
			if( !( m_mappins[ i ].enabled ) )
			{
				continue;
			}
			else if( direction != 0 )
			{
				direction *= -1;
				offsetValue = m_offsetValue * ( ( Float )( direction ) );
			}
			else if( direction == 0 )
			{
				offsetValue = 0.0;
				direction = 1;
			}
			currentOffset = rootPos + m_mappins[ i ].offset;
			currentOffset.X = currentOffset.X + offsetValue;
			currentPos = WorldPosition.ToVector4( WorldTransform.TransformPoint( transform, currentOffset ) );
			m_mappins[ i ].position = currentPos;
			currentOffset = Vector4( 0.0, 0.0, 0.0, 0.0 );
			currentPos = Vector4( 0.0, 0.0, 0.0, 0.0 );
		}
	}

	private function GetNextAxis( currentAxis : EAxisType ) : EAxisType
	{
		var nextAxis : EAxisType;
		var axisValue : Int32;
		if( ( ( Int32 )( currentAxis ) ) < 3 )
		{
			axisValue += 1;
			nextAxis = ( ( EAxisType )( axisValue ) );
		}
		else
		{
			nextAxis = ( ( EAxisType )( 0 ) );
		}
		return nextAxis;
	}

	public function ShowMappins( owner : GameObject )
	{
		var i : Int32;
		var mappinData : MappinData;
		var system : MappinSystem;
		EvaluatePositions( owner );
		for( i = 0; i < m_mappins.Size(); i += 1 )
		{
			if( m_mappins[ i ].enabled && !( m_mappins[ i ].active ) )
			{
				mappinData.mappinType = m_mappins[ i ].mappinType;
				mappinData.variant = m_mappins[ i ].mappinVariant;
				mappinData.active = true;
				mappinData.debugCaption = m_mappins[ i ].caption;
				system = GameInstance.GetMappinSystem( owner.GetGame() );
				m_mappins[ i ].id = system.RegisterMappin( mappinData, m_mappins[ i ].position );
				m_mappins[ i ].active = true;
			}
		}
	}

	public function HideMappins( owner : GameObject )
	{
		var i : Int32;
		for( i = 0; i < m_mappins.Size(); i += 1 )
		{
			if( m_mappins[ i ].active )
			{
				HideSingleMappin( i, owner );
			}
		}
	}

	private function HideSingleMappin( index : Int32, owner : GameObject )
	{
		GameInstance.GetMappinSystem( owner.GetGame() ).UnregisterMappin( m_mappins[ index ].id );
		m_mappins[ index ].active = false;
	}

	private function HasMappin( mappinVariant : gamedataMappinVariant ) : Bool
	{
		var i : Int32;
		for( i = 0; i < m_mappins.Size(); i += 1 )
		{
			if( m_mappins[ i ].mappinVariant == mappinVariant )
			{
				return true;
			}
		}
		return false;
	}

	private function HasMappin( const data : ref< SDeviceMappinData > ) : Bool
	{
		var i : Int32;
		for( i = 0; i < m_mappins.Size(); i += 1 )
		{
			if( ( m_mappins[ i ].mappinVariant == data.mappinVariant && ( m_mappins[ i ].mappinType == data.mappinType ) ) && m_mappins[ i ].caption == data.caption )
			{
				return true;
			}
		}
		return false;
	}

	public function ToggleMappin( owner : GameObject, mappinVariant : gamedataMappinVariant, enable : Bool )
	{
		var i : Int32;
		for( i = 0; i < m_mappins.Size(); i += 1 )
		{
			if( m_mappins[ i ].mappinVariant == mappinVariant )
			{
				m_mappins[ i ].enabled = enable;
				if( !( enable ) )
				{
					if( m_mappins[ i ].active )
					{
						HideSingleMappin( i, owner );
					}
				}
			}
		}
	}

	public function AddMappin( const data : ref< SDeviceMappinData > )
	{
		if( !( HasMappin( data ) ) )
		{
			m_mappins.PushBack( data );
		}
	}

}

