/*=============================================================================
 *
 *  Filename:						MatList.hpp
 *  Version:            1.0
 *  Date:								06/11/96
 *  Author:             V.L.
 *
 *  Description:				interface of MaterialList view
 *
 *===========================================================================*/

#ifndef __MATLIST_HPP__
#define __MATLIST_HPP__

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

#include <afxtempl.h>
#include <afxcview.h>

#include "Acp_base.h"
#include "itf.h"
#include "gmt.h"
//#include "Sort3Lst.hpp"
//#include "cpamdf.hpp"

class Material_Interface;
class tdoEditorGameMaterial;
class tdoEditorVisualMaterial;
class tdoDeleteEngineMechanicsModif;
class tdoDeleteEngineCollideModif;
class Geometry3D;

/*=============================================================================
* C3ListView : view that display a ThreeSortedList
=============================================================================*/

#define C_szNoBitmapName         "edt_data\\tools\\Material\\NoBitmap.bmp"
#define C_szUnviewableBitmapName "edt_data\\tools\\Material\\UnviewableBitmap.bmp"

class CMaterialListView : public C3ListView
{
	friend class Material_ApplyMaterialModif;
	friend class Material_CreateOrCopyMaterialModif;
	friend class Material_DestroyMaterialModif;

	DECLARE_DYNCREATE(CMaterialListView)

protected:
	Material_Interface	*m_p_oInterface;
	BOOL m_bDisplayAll;
	CBitmap m_oHatchBitmap;
	CBrush m_oHatchBrush;

public:
	CMaterialListView();
	~CMaterialListView();

	void m_fn_vSetInterface( Material_Interface *_p_oInterface){	m_p_oInterface = _p_oInterface;	}
	void m_fn_vChangeSelectedItemImage( int iImage );
	void m_fn_vRedrawSelectedItem(int iItem = -1);
	void m_vResetMaterialItemTexture(tdoEditorGameMaterial *_p_oGameMaterial);

	void m_fn_vSelectMaterial(tdoEditorGameMaterial *_p_oGameMaterial);
	int  m_fn_iFindMaterial(tdoEditorGameMaterial *_p_oGameMaterial);
	int  m_iGetTextureIndexForGameMaterial(tdoEditorGameMaterial *_p_oGameMaterial, BOOL _bLoadIfNotFound);
	void m_vAnalyzeAllMaterials();

	void m_fn_vCreateNewMaterial(tdoEditorGameMaterial *_p_oTemplateMaterial, CString _csName);
	void m_fn_vDeleteMaterial(tdoEditorGameMaterial *_p_oMaterialToDelete);
	void m_vBitmapListWasRefreshed(void);
	void m_vRefreshDisplayedMaterialList(BOOL _bAllMaterials, BOOL _bKillAll = FALSE);
	BOOL m_bAllMaterialsDisplayed() { return m_bDisplayAll; }
	void m_vSetMaterialDisplayFilter(BOOL _bFilter) { m_bDisplayAll = !_bFilter; }
	void m_vRememberSpecialImage(short _wImage) { m_wSpecialImage = _wImage; }
	void m_vApplyCurrentMaterialToObjectUnderCursor(HIE_tdstPickInfo *_p_stPickInfo);
	//so that the interface can fake a selection
	void OnSelectItem( short wCase );

protected:
	virtual void _OnCommand(short _wMenuId);
	virtual void _InitPopupMenu(CMenu &r_oMenu, short wFirstValue);
	virtual void m_fn_vOverriddenDrawItem(short wItem, CDC *pDC, RECT *rect);
	short m_wSpecialImage;

	// Generated message map functions
	//{{AFX_MSG(CMaterialListView)
	afx_msg void OnLButtonDown(UINT nFlags, CPoint pt );
	afx_msg int OnCreate( LPCREATESTRUCT );
	afx_msg void OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);
	afx_msg void OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags);
	//}}AFX_MSG

	DECLARE_MESSAGE_MAP()
};

class Material_ApplyMaterialModif : public CPA_Modif
{
public:
	Material_ApplyMaterialModif(HIE_tdstPickInfo &_r_a_stPickInfo);
	~Material_ApplyMaterialModif() {};
	BOOL Do();
	BOOL Undo();
	BOOL m_bDoIt(
		tdoEditorGameMaterial *m_p_oMaterialBeforeDo,
		tdoEditorGameMaterial *m_p_oMaterialAfterDo,
		BOOL _bSplitElement
	);

protected:
private:
	CMaterialListView *m_p_oMaterialListView;
	Geometry3D *m_p_oGeometry;
	ACP_tdxIndex m_xPickedElement, m_xIndexInElement;
	ACP_tdxIndex m_xElementFMD, m_xFaceFMD; //for IT to FMD face displacement
	BOOL m_bSwingFace; //for IT to FMD face displacement
	tdoEditorGameMaterial *m_p_oMaterialBeforeDo, *m_p_oMaterialAfterDo;
};

class Material_CreateOrCopyMaterialModif : public CPA_Modif
{
public:
	Material_CreateOrCopyMaterialModif(
		tdoEditorGameMaterial *_p_oTemplateMaterial,
		CString _csName
	);
	~Material_CreateOrCopyMaterialModif();
	BOOL Do();
	BOOL Undo();

protected:
private:
	Material_DestroyMaterialModif *m_p_oDestroyModif;
	CMaterialListView *m_p_oMaterialListView;
	GMT_tdxHandleToGameMaterial m_hTemplateMaterial;
	CString m_csNameToGive;
};

class Material_DestroyMaterialModif : public CPA_Modif
{
public:
	Material_DestroyMaterialModif(tdoEditorGameMaterial *_p_oDeletedGameMaterial);
	~Material_DestroyMaterialModif();
	BOOL Do();
	BOOL Undo();

protected:
private:
	BOOL m_bMaterialWasInList;
	CMaterialListView *m_p_oMaterialListView;
	tdoEditorGameMaterial *m_p_oDeletedGameMaterial;
	tdoEditorVisualMaterial *m_p_oDeletedVisualMaterial;
	//modifs to handle the destruction of the	referenced submaterials
	tdoDeleteEngineMechanicsModif *m_p_oDeleteEngineMechanicsModif;
	tdoDeleteEngineCollideModif *m_p_oDeleteEngineCollideModif;
	/*long m_lIndexBeforeDo;
	short m_wItemImageIndex;*/
};

#endif /* __MATLIST_HPP__ */
