#ifdef ASURA_USE_AXON
//////////////////////////////////////////////////////////////////////////////
//
// Tools_EntityNode_GS2Node.h
//
// Copyright (C) 2008 Rebellion. All Rights Reserved.
//
//////////////////////////////////////////////////////////////////////////////

// B E G I N   F I L E   W R A P P E R ///////////////////////////////////////

#ifdef ASURA_USE_PRAGMA_ONCE
#pragma once
#endif

#ifndef __TOOLS_ENTITYNODE_GS2NODE_H__
#define __TOOLS_ENTITYNODE_GS2NODE_H__ 1

// E N D   F I L E   W R A P P E R ///////////////////////////////////////////

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

// asura
#include "Core/Asura_HashedList.h"

// tools
#include "Entity/Locations/OrientedNode/Tools_EntityNode_OrientedNode.h"

// F O R W A R D   D E C L A R A T I O N S ///////////////////////////////////

class Asura_DropDown_List_Dialog;
class Asura_Overlay;
class Asura_ServerNode_GS2Node;
class Asura_Table_Dialog;
class Asura_TableCell_Dialog;
class Asura_Vector_2;
class Axon_BehaviourParams;
template< typename T > class List;
class Tools_Parameter;

//////////////////////////////////////////////////////////////////////////////
//
// Tools_EntityNode_GS2Node
//
//////////////////////////////////////////////////////////////////////////////

class Tools_EntityNode_GS2Node : public Tools_EntityNode_OrientedNode
{
	typedef Tools_EntityNode_OrientedNode PARENT;

public:
	Tools_EntityNode_GS2Node( Asura_Entity* pxEntity );
	virtual ~Tools_EntityNode_GS2Node();

	virtual const char* GetTypeDescription() { return "GS2 Node"; }
	virtual bool IsBaseOrDerivativeOf( int iToolsObjectType ) const;

	virtual const char* GetMyNamePrefix() const { return Tools_EntityNode_GS2Node::GetNamePrefix(); }

	virtual void AddOverlayControls( Asura_Overlay* pxNewOverlay, Asura_Vector_2& xOffset );
	virtual bool IsSelectable();
	virtual bool HandlesThisMessage( int iMessageID );
	virtual bool HandlesThisEvent( int iEventID ) const;
	virtual bool OwnsThisMessageBlock( unsigned short usMessageBlockID );
	virtual void Render();
	virtual void Update();
	virtual void UpdateWhileSelected();
	virtual void RefreshOverlay();
	virtual void UpdatePositionInAsuraData( bool bUpdateLinkedObjects );
	virtual bool GetParameter( Asura_Hash_ID uParamID, Tools_Parameter* pxParam ) const;
	virtual bool SetParameter( Asura_Hash_ID uParamID, const Tools_Parameter* pxParam );
	virtual void AddFilesToExportList( List< Asura_String >& xNameList ) const;
	virtual void AddFilesToExportListFromMessage( u_short usMessageID, void* pData, List< Asura_String >& xNameList ) const;
	virtual bool Verify( const bool bAutomatic );
	virtual void PrintInfo( float& fX, float& fY );

	virtual bool          CanBeCopied() const { return ( Type == TOT_Entity_GS2Node ); }
	virtual void          Copy( const Tools_Object* pxObject );
	virtual Tools_Object* CreateObjectOfThisType() const;

	Asura_Guid			GetOwnerGuid() const { return m_uOwnerGuid; }
	void				SetOwnerGuid( Asura_Guid uOwnerGuid ) { m_uOwnerGuid = uOwnerGuid; }
	const Asura_String& GetOwnerSkinName() const { return m_xOwnerSkinName; }
	void				SetOwnerSkinName( const Asura_String& xSkinName ) { m_xOwnerSkinName = xSkinName; }
	bool				PromptForOwnerSkinName();

	void UpdateBehaviourTree();

	Asura_ServerNode_GS2Node* GetGameGS2Node() const;

	virtual void StartPreview();
	virtual void StopPreview();
	bool PreviewIsOccupied() const { return m_bPreviewIsOccupied; }
	void PreviewSetIsOccupied( const bool bOccupied ) { m_bPreviewIsOccupied = bOccupied; }
	void PreviewIncPendingCount() { ++m_uPreviewPendingCount; }
	void PreviewDecPendingCount() { Asura_Assert( m_uPreviewPendingCount > 0, "Tools_EntityNode_GS2Node::PreviewDecPendingCount - pending count going negative" ); --m_uPreviewPendingCount; }
	bool PreviewHasPendingActors() const { return ( m_uPreviewPendingCount > 0 ); }

	static void TransferToolsModeData( Tools_ModeDataFile& xFile );

	static void						 Create();
	static Tools_EntityNode_GS2Node* CreateAndReturn();

	static Tools_EntityNode_GS2Node* FindEntity( const Asura_Guid uGuid ) { return s_xList.FindEntity( uGuid ); }
	static Asura_Hashed_List< Tools_EntityNode_GS2Node >* GetList() { return &s_xList; }

	static const char* GetNamePrefix() { return "GS2N_"; }

protected:
	virtual void AddPropertiesTabControls( Asura_Tabs_Dialog* pxTabsDialogue, Asura_Vector_2& xOffset );
	virtual void AddBehaviourTabControls( Asura_Tabs_Dialog* pxTabsDialogue, Asura_Vector_2& xOffset );
	virtual void AddUnderTabsControls( Asura_Overlay* pxNewOverlay, Asura_Vector_2& xOffset );

	virtual Asura_Vector_2* GetDefaultsOverlayPosition() { return &s_xDefaultsOverlayPosition; }
	virtual const char*     GetDefaultsOverlayTitle()    { return "GS2 Node Defaults"; }
	virtual u_int           GetDefaultsOverlayID()       { return 0x9d0ab8d6; } // Asura_GetHashID( "GS2 Node Defaults" )
	virtual void SetDefaultsToThis();
	virtual void AddDefaultsOverlayControls( Asura_Overlay* pxNewOverlay, Asura_Vector_2& xOffset );
	virtual void AddPropertiesDefaultControls( Asura_Overlay* pxNewOverlay, Asura_Vector_2& xOffset );
	virtual void AddBehaviourDefaultControls( Asura_Overlay* pxNewOverlay, Asura_Vector_2& xOffset );

	void AddCollisionsDialogues( Asura_Tabs_Dialog* pxTabsDialogue, Asura_Vector_2& xOffset );
	void AddFollowSurfaceDialogue( Asura_Tabs_Dialog* pxTabsDialogue, Asura_Vector_2& xOffset );
	void AddStructureTypeDialogue( Asura_Tabs_Dialog* pxTabsDialogue, Asura_Vector_2& xOffset );
	void AddLinkWeightsDialogue( Asura_Tabs_Dialog* pxTabsDialogue, Asura_Vector_2& xOffset );
	void AddLinkControls( Asura_Overlay* pxNewOverlay, Asura_Vector_2& xOffset );

	void UpdatePreview();

protected:
	Asura_Tabs_Dialog* m_pxTabsDialogue;

private:
	void CreateLinkNameList();
	void DestroyLinkNameList();

	static Asura_TableCell_Dialog* CreateWeightTableCell( Asura_Table_Dialog& xTableDialog,
														  const Asura_Vector_2& xOffset, const Asura_Vector_2& xMinCellSize,
														  const u_int uRow, const u_int uColumn, void* const pxUserData );

	static void PickStructureType( int iThis );
	static void PickBehaviourSet( int iThis );

	static void PickDefaultStructureType( int iThis );
	static void PickDefaultBehaviourSet( int iThis );

	static void CreateLinkedNode();
	static void CreateLink();

private:
	Asura_Guid   m_uOwnerGuid;
	Asura_String m_xOwnerSkinName;
	bool         m_bPreviewing;
	bool         m_bPreviewIsOccupied;
	u_int		 m_uPreviewPendingCount;
	u_int				m_uLinkNameListSize;
	char**				m_ppszLinkNameList;
	Asura_Table_Dialog* m_pxWeightTableDialogue;

	enum { MAX_NUM_BEHAVIOUR_STRINGS = 64 };
	static const char* s_aszBehaviourStringList[ MAX_NUM_BEHAVIOUR_STRINGS ];
	static int		   s_iNumListEntries;

	static Asura_Hashed_List< Tools_EntityNode_GS2Node > s_xList;

	enum Tabs { TAB_PROPERTIES, TAB_BEHAVIOUR, TAB_END_ENUM };
	static const char* s_aszTabNames[ TAB_END_ENUM ];
	static u_int	   s_uCurrentTab;

	static const u_int uCURRENT_TOOLS_DATA_VERSION = 1;
	static Asura_Vector_2 s_xDefaultsOverlayPosition;
	static bool s_bRefreshDefaultsOverlay;
	static int s_iDefaultStructureType;
	// Although this is a member of Tools_Entity_Node no classes above us need it.
	static bool s_bDefaultSmoothOverNode;
	static bool s_bDefaultFollowSurface;
	static bool s_bDefaultTestForCollisions;
	static bool s_bDefaultIgnoreCollisions;
	static int s_iDefaultBehaviourSet;
};

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

#endif //__TOOLS_ENTITYNODE_GS2NODE_H__
#endif // ASURA_USE_AXON
