//////////////////////////////////////////////////////////////////////////////
//
// ToolsAVP_Entity_InteractInvisiSwitch.cpp
//
// Created by CAH 26/2/09
//
// Copyright (c) 2009 Rebellion. All rights reserved.
//
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// INCLUDES

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

// PERSONAL
#include "Entity/PhysicalObject/Interact/InvisiSwitch/ToolsAVP_Entity_InteractInvisiSwitch.h"

// ASURA
#include "Entity/Asura_StaticMessage_System.h"

// AVP
#include "Entity/PhysicalObject/Interact/InvisiSwitch/AVP_ServerEntity_InteractInvisiSwitch.h"
#include "Entity/PhysicalObject/Pickup/AVP_ServerEntity_Pickup.h"

// TOOLS ASURA
#include "Load&Save/Tools_SaveAsura.h"

// TOOLS AVP
#include "Entity/Tools_MessageEditor.h"
#include "ToolsAVP_ChooseObjects.h"

#include "Entity/AVP_Entity_EventIDs.h"
#include "Entity/AVP_Messages.h"

//////////////////////////////////////////////////////////////////////////////
// STATIC AND GLOBAL DECLARATIONS

ToolsAVP_Entity_InteractInvisiSwitch* ToolsAVP_Entity_InteractInvisiSwitch::s_pxSelectedInvisiSwitch = NULL;
Asura_Hashed_List<ToolsAVP_Entity_InteractInvisiSwitch> ToolsAVP_Entity_InteractInvisiSwitch::s_xList;


//////////////////////////////////////////////////////////////////////////////
// CLASS FUNCTIONS
// ToolsAVP_Entity_InteractInvisiSwitch

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch - Constructor
// Author       : Callum Hope CAH
// Date         : 26/02/09
// Scope		: Protected
////////////////////////////////////////////////////////////////////////////////

ToolsAVP_Entity_InteractInvisiSwitch::ToolsAVP_Entity_InteractInvisiSwitch( AVP_ServerEntity_InteractInvisiSwitch* pxInteractObject )
: PARENT( pxInteractObject )
, Tools_Entity_PhysicalObject( pxInteractObject )
, m_pxOverlay(NULL)
{
	Type = TOT_Entity_InteractInvisiSwitch;
	s_xList.AddToList(this);
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch - Destructor
// Author       : Callum Hope CAH
// Date         : 26/02/09
// Scope		: Protected
////////////////////////////////////////////////////////////////////////////////

ToolsAVP_Entity_InteractInvisiSwitch::~ToolsAVP_Entity_InteractInvisiSwitch()
{
	s_xList.RemoveFromList(this);
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch::Create
// Author       : Callum Hope CAH
// Date         : 26/02/09
// Scope		: Static Public
//
// Desc			: Create overload to support tools integerated functionality, creates a server entity. 
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_InteractInvisiSwitch::Create()
{
	CreationHelper( "Invisible Switch", "InvisiSwitch", AVP_ServerEntity_InteractInvisiSwitch::CreateFromTools, Create);
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch::Create
// Author       : Callum Hope CAH
// Date         : 26/02/09
// Scope		: Static Public
//
// Desc			: Create overload to support tools integerated functionality, creates a tool entity. 
////////////////////////////////////////////////////////////////////////////////

Tools_Object* ToolsAVP_Entity_InteractInvisiSwitch::Create( Asura_Entity* pxEntity )
{
	ToolsAVP_Entity_InteractInvisiSwitch* pxObject = new ToolsAVP_Entity_InteractInvisiSwitch( AVP_ServerEntity_InteractInvisiSwitch::FindEntity( pxEntity->GetGuid() ) );
	pxObject->UpdateToolsData();
	return pxObject;
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch::CreateObjectOfThisType
// Author       : Callum Hope CAH
// Date         : 26/02/09
// Scope		: Virtual Public
//
// Desc			: Tools functionality for this entity. Creates both server and tool objects in 3D space. 
////////////////////////////////////////////////////////////////////////////////

Tools_Object* ToolsAVP_Entity_InteractInvisiSwitch::CreateObjectOfThisType() const
{
	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( "Invisible Switch", "Invisiswitch", uGuid );

	if( pxToolsData == NULL )
	{
		Asura_Assert( false, "ToolsAVP_Entity_InteractInvisiSwitch::CreateObjectOfThisType\n, no tools data was found, entity can not be created. " );
	}
	else
	{
		AVP_ServerEntity_InteractInvisiSwitch* pxServerObject = new AVP_ServerEntity_InteractInvisiSwitch( uGuid );
		pxServerObject->ToolsData = pxToolsData;
		ToolsAVP_Entity_InteractInvisiSwitch *pxToolsObject = new ToolsAVP_Entity_InteractInvisiSwitch( pxServerObject );
		Tools_Object_System::SelectObject( pxToolsObject );

		pxToolsObject->Position = *Asura_Camera::GetPosition();
		pxToolsObject->Orientation.Identity();

		Tools_SaveAsura::SetEntityModified();
		return pxToolsObject;
	}
	return NULL;
}

bool ToolsAVP_Entity_InteractInvisiSwitch::HandlesThisEvent( int iEventID ) const
{
	switch (iEventID)
	{
		case AVP_ENTITY_EVENT_MARINE_INTERACT:
		case AVP_ENTITY_EVENT_ALIEN_INTERACT:
		case AVP_ENTITY_EVENT_PREDATOR_INTERACT:
		{
			return true;
		}break;

		default:
		{
			return PARENT::HandlesThisEvent(iEventID);
		}
	}
}

bool ToolsAVP_Entity_InteractInvisiSwitch::HandlesThisMessage( int iMessageID )
{
//	switch (iMessageID)
	{
// 		case AVP_MSGID_SENTRYGUN_ENABLE:
// 		case AVP_MSGID_SENTRYGUN_DISABLE:
// 		case AVP_MSGID_SENTRYGUN_DESTROY:
// 		{
// 			return true;
// 		}break;
// 
// 		default:
		{
			return PARENT::HandlesThisMessage(iMessageID);
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch::Destroy
// Author       : Callum Hope CAH
// Date         : 26/02/09
// Scope		: Virtual Public
//
// Desc			: using the parent implementation
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_InteractInvisiSwitch::Destroy()
{
	PARENT::Destroy();
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch::OnSelection
// Author       : Callum Hope CAH
// Date         : 26/02/09
// Scope		: Virtual Public
//
// Desc			: sets this as the static pointer all of the switches hold
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_InteractInvisiSwitch::OnSelection()
{
	s_pxSelectedInvisiSwitch = this;

	PARENT::OnSelection();
}

////////////////////////////////////////////////////////////////////////////////
// Function     : ToolsAVP_Entity_InteractInvisiSwitch::OnSelection
// Author       : Callum Hope CAH
// Date         : 10/03/09
// Scope		: Virtual Public
//
// Desc			: clears the static pointer held by all the invisiSwitches. 
////////////////////////////////////////////////////////////////////////////////

void ToolsAVP_Entity_InteractInvisiSwitch::OnDeselection()
{
	s_pxSelectedInvisiSwitch = NULL;

	PARENT::OnDeselection();
}




