// ScriptParamDlg.cpp : implementation file
//

#include "stdafx.h"
#include "mw4gameed2.h"
#include "ScriptParamDlg.h"
#include "EdScript.h"



/////////////////////////////////////////////////////////////////////////////
// CScriptParamDlg dialog


CScriptParamDlg::CScriptParamDlg(EdScript *script,CWnd* pParent /*=NULL*/)
	: CPanelHolderDlg(CScriptParamDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScriptParamDlg)
	//}}AFX_DATA_INIT
	LMode=PDL_FIXHOR;
	BuildFromScript(script);
}


void CScriptParamDlg::DoDataExchange(CDataExchange* pDX)
{
	CPanelHolderDlg::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScriptParamDlg)
	DDX_Control(pDX, IDOK, m_OKBut);
	DDX_Control(pDX, IDCANCEL, m_CancelBut);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CScriptParamDlg, CPanelHolderDlg)
	//{{AFX_MSG_MAP(CScriptParamDlg)
	ON_WM_CREATE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScriptParamDlg message handlers


int CScriptParamDlg::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CPanelHolderDlg::OnCreate(lpCreateStruct) == -1)
		return -1;
	

	// TODO: Add your specialized creation code here
	
	return 0;
}

BOOL CScriptParamDlg::OnInitDialog() 
{
	CPanelHolderDlg::OnInitDialog();
	

	//Resize Windows for Buttons;
	int ysize;
	CRect okrct,canrct,rct;
	m_OKBut.GetWindowRect(&okrct);
	ScreenToClient(&okrct);
	m_CancelBut.GetWindowRect(&canrct);
	ScreenToClient(&canrct);
	ysize=okrct.Height()<canrct.Height()?okrct.Height():canrct.Height();

	GetWindowRect(&rct);
	SetWindowPos(NULL,-1,-1,rct.Width(),rct.Height()+10+ysize,SWP_NOMOVE|SWP_NOZORDER);

	m_OKBut.SetWindowPos(NULL,okrct.left,rct.Height()-GetSystemMetrics(SM_CYCAPTION),-1,-1,SWP_NOSIZE|SWP_NOZORDER);
	m_CancelBut.SetWindowPos(NULL,rct.Width()-(canrct.Width()+20),rct.Height()-GetSystemMetrics(SM_CYCAPTION),-1,-1,SWP_NOSIZE|SWP_NOZORDER);

	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}


void CScriptParamDlg::AddField(ScriptField *field)
{
	switch(field->Type)
	{
		case ScriptField::INTDATA:
		AddIntField(&(field->IntData),field->Name);
		break;
		case ScriptField::TEXTDATA:
		AddTextEditField(&(field->Value),field->Name);
		break;
		case ScriptField::STATICTEXT:
		AddStaticTextField(field->Name);
		break;
		case ScriptField::FLOATDATA:
		AddFloatField(&(field->FloatData),field->Name);
		break;
	}

}

void CScriptParamDlg::BuildFromScript(EdScript *script)
{
int i;
for(i=0;i<script->TotFields;i++)
	{
	AddField(&(script->Fields[i]));
	}
}
