// ObjectEdit.cpp : implementation file
//

#include "stdafx.h"
#include "mapeditor.h"
#include "ObjectEdit.h"

#include "MainFrm.h"
#include "MapEditor.h"
#include "MapEditorDoc.h"
#include "MapEditorView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CObjectEdit dialog


CObjectEdit::CObjectEdit(CWnd* pParent /*=NULL*/)
	: CDialog(CObjectEdit::IDD, pParent)
{
	//{{AFX_DATA_INIT(CObjectEdit)
	m_dwNewObjType = 0;
	m_dwOldObjType = 0;
	//}}AFX_DATA_INIT
}


void CObjectEdit::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CObjectEdit)
	DDX_Text(pDX, IDC_EDIT_NEW_OBJTYPE, m_dwNewObjType);
	DDX_Text(pDX, IDC_EDIT_OLD_OBJTYPE, m_dwOldObjType);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CObjectEdit, CDialog)
	//{{AFX_MSG_MAP(CObjectEdit)
	ON_EN_CHANGE(IDC_EDIT_NEW_OBJTYPE, OnChangeEditNewObjtype)
	ON_EN_CHANGE(IDC_EDIT_OLD_OBJTYPE, OnChangeEditOldObjtype)
	ON_BN_CLICKED(IDC_BUTTON_OBJUPDATE, OnButtonObjupdate)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CObjectEdit message handlers

void CObjectEdit::OnChangeEditNewObjtype() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CObjectEdit::OnChangeEditOldObjtype() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData();
}

void CObjectEdit::OnButtonObjupdate() 
{
	// TODO: Add your control notification handler code here
	CMainFrame* pFrame = (CMainFrame*)AfxGetMainWnd();
	CMapEditorView* pView = (CMapEditorView*)pFrame->GetActiveView();

	map<INT,CAtumNode *>::iterator it = pView->m_pBackground->m_mapObjectData.begin();
	while(it != pView->m_pBackground->m_mapObjectData.end())
	{
		CObjectChild * pObject = (CObjectChild *)it->second->m_pChild;
		while(pObject)
		{
			if(pObject->m_dwPartType == m_dwOldObjType)
				pObject->m_dwPartType = m_dwNewObjType;
			pObject = (CObjectChild *)pObject->m_pNext;
		}
		it++;
	}
}
