// OpenFileTypeDlg.cpp : インプリメンテーション ファイル
//

#include "stdafx.h"
#include "DM2GDED.h"
#include "OpenFileTypeDlg.h"
#include "GDAT.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

COpenFileTypeDlg::OpenTbl COpenFileTypeDlg::m_tblOpen[] ={
	//                                 LE, L, P, S, 8, R
	{"DM2 PC",                          1, 0, 0, 1, 1, 0},
	{"DM2 PC v0.9 Beta",                1, 1, 1, 2 ,0, 1},
	{"DM2 Macintosh (Experimental)",    0, 0, 0, 1 ,1, 0},
	{"DM2 Amiga",                       0, 0, 0, 1 ,0, 1},
	{"DM2 Sega",                        0, 0, 2, 3 ,0, 1},
	{"DM2 PC98",                        1, 2, 0, 0 ,0, 0},
	{NULL,                              0, 0, 0, 0, 0, 0},
};

/////////////////////////////////////////////////////////////////////////////
// COpenFileTypeDlg ダイアログ

COpenFileTypeDlg::COpenFileTypeDlg(LPCTSTR pszFileIn, CWnd* pParent /*=NULL*/)
	: CDialog(COpenFileTypeDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(COpenFileTypeDlg)
	m_iLangSel = -1;
	m_iPlatformSel = -1;
	m_strFileIn = _T("");
	m_iSndSel = -1;
	m_iPalSel = -1;
	m_fUse8bpp = FALSE;
	m_fRestrictPal = FALSE;
	//}}AFX_DATA_INIT

	m_strFileIn = pszFileIn;
}


void COpenFileTypeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COpenFileTypeDlg)
	DDX_Control(pDX, IDC_COMBO_PLATFORM, m_wndPlatform);
	DDX_CBIndex(pDX, IDC_COMBO_LANG, m_iLangSel);
	DDX_CBIndex(pDX, IDC_COMBO_PLATFORM, m_iPlatformSel);
	DDX_Text(pDX, IDC_EDIT_FILEIN, m_strFileIn);
	DDX_CBIndex(pDX, IDC_COMBO_SND, m_iSndSel);
	DDX_CBIndex(pDX, IDC_COMBO_PAL, m_iPalSel);
	DDX_Check(pDX, IDC_CHECK_SUPPORT_8BPP, m_fUse8bpp);
	DDX_Check(pDX, IDC_CHECK_FREEDOM_PALETTE, m_fRestrictPal);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(COpenFileTypeDlg, CDialog)
	//{{AFX_MSG_MAP(COpenFileTypeDlg)
	ON_CBN_SELCHANGE(IDC_COMBO_PLATFORM, OnSelchangeComboPlatform)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COpenFileTypeDlg メッセージ ハンドラ

void COpenFileTypeDlg::OnSelchangeComboPlatform() 
{
	if (!UpdateData()) return;

	int i = m_iPlatformSel;
	OpenTbl *pTbl = m_tblOpen;
	while (pTbl->pszName != NULL && i != 0) i--, pTbl++;

//	m_iEndianSel = pTbl->fLE ? 0 : 1;
	m_iLangSel = pTbl->iLang;
//	m_fTraditional = pTbl->fTraditional;
	m_iSndSel = pTbl->iSnd;
//	m_fPalIndependent = pTbl->fPaletteIndependent;
	m_iPalSel = pTbl->iPal;
	m_fUse8bpp = pTbl->fUse8bpp;
	m_fRestrictPal = pTbl->fRestrictPal;

	UpdateData(FALSE);
	
}

UINT COpenFileTypeDlg::GetGDOF()
{
	return 0
//		|((m_iEndianSel == 0) ? GDFF_LITTLE_ENDIAN : 0)
		|((m_iLangSel == 0) ? GDFF_LANG_EN_ENC : 0)
		|((m_iLangSel == 1) ? GDFF_LANG_EN : 0)
		|((m_iLangSel == 2) ? GDFF_LANG_JP_ENC : 0)
		|((m_iSndSel == 1) ? GDFF_SND5SND6 : 0)
		|((m_iSndSel == 2) ? GDFF_SND3 : 0)
		|((m_iSndSel == 3) ? GDFF_SND7 : 0)
		|((m_iPalSel == 0) ? GDFF_PAL_IMAGE : 0)
		|((m_iPalSel == 1) ? GDFF_PAL_RAW : 0)
		|((m_iPalSel == 2) ? GDFF_PAL_SCENE : 0)
		|((m_fUse8bpp) ? GDFF_USE_8BPP : 0)
		|((m_fRestrictPal) ? GDFF_RESTRICT_PAL : 0)
		;
}

void COpenFileTypeDlg::OnOK() 
{
	if (!UpdateData()) return;

	if (GetACP() != 932 && m_iLangSel == 2) {
		int r = AfxMessageBox(IDS_WARN_NOT_CP932, MB_RETRYCANCEL|MB_ICONEXCLAMATION);
		if (r != IDRETRY) return;
	}
	
	CDialog::OnOK();
}

BOOL COpenFileTypeDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	UINT i;
	for (i = 0; m_tblOpen[i].pszName != NULL; i++) {
		m_wndPlatform.AddString(m_tblOpen[i].pszName);
	}
	
	return TRUE;  // コントロールにフォーカスを設定しないとき、戻り値は TRUE となります
	              // 例外: OCX プロパティ ページの戻り値は FALSE となります
}
