/**
*
* \file Tools_Entity_ParticleGenerator_Object.h
*
* Created by James Paulin - 16/09/2002 17:29:05
*
* Copyright (C) 2002 Rebellion, All Rights Reserved.
*
* (MH - 12.01.2003) - the templates weren't storing all the information
* required to make a generator. I added the generator templates to work
* around this without having to modify the rest of the system. I'm not
* convinced that the system is all that stable so at some point it needs
* to be rewritten and replaced by something more coherent.
*
**/
#ifdef ASURA_USE_PRAGMA_ONCE
	#pragma once
#endif

#ifndef __TOOLS_ENTITY_PARTICLEGENERATOR_OBJECT_H__
#define __TOOLS_ENTITY_PARTICLEGENERATOR_OBJECT_H__

#include "Entity/ParticleGenerator/Asura_ClientEntity_ParticleGenerator.h"
#include "SpecialFX/Asura_Particle.h"
#include "SpecialFX/Asura_Particle_TemplateStore.h"   // ASURA_PARTICLE_TEMPLATESTORE_MAX_NAME_CHARS

#include "Entity/Tools_Entity_Object.h"

class Tools_ParticleGenerator_Wind_Vector;
class Tools_UV_Editor;

class Tools_Entity_ParticleGenerator_Object : public Tools_Entity_Object
{
	public:
		Tools_Entity_ParticleGenerator_Object(Asura_Entity* xEntity);
	   ~Tools_Entity_ParticleGenerator_Object();

		const char* GetTypeDescription(){return "ParticleGenerator";}
		void UpdateWhileSelected();
		void Update();
		void AddOverlayControls(class Asura_Overlay* xNewOverlay,class Asura_Vector_2& xOffset);
		bool HandlesThisMessage(int iMessageID);
		void Destroy();
		void Render();
		
		virtual void UpdatePositionInAsuraData(bool);

		virtual const char* GetMyNamePrefix() const { return Tools_Entity_ParticleGenerator_Object::GetNamePrefix(); }
		static const char* GetNamePrefix() { return "PG_"; }
	
		static void Create();
		static void Create(const class Tools_Entity_ParticleGenerator_Object* pxBaseEntity);

		
	private:

		void OnSelection(void);
		void OnDeselection(void);

		void StartUVEdit();
		void FinishUVEdit();
		void UpdateUVEdit();
	
		static void TestParticleGenerator();
		static void StopParticleGenerator();
		static void StopAllParticleGenerators();
		static void CopyParticleGenerator();
		static void ParticlePropertiesDialog(void);
		static void UpdateParticlePropertiesDialog();
		static void ChooseTranslucencyMode(void);
		static void WindPropertiesOverlay(void);
		static void EditWindVector(void);
		static void CreateDummyParticleTemplate(void);
		static void CreateDummyWindProperties(void);
		static void AttachToEntity(void);
		static void FinalizeAttachment(void);
		static void RemoveAttachment(void);
		static void ChooseTemplate(void);
		static void SaveTemplate(void);
		void UpdateFromParticleTemplate(const Asura_Particle_Template* pxParticleTemplate);
        static void ChooseGeneratorTemplate(void);
        static void SaveGeneratorTemplate(void);
        void FillOutParticleGeneratorTemplate(Asura_ParticleGenerator_Template& xTemplate);
        void UpdateFromGeneratorTemplate(const Asura_ParticleGenerator_Template& xTemplate);

		static void SelectThisObject(void);
		
		static Asura_Particle_Template  s_xDummyParticleTemplate;
		static Asura_ParticleGenerator_WindProperties s_xDummyWindProperties;

		Asura_ParticleGenerator_WindProperties m_xWindProperties;
		Asura_Particle_Template  m_xParticleTemplate;
		Asura_Vector_3			 m_xPosition;
		Asura_Vector_3			 m_xOrientation;
		float					 m_fVelocity;
		float					 m_fRate;
		float					 m_fDuration;
		float					 m_fRandomness;
		float					 m_fGravity;
		bool					 m_bInfiniteLifetime;
		bool					 m_bDestroyable;
		bool					 m_bStartsActive;
		float					 m_fDecayRate;

		//Staccato generation
		bool					 m_bStaccatoGenerator;
		float					 m_fLaunchProbability;

		//Template store
		bool					 m_bUseTemplateFromStore;
		char					 m_szTemplateName[ASURA_PARTICLE_TEMPLATESTORE_MAX_NAME_CHARS];
		bool					 m_bUseTemplateStoreStatusHasChanged;

		Asura_ClientEntity_ParticleGenerator* m_pxClientEntity;
		static Tools_Entity_ParticleGenerator_Object* s_pxThisObjectForTesting;
		static List<Tools_Entity_ParticleGenerator_Object*> s_xParticleGeneratorList;
		
		Tools_ParticleGenerator_Wind_Vector* m_pxWindVectorObject;

		//Attachment to another entity
		static bool		 s_bDoAttach;
		Asura_Vector_3	 m_xTargetOffset;
		Asura_Guid		 m_uiTargetGuid;
		Asura_Matrix_3x3 m_xTargetOrientationOffset;
		
		//Require local copies of pcle template variables since dialog's cannot deal
		//with unsigned ints
		bool m_bUseColourLerp;
		bool m_bUseDynamics;			
		bool m_bUseLighting;			
		bool m_bUseMotionBlur;	
		bool m_bUseRandomRotation;	
		bool m_bUseSizeLerp;	
		bool m_bUseStandardGravity;
		bool m_bUseVelocityDecay;
		bool m_bDecayRateChanged;
		//int  m_iTranslucencyMode;
		bool m_bUseWind;
		bool m_bUseRandomDirection;
		bool m_bUseRandomVelocity;

		Tools_UV_Editor* m_pxTextureEdit;
	
	public:

		bool Changed;
		bool m_bGameEntitiesNeedUpdating;
		bool m_bTemplatePropertiesChanged;
		static bool m_bPreviewEffect;

		enum DialogID
		{
			DialogID_Translucency,
		};

};

class Tools_ParticleGenerator_Wind_Vector : public Tools_Object
{
	public:
		Tools_ParticleGenerator_Wind_Vector();
		~Tools_ParticleGenerator_Wind_Vector();

		virtual void UpdatePositionInAsuraData(bool);
		void OnDeselection();
		const char* GetTypeDescription(){return "Wind Vector (PGen)";}
		const char* GetName(){return "Wind vector for currently selected PGen";}

		bool m_bGameEntitiesNeedUpdating;
		bool m_bReadyToDelete;
};




#endif//__TOOLS_ENTITY_PARTICLEGENERATOR_OBJECT_H__
