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

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

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

// header
#include "Entity/Locations/Spline/GamesceneSpline/ToolsAVP_Node_GS2Spline.h"

// asura

// axon
#include "Behaviour/BehaviourTypes/Axon_Behaviour_Types.h"

// avp
#include "Entity/Locations/OrientedNode/GamesceneNode/AVP_ServerNode_GS2Node.h"
#include "Entity/Locations/Spline/GamesceneSpline/AVP_ServerNode_GS2Spline.h"

// tools
#include "Entity/Locations/OrientedNode/GamesceneNode/Tools_EntityNode_GS2Node.h"
#include "Load&Save/Tools_SaveAsura.h"
#include "Misc/Tools_Timed_Messages.h"
#include "Objects/ToolsAVP_Object_Type.h"
#include "Objects/Axon/Tools_Object_Axon_Interface.h"

//////////////////////////////////////////////////////////////////////////////
//
// ToolsAVP_Node_GS2Spline
//
//////////////////////////////////////////////////////////////////////////////

ToolsAVP_Node_GS2Spline::ToolsAVP_Node_GS2Spline( Asura_Entity* pxEntity )
: PARENT( pxEntity )
{
	Type = TOT_Entity_AVPGS2Spline;
}

bool ToolsAVP_Node_GS2Spline::IsBaseOrDerivativeOf( int iToolsObjectType ) const
{
	if ( iToolsObjectType == TOT_Entity_AVPGS2Spline )
	{
		return true;
	}
	else
	{
		return PARENT::IsBaseOrDerivativeOf( iToolsObjectType );
	}
}

ToolsAVP_Node_GS2Spline* ToolsAVP_Node_GS2Spline::Create()
{
	if ( Tools_Object_System::SelectedObjectList.size() != 2 ) { return NULL; }

	const Asura_Guid uSourceGuid = Tools_Object_System::SelectedObjectList.first_entry()->GetGuid();
	const Asura_Guid uTargetGuid = Tools_Object_System::SelectedObjectList.last_entry()->GetGuid();

	Asura_ServerNode_GS2Node* pxSourceNode = Asura_ServerNode_GS2Node::FindEntity( uSourceGuid );
	const Asura_ServerNode_GS2Node* pxTargetNode = Asura_ServerNode_GS2Node::FindEntity( uTargetGuid );
	if ( !pxSourceNode || !pxTargetNode ) { return NULL; }

	// Create the game object.
	// Get a new GUID
	const Asura_Guid uGuid = Asura_Entity_System::GetCreatedByToolsGuid();

	// Set up tools data and auto-create a unique name (prompt for new name if there is a clash).
	Tools_Entity_Data* pxToolsData = CreateToolsDataWithDefaultName( "AVP GS2 Spline", "AVP GS2 Spline", uGuid );
	if ( !pxToolsData ) { return NULL; }

	// Create the game specfic server object and set its data.
	AVP_ServerNode_GS2Spline* pxGameSpline = new AVP_ServerNode_GS2Spline( uGuid );
	if ( !pxGameSpline ) { return NULL; }
	pxGameSpline->ToolsData = pxToolsData;

	Asura_Vector_3 xPosition;
	GetSplineRenderPosition( xPosition, uSourceGuid, uTargetGuid );
	pxGameSpline->SetPosition( xPosition );
	pxGameSpline->SetSourceGuid( uSourceGuid );
	pxGameSpline->SetTargetGuid( uTargetGuid );
	pxGameSpline->CreateBasePoints();
	pxSourceNode->AddNewSpline( pxGameSpline->GetGuid() );

	// Create the tools object.
	ToolsAVP_Node_GS2Spline* pxToolsSpline = new ToolsAVP_Node_GS2Spline( pxGameSpline );
	if ( !pxToolsSpline ) { return NULL; }

	pxToolsSpline->Position = pxGameSpline->GetPosition();
	pxToolsSpline->SetThisToDefaults();

	Tools_Object_System::SelectObject( pxToolsSpline );

	Tools_Timed_Message_System::AddMessage( Tools_Timed_Message_System::COLOUR_DEFAULT, "Created new AVP GS2 spline." );
	Tools_SaveAsura::SetEntityModified();

	return pxToolsSpline;
}

ToolsAVP_Node_GS2Spline* ToolsAVP_Node_GS2Spline::Create( Asura_Entity* pxEntity )
{
	return new ToolsAVP_Node_GS2Spline( pxEntity );
}

TOOLS_DECLARE_SHARED_PARAM( bool,         0xb70276b9, AVPGS2Spline_IntegrateWithNavData );	// Asura_GetHashID( "AVPGS2Spline_IntegrateWithNavData" )
TOOLS_DECLARE_SHARED_PARAM( bool,         0xe3af3f3b, AVPGS2Spline_LeaveOnThreatInfo );		// Asura_GetHashID( "AVPGS2Spline_LeaveOnThreatInfo" )

void ToolsAVP_Node_GS2Spline::AddPropertiesTabControls( Asura_Tabs_Dialog* pxTabsDialogue, Asura_Vector_2& xOffset )
{
	PARENT::AddPropertiesTabControls( pxTabsDialogue, xOffset );

	Asura_Dialog* pxNewDialog;

	pxNewDialog = new Asura_SharedTickbox_Dialog( "Integrate With Nav Data", xOffset, &g_xParam_AVPGS2Spline_IntegrateWithNavData );
	pxNewDialog->SetHelpText( "Determines whether this spline should integrate into the navigation data." );
	pxTabsDialogue->AddDialog( pxNewDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();

	pxNewDialog = new Asura_SharedTickbox_Dialog( "Leave Gamescene on Threat Information", xOffset, &g_xParam_AVPGS2Spline_LeaveOnThreatInfo );
	pxNewDialog->SetHelpText( "If the actor gains threat or alert knowledge and this is selected the actor will leave gamescene." );
	pxTabsDialogue->AddDialog( pxNewDialog );
	xOffset.y += Asura_Dialog::DefaultSpacing();
}

AVP_ServerNode_GS2Spline* ToolsAVP_Node_GS2Spline::GetAVPGameSpline() const
{
	return static_cast< AVP_ServerNode_GS2Spline* >( Entity );
}

bool ToolsAVP_Node_GS2Spline::GetParameter( Asura_Hash_ID uParamID, Tools_Parameter* pxParam ) const
{
	switch ( uParamID )
	{
		case g_uHash_AVPGS2Spline_IntegrateWithNavData:
		{
			pxParam->SetBool( GetAVPGameSpline()->m_bIntegrateWithNavData );
			return true;
		}

		case g_uHash_AVPGS2Spline_LeaveOnThreatInfo:
		{
			pxParam->SetBool( GetAVPGameSpline()->m_bLeaveGamesceneOnKnowledge );
			return true;
		}

		default:
		{
			return PARENT::GetParameter( uParamID, pxParam );
		}
	}
}

bool ToolsAVP_Node_GS2Spline::SetParameter( Asura_Hash_ID uParamID, const Tools_Parameter* pxParam )
{
	switch ( uParamID )
	{
		case g_uHash_AVPGS2Spline_IntegrateWithNavData:
		{
			GetAVPGameSpline()->m_bIntegrateWithNavData = pxParam->GetBool();
			Tools_SaveAsura::SetEntityModified();
			return true;
		}

		case g_uHash_AVPGS2Spline_LeaveOnThreatInfo:
		{
			GetAVPGameSpline()->m_bLeaveGamesceneOnKnowledge = pxParam->GetBool();
			Tools_SaveAsura::SetEntityModified();
			return true;
		}

		default:
		{
			return PARENT::SetParameter( uParamID, pxParam );
		}
	}
}

void ToolsAVP_Node_GS2Spline::Copy( const Tools_Object* pxObject )
{
	// Copy parent data.
	PARENT::Copy( pxObject );

	// Copy our data.
	const ToolsAVP_Node_GS2Spline* pxFromObject = static_cast< const ToolsAVP_Node_GS2Spline* >( pxObject );

	// Copy the engine entity's data across.
	AVP_ServerNode_GS2Spline* pxToEntity   = static_cast< AVP_ServerNode_GS2Spline* >( Entity );
	AVP_ServerNode_GS2Spline* pxFromEntity = static_cast< AVP_ServerNode_GS2Spline* >( pxFromObject->Entity );

	pxToEntity->m_bIntegrateWithNavData = pxFromEntity->m_bIntegrateWithNavData;
	pxToEntity->m_bLeaveGamesceneOnKnowledge = pxFromEntity->m_bLeaveGamesceneOnKnowledge;
}

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