// Tools_Entity_DialogueController.h
// Thomas Young - 17.11.08
// Copyright (C) 2008 Rebellion, All Rights Reserved.

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

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_ENTITY_DIALOGUECONTROLLER_H__
#define __TOOLS_ENTITY_DIALOGUECONTROLLER_H__

#ifdef ASURA_USE_DIALOGUE_SYSTEM

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

#include "Entity/Tools_Entity_Activatable_Object.h"
#include "Sound/Asura_Dialogue.h"

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

class Asura_Dialogue_CharacterMapping;
class Asura_ServerEntity_DialogueController;

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

// ___________________________ Tools_ChooseObject_CharacterMap_Controller _______________________________________

class Tools_Entity_DialogueController : public Tools_Entity_Activatable_Object
{
	friend class Tools_ChooseObject_CharacterMap_Controller;

	public :
		
		Tools_Entity_DialogueController		( Asura_Entity* pxEntity );
		~Tools_Entity_DialogueController	( );
		
		//virtual function overides

		virtual const char*		GetTypeDescription			( )			{ return "Dialogue Controller"; }
		virtual bool			CanBeCopied					( ) const	{ return Type == TOT_Entity_DialogueController; }

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

		virtual void			AddOverlayControls			( class Asura_Overlay* pxOverlay, class Asura_Vector_2& xOffset );
		virtual void			Copy						( const Tools_Object* pxObject );
		virtual Tools_Object*	CreateObjectOfThisType		( ) const;
		virtual void			UpdateOverlayControls		( class Asura_Overlay* pxOverlay );
		virtual void			Destroy						( );
		virtual bool			HandlesThisMessage			( int iMessageID );
		virtual bool			HandlesThisEvent			( int iEventID ) const;
        virtual void			AddFilesToExportList		( List<Asura_String>& xNameList ) const;
		virtual void			UpdateWhileSelected			( );
		virtual void			PrintInfo					( float& fX,float& fY );
		virtual bool			OwnsThisMessageBlock		( unsigned short usMessageBlockID );
		virtual bool			GetEventDescForMessageBlock	( unsigned short usMessageBlockID,Asura_String& xOutputDesc );
		virtual void			OnSelection					( );
		virtual void			OnDeselection				( );
		virtual void			UpdateCharacterMappings		( );

		// Static functions

		static void								Create	( );
		static Tools_Entity_DialogueController*	Create	( bool bGenerateName );


		static void AddOverlayControls_ToggleLine	(Asura_StaticMessage* pxMessage, Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset);
		static void AddOverlayControls_Interrupt	(Asura_StaticMessage* pxMessage, Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset);
		static void AddOverlayControls_TriggerLine	(Asura_StaticMessage* pxMessage, Asura_Overlay* pxOverlay, Asura_Vector_2& xOffset);

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

	private :

		// Callbacks for dialog controls

		static	void _SelectEvent		()				{ s_pxThis->SelectEvent ();			}
				void  SelectEvent		();
		
		static	void _ViewEvent			()				{ s_pxThis->ViewEvent	();			}
				void  ViewEvent			();

		static	void _SelectLine		( int iLine )	{ s_pxThis->SelectLine	( iLine );	}
				void  SelectLine		( int iLine );

		static	void _EditStartMsgs		( int iLine )	{ s_pxThis->EditStartMsgs( iLine ); }
				void  EditStartMsgs 	( int iLine );

		static	void _EditEndMsgs		( int iLine )	{ s_pxThis->EditEndMsgs( iLine );	}
				void  EditEndMsgs		( int iLine );

		static	void _DeleteLine		( int iLine )	{ s_pxThis->DeleteLine( iLine );	}
				void  DeleteLine		( int iLine );

		static	void _MoveLineUp		( int iLine )	{ s_pxThis->MoveLineUp( iLine );	}
				void  MoveLineUp		( int iLine );

		static	void _MoveLineDown		( int iLine )	{ s_pxThis->MoveLineDown( iLine );	}
				void  MoveLineDown		( int iLine );

		static	void _AddLine			( )				{ s_pxThis->AddLine	( );			}
				void  AddLine			( );

		static	void _EditCharMap		( int iIgnore )	{ s_pxThis->EditCharMap( );			}
				void  EditCharMap		( );

		static	void _ClearCharMap		( )				{ s_pxThis->ClearCharMap( );		}
				void  ClearCharMap		( );

		static	void _ClickedRandDelay	( )				{ s_pxThis->ClickedRandDelay( );	}
				void  ClickedRandDelay	( );

		// Other functions

		void				EditCharacterMap_GuidSelected	( Asura_Guid uGuid );

		void				UpdateCharacterMapStrings		( );
		void				DeleteCharacterMapStrings		( );
	
		static Asura_Guid	GetDefaultCharacterMapping		( Asura_Hash_ID uCharacterHash );
		
		static void			AddToRecentCharacterMappings	( const Asura_Dialogue_CharacterMapping& xMapping );

		void				StoreAnimationData				( const int iLine, Asura_Dialog* pxDialog );
		void				ClearAnimationData				( );

		// Enumerations

		enum ANIMATION_TYPE
		{
			ANIMATION_TYPE_NONE,
			ANIMATION_TYPE_REMOVE,
			ANIMATION_TYPE_MOVE_UP,
			ANIMATION_TYPE_MOVE_DOWN
		};

		// Structs

		class Animated_Line_Entry
		{
			public:

				Asura_Dialog*	m_pxDialog;
				Asura_Vector_2	m_xOrigin;
				Asura_Vector_2	m_xDestination;
		};
		
		// Variables

		int				m_iSelectedCharacter;
		int				m_iNumCharacterMapStrings;
		char**			m_pszCharacterMapStrings;

		u_int			m_uCharacterMappingValidity;

		static List<Asura_Dialogue_CharacterMapping> s_xRecentCharacterMappings;

		static Tools_Entity_DialogueController* s_pxThis;

		ANIMATION_TYPE						m_eAnimation;
		int									m_iAnimationLine;
		float								m_fAnimationTimer;
		Asura_List<Animated_Line_Entry>		m_xAnimationList;
		Asura_Overlay*						m_pxOverlay;
		Asura_Numerical_Dialog*				m_pxRandDelayDialogs[2];

		// Typedefs

		typedef Tools_Entity_Activatable_Object PARENT;
};

// ______________________________ Tools_DialogueLineHash_DropDownList_Dialog ___________________________________

class Tools_DialogueLineHash_DropDownList_Dialog : public Asura_Hash_DropDownList_Dialog
{
	public:

		Tools_DialogueLineHash_DropDownList_Dialog	( const char* szName, Asura_Vector_2& xOffset, Asura_Hash_ID* puHash, const Asura_ServerEntity_DialogueController* pxEvent, const char* szZeroHashText = 0 );
		
		virtual			u_int	GetNumberOfHashValues	( )				const; 
		virtual const	char*	GetNameByIndex			( int iIndex )	const;
		
	protected:

		virtual const char* GetZeroHashText() const { return m_szZeroHashText ? m_szZeroHashText : "*All Lines*"; }

		bool m_bChanged;
		const Asura_ServerEntity_DialogueController* m_pxEntity;
		const char* m_szZeroHashText;
};


#endif // ASURA_USE_DIALOGUE_SYSTEM

#endif // __TOOLS_ENTITY_DIALOGUECONTROLLER_H__

//eof

