//
// Tools_Entity_CountedTrigger_Object.h
//
// Created by Richard Rice - 20/09/2006
// 
// Copyright (C) 2006 Rebellion, All Rights Reserved.
//

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __TOOLS_ENTITY_COUNTEDTRIGGER_OBJECT_H__
#define __TOOLS_ENTITY_COUNTEDTRIGGER_OBJECT_H__


#include "Entity/Tools_Entity_Trigger_Object.h"

class Tools_Entity_CountedTrigger_Object : public Tools_Entity_Trigger_Object
{
	public :
		Tools_Entity_CountedTrigger_Object(Asura_Entity* pxEntity);
		~Tools_Entity_CountedTrigger_Object();

		static void Create();
		static Tools_Entity_CountedTrigger_Object* Create(bool bGenerateName);
		
		//virtual function overides
		const char* GetTypeDescription(){return "Counted Trigger";}
		void Destroy();
		void UpdateWhileSelected();
		virtual void PrintInfo(float& x,float& y);

		virtual bool UsesTriggerMessage() { return false; }

		static const char* GetNamePrefix() { return "CT_"; }
		virtual const char* GetMyNamePrefix() const { return Tools_Entity_CountedTrigger_Object::GetNamePrefix(); }

		void AddOverlayControls(class Asura_Overlay* pxNewOverlay,class Asura_Vector_2& xOffset);
		bool HandlesThisMessage(int iMessageID);


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

		virtual bool OwnsThisMessageBlock(unsigned short usMessageBlockID);
		virtual bool GetEventDescForMessageBlock(unsigned short usMessageBlockID,Asura_String& xOutputDesc);

		//controls for editing messages to a timeline trigger
		static void AddOverlayControls_EnableMessage(struct Asura_StaticMessage* pxMessage,class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset);
		static void AddOverlayControls_SetTriggerCount(struct Asura_StaticMessage* pxMessage,class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset);
		static void AddOverlayControls_SetCounter(struct Asura_StaticMessage* pxMessage,class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset);
		static void AddOverlayControls_AddCounter(struct Asura_StaticMessage* pxMessage,class Asura_Overlay* pxOverlay,class Asura_Vector_2& xOffset);
		
		static void EditMessageBlockHash(Asura_StaticMessage* pxMessage);

	
		const char* GetMessageBlockNameFromHash(Asura_Hash_ID uNameHash) const;

		virtual u_short* AddCustomEvent() { AddMessage(); return m_pxServerEntity->GetCustomEvent(m_pxServerEntity->GetNumCustomEvents() - 1); }
		virtual bool DeleteCustomEvent(int iIndex) { DeleteMessage((int)this, iIndex); return true; }
		virtual bool RenameCustomEvent(int iIndex) { RenameMessage((int)this, iIndex); return true; }


protected :
		//prompt for a message block to be chosen , returns index of selection , or -1
		int SelectMessageIndex(const char* pszMessage);
		Asura_Hash_ID SelectMessageHash(const char* pszMessage);

		#define OVERLAY_VOID_CALLBACK(__FnName)\
		static void __FnName(int iThis){((Tools_Entity_CountedTrigger_Object*)iThis)->__FnName();}\
		void __FnName();

		//overlay functions
		OVERLAY_VOID_CALLBACK(AddMessage)
		OVERLAY_VOID_CALLBACK(DeleteMessage)
		OVERLAY_VOID_CALLBACK(RenameMessage)

		void DeleteMessage(int iThis, int iIndex);
		void RenameMessage(int iThis, int iIndex);

		static void EditMessages(int iIndex);
		#undef OVERLAY_VOID_CALLBACK

		//allocates arrays for tools copy of data ,and updates from the entity
		void AllocateArrays();


		static void EditMessageBlockHash(int iMessage);

		bool* m_pbActive;
		bool* m_pbRetriggerable;
		int* m_piTriggerCount;
};

#endif //__TOOLS_ENTITY_COUNTEDTRIGGER_OBJECT_H__
