//
// Tools_Event_DialogueTrigger.h
//
// Created by Richard Rice - 07/11/2006
// 
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_ENTITY_DIALOGUETRIGGER__
#define __TOOLS_ENTITY_DIALOGUETRIGGER__
#ifdef ASURA_USE_DIALOGUE_SYSTEM

#include "Entity/Tools_Entity_Activatable_Object.h"

class Asura_Dialogue_CharacterMapping;


class Tools_Entity_DialogueTrigger : public Tools_Entity_Activatable_Object
{
	friend class Tools_ChooseObject_CharacterMap;

	public :
		Tools_Entity_DialogueTrigger(Asura_Entity* pxEntity);
		~Tools_Entity_DialogueTrigger();
		static void Create();
		static Tools_Entity_DialogueTrigger* Create(bool bGenerateName,Asura_Hash_ID uEventHash);
		
		//virtual function overides
		const char* GetTypeDescription(){return "Dialogue Trigger";}

		static const char* GetNamePrefix() { return "DlgT_"; }
		virtual const char* GetMyNamePrefix() const { return Tools_Entity_DialogueTrigger::GetNamePrefix(); }

		void AddOverlayControls(class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset);

		virtual void Copy(const Tools_Object*);
		virtual bool CanBeCopied() const {return Type == TOT_Entity_DialogueTrigger;}
		virtual Tools_Object* CreateObjectOfThisType() const;
		virtual void UpdateOverlayControls(class Asura_Overlay* pxOverlay);
		virtual void Destroy();
		virtual bool HandlesThisEvent(int iEventID) const;
        virtual void AddFilesToExportList(List<Asura_String>& nameList) const;
		virtual void UpdateWhileSelected();
		virtual void PrintInfo(float& fX,float& fY);


		// Returns true if the message block belongs to this entity
		virtual bool OwnsThisMessageBlock(unsigned short usMessageBlockID);
		// Gets description of what causes message block to be sent, returns false if not implemented, or message isn't found.
		virtual bool GetEventDescForMessageBlock(unsigned short usMessageBlockID,Asura_String& xOutputDesc);

	private :
		//overlay callback functions
		//defines for routeing static callback functions to non-static versions
		#define OVERLAY_VOID_CALLBACK(__FnName)\
		static void __FnName(int iThis){((Tools_Entity_DialogueTrigger*)iThis)->__FnName();}\
		void __FnName();

		OVERLAY_VOID_CALLBACK(ChooseDialogue);
		OVERLAY_VOID_CALLBACK(EditCharacterMap);
		OVERLAY_VOID_CALLBACK(ClearCharacterMap);						
		OVERLAY_VOID_CALLBACK(EditMessages);
		OVERLAY_VOID_CALLBACK(ConvertToController);

		#undef OVERLAY_VOID_CALLBACK

		void EditCharacterMap_GuidSelected(Asura_Guid uGuid);

		void UpdateCharacterMapStrings();
		void DeleteCharacterMapStrings();

		//Gets list of characters used by event , and updates the mapping list to match
		void UpdateCharacterMappings();

		//generates a default name for a dialogue trigger
		static void GenerateName(Asura_Hash_ID uEventHash, Asura_String& xOutput);

		//renames entity if needed in response to the event being changed
		void UpdateName(Asura_Hash_ID uEventHash);

		//gets a default mapping to use for a new character mapping
		static Asura_Guid GetDefaultCharacterMapping(Asura_Hash_ID uCharacterHash);

		//Adds mapping to list of recently created mappings
		static void AddToRecentCharacterMappings(const Asura_Dialogue_CharacterMapping& xMapping);

		int m_iSelectedCharacter;
		int m_iNumCharacterMapStrings;
		char** m_pszCharacterMapStrings;

		u_int m_uCharacterMappingValidity;


		static List<Asura_Dialogue_CharacterMapping> s_xRecentCharacterMappings;


};



#endif //ASURA_USE_DIALOGUE_SYSTEM
#endif //__TOOLS_ENTITY_DIALOGUETRIGGER__
