//////////////////////////////////////////////////////////////////////////////
//
// Tools_Object_Axon_ChooseObjects.cpp
//
// Copyright (C) 2008 Rebellion. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

// I N C L U D E S ///////////////////////////////////////////////////////////

// core
#include "Core/Asura.h"

#ifdef ASURA_USE_AXON

// header
#include "Objects/Axon/Tools_Object_Axon_ChooseObjects.h"

// asura
#include "Entity/PhysicalObject/Asura_ServerEntity_PhysicalObject.h"
#include "Entity/Locations/OrientedNode/GamesceneNode/Asura_ServerNode_GS2Node.h"
#include "Entity/Locations/Spline/GamesceneSpline/Asura_ServerNode_GS2Spline.h"

// axon

//////////////////////////////////////////////////////////////////////////////
//
// Tools_Object_Axon_ChooseObjects
//
//////////////////////////////////////////////////////////////////////////////

bool Tools_ChooseObject_GS2Base::CanBeSelected( Tools_Object* pxObject )
{
	if ( pxObject )
	{
		return ( m_xGuidsToIgnore.Find( pxObject->GetGuid() ) == NULL );
	}
	else
	{
		return false;
	}
}

void Tools_ChooseObject_GS2Base::ObjectSelected( Tools_Object* pxObject )
{
	if ( SupportMultipleSelection() )
	{
		for ( CLIF< Tools_Object* > xIter( GetSelectionList() ); !xIter.done(); xIter.next() )
		{
			if ( m_puGuidToSet )
			{
				*m_puGuidToSet = xIter()->GetGuid();
			}
			if ( m_pfnOnChosenGuid )
			{
				m_pfnOnChosenGuid( xIter()->GetGuid() );
			}
			if ( m_pfnOnChosenIntGuid )
			{
				m_pfnOnChosenIntGuid( m_iUserData, xIter()->GetGuid() );
			}
			if ( m_pbChanged )
			{
				*m_pbChanged = true;
			}
		}
	}
	else
	{
		const Asura_Guid uObjectGuid = pxObject ? pxObject->GetGuid() : ASURA_GUID_UNREGISTERED;
		if ( m_puGuidToSet )
		{
			*m_puGuidToSet = uObjectGuid;
		}
		if ( m_pfnOnChosenGuid )
		{
			m_pfnOnChosenGuid( uObjectGuid );
		}
		if ( m_pfnOnChosenIntGuid )
		{
			m_pfnOnChosenIntGuid( m_iUserData, uObjectGuid );
		}
		if ( m_pbChanged )
		{
			*m_pbChanged = true;
		}
	}
}

bool Tools_ChooseObject_GS2Node::CanBeSelected( Tools_Object* pxObject )
{
	if ( !pxObject ) { return false; }
	return ( Tools_ChooseObject_GS2Base::CanBeSelected( pxObject ) && Asura_ServerNode_GS2Node::FindEntity( pxObject->GetGuid() ) );
}

bool Tools_ChooseObject_GS2AttractorTarget::CanBeSelected( Tools_Object* pxObject )
{
	if ( !pxObject ) { return false; }
	// Any physical object can be chosen.
	return ( Tools_ChooseObject_GS2Base::CanBeSelected( pxObject ) && Asura_ServerEntity_PhysicalObject::FindEntity( pxObject->GetGuid() ) );
}

bool Tools_ChooseObject_GS2Spline::CanBeSelected( Tools_Object* pxObject )
{
	if ( !pxObject ) { return false; }
	return ( Tools_ChooseObject_GS2Base::CanBeSelected( pxObject ) && Asura_ServerNode_GS2Spline::FindEntity( pxObject->GetGuid() ) );
}

//////////////////////////////////////////////////////////////////////////////
//
// 
//
//////////////////////////////////////////////////////////////////////////////

#endif // ASURA_USE_AXON
