//*******************************************************************
//
// File: Tools_BotanicalCreation_StateTables.h
//
// Created: 06 December 2006 DLH
//
// Description: 
//
//*******************************************************************

#ifndef __TOOLS_BOTANICALCREATION_STATETABLES_H__
#define __TOOLS_BOTANICALCREATION_STATETABLES_H__

// other libraries

#include "Botanicals/Asura_Botanical_Game_Render_Constants.h"

#if defined( ASURA_BOTANICAL_SUPPORT_STATES) && 1 == ASURA_BOTANICAL_SUPPORT_STATES

// internal dependencies
#include "Interface/Asura_Overlay.h"
#include "Misc/Tools_DynamicArray.h"
#include "Mesh/Asura_CollisionMesh.h"

// forward declarations
class Asura_BotanicalShape;
class Asura_DropDown_List_Dialog;
class Asura_Function_Dialog;
class Asura_List_Dialog;
class Asura_Numerical_Dialog;
class Asura_Tickbox_Dialog;

class Tools_BotanicalShape;
class Tools_BotanicalSection;
class Tools_BotanicalVersion;
class Tools_Botanical_StateTable1D;
class Tools_Botanical_StateTable1D_Section;
class Tools_Botanical_StateTable1D_Section_VersionRange;

//*******************************************************************
// Constants
//*******************************************************************


//*******************************************************************
// Class Definitions
//*******************************************************************

class Asura_Overlay_Botanical_State_Tables : public Asura_Overlay
{
public:
	Asura_Overlay_Botanical_State_Tables( const char* pszOverlayName, const bool bAlwaysOnTop, Asura_Vector_2* pxPosition);
	virtual ~Asura_Overlay_Botanical_State_Tables();

	void Update();

	bool CreateControls();

private:
	// Section

	int GetThisAsInt() { return( reinterpret_cast< int>( this));}
	static Asura_Overlay_Botanical_State_Tables* GetIntAsClass( const int ipxClass) { return( reinterpret_cast< Asura_Overlay_Botanical_State_Tables*>( ipxClass));}

	// State
	Asura_Dialog* CreateStateDropDown( Asura_Vector_2& xOffset);

	void UpdateStateDropDown();

	void CreateStateDropDownNameArray();
	void DeleteStateDropDownNameArray();
	void CreateState();
	void DeleteState();
	Asura_String CreateStateUniqueName();
	void SetupStatePointerFromSelection();
	void ChangeState();

	static void AddStateButton( int ipxData);
	static void DeleteStateButton( int ipxData);
	static void RenameStateButton( int ipxData);
	static void SelectionChangedStateDropDown( int ipxData);

	// State Section
	Asura_Dialog* CreateStateSectionList( Asura_Vector_2& xOffset);

	void UpdateStateSectionList();

	void CreateStateSectionListNameArray();
	void DeleteStateSectionListNameArray();
	bool CreateStateSection();
	bool CreateStateSection_GetName( Asura_String& xSectionName);
	void DeleteStateSection();
	void SetupStateSectionPointerFromSelection();
	void ChangeStateSection();

	static void AddStateSectionButton( int ipxData);
	static void DeleteStateSectionButton( int ipxData);
	static void SelectionChangedStateSectionList( int ipxData);

	// State Section Version
	Asura_Dialog* CreateStateSectionVersionList( Asura_Vector_2& xOffset);
	Asura_Dialog* CreateStateSectionVersionStart( Asura_Vector_2& xOffset);
	Asura_Dialog* CreateStateSectionVersionStop( Asura_Vector_2& xOffset);

	void UpdateStateSectionVersionList();

	void CreateStateSectionVersionListNameArray();
	void DeleteStateSectionVersionListNameArray();
	void CreateStateSectionVersion();
	void DeleteStateSectionVersion();
	void SetupStateSectionVersionPointerFromSelection();
	void ChangeStateSectionVersion();
	void SetStateSectionVersionData();

	static void AddStateSectionVersionButton( int ipxData);
	static void DeleteStateSectionVersionButton( int ipxData);
	static void SelectionChangedStateSectionVersionList( int ipxData);
	static void SetStateSectionVersionCollMesh( int ipxData);

	// Section
	Asura_Dialog* CreateSectionDropDown( Asura_Vector_2& xOffset);

	void UpdateSectionVersionList();

	void CreateSectionDropDownNameArray();
	void DeleteSectionDropDownNameArray();
	void SetupSectionPointerFromSelection();
	void ChangeSection();

	static void SelectionChangedSectionDropDown( int ipxData);

	// Section Version Add DropDown
	Asura_Dialog* CreateSectionVersionDropDown( Asura_Vector_2& xOffset);

	void CreateSectionVersionDropDownNameArray();
	void DeleteSectionVersionDropDownNameArray();
	void SetSectionVersionSelection();
	//	void CreateState();
	//	void DeleteState();
	//	Asura_String CreateStateUniqueName();
	//	void SetupStatePointerFromSelection();
	void ChangeSectionVersion();

	static void SelectionChangedSectionVersionDropDown( int ipxData);

	// Project specific functions...
	void 	Project_CreateVersionOverlay(Asura_Vector_2& xOffset, float& xMaxColumnWidth);


public:
	Tools_Botanical_StateTable1D* GetCurrentStateTable()	   {return m_pxStateTable;};
	int							  GetSectionListSelectionIdx() {return m_iStateSectionListNameSelected;}
	int							  GetVersionListSelectionIdx() {return m_iStateSectionVersionListNameSelected;}

	Asura_BotanicalShape* m_pxAsuraShape;
	Tools_BotanicalShape* m_pxToolShape;
	Tools_BotanicalSection* m_pxToolShapeSection;

	Tools_Botanical_StateTable1D* m_pxStateTable;
	Tools_Botanical_StateTable1D_Section* m_pxStateTableSection;
	Tools_Botanical_StateTable1D_Section_VersionRange* m_pxStateTableSectionVersion;

	bool m_bDataChanged;

	// States
	//Asura_DropDown_List_Dialog* m_pxState_DropDown;
	Asura_List_Dialog* m_pxState_List;

	int m_iStateDropDownNameCount;
	int m_iStateDropDownNameSelected;
	Tools_DynamicArray< char*> m_xArray_pszStateDropDownNames;

	// Sections
#if 0
	Asura_DropDown_List_Dialog* m_pxSection_DropDown;

	int m_iSectionDropDownNameCount;
	int m_iSectionDropDownNameSelected;
	Tools_DynamicArray< char*> m_xArray_pszSectionDropDownNames;
#endif

	// State Sections
	Asura_List_Dialog* m_pxStateSection_List;

	int m_iStateSectionListNameCount;
	int m_iStateSectionListNameSelected;
	Tools_DynamicArray< char*> m_xArray_pszStateSectionListNames;

	// State Sections Version
	Asura_List_Dialog* m_pxStateSectionVersion_List;
	Asura_Function_Dialog* m_pxStateSectionVersion_Add;
	Asura_Function_Dialog* m_pxStateSectionVersion_Delete;
	Asura_Numerical_Dialog* m_pxStateSectionVersion_Start;
	Asura_Numerical_Dialog* m_pxStateSectionVersion_Stop;
	Asura_Function_Dialog*  m_pxStateSectionVersion_SetCollisionMesh;
	Asura_Numerical_Dialog* m_pxStateSectionVersion_CollisionMeshDensity;
	Asura_Tickbox_Dialog*   m_pxStateSectionVersion_CollisionUseBoundingBox;

	int m_iStateSectionVersionListNameCount;
	int m_iStateSectionVersionListNameSelected;
	Tools_DynamicArray< char*> m_xArray_pszStateSectionVersionListNames;

	float m_fVersionStart;
	float m_fVersionStop;
	float m_fVersionMin;
	float m_fVersionMax;
	u_int m_uProjectFlags;

	bool		  m_bVersionCollisionUseBoundingBox;
	float		  m_fVersionCollisionMeshDensity;
	Asura_Hash_ID m_xVersionCollisionMeshHash;
	Asura_String  m_xVersionCollisionMeshName;

	Asura_DropDown_List_Dialog* m_pxSectionVersion_DropDown;
	int m_iSectionVersionDropDownNameCount;
	int m_iSectionVersionDropDownNameSelected;
	Tools_DynamicArray< char*> m_xArray_pszSectionVersionDropDownNames;

};


class Tools_BotanicalCreation_StateTables
{
public:
	static void Reset();				// Call this at startup, and when the number of loaded elements/lods changes
	static void CreateOverlay();
	static void CloseOverlay();
	static void Update();
	static void Render();

private:

	static Asura_Vector_2 s_xOverlayPosition;
	static Asura_Overlay_Botanical_State_Tables* s_pxOverlay;
	

public:
	// Control over which elements are rendered. Public so they can
	// be attached to tools UI elements
	static bool s_bShowCurrentVersionOnly;
	static bool s_bPreviewStateValue;
	static bool s_bShowFoliageCollisionMeshes;
	static bool s_bShowCurrentVersionOnlyChanged;
	static bool s_bPreviewStateValueChanged;
	static bool s_bShowFoliageCollisionMeshesChanged;
	static int  s_iStateValueToPreview;

	// This is called to determine which sections/versions should be visible in the tools preview
	static bool IsSectionVersionVisible( const Tools_BotanicalSection* pxToolSection, const Tools_BotanicalVersion* pxToolVersion);

	static bool IsSectionVersionVisibleFiltered( void);
	static void ClearSectionVersionVisibleFilters( void);

	static const Asura_CollisionMesh *GetVisibleSectionVersionCollisionMesh( const Tools_BotanicalSection* pxToolSection, const Tools_BotanicalVersion* pxToolVersion);

#if 0
	static bool s_bOverlayOpen;


	static bool s_bEnableBasicInteractive;
	static float s_fMass;
	static float s_fDrag;
	static float s_fSpringStrength;
	static float s_fSpringLength;
	static float s_fBoneWeightGamma;
	static Asura_Vector_3 s_xPositionBone0;
	static Asura_Vector_3 s_xPositionBone1;
	static Asura_Mesh* s_pxBoneMesh;
#endif
};

//*******************************************************************
// Inline Function Definitions
//*******************************************************************


//*******************************************************************
//
// (c) 2006 Rebellion
//
// Warning: This computer program is protected by copyright law and 
// international treaties. Unauthorized reproduction or distribution
// of this program, or any portion of it, may result in severe civil and
// criminal penalties, and will be prosecuted to the maximum extent 
// possible under the law.
//
//*******************************************************************

#endif // ASURA_BOTANICAL_SUPPORT_STATES

#endif // __TOOLS_BOTANICALCREATION_STATETABLES_H__
