/*=========================================================================
*
* DlgMain.h	- Header file for main window class
*
* Version			1.0
* Revision date
*
*=======================================================================*/
#ifndef __DLGMAIN_H__ 
#define __DLGMAIN_H__

//--- Includes --------------------------------------------------------

#include <shlobj.h>

#include "Resource.h"

#include "GIType.h"


//--- Global --------------------------------------------------------

extern int  g_iResultIndex[100];
extern int  g_iCommandIndex[1000];

extern char g_szInitialDirectory[_MAX_PATH];

extern int  g_iNbConfDirs;
extern char g_szConfDirs[20][20];

extern int	g_iNbConfOptions;
extern char g_szConfOptions[20][20];

extern int	g_iNbConfSelects;
extern char g_szConfSelects[20][20];

extern char g_szAnimsObj[25][256];
extern char g_szBanksObj[25][256];
extern char g_szLevelsObj[25][256];
extern char g_szClassesObj[25][256];
extern char g_szFamiliesObj[25][256];
extern char g_szTexturesObj[25][256];

extern int  g_iNbAnimsObj;
extern int  g_iNbBanksObj;
extern int  g_iNbLevelsObj;
extern int  g_iNbClassesObj;
extern int  g_iNbFamiliesObj;
extern int  g_iNbTexturesObj;

extern BOOL g_bChangeComboDir;
extern int g_iCurrentIndexDir;

extern BOOL g_bChangeComboOption;
extern int g_iCurrentIndexOption;

extern BOOL g_bChangeComboSelect;
extern int g_iCurrentIndexSelect;

extern char g_szDirConfig[256];
extern char g_szSelectConfig[256];
extern char g_szOptionConfig[256];

extern char	g_szRayman2[_MAX_PATH];
extern char	g_szModifLst[_MAX_PATH];
extern char	g_szEraseMdf[_MAX_PATH];
extern char	g_szIgnoreZoo[_MAX_PATH];
extern char	g_szIgnoreSct[_MAX_PATH];
extern char	g_szIgnoreSpo[_MAX_PATH];
extern char	g_szIgnoreGmt[_MAX_PATH];
extern char	g_szIgnoreVmt[_MAX_PATH];
extern char	g_szCopyAnims[_MAX_PATH];
extern char	g_szCopyTextures[_MAX_PATH];
extern char	g_szGenerateRLI[_MAX_PATH];
extern char	g_szUpdateGameDSC[_MAX_PATH];
extern char	g_szEraseDuplicated[_MAX_PATH];
extern char	g_szEraseUnused[_MAX_PATH];
extern char	g_szForceCommon[_MAX_PATH];
extern char	g_szForceSpecific[_MAX_PATH];
extern char g_szCreateBasicFamily[_MAX_PATH];

//--- Functions --------------------------------------------------------

extern LRESULT CALLBACK Command(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);

extern void MLT_vSetDataSpecific1	();
extern void MLT_vSetDataSpecific2	();

/*
 =======================================================================================
	CDlgMain dialog class
 =======================================================================================
 */

class CDlgMain : public CDialog
{
public:

	// lists
	CListBox	*m_oListType;			
	CListBox	*m_oListObject;	

	// command window
	CRichEditCtrl	m_oRichEditCom;				
	CHARFORMAT		m_stCharFormatCom;

	// result window
	CRichEditCtrl	m_oRichEditRes;				
	CHARFORMAT		m_stCharFormatRes;
	
	// the possible types in the first list box
	GI_Type		*m_p_oTypeAnims;		
	GI_Type		*m_p_oTypeBanks;		
	GI_Type		*m_p_oTypeClasses;
	GI_Type		*m_p_oTypeFamilies;
	GI_Type		*m_p_oTypeLevels;
	GI_Type		*m_p_oTypeTextures;

	// the number of all selections in all list associated with the types
	int			m_iCountOfSelections;	
	int			m_iInd; 

	// used for displaying a cross in front of an active object in the second list
	BOOL		m_bFirstShow;			
	CDC			m_oCrossDC;
	CBitmap		m_oCrossBitmap;

	BOOL		m_bConversion;
	BOOL		m_bInit;					
	BOOL		m_bRun;
    
	int			m_nIndexLast;

	CStatic     m_oVersion;


	// window controls for resizing 

// FIRST PANEL
	
	UINT			m_a_uiGroupButtons[5];		
	char			m_cNbGroupButtons;

	UINT			m_a_uiEditControls[6];		
	char			m_cNbEditControls;

	UINT			m_a_uiEditNameControls[4];		
	char			m_cNbEditNameControls;

	UINT			m_a_uiBrowseButtons[12];		
	char			m_cNbBrowseButtons;

	UINT			m_a_uiCustomConfigControls[7];		
	char			m_cNbCustomConfigControls;

	UINT			m_a_uiCustomStaticControls[6];		
	char			m_cNbCustomStaticControls;

	UINT			m_a_uiCustomEditControls[6];		
	char			m_cNbCustomEditControls;

	UINT			m_a_uiMainButtons[3];		
	char			m_cNbMainButtons;

// SECOND PANEL
	
	UINT			m_a_uiSelectButtons[2];		
	char			m_cNbSelectButtons;

	UINT			m_a_uiClearButtons[2];		
	char			m_cNbClearButtons;

	UINT			m_a_uiSelectConfigButtons[7];		
	char			m_cNbSelectConfigButtons;

	UINT			m_a_uiConflictStaticButtons[5];		
	char			m_cNbConflictStaticButtons;

	UINT			m_a_uiConflictMaxButtons[5];		
	char			m_cNbConflictMaxButtons;

	UINT			m_a_uiConflictEdsButtons[5];		
	char			m_cNbConflictEdsButtons;

	UINT			m_a_uiOptionButtons[5];		
	char			m_cNbOptionButtons;

	UINT			m_a_uiEraseButtons[2];		
	char			m_cNbEraseButtons;

	UINT			m_a_uiFamilyButtons[3];			
	char			m_cNbFamilyButtons;

	UINT			m_a_uiOptionConfig[7];
	char			m_cNbOptionConfig;


// Construction
public:
	CDlgMain(CWnd* pParent = NULL);			
	~CDlgMain();							

// Dialog Data
	//{{AFX_DATA(CDlgMain)
	enum { IDD = IDD_DIALOGMAIN };

	// panels
	CTabCtrl	m_oMainPanel;				
	CTabCtrl	m_oConfigPanel;
	
	// directory configs
	CEdit		m_oEditRegisterDir;				
	CEdit		m_oEditCreateDir;				
	CButton		m_oButtonRegisterDir;
	CButton		m_oButtonCreateDir;
	CButton		m_oButtonDeleteDir;
	CButton		m_oButtonSaveDir;
	CComboBox	m_oComboChooseDir;

	// rawdata
	CButton		m_oCheckRawData;
	CButton		m_oCheckRawSP1;
	CButton		m_oCheckRawSP2;
	CEdit		m_oEditRawSp1;				
	CEdit		m_oEditRawSp2;				
	// gamedata
	CButton		m_oCheckGameData;
	CButton		m_oCheckGameSP1;
	CButton		m_oCheckGameSP2;
	CEdit		m_oEditGameSp1;				
	CEdit		m_oEditGameSp2;				
	// main options
	CButton		m_oCheckRayman2;
	CButton		m_oCheckModifLst;
	CButton		m_oCheckEraseMdf;

	// selection buttons
	CButton		m_oSelectList;
	CButton		m_oSelectAll;
	CButton		m_oClearList;
	CButton		m_oClearAll;
	// select configs buttons
	CEdit		m_oEditCreateSelect;				
	CEdit		m_oEditRegisterSelect;				
	CButton		m_oButtonRegisterSelect;
	CButton		m_oButtonCreateSelect;
	CButton		m_oButtonDeleteSelect;
	CButton		m_oButtonSaveSelect;
	CComboBox	m_oComboChooseSelect;
	// conflict options
	CButton		m_oCheckZooMax;
	CButton		m_oCheckSctMax;
	CButton		m_oCheckSpoMax;
	CButton		m_oCheckGmtMax;
	CButton		m_oCheckVmtMax;
	CButton		m_oCheckZooEds;
	CButton		m_oCheckSctEds;
	CButton		m_oCheckSpoEds;
	CButton		m_oCheckGmtEds;
	CButton		m_oCheckVmtEds;
	// conversion options
	CButton		m_oCheckCopyAnims;
	CButton		m_oCheckCopyTextures;
	CButton		m_oCheckGenerateRLI;
	CButton		m_oCheckUpdateGameDsc;
	// erase options
	CButton		m_oCheckEraseDup;
	CButton		m_oCheckEraseUnused;
	// family options
	CButton		m_oCheckAskFamily;
	CButton		m_oCheckCommon;
	CButton		m_oCheckSpecific;
	// bank options
	CButton		m_oCheckCreateFamily;

	// options configs
	CEdit		m_oEditCreateOption;				
	CEdit		m_oEditRegisterOption;				
	CButton		m_oButtonRegisterOption;
	CButton		m_oButtonCreateOption;
	CButton		m_oButtonDeleteOption;
	CButton		m_oButtonSaveOption;
	CComboBox	m_oComboChooseOption;

	// convert button
	CButton		m_oConvert;

	// progress bar
	CProgressCtrl	m_oProgress;


	//}}AFX_DATA


public:

//==============================================================================================================
//			DlgMain2.cpp : Main conversion functions
//==============================================================================================================
	
	// main function
	void m_fn_vConvertData();
	
	// command line
	void m_fn_vBuildCommandLine		(char *szCommand);

	// convert for each type
	void m_fn_vConvertAnimations	(char *sGameDir, char *sRaw, char *sGame, int *j, int *l);
	void m_fn_vConvertBanks			(char *sGameDir, char *sRaw, char *sGame, int *j, int *l);
	void m_fn_vConvertClasses		(char *sGameDir, char *sRaw, char *sGame, int *j, int *l);
	void m_fn_vConvertFamilies		(char *sGameDir, char *sRaw, char *sGame, int *j, int *l);
	void m_fn_vConvertLevels		(char *sGameDir, char *sRaw, char *sGame, int *j, int *l);
	void m_fn_vConvertTextures		(char *sGameDir, char *sRaw, char *sGame, int *j, int *l);

	// family conversion
	void m_fn_vPrepareCommonFamily		(BOOL bForce, char sFile1[40][_MAX_PATH], BOOL *bContinue, int iIndex, int iProgress);
	void m_fn_vPrepareSpecificFamily	(BOOL bForce, char sFile1[40][_MAX_PATH], BOOL *bContinue, int iIndex);

	// level conversion
	void m_fn_vUpdateGameDSC			(void);


	static UINT ms_fn_vConvertData( void* ptr)
	{
		((CDlgMain*)ptr)->m_fn_vConvertData();
		return 0;
	};

	// init all options
	void m_fn_vInitAllOptions (char *p_szCommanLine, char *szAnims, char *szBanks, char *szClasses, char *szFamilies, char *szLevels, char *szTextures);
	

//==============================================================================================================
//			DlgMain3.cpp : Dialog management functions
//==============================================================================================================

	// warnings
	BOOL m_fn_vTestIniDatas			();
	BOOL m_fn_bWarningUser			();
	void m_fn_vShowPartialWarning	(BOOL bSet, char *szPath, char *_szMessage, BOOL * bDisplay, int iID, char *szDir);

	// show controls according to main panel
	void m_fn_TabC_vShowControlsPanelDir () ;
	void m_fn_TabC_vShowControlsPanelSel () ;
	void m_fn_TabC_vShowControlsPanelRes () ;
	// Show or hide the buttons in the main panel 
	void m_fn_TabC_vChangeShowControlsPanelDir (BOOL bChange) ;
	void m_fn_TabC_vChangeShowControlsPanelSel (BOOL bChange) ;
	void m_fn_TabC_vChangeShowControlsPanelRes (BOOL bChange) ;
	// disable or enable buttons 
	void m_fn_TabC_vEnableButtons		() ;
    void m_fn_TabC_vDisableAllButtons	(); 
	void m_fn_TabC_vDisableSelButtons	();

	// show controls acording to config panel
	void m_fn_vShowControlsPanelCustom	();
	void m_fn_vShowControlsPanelCurrent	();
	// show or hide the buttons in the config panel
	void m_fn_vChangeShowControlsPanelCurrent	(BOOL bChange);
	void m_fn_vChangeShowControlsPanelCustom	(BOOL bChange);

	// browse functions
	void m_fn_vBrowseStartingFromDirectory	(char *szPath, int *iResult) ;
	void m_fn_vBrowseDirectory				(char* szPath, int *p_iResult, ITEMIDLIST *p_stItemRoot);

	// search for directories or and files
	BOOL m_fn_bExistDirectories	(char *szPath);
	BOOL m_fn_bGetFiles			(char *szFile, HANDLE *hHandle, WIN32_FIND_DATA *stFindFileData);
	
	// get available types and data
	void m_fn_vGetAllTypes			();
	void m_fn_vGetDatas				(char *szType, char *szPath);
	void m_fn_vGetSetDatasInList	(char *szAnims, char *szBanks, char *szClasses, char *szFamilies, char *szLevels,  char *szTextures);
	
	// create lists
	int  m_fn_iAddTestDirType	(char *szFiles);
	void m_fn_vCreateLists		(CList<GI_Item *,GI_Item *> *_oListObject, char *szPath, char *szType, GI_Item * _p_oItem);
	void m_fn_vSetTypeInList	(GI_Type ** _p_oType, char *szType, int iNumber);
	void m_fn_vAddType			(GI_Type * p_oType, char *szReturn, char *szType, char *szDir, int *iNumber);

	void m_fn_vAddAnim			(void);
	void m_fn_vAddAnims			(void);
	void m_fn_vAddBank			(void);
	void m_fn_vAddBanks			(void);
	void m_fn_vAddClass			(void);
	void m_fn_vAddClasses		(void);
	void m_fn_vAddFamily		(void);
	void m_fn_vAddFamilies		(void);
	void m_fn_vAddLevel			(void);
	void m_fn_vAddLevels		(void);
	void m_fn_vAddTexture		(void);
	void m_fn_vAddTextures		(void);

	// return the total number of objects in all lists
	int  m_fn_iGetAllObjects();

	// update list boxes
	void m_fn_vUpdateListBox	(CList<GI_Item *,GI_Item *> *_oListObject, char *szPath, char *szType);
	void m_fn_vUpdateAll		();
	
	// draw items in list boxes
	void m_fn_vOnDrawItemListBoxType	(LPDRAWITEMSTRUCT lpDIS);
	void m_fn_vOnDrawItemListBoxObject	(LPDRAWITEMSTRUCT lpDIS);

	// selection
	BOOL m_fn_bOnChangeActivation	(GI_Item *_p_oItem, int iIndexItem);
	void m_fn_vChange				(GI_Item *p_oItem, GI_Type *p_oType, BOOL bSet);

	// selection of the items 
	void m_fn_vResetSelection	();
	void m_fn_vSelectAll		(BOOL bSet) ;
	void m_fn_vSelectAllForType	(BOOL bSet);
	void m_fn_vSelectAllInList	(GI_Type * _p_oType, BOOL bSet) ;

	// enable/disable buttons in the second panel 
	void m_fn_vEnableButtons		(BOOL bSet) ;
	void m_fn_vEnableButtonAll		();
	void m_fn_vEnableButtonConvert	();

	// options
	void m_fn_vSetOptions			();
	void m_fn_vChangeCheck			(int iId, int iId1, BOOL *bChange);
	void m_fn_vChangeCheckButton	(int iId, BOOL *bChange);

	// free allocated memory
	void m_fn_vFreeMemory			();
	void m_fn_vFreeMemoryForType	(GI_Type **_p_oType) ;

	// read from the rich edit and write in the file Win_M23D.log
	int m_fn_vWriteInFile	(BOOL bTest);

	// use file lists
	void m_fn_vReadIniFile		(char *szName, GI_Type *p_oType, BOOL bTwo);
	BOOL m_fn_bSearchInFile		(char *szName, char *szObject) ;
	void m_fn_vSetFromFileList	(char *szName, char *szObject);
	void m_fn_vSelectDir		(char *sDir, char *szName);


//==============================================================================================================
//			DlgMain4.cpp : Configuration functions
//==============================================================================================================

	// directories configs
	void m_fn_vInitDirCombo			();
	void m_fn_vSetDefaultDirConfig	();
	void m_fn_vUpdateForDirConfig	();
	void m_fn_vUpdateDirectories	();
	void m_fn_vRegisterAllPaths		(int iNumConfig);

	// selections configs
	void m_fn_vInitSelectCombo			();
	void m_fn_vSetDefaultSelectConfig	();
	void m_fn_vUpdateForSelectConfig	();
	void m_fn_vUpdateSelectLists		();
	void m_fn_vUpdateSelections			();
	void m_fn_vRegisterSelections		(int iNumConfig);
	void m_fn_vUpdateSelectListForType	(char *szType, char *szObjects, int  *iNbObjects);
	void m_fn_vUpdateSelectionForType	(char *szType, int g_iNb );
	void m_fn_vRegisterSelectionForType	(char *szName, char *szType); 
	void m_fn_vReadCurrentSelection		(); 

	// directories configs
	void m_fn_vInitOptionCombo			();
	void m_fn_vSetDefaultOptionConfig	();
	void m_fn_vUpdateForOptionConfig	();
	void m_fn_vRegisterAllOptions		(int iNumConfig);


// Implementation
protected:

//==============================================================================================================
//			DlgMain.cpp : Main Dialog functions
//==============================================================================================================

	// Generated virtual function overrides
	//{{AFX_VIRTUAL(CDlgMain)
	virtual BOOL PreTranslateMessage(MSG* pMsg);
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
	//}}AFX_VIRTUAL

	// Generated message map functions
	//{{AFX_MSG(CDlgMain)
	// main functions
	afx_msg BOOL OnInitDialog();
	afx_msg void OnPaint();
	afx_msg void OnSize(UINT nType, int cx, int cy);
	afx_msg void OnSizing(UINT nSide, LPRECT lpRect);
	afx_msg void OnDestroy();
	afx_msg void OnClose();
	afx_msg void OnQuit();

//==============================================================================================================
//			DlgMain1.cpp : Main Dialog functions
//==============================================================================================================

	// help
	afx_msg void OnCheckHelp();
	afx_msg void OnHelp();
	afx_msg BOOL OnHelpInfo(HELPINFO* pHelpInfo) ;

	// change panel
	afx_msg void OnSelchangePanel(NMHDR* pNMHDR, LRESULT* pResult);
	afx_msg void OnSelchangeTab(NMHDR* pNMHDR, LRESULT* pResult);

	// rename directories
	afx_msg void OnKillFocusGameSpecific1();
	afx_msg void OnKillFocusGameSpecific2();
	afx_msg void OnKillFocusRawSpecific1();
	afx_msg void OnKillFocusRawSpecific2();
	// choose directories
	afx_msg void OnCheckGameData();
	afx_msg void OnCheckGameSpecific1();
	afx_msg void OnCheckGameSpecific2();
	afx_msg void OnCheckRawData();
	afx_msg void OnCheckRawSpecific1();
	afx_msg void OnCheckRawSpecific2();
	// browse directories
	afx_msg void OnButtonBrowseGameData();
	afx_msg void OnButtonBrowseGameSpecific1();
	afx_msg void OnButtonBrowseGameSpecific2();
	afx_msg void OnButtonBrowseRawData();
	afx_msg void OnButtonBrowseRawSpecific1();
	afx_msg void OnButtonBrowseRawSpecific2();

	// directory configuration 
	afx_msg void OnCreateConfigDir();
	afx_msg void OnRegisterConfigDir();
	afx_msg void OnSaveConfigDir();
	afx_msg void OnDeleteConfigDir();
	afx_msg void OnChooseConfigDir();
	afx_msg void OnKillFocusEditCreateConfigDir();
	afx_msg void OnKillFocusEditRegisterConfigDir();
	afx_msg void OnKillFocusComboChooseConfigDir();

	// browse custom directories
	afx_msg void OnButtonBrowseAnims();
	afx_msg void OnButtonBrowseBanks();
	afx_msg void OnButtonBrowseClasses();
	afx_msg void OnButtonBrowseFamilies();
	afx_msg void OnButtonBrowseLevels();
	afx_msg void OnButtonBrowseTextures();

	// main options
	afx_msg void OnRayman2();
	afx_msg void OnModifLst();
	afx_msg void OnEraseMdf();

	// listbox functions
	afx_msg void OnSelchangeListType();
	afx_msg BOOL OnLButtonDownListBoxObject(MSG *pMsg);
	afx_msg void OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDIS);
	afx_msg void OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct) ;

	// selection buttons
	afx_msg void OnSelectAll();
	afx_msg void OnSelectList();
	afx_msg void OnClearList();
	afx_msg void OnClearAll();
	// select config buttons
	afx_msg void OnCreateConfigSelect();
	afx_msg void OnRegisterConfigSelect();
	afx_msg void OnSaveConfigSelect();
	afx_msg void OnChooseConfigSelect();
	afx_msg void OnDeleteConfigSelect();
	afx_msg void OnKillFocusEditCreateConfigSelect();
	afx_msg void OnKillFocusEditRegisterConfigSelect();
	afx_msg void OnKillFocusComboChooseConfigSelect();

	// convert button
	afx_msg void OnConvert();

	// ignore options
	afx_msg void OnCheckZooMax();
	afx_msg void OnCheckZooEds();
	afx_msg void OnCheckSctMax();
	afx_msg void OnCheckSctEds();
	afx_msg void OnCheckSpoMax();
	afx_msg void OnCheckSpoEds();
	afx_msg void OnCheckVmtMax();
	afx_msg void OnCheckVmtEds();
	afx_msg void OnCheckGmtMax();
	afx_msg void OnCheckGmtEds();
	// conversion options
	afx_msg void OnCopyAnims();
	afx_msg void OnCopyTextures();
	afx_msg void OnGenerateRLI();
	afx_msg void OnUpdateGameDSC();
	// erase options
	afx_msg void OnEraseDuplicated();
	afx_msg void OnEraseUnused();
	// family options
	afx_msg void OnForceCommon();
	afx_msg void OnForceSpecific();
	afx_msg void OnAskFamily();
	// bank option
	afx_msg void OnCreateBasicFamily();

	// option configuration
	afx_msg void OnCreateConfigOption();
	afx_msg void OnRegisterConfigOption();
	afx_msg void OnSaveConfigOption();
	afx_msg void OnChooseConfigOption();
	afx_msg void OnDeleteConfigOption();
	afx_msg void OnKillFocusEditCreateConfigOption();
	afx_msg void OnKillFocusEditRegisterConfigOption();
	afx_msg void OnKillFocusComboChooseConfigOption();

	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Developer Studio will insert additional declarations immediately before the previous line.

#endif //__DLGMAIN_H__
