//**************************************
// This is the base class of your DLL interface
// All methods of CPA_ToolDLLBase are
// present in that class.
//**************************************

#ifndef __MaterialINTERF_HPP__
#define __MaterialINTERF_HPP__

#ifdef ACTIVE_EDITOR

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

// if you want only one instance of your DLL
// activate the next line
#define DLL_ONLY_ONE_INSTANCE

#include "Acp_base.h"
#include "itf.h"

class CMaterialListView;
class DiaView;
class DiaMeca;
class DiaSound;
class DiaCol;
class DiaMain;
class DiaText;
class tdoEditorGameMaterial;
class tdoEditorCollideMaterial;
class tdoEditorVisualMaterial;
class tdoEditorMechanicsMaterial;
class CTextureDlg;

typedef enum tdeRefreshListsMode_
{
	E_rlm_DoNothing = 0,
	E_rlm_DestroyAndRebuild,
	E_rlm_UpdateWithoutDestruction
} tdeRefreshListsMode;

#define C_szFileReferencedNameKey "MaterialRef"
#define C_szFileMinimalNameKey "MaterialMin"

//structure used to highlight display
typedef struct stHighlightItem_
{
	GMT_tdxHandleToGameMaterial hGameMaterial;
	ACP_tdxHandleOfMaterial hHighlightVisualMaterial;
	ACP_tdxHandleOfMaterial hOriginalVisualMaterial;
} tdstHighlightItem;

typedef enum eActivationMode_
{
	E_am_InvalidMode,
	E_am_Never,
	E_am_Once,
	E_am_Always
} tdeActivationMode;

//ANNECY Shaitan DisableFunctions (16/04/98) {
extern BOOL g_bMasterEditor;
#define C_szCommon "World\\Libraries\\Materials\\Common\\Common.gmt"
//ENDANNECY Shaitan DisableFunctions }

//----------------------------------------------------------
// Tool DLL interface class
//----------------------------------------------------------
class Material_Interface : public CPA_ToolDLLBase
{
private:
	CBitmapList				m_oTextureList;						// List of all bitmaps in Data directory
	CSplitFrame *m_p_oLeftSplitFrame;		// Main frame of the editor
	CSplitFrame *m_p_oBottomSplitFrame;
	//BOOL    m_bIsActivated;     // are the dialogs displayed on the screen ?
	//BOOL m_bIsSelected; //is it the current dll ?
	CMaterialListView	*m_p_oMaterialListView;
	DiaView			*m_p_oMaterialView;
	DiaMeca			*m_p_oMaterialMeca;		// pointer to mecanics dialog
	DiaSound			*m_p_oMaterialSound;	// pointer to sound dialog
	DiaCol				*m_p_oMaterialCol;		// pointer to collision dialog
	DiaMain				*m_p_oMaterialMain;		// pointer to the main dialog
	DiaText       *m_p_oTextureDialog; //pointer to texture edition dialog
	CTextureDlg				*m_p_oTextureDlg;		 // texture modal dialog box to choose a texture for the current material
	CPA_SuperObject	*m_p_oWorldRoot;
	BOOL m_bDisplayMaterialUnderCursor;	// display material name on status bar

	void m_vRefreshMaterialSuperObjectLinks(void);
	tdeRefreshListsMode m_eRefreshListsMode;
	void m_vSavePreferences(void);
	BOOL m_bModeIsMaterialSelect;
	BOOL m_bModeIsIndexedTriangleSplit;
	BOOL m_bEnteredEditorAtLeastOnce;
	tdeActivationMode m_eLoadWarningsActivation;

	GMT_tdxHandleToGameMaterial m_hQueriedDefaultGameMaterial;
	CPA_List<CPA_BaseObject> m_oFileObjectList;
	HIE_aDEF_stTabOfPickInfo m_a_stPickInfo;
	tdoEditorGameMaterial *m_p_oMaterialUnderCursor;
	BOOL m_bCanSaveModifs;
	BOOL m_bTexturesLoaded;
  CPA_KeyActionConfiguration *m_p_oKeyConfiguration;
	CList<tdstHighlightItem *, tdstHighlightItem *> m_oHighlightList;

public:
	Material_Interface(void);
	~Material_Interface(void);
	tdeRefreshListsMode m_eGetRefreshListMode() { return m_eRefreshListsMode; }
	CString m_csGetIdPartOfSectionName(CString _csSectionName);
	CString m_csGetActionPartOfSectionName(CString _csSectionName);
	CString m_csGetFilePartOfSectionName(CString _csSectionName);
	CBitmapList *m_p_oGetMaterialsTextureList() { return &m_oTextureList; }
	CMaterialListView	*m_p_oGetMaterialListView()			{ return m_p_oMaterialListView; }
	DiaView			*m_p_oGetVisualView()				{ return m_p_oMaterialView; }
	DiaMeca			*m_p_oGetMecaView()				{ return m_p_oMaterialMeca; }
	DiaSound		*m_p_oGetSoundView()			{ return m_p_oMaterialSound; }
	DiaCol			*m_p_oGetCollView()				{ return m_p_oMaterialCol; }
	DiaMain			*m_p_oGetMainView()				{ return m_p_oMaterialMain; }
	DiaText *m_p_oGetTexView() { return m_p_oTextureDialog; }
	CPA_SuperObject	*m_p_oGetWorldSuperObject(void)		{ return m_p_oWorldRoot; }
	tdoEditorGameMaterial *m_p_oGetEditedMaterial();
	CTextureDlg			*m_p_oGetTextureChooserDialog(void) { return m_p_oTextureDlg; }
	void m_fn_vShowMaterialAll(tdoEditorGameMaterial *_p_oMaterial = NULL);
	void m_vSetEditedMaterial(tdoEditorGameMaterial *_p_oMaterial);
	BOOL m_bEditPickedMaterial(HIE_tdstPickInfo *_p_stPickInfo);
	BOOL m_bLoadWarningsAreEnabled();
	CPA_FileObject *m_p_oGetCurrentFileObject();
	void m_vFindMaterialUnderCursor(CPoint _oPoint, BOOL _bVerbose = FALSE);
	
	//Mircea Dunka 5.11.1998
	void m_vFindColorUnderCursor(CPoint _oPoint, BOOL _bVerbose);
	BOOL m_bGetGlidePixel;
	//end Mircea Dunka
	
	BOOL m_bSplitIndexedTriangle() { return m_bModeIsIndexedTriangleSplit; }
	void m_vLoadHighlightInfo();
	void m_vSaveHighlightInfo();

	void m_vShowEditor();
	void m_vHideEditor();
//    ~Material_Interface(void);
	//void m_vRefreshMaterialList<tdoEditorGameMaterial>(CString _csExtension);
	void m_vRefreshFileObjectList();
	void m_vDoRefreshLists(long _lStartInLinkTable = 0, tdeRefreshListsMode _eOverrideMode = E_rlm_DoNothing, BOOL _bLoadTextures = TRUE);

	CPA_SaveObject *m_p_oGetEditorObjectForEngine(ACP_tdxHandleOfMaterial _hVisualMaterial);
	CPA_SaveObject *m_p_oGetEditorObjectForEngine(DNM_tdxHandleToMecMatCharacteristics _hMechanicsMaterial);
	CPA_SaveObject *m_p_oGetEditorObjectForEngine(GMT_tdxHandleToCollideMaterial _hCollideMaterial);
	CPA_SaveObject *m_p_oGetEditorObjectForEngine(GMT_tdxHandleToGameMaterial _hGameMaterial);
	CPA_SaveObject *m_p_oGetEditorObjectForEngine(GLI_tdstTexture *_hTexture);


/*===========================================================================
	Messages
=========================================================================*/
	virtual BOOL fn_bAcceptToSave(void);
	virtual void fn_vBeforeSaveAll(void);
	virtual void fn_vAfterSaveAll(void);
// engine - editor
 void fn_vBeforeEngine (void);
 void fn_vBeforeEditor (void);
// engine
//    BOOL fn_bAcceptToRunEngine      (void) { return TRUE; };
//    BOOL fn_bAcceptToRunTimerEngine (void) { return TRUE; };
// end appli
//    void fn_vJustBeforeClosing  (void) { };
//    BOOL fn_bAcceptToExit       (void) { return TRUE; };
// keys
	virtual BOOL _OnKeyDown (UINT nChar, UINT nRepCnt, UINT nFlags);
	virtual BOOL _OnKeyUp	(UINT nChar, UINT nRepCnt, UINT nFlags);
// mouse
	virtual BOOL _OnMouseMove(UINT nFlags, tdstMousePos *p_stPos, MTH3D_tdstVector *p_stVect);
//    BOOL _OnLButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo) { return FALSE; };
//    BOOL _OnRButtonDblClk (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo) { return FALSE; };
    virtual BOOL _OnLButtonDown(UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo);
//    BOOL _OnRButtonDown   (UINT nFlags, tdstMousePos *p_stPos, ACP_tdxIndex xIndex, HIE_tdstPickInfo *p_stPickInfo) { return FALSE; };
//    BOOL _OnLButtonUp     (UINT nFlags, tdstMousePos *p_stPos)  { return FALSE; };
//    BOOL _OnRButtonUp     (UINT nFlags, tdstMousePos *p_stPos)  { return FALSE; };
// command
//    BOOL _OnCommand         (UINT IDCmdMsg)             { return FALSE; };
//    BOOL _OnUpdateCommandUI (UINT uiID, CCmdUI *pCmdUI) { return FALSE; };
// dragdrop
//    BOOL _OnDragDropEnd         (WPARAM wParam, LPARAM lParam)  { return FALSE; };
//    BOOL _OnDragDropMove        (WPARAM wParam, LPARAM lParam)  { return FALSE; };
//    BOOL _OnDragDropLooseFocus  (WPARAM wParam, LPARAM lParam)  { return FALSE; };
//    BOOL _OnDragDropGainFocus   (WPARAM wParam, LPARAM lParam)  { return FALSE; };
// add objects to draw
	virtual void fn_vBeforeDrawingWorld(GLD_tdstViewportAttributes *p1, GLI_tdxHandleToLight p2, DEV_ViewPort* p3);
	virtual void fn_vAddObjectsToDraw	(GLD_tdstViewportAttributes *p1, GLI_tdxHandleToLight p2, DEV_ViewPort* p3);
	virtual void fn_vAddObjectsToDraw2	(GLD_tdstViewportAttributes *p1, GLI_tdxHandleToLight p2);

/*===========================================================================
	Reachable Objects
=========================================================================*/

	virtual BOOL fn_bLoadBaseObject	(CPA_BaseObject *p_oObject);

/*===========================================================================
	Reinit
=========================================================================*/

    void fn_vOnChangeRoot(void)  
		{ 
			m_p_oWorldRoot = M_GetWorld()->GetRoot(); 
		}
    void fn_vOnChangeWorld(void)  
		{ 
			m_p_oWorldRoot = M_GetWorld()->GetRoot(); 
		}
    void fn_vOnChangeDevice(void) 
		{ 
			m_p_oWorldRoot = M_GetWorld()->GetRoot(); 
		}

/*===========================================================================
	for Dialog List
=========================================================================*/

//    CPA_ReachableObject  * GetDialogSelection (CPA_DialogList *pDialog, CString csTypeName, tdeListDrawMode eDrawMode)  { return NULL; };
//    void                   GetListsForDialog  (CPA_DialogList *pDialog) { };

//    BOOL fn_bOnSelChangeHierarchyTree   (CPA_DialogList *pDialog, CString csTypeName, CPA_SuperObject *pSelectedObject)       { return FALSE; };
//    BOOL fn_bOnDblClkHierarchyTree      (CPA_DialogList *pDialog, CString csTypeName, CPA_SuperObject *pSelectedObject)       { return FALSE; };
//    BOOL fn_bOnSelChangeListObjects     (CPA_DialogList *pDialog, CString csTypeName, CPA_ReachableObject *pSelectedObject, BOOL bUnselect)  { return FALSE; };
//    BOOL fn_bOnDblClkListObjects        (CPA_DialogList *pDialog, CString csTypeName, CPA_ReachableObject *pSelectedObject)      { return FALSE; };
//    BOOL fn_bCanDragItemInHierarchyTree (CPA_DialogList *pDialog, CString csTypeName, CPA_SuperObject *pObjectToDrag)         { return FALSE; };
//    BOOL fn_bCanDropItemInHierarchyTree (CPA_DialogList *pDialog, CString csTypeName, CPA_SuperObject *pObjectToDrop, CPA_SuperObject *pTarget) { return FALSE; };
//    BOOL fn_bOnDragDropInHierarchyTree  (CPA_DialogList *pDialog, CString csTypeName, CPA_SuperObject *pObject, CPA_SuperObject *pTarget)  { return FALSE; };
//    BOOL fn_bOnSelChangeComboList       (CPA_DialogList *pDialog, CString csTypeName)                                         { return FALSE; };
//    BOOL fn_bOnButtonTest               (CPA_DialogList *pDialog, CString csTypeName, tdeListDrawMode eDraw)                  { return FALSE; };

//    void fn_vInitDefaultParameters      (CPA_DialogList *pDialog);

//    void fn_vSetANewTest                (CPA_DialogList *pDialog, CString csCurrentList)    { };
//    BOOL fn_bTestFunction               (CString csCurrentType, CString csTestName, CPA_ReachableObject *pEdObj)    { return TRUE; };

//    BOOL fn_bSetCustomTest              (CPA_DialogList *pDialog) { return FALSE; }
//    BOOL fn_bCustomTestFunction         (CString csCurrentType, CString csTestName, CPA_ReachableObject *pEdObj) { return TRUE; }

/*===========================================================================
	Dialog Bar - Mircea Dunka 31 Aug. 1998
=========================================================================*/
	void fn_vDefineDlgBarBtnIcon (tde_DlgBarCategory wCategory, tds_DlgBarBtn *_pDlgBarBtn);

/*===========================================================================
	SubMenus and PopupMenu
=========================================================================*/

    BOOL fn_bDefineSubMenu      (EDT_SubMenu *_p_oEDTSubMenu)  ;
    void _OnSubMenuCommand      (EDT_SubMenu *_p_oEDTSubMenu,UINT uiMsgID) ;

	BOOL fn_bDefinePopupMenu(EDT_PopUpMenu *pPopup, CPA_List<CPA_SuperObject> *pSelection, BOOL bAsCurrentEditor);
	void _OnPopUpMenuCommand(UINT m_IDCmdMsg);

/*===========================================================================
	Messages from Evt_Editor
=========================================================================*/

    // To pre translate all messages
//    BOOL fn_bPreTranslateMessage(MSG * /*p_stMsg*/) { return FALSE; };

// Called just after editor has been inserted in list of all editors
    void fn_vJustAfterRegistered(void) ;

// Called just before windows main loop processing
    void fn_vConstruct(void) ;

    // Called to refresh datas of DLL if "fn_vCanBeRefresh" returns TRUE
//    void fn_vRefreshDatas(void) {};
	// Called when level has changed
    void fn_vLevelHasChanged(void);
    // Current editor -> No current editor
//    void fn_vHasLostFocus(void) {};
    // No current editor -> Current editor
//    BOOL fn_bHasGainedFocus(void) { return TRUE; };

/*===========================================================================
	Messages from Evt_Editor
=========================================================================*/

// Editor Modifs
//    void fn_vOnModifDelete  (CPA_List<EDT_SaveParents> *pListObjects, tdeTypeModif eType, tdeStatus eStatus) { }
//    void fn_vOnModifParent  (CPA_List<EDT_SaveParents> *pListObjects, tdeTypeModif eType, tdeStatus eStatus) { }
//    void fn_vOnModifCopy    (CPA_List<EDT_SaveParents> *pListObjects, tdeTypeModif eType, tdeStatus eStatus) { }
//    void fn_vOnModifName    (CPA_SuperObject *pEdObj, CString csInitalName, CString csFinalName, tdeTypeModif eType, tdeStatus eStatus) { }
//    void fn_vOnSelect       (CPA_SuperObject *pEdObj, tdeTypeModif eType, tdeStatus eStatus) { }

//    void fn_vOnModifInsert  (CPA_SuperObject *pEdObj, CPA_SuperObject *pParent,
//                                     tdstPosition *p_stPosition, tdeTypeModif eType, tdeStatus eStatus) { }

// Moves
//    void fn_vOnModifMove (CPA_List<EDT_SavePos> *pListObjects, CPA_List<EDT_SaveGlobalPos> *pListConcerned, tdeTypeModif eType, tdeStatus eStatus)  { }
//    void fn_vOnBeginMove (CPA_List<CPA_SuperObject> *pListObjects, CPA_List<CPA_SuperObject> *pListConcerned, tdeStatus eStatus) { }
//    void fn_vOnMoving    (CPA_List<CPA_SuperObject> *pListObjects, CPA_List<CPA_SuperObject> *pListConcerned, tdeStatus eStatus) { }

// Models
//    void fn_vOnAddModelToList   (CPA_ObjectDLLBase *pOwnerDLL, CString csListName, CString csModelName, tdeTypeModif eType) { }

// permission
//    BOOL fn_bAcceptModifDelete      (CPA_List<CPA_SuperObject> *pListObjects, tdeStatus eStatus)  { return TRUE; }
//    BOOL fn_bAcceptModifParent      (CPA_List<CPA_SuperObject> *pListObjects, tdeStatus eStatus)  { return TRUE; }
//    BOOL fn_bAcceptModifCopy        (CPA_List<CPA_SuperObject> *pListObjects, tdeStatus eStatus)  { return TRUE; }
//    BOOL fn_bAcceptModifTranslate   (CPA_List<CPA_SuperObject> *pListObjects, tdeStatus eStatus)  { return TRUE; }
//    BOOL fn_bAcceptModifRotate      (CPA_List<CPA_SuperObject> *pListObjects, tdeStatus eStatus)  { return TRUE; }
//    BOOL fn_bAcceptModifInsert      (CPA_SuperObject *pEdObj, CPA_SuperObject *pParent, tdeStatus eStatus) { return TRUE; }
//    BOOL fn_bAcceptModifScale       (CPA_SuperObject *pEdObj, tdeStatus eStatus) { return TRUE; }
//    BOOL fn_bAcceptModifName        (CPA_SuperObject *pEdObj, tdeStatus eStatus) { return TRUE; }
//    BOOL fn_bAcceptMultiSelect      (void)  { return TRUE; }

// to precise selection
//    tdeTypeAnswer fn_bAcceptSelect  (CPA_SuperObject *pEdObj, ACP_tdxIndex xIndex, HIE_tdstPickInfo *pPicking, tdeStatus eStatus) { return C_Accept; }

/*===========================================================================
	Current Editor
=========================================================================*/

	virtual tdePermission fn_eAcceptNewEditor	(CPA_EditorBase *pNewEditor)	 { return C_CloseBefore; }

	virtual BOOL fn_bCanActivateEditor	(CPA_List<CPA_BaseObject> *pParams) 
	{ 
		return
			#ifdef __INACTIVE_INTERFACE__
			FALSE
			#else
			!fn_bIsCurrentEditor();
			#endif
			;
	}
//    BOOL fn_bCanCloseEditor     (void)                                   { return TRUE; }

  virtual void fn_vOnActivateEditor (CPA_List<CPA_BaseObject> *pParams, BOOL bBackActivated=FALSE);
  void fn_vOnCloseEditor      (void);

//    CString GetCurrentEditorName (void) { return GetName(); }

//    void fn_vOnChangeCurrentEditor (CPA_DLLBase *pCurrentEditor, CPA_DLLBase *pNewEditor) { }

//    void fn_vBackActiveMe           (void *pMyData) { };
//    void fn_vEraseWalkDataStructure (void *pMyData) { };

/*===========================================================================
	General Purpose
=========================================================================*/

  virtual long OnQueryAction(CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM);
//    long OnQueryInfos   (CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM) { return 0; };
//    long OnQueryOpen    (CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM) { return 0; };
//    long OnQueryClose   (CPA_EditorBase * /*p_oSender*/, WPARAM, LPARAM) { return 0; };

/*===========================================================================
	Coherence
=========================================================================*/

  virtual void fn_vOnModifyChild(CPA_BaseObject *pOwner, CPA_BaseObject *pReferencedObject, unsigned long _ulData);
  virtual BOOL fn_bOnInvalidateLink(CPA_BaseObject *pOwner, CPA_BaseObject *pReferencedObject, BOOL bDestroyed);
  virtual void fn_vOnRestoreLink(CPA_BaseObject *pOwner, CPA_BaseObject *pReferencedObject);
};

extern tdstDLLIdentity g_stMaterialIdentity;


#define M_p_oGetEditManager() (((DEV_MultiDevice3D *) gs_p_oMaterialInterface->GetInterface()->GetMultiDevice())->GetEditManager())

void fn_vGiveProgressInfo(CString csMessage, long lPercentage, short _wHighLight = C_STATUS_NORMAL);
ACP_tdxIndex xGetPickInfoUnderPoint(HIE_aDEF_stTabOfPickInfo *_p_xRetrievedPickInfo, CPoint _oScreenCursor);

CPA_FileObject *p_oGetFileObjectForCompletePath(CString _csPath);
CPA_FileObject *p_oGetFileObjectForReferencedPath(CString _csPath, CString _csKey = C_szFileReferencedNameKey);

const char *fn_pszBaseName0(const char *_pszName);
//TODO: should be useless once textures have proper entries in the link tables
const char *fn_pszBaseName1(const char *_pszName);

#endif // ACTIVE_EDITOR
#endif // __MaterialINTERF_HPP__
