//////////////////////////////////////////////////////////////////////////////
//
// ToolsAVP_Entity_PhysicsObject.cpp
//
// Copyright (c) 2006 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

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

#include "Core/Asura.h"

// This file's header.
#include "Entity/PhysicalObject/PhysicsObject/ToolsAVP_Entity_PhysicsObject.h"

// Project independent.
#include "Entity/PhysicalObject/PhysicsObject/AVP_ServerEntity_PhysicsObject.h"

// G L O B A L S /////////////////////////////////////////////////////////////

static bool g_bNextObjectIsStatic;

// C L A S S   I M P L E M E N T A T I O N S /////////////////////////////////

//
// Tools_Entity_PhysicsObject
//

void Tools_Entity_PhysicsObject::Project_Create( void )
{
    ToolsAVP_Entity_PhysicsObject::Create( false );
}


void Tools_Entity_PhysicsObject::Project_CreateStatic( void )
{
    ToolsAVP_Entity_PhysicsObject::Create( true );
}

//
// ToolsAVP_Entity_PhysicsObject
//

Asura_Hashed_List<ToolsAVP_Entity_PhysicsObject> ToolsAVP_Entity_PhysicsObject::s_xList( 5 );


void ToolsAVP_Entity_PhysicsObject::Create( bool bStatic )
{
    AVP_ServerEntity_PhysicsObject::SetNewObjectShouldBeStatic( bStatic );

    CreationHelper( PARENT_ASURA::s_szLongName,
                    PARENT_ASURA::s_szShortName, 
                    AVP_ServerEntity_PhysicsObject::CreateFromTools, 
                    Create );
}


Tools_Object* ToolsAVP_Entity_PhysicsObject::Create( Asura_Entity* pxEntity )
{
    return new ToolsAVP_Entity_PhysicsObject( AVP_ServerEntity_PhysicsObject::FindEntity(pxEntity->GetGuid()) );
}


ToolsAVP_Entity_PhysicsObject::ToolsAVP_Entity_PhysicsObject( AVP_ServerEntity_PhysicsObject* pxPhysicsObject )
: Tools_Entity_PhysicalObject(pxPhysicsObject)
, PARENT(pxPhysicsObject)
{
    s_xList.AddToList( this );

    m_pxPhysicsObject = pxPhysicsObject;
}


ToolsAVP_Entity_PhysicsObject::~ToolsAVP_Entity_PhysicsObject( void )
{
    s_xList.RemoveFromList( this );
}


void ToolsAVP_Entity_PhysicsObject::Edit( void ) 
{ 
    PARENT_ASURA::Edit(); 
}


bool ToolsAVP_Entity_PhysicsObject::GetParameter( Asura_Hash_ID uParamID, Tools_Parameter* pxParam ) const
{
    return( PARENT_ASURA::GetParameter(uParamID, pxParam) || PARENT::GetParameter(uParamID, pxParam) );
}


const char* ToolsAVP_Entity_PhysicsObject::GetTypeDescription( void ) 
{ 
    return PARENT_ASURA::GetTypeDescription(); 
}

void ToolsAVP_Entity_PhysicsObject::AddOverlayControls(Asura_Overlay* pxNewOverlay, Asura_Vector_2& xOffset)
{
	PARENT::AddOverlayControls( pxNewOverlay, xOffset );
	xOffset.y += Asura_Dialog::LargeSpacing() - Asura_Dialog::DefaultSpacing();

	// Disable all controls below this point if we have a blueprint.
	const bool bGotBlueprint = ( m_pxPhysicsObject->GetBlueprintHashID() != ASURA_HASH_ID_UNSET &&
		m_pxPhysicsObject->GetBlueprintTypeHashID() != ASURA_HASH_ID_UNSET );

	const Asura_Dialog* const pxLastEnabledDialog = pxNewOverlay->m_pxDialogList;

	PARENT_ASURA::AddOverlayControls( pxNewOverlay, xOffset );

	if ( bGotBlueprint )
	{
		Asura_Dialog* pxDialogToDisable = pxNewOverlay->m_pxDialogList;
		while ( pxDialogToDisable && pxDialogToDisable != pxLastEnabledDialog )
		{
			pxDialogToDisable->SetEnabled( false );
			pxDialogToDisable = pxDialogToDisable->m_pxNextDialog;
		}
	}
}

void ToolsAVP_Entity_PhysicsObject::UpdateWhileSelected(void)
{
	PARENT_ASURA::UpdateWhileSelected();
	PARENT::UpdateWhileSelected();
}

bool ToolsAVP_Entity_PhysicsObject::HandlesThisMessage( int iMessageID )
{
	return( PARENT_ASURA::HandlesThisMessage(iMessageID) || PARENT::HandlesThisMessage(iMessageID) );
}

void ToolsAVP_Entity_PhysicsObject::PrintInfo( float& fX, float& fY )
{
    PARENT_ASURA::PrintInfo( fX, fY );
    PARENT::PrintInfo( fX, fY );
}

bool ToolsAVP_Entity_PhysicsObject::SetParameter( Asura_Hash_ID uParamID, const Tools_Parameter* pxParam )
{
    return( PARENT_ASURA::SetParameter(uParamID, pxParam) || PARENT::SetParameter(uParamID, pxParam) );
}

void ToolsAVP_Entity_PhysicsObject::UpdateToolsData()
{
	if (m_pxPhysicsObject)
	{
		SetToolsSkinAndAnim(m_pxPhysicsObject->GetSkinFileID(), m_pxPhysicsObject->GetSkinID(), m_pxPhysicsObject->GetAnimID(), m_pxPhysicsObject->GetAnimFileID());
		UpdateAnim();

		m_uPhysicalObjectFlags = m_pxPhysicsObject->GetPhysicalObjectFlags();
/*
		int iFlags = m_pxPhysicsObject->GetAnimFlags();
		bool bReversed = iFlags & AsuraAnimationFlag_Reversed;
		bool bLoop = iFlags & AsuraAnimationFlag_Loop;
		bool bUseAnimMovement = iFlags & AsuraAnimationFlag_UseMovementOffset;
*/
	}
}

bool ToolsAVP_Entity_PhysicsObject::AddSharedParamDialogToOverlay( Asura_Overlay* pxOverlay, const Asura_Vector_2& xOffset, Asura_Hash_ID uParamID )
{
	return ( PARENT_ASURA::AddSharedParamDialogToOverlay( pxOverlay, xOffset, uParamID ) ||
		PARENT::AddSharedParamDialogToOverlay( pxOverlay, xOffset, uParamID ) );
}
