// Definitions for the class CMyDocument
/////////////////////////////////////////////
#ifndef _ED_ACTORS_DOCUMENT_
#define _ED_ACTORS_DOCUMENT_

#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000

#include "EDACMStr.hpp"
#include "EDACDef.hpp"
#include "Defines.hpp"
#include "EDACCust.hpp"

//External Modules
//For Families
#include "ITF.h"
#include "CTL.h"
//End of External Modules

class EdActors_ActorsView;
//-----------------IR-------------------------
class CPA_EdIR_DesignerVariablesView;
//--------------------------------------------
class EdActors_MiniStrucView;
class EdActors_EditorActor;
class EdActors_ActorMiniStructureList;
class EdActors_EditorActorInstance;
class EdActors_EditorActorModel;
class EdActors_ListOfActors;
class CPA_Actor;
class CPA_DialogList;
class CPA_Family;
class CTL_Editor_Control;
class CPA_Action;
class EditorObjectTable;
//CPA2 Stegaru Cristian 98/07/16
class CPA_Actor_Editor_Interface;
//End CPA2 Stegaru Cristian 98/07/16


//###############################################################
typedef enum ED_ACTORS_eDisplayMode
{
	ED_ACTORS_eDisplayMode_Model = 0,
	ED_ACTORS_eDisplayMode_Instance,
	ED_ACTORS_eDisplayMode_AlwaysModel,

} ED_ACTORS_tdeDisplayMode;

//###############################################################
typedef enum ED_ACTORS_eModeOfActorSelection
{
	ED_ACTORS_eModeOfActorSelection_Unknown = 0,
	ED_ACTORS_eModeOfActorSelection_InHierarchy,
	ED_ACTORS_eModeOfActorSelection_InTreeView,
	ED_ACTORS_eModeOfActorSelection_InListDialog,
	ED_ACTORS_eModeOfActorSelection_InActorsView,

} ED_ACTORS_tdeModeOfActorSelection;

//CPA2 Stegaru Cristian 98-05
struct AlwEntry
{
	CString m_csAlwaysName;
	CString m_csAlwFile;
	AlwEntry (CString csAlwaysName, CString csAlwFile)
	{
		m_csAlwaysName = csAlwaysName;
		m_csAlwFile = csAlwFile;
	}
};

class CPA_UnloadedAlways : public CPA_BaseObject
{
private:
	CString m_csUnloadedAlwaysName;
	CString m_csAlwFile;
	BOOL m_bLoaded;
public:
	BOOL m_bOnceDblClk;
	CPA_UnloadedAlways (CPA_EditorBase * pEditor, const CString csType, CString csName = "");
	void mfn_vSetAlwFile (CString csAlwFile) { m_csAlwFile = csAlwFile;}
	CString mfn_csGetAlwFile () { return m_csAlwFile;}
	void mfn_vSetUAlwaysName (CString csUAlwaysName) { m_csUnloadedAlwaysName = csUAlwaysName;}
	CString mfn_csGetUAlwaysName () { return m_csUnloadedAlwaysName;}
	void mfn_vSetLoaded (BOOL bLoaded = TRUE) { m_bLoaded = bLoaded;}
	BOOL mfn_bIsLoaded () { return m_bLoaded;}
//virtual
    virtual long   GetDataType	(void) { return 0;}
    virtual void * GetData		(void) { return NULL;}
	virtual CString GetNameToDraw	(void)	{ return mfn_csGetUAlwaysName ();}
};
//End CPA2 Stegaru Cristian 98-05

//CPA2 Stegaru Cristian 98/06/24
struct MS_Field
{
	CString m_csModelName;
	CTL_Editor_Data *m_pModifiedData;
	MS_Field () { m_pModifiedData = NULL;}
};
//End CPA2 Stegaru Cristian 98/06/24


//CPA2 Stegaru Cristian 98/07/16
#define		UPDATE_ALW_FILE			21
class ModifUpdateAlwFile : public CPA_Modif
{
protected:
	CPA_Actor_Editor_Interface *m_pInterface;
	CStringList					m_lstAlwObjects;
public:
	ModifUpdateAlwFile (CPA_Actor_Editor_Interface *pInterface, CStringList &rlstAlwObjects, BOOL pBlock = FALSE);

	BOOL Do (void);
	BOOL Undo (void);

};
//End CPA2 Stegaru Cristian 98/07/16

//###############################################################
class EdActors_MyDocument
{
public:
	EdActors_MyDocument();
	~EdActors_MyDocument();

//Attributes
public:
	//////////
	// TEMP //
	//////////
	CStringList m_clListOfFilesToDelete;

	//The list of enum descriptors
	CTL_Editor_EnumDescriptorList m_clListOfEnumDescriptors;

	//The list of Masks descriptors
	CTL_Editor_MaskList m_clListOfMasksDescriptors;

	//The lists of mini-structures (controls)
	EdActors_MSListsList m_clListOfMSLists;
	
	//The current MS list
	EdActors_MiniStructureList *m_pclCurrentMiniStructureList;

	//Pointers on the views
	CPA_DialogList *m_pclDialogList;
	EdActors_ActorsView *m_pclActorsView;
	EdActors_MiniStrucView *m_pclMiniStrucView;
//-----------------IR-------------------------
	CPA_EdIR_DesignerVariablesView	*m_pclDesignerVariablesView;
	int m_iMSEditorOldHeight;
	BOOL m_bDesignerVarEditorIsVisible;
//--------------------------------------------

	//The currently selected actor
	EdActors_EditorActor *m_pclSelectedActor;

	//The current Instance
	EdActors_EditorActorInstance *m_pclCurrentInstance;

	//The current Model
	EdActors_EditorActorModel *m_pclCurrentModel;

	CPA_BaseObject *m_pclCurrentFamily;

	//Indicates the current display mode
	ED_ACTORS_tdeDisplayMode m_eCurrentDisplayMode;

	//Indicates wether currently edited datas must be refreshed or not
	BOOL m_bMustRefreshDatas;

//Members for Dialog List
//-----------------------
	//The list of Models
	CPA_BaseObjectList m_clModelsList;
	//The list of Instances
	CPA_BaseObjectList m_clInstancesList;
	//The list of Always
	CPA_BaseObjectList m_clAlwaysList;
	//CPA2 Stegaru Cristian 98-05
	//The list of Unloaded Always
	CPA_BaseObjectList m_clUnloadedAlwaysList;
	CPA_BaseObjectList m_clInitializedAlwaysList;
	//End CPA2 Stegaru Cristian 98-05

	//Pointer on the current list to treat
	CPA_BaseObjectList *m_pclCurrentActorsList;					 

//Saving & Restoring
//------------------
	CString m_csModelsBitmapsPath;
	CString m_csModelsBitmapsCompletePath;
	CString m_csModelsBitmapsPathForGenDoors;
	CString m_csModelsBitmapsCompletePathForGenDoors;

//Editor's setup variables
//------------------------
	//Internal Setup
	CString m_csIniFileName;
	BOOL m_bMustConfirmUnallocation;
	BOOL m_bMustConfirmAllocation;
	BOOL m_bMustConfirmWatchSuppression;
	BOOL m_bMustDisplayModelFieldsInInstance;
 	BOOL m_bMustDisplayUnallocatedMS;
 	BOOL m_bMustDisplayHelpOnActiveView;
  BOOL m_bMustSynchronizeDialogListWithEdition;
  BOOL m_bWatchAlwaysVisible;
  BOOL m_bProposeUnloadedModels;
  BOOL m_bRestoreGroup;
  BOOL m_bAskForNewInstanceName;

//Colors for the name's (model or instance) static
	COLORREF m_pub_colref_NameTextColor;
	COLORREF m_pub_colref_NameBackgroundColor;

//Colors for the model's static
	COLORREF m_pub_colref_ModelTextColor;
	COLORREF m_pub_colref_ModelBackgroundColor;

//Colors for the family's static
	COLORREF m_pub_colref_FamilyTextColor;
	COLORREF m_pub_colref_FamilyBackgroundColor;

//Colors for the fields' static				
	COLORREF m_pub_colref_FieldInstanceTextColor;
	COLORREF m_pub_colref_FieldInstanceBackgroundColor;
	COLORREF m_pub_colref_FieldInitialTextColor;
	COLORREF m_pub_colref_FieldInitialBackgroundColor;
	COLORREF m_pub_colref_FieldCurrentTextColor;
	COLORREF m_pub_colref_FieldCurrentBackgroundColor;
	COLORREF m_pub_colref_InWatchFieldTextColor;
	COLORREF m_pub_colref_InWatchFieldBackgroundColor;
	COLORREF m_pub_colref_FieldModelTextColor;
	COLORREF m_pub_colref_FieldModelBackgroundColor;

	//Menu preferences
	unsigned long m_ulListViewHeight;
	unsigned long m_ulControlViewHeight;
	unsigned long m_ulMSViewHeight;
	unsigned long m_ulModelViewHeight;
	unsigned long m_ulAIViewHeight;
	unsigned long m_ulCharacEditorWidth;
//	unsigned char m_ucCurrentDataLevel;
	BOOL m_bIAActivated;
	BOOL m_bWatchActivated;
	BOOL m_bVariablesActivated;
	BOOL m_bDisplayCurrentValue;
	BOOL m_bDisplayInitialValue;
	BOOL m_bAIFirstTime;
	BOOL m_bModelFirstTime;
	CString m_csInitDialogListType;

	BOOL m_pri_bTreeMustShowUnloadedObjects;
	BOOL m_pri_bTreeMustOnlyShowFamiliesWithModels;


//Editor's Help variables
//------------------------
	CString m_csHelpFileNameAndPath;
//-----------------IR-------------------------
	CString	m_csBrainHelpFileNameAndPath;
//--------------------------------------------

	//Data path
	CString m_pub_csCommonDataPath;
	CString m_pub_csLevelDataPath;

	//For help display on fields
	BOOL m_pub_bMustDisplayHelpOnFields;
	HCURSOR m_hPreviousCursorForHelpOnFields;
	HCURSOR m_hHelpCursor;
	HCURSOR m_hHelpDisabledCursor;

	//
	BOOL m_pub_bUnloadedModelsArePrepared;

	//
	BOOL m_pub_bMustShowLinks;
 
	//
	BOOL m_pub_bWatchWindowIsVisible;

	//
	HICON m_pub_hWatchIcon_Field;
	HICON m_pub_hWatchIcon_Actor;
	HICON m_pub_hWatchIcon_MS;

	//
	BOOL m_bDisplayActor;

	CPA_Actor *m_pLoadedModel;

protected:

private:
	//CPA2 Stegaru Cristian 98/06/24
	MS_Field m_stLastModifiedField;
   //End CPA2 Stegaru Cristian 98/06/24

//Functions
public:
	///////////////////////////////////
	// Models and Instances handling //
	///////////////////////////////////
	void m_fn_vCreateCopiesOfActor(CPA_Actor *_pclSourceActor);

	/////////////////////
	// Models handling //
	/////////////////////

	//Called to create a model and add it in the list of models
	CPA_SuperObject *m_fn_pclCreateModel(CString &r_csModelBitmapName);
	//Called to create a model for Loading
	CPA_SuperObject *m_fn_pclCreateModelForLoad(CString,
																							CPA_Actor *pclEditorActor = NULL);	
	//Called to add a Model in the list of models
	void m_fn_vAddLoadedModelInList(EdActors_EditorActorModel *pclModel,
																	BOOL bMustAddInGlobalList = TRUE);
	//Called to create an INstance for Loading
	CPA_SuperObject *m_fn_pclCreateInstanceForLoad(	CString csName,
																									CAR_EDIT_TDSTACTOR *pclActor = NULL);

	//Called to create single or multiple copy of a model
	void m_fn_vCreateCopiesOfModel(	CPA_Actor *_pclModelToCopy, 
																	long _lCopiesNumber, 
																	CString _csNewName);

	//Called to remove a model from the list, and delete it
	void m_fn_vDeleteModel(CPA_Actor *_pclModelToDelete);

	//Loads unloaded Models
	void m_fn_vLoadUnloadedModels();

	////////////////////////
	// Instances handling //
	////////////////////////
	
	//Called to create single or multiple instances from a model
	BOOL m_fn_bCanInstantiateModel(	CString csSourceModelName,
																	CString &r_csInstanceName);

	//Called to create single or multiple copy of an existing instance
	void m_fn_vCreateCopiesOfInstance(	CPA_Actor *_pclInstanceToCopy,
																			long _lCopiesNumber, 
																			CString _csNewName);

	//Called to remove an Instance from the lists ( <--> DO for Delete)
	void m_fn_vDeleteInstance(CPA_Actor *pclInstanceToDelete);
	//Called to re-put an Instance in the lists	(<--> UNDO for Delete)
	void m_fn_vUndeleteInstance(CPA_Actor *pclInstanceToDelete);

	//Called to set inital position of an actor as its actual's one
	void m_fn_vSetCurrentActorPositionAsInitial(CPA_Actor *_pclActor);

	/////////////////////
	// Editor's aspect //
	/////////////////////
	
	//To refresh editor when a new actor (Instance or Model) is selected
	void m_fn_vDisplayActor(EdActors_EditorActor *pclNewSelectedActor,
													ED_ACTORS_tdeModeOfActorSelection _tdeSelectionType);

//-----------------IR-------------------------
	void m_fn_vDisplayActorIA();
//--------------------------------------------

	//Indicates the current display mode
	ED_ACTORS_tdeDisplayMode m_pub_fn_tdeGetCurrentDisplayMode();
	BOOL m_pub_fn_bCurrentModeIsInstance();
	BOOL m_pub_fn_bCurrentModeIsModel();
	BOOL m_pub_fn_bCurrentModeIsAlwaysModel();

	//Called to update editor (and watch) currently edited values
	void m_fn_vUpdateEditedValues();

	//Called to set the current MS List
	void m_fn_vSetCurrentList(char cChoice, 
														BOOL bMustRepaint = TRUE);

	//Called to update controls when current actor's name has changed
	void m_fn_vUpdateName();

	//Updates controls of the editor for the currently edited Instance 
	void m_fn_vUpdateControlsForInstance();

	//Updates controls of the editor for the currently edited Model 
	void m_fn_vUpdateControlsForModel();

	//Sets the data pointers of the controls in tree to the actor's ones
	void m_fn_vSetPointersForSelectedActor();
	void m_fn_vSetPointers(	EdActors_MiniStructureList *pclMSList, 
													EdActors_ActorMiniStructureList *pclActorMSList);

	//Displays the given Actor, then shows the given Data
	void m_fn_vShowData(EdActors_EditorActor *pclActor, 
											CTL_Editor_Data *pclData);

	//Re-init. the MS with init. values
	void m_fn_vReInitMiniStructure(EdActors_ActorMiniStructure *pclActorMS);
	//Re-init. all MS with init. values
	void m_fn_vReInitAllMiniStructures(EdActors_EditorActor *pclActor);

	//To show or hide the Gen Doors
	void m_fn_vHideGenDoors();
	void m_fn_vShowGenDoors();

	//
	void m_fn_vLoadObjectTables();

	//To Display or Hide the IA Editor
	void m_fn_vActivateIAEditor(BOOL bActivate = TRUE);

	//Saving & Loading
	void m_fn_vSaveMotorLevel(SCR_tdst_File_Description *p_tdstFile,
														CString csSectionName,
														SCR_tde_Ntfy_Action _eAction);
	void m_fn_vSaveMotorInstance(	SCR_tdst_File_Description *p_tdstFile,
																CPA_Actor *p_clActor);
	void m_fn_vSaveAllMSOfMotorInstance(SCR_tdst_File_Description *p_tdstFile,
																			CPA_Actor *p_clActor);
	void m_fn_vNotifyLevel(	CPA_Actor *pclCauseActor, 
													BOOL bAddSection = TRUE,
													CString csActorsName = "");
	void m_fn_vNotifyFixFile();

	//Data Paths
	void m_fn_vComputeDataPaths();
	CString m_fn_csGetLevelName();

	//
	void m_pub_fn_vCheckAllInstancesForActionChange(CPA_Action *);
	void m_pub_fn_vCheckAllActorsForObjectTableChange(EditorObjectTable *);

	//To fill special Enum Descriptors
	void m_pub_fn_vUpdateActorsEnumDescriptor();
	void m_pub_fn_vUpdatePartGenEnumDescriptor();
	void m_pub_fn_vUpdateGameMaterialsEnumDescriptor();
 	void m_pub_fn_vUpdateSectorsEnumDescriptor();
 	void m_pub_fn_vUpdateGraphEnumDescriptor();
	//
	void m_pub_fn_vConstructListOfAlways();

protected:

private:
 	//Called to update editor' mode (Models or Instances or Always Model)
 	void m_fn_vSetMode(ED_ACTORS_tdeDisplayMode _eNewMode, CPA_Actor *_pclNewActor = NULL);

	void m_fn_vInitialize();
	void m_fn_vChangeSize();
	void m_fn_vFillMiniStructureList();
	void m_fn_vConstructListOfEnumDescriptors();
	void m_fn_vConstructListOfMaskDescriptors();
	void m_fn_vSetPointersForActor(EdActors_EditorActor *pclActor);
	
	void m_fn_vScanDirectoryForUnloadedModels(CString,int Level);
	BOOL m_fn_bScanDirectoryForUnloadedModels(CString,int Level);

	BOOL m_fn_bReadIniFile();
	BOOL m_fn_bWriteIniFile();

	BOOL m_pri_fn_bSaveDimensions();
	BOOL m_pri_fn_bLoadDimensions();

	//To save fields in Watch
	BOOL m_pri_fn_bSaveFieldsInWatch();
	BOOL m_pri_fn_bLoadFieldsInWatch();
	CString m_pri_fn_csGetEditorLevelFileName();

	void m_pri_fn_vGetEditorCurrentSettings();
	//CPA2 Stegaru Cristian 98-06
	void m_fn_vLoadFamilyModels (CString csFamilyName);
	//End CPA2 Stegaru Cristian 98-06
	//Saving & Loading
	CPA_Actor *m_fn_pclLoadModel(	CString csModelName = "",
																CPA_Actor *pclModel = NULL);


	//CPA2 Stegaru Cristian 98/07/16
	void mfn_vExtractAlwaysModelsFromBehaviour (CString &rcsAIText, CStringList &rlstOfAlways);
	CString GetFunctionArgument (CString &rText, int iFunctionInx);
	//End CPA2 Stegaru Cristian 98/07/16

public:
	static SCR_tde_Anl_ReturnValue m_fn_tdeCallBackLoadModel(	SCR_tdst_File_Description *_p_stFile,
																														char *_p_szName,
																														char *_ap_szParams[],
																														SCR_tde_Anl_Action _eAction);
	
	static SCR_tde_Anl_ReturnValue m_fn_tdeCallBackLoadFieldsInWatch(	SCR_tdst_File_Description *_p_stFile,
																																		char *_p_szName,
																																		char *_ap_szParams[],
																																		SCR_tde_Anl_Action _eAction);
	//Save Functions
	static void s_m_fn_vCallBackSaveFixFile(SCR_tdst_File_Description *_p_stFile,
																					char *_p_szSectionName,
																					void *_p_vData,
																					SCR_tde_Ntfy_Action _eAction);

// Shaitan => state list in the level
	static void s_m_fn_vCallBackSaveStateList (SCR_tdst_File_Description *_p_stFile,
																					char *_p_szSectionName,
																					void *_p_vData,
																					SCR_tde_Ntfy_Action _eAction);

	void m_fn_vUpdateReferencesForAllActions	(void);

	void m_fn_vUpdateListOfUsedActionsForFamily (CPA_Family *pFamily);
// End Shaitan => state list in the level

// Shaitan => module list in the level
	static void s_m_fn_vCallBackSavePOList (SCR_tdst_File_Description *_p_stFile,
																					char *_p_szSectionName,
																					void *_p_vData,
																					SCR_tde_Ntfy_Action _eAction);

	void m_fn_vUpdateListOfUsedObjectTablesForFamily (CPA_Family *pFamily);

	void m_fn_vUpdateListOfUsedPOsForFamily			 (CPA_Family *pFamily);
// End Shaitan => module list in the level

	void m_pri_fn_vSaveAllActorsInFixFile(SCR_tdst_File_Description *_p_stFile,
			 																  CPA_BaseObjectList *_pclList,
																				CString _csEntryName);

	//CPA2 Stegaru Cristian 98-04
	void m_fnUpdateWithExternData ();
	//End CPA2 Stegaru Cristian 98-04
	//CPA2 Stegaru Cristian 98-05
	void m_fn_ConstructListOfUnloadedAlways ();
	void mfn_vGetAlwaysNamesFromAlwFile (CString csFileName, CStringList &rlstOfAlwaysName);
	void mfn_vFillAlwaysObjectsFromDirectory (CString csDirectoryName, int iRelativePathInx, CStringList &rlstOfCurrentLevelAlwaysName);
	void mfn_vSearchDirForAlways (CString csDirectoryName, int iRelativePathInx, CTypedPtrList <CPtrList, AlwEntry*> &rlstOfAlwEntry);
	void mfn_vGetAlwaysFromCharactDirectory (CString csDirectoryName, int iRelativePathInx, CTypedPtrList <CPtrList, AlwEntry*> &rlstOfAlwEntry);
	//End CPA2 Stegaru Cristian 98-05
	//CPA2 Stegaru Cristian 98/06/24
	void mfn_vSetLastModifiedField (MS_Field stField) { m_stLastModifiedField = stField;}
	MS_Field mfn_stGetLastModifiedField () { return m_stLastModifiedField;}
	//End CPA2 Stegaru Cristian 98/06/24
	//CPA2 Stegaru Cristian 98/07/16
	void mfn_vFillRefAlwaysForModel (CPA_Actor *pModel, CStringList &rlstOfRefAlways);
	void mfn_vCheckModelToUpdateAlwFile (CPA_Actor *pModel);
	//End CPA2 Stegaru Cristian 98/07/16
friend class EdActors_ActorsView;
friend class CPA_Actor_Editor_Interface;
friend class EdActors_DialogModelLoad;
friend class CPA_Actor;
friend class EdActors_EditorSetupDialog;
};

#endif //_ED_ACTORS_DOCUMENT_


