// TNPanel.cpp : implementation file
//

#include "stdafx.h"
#include "mw4gameed2.h"
#include "TNPanel.h"
#include "EdGUIObject.h"
#include "UndoManager.h"
#include "ObjProps.h"
#include "ObjProps.h"



/////////////////////////////////////////////////////////////////////////////
// CTNPanel dialog
CTNPanel::CTNPanel(EdGUIObject *gobj,UndoCommand **cmd,CWnd* pParent /*=NULL*/)
: CPanelDlg(CTNPanel::IDD, pParent)
{
	MyObj=gobj;
	CmdLst=cmd;
	MyMultiProps=NULL;
	//{{AFX_DATA_INIT(GUIObjPanel)
	m_Name = _T("");
	m_ObjType = _T("");
	m_UseInGame = false;
	//}}AFX_DATA_INIT
}

CTNPanel::CTNPanel(CObjProps *gobj,CWnd* pParent): CPanelDlg(CTNPanel::IDD, pParent)   // standard constructor
{
	MyMultiProps=gobj;
	MyObj=NULL;
	CmdLst=NULL;
	m_Name = _T("");
	m_ObjType = _T("");
	m_UseInGame = false;


}


void CTNPanel::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTNPanel)
	DDX_Text(pDX, IDC_NAME, m_Name);
	DDX_Text(pDX, IDC_OBJTYPE, m_ObjType);
	DDX_Check(pDX, IDC_USEINGAME, m_UseInGame);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CTNPanel, CPanelDlg)
	//{{AFX_MSG_MAP(CTNPanel)
	ON_EN_CHANGE(IDC_NAME, OnChangeName)
	ON_BN_CLICKED(IDC_USEINGAME, OnUseingame)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTNPanel message handlers


BOOL CTNPanel::OnInitDialog() 
{
	CPanelDlg::OnInitDialog();
	
	Verify(!(MyMultiProps && MyObj));
	if(MyMultiProps==NULL)
	{
		m_Name=MyObj->GetName();
		m_ObjType=MyObj->GetTypeName();
		m_UseInGame = MyObj->HasLocalizedName();

	}
	else
	{
		m_Name=MyMultiProps->GetName();
		m_UseInGame=MyMultiProps->GetUseInGame();
		m_ObjType="Multiple Objects";
	}
	
	UpdateData(FALSE);
	NameChange=false;
	UIGChange=false;

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

void CTNPanel::OnChangeName() 
{
	NameChange=true;
	
}

void CTNPanel::OnOK() 
{
	UpdateData(TRUE);
	
	Verify(!(MyMultiProps && MyObj));
	if(MyMultiProps!=NULL)
	{
		
		if(NameChange)		MyMultiProps->SetName(m_Name);
		if(UIGChange)		MyMultiProps->SetUseInGame(m_UseInGame?true:false);
		
	}
	else
	{
		UndoCommand *cmd=new RenameCommand(MyObj);
		MyObj->SetName(m_Name);
		MyObj->UseLocalizedName(m_UseInGame?true:false);
		if(*CmdLst==NULL)
		{
			*CmdLst=cmd;
		}
		else
		{
			(*CmdLst)->Attach(cmd);
		}
	}
	//CPanelDlg::OnOK();
}

void CTNPanel::OnUseingame() 
{
	 UIGChange=true;
	
}
