⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 laomapedtdoc.cpp

📁 RPG四大编辑器:场景/道具/角色/地图四大编辑器源代码 vc++ 6.0
💻 CPP
字号:
// LaoMapEdtDoc.cpp : implementation of the CLaoMapEdtDoc class
//

#include "stdafx.h"
#include "LaoMapEdt.h"

#include "LaoMapEdtDoc.h"
#include "LaoMapEdtView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CLaoMapEdtDoc

IMPLEMENT_DYNCREATE(CLaoMapEdtDoc, CDocument)

BEGIN_MESSAGE_MAP(CLaoMapEdtDoc, CDocument)
	//{{AFX_MSG_MAP(CLaoMapEdtDoc)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CLaoMapEdtDoc construction/destruction

CLaoMapEdtDoc::CLaoMapEdtDoc()
{
	// TODO: add one-time construction code here

}

CLaoMapEdtDoc::~CLaoMapEdtDoc()
{
}

BOOL CLaoMapEdtDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)
	POSITION pos = GetFirstViewPosition();
	CLaoMapEdtView *pView = (CLaoMapEdtView*)GetNextView(pos);
	pView->m_csPicName.Empty();
	
	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CLaoMapEdtDoc serialization

void CLaoMapEdtDoc::Serialize(CArchive& ar)
{
	POSITION pos = GetFirstViewPosition();
	CLaoMapEdtView *pView = (CLaoMapEdtView*)GetNextView(pos);
	char *cTitle = "GMAP";
	DWORD dwVer = 0x0101;
	char cPicName[32];
	ZeroMemory(cPicName, 32);
	strncpy(cPicName, pView->m_csPicName.GetBuffer(pView->m_csPicName.GetLength()),31);

	if(ar.IsStoring())
	{
		// TODO: add storing code here
		ar.Write(cTitle, 4/*strlen(cTitle)*/);
		ar.Write(&dwVer, sizeof(DWORD));
		ar.Write(cPicName, 32);
		ar.Write(&pView->m_lBkWidth, sizeof(long));
		ar.Write(&pView->m_lBkHeight, sizeof(long));
		ar.Write(pView->m_pArray, pView->m_lBkWidth*pView->m_lBkHeight/(_BLOCK_SIZE*_BLOCK_SIZE)*sizeof(WORD));
		long i;
		for (i=0; i<0xff; i++)
		{
			DWORD count = 0;
			CRectList *temp = pView->m_pLayerRect[i];
			while (temp)
			{
				count++;
				temp = temp->m_pNext;
			}
			ar.Write(&count, sizeof(DWORD));
			temp = pView->m_pLayerRect[i];
			while (temp)
			{
				WORD data;
				data = temp->left;
				ar.Write(&data, sizeof(WORD));
				data = temp->top;
				ar.Write(&data, sizeof(WORD));
				data = temp->Width();
				data+=17;
				ar.Write(&data, sizeof(WORD));
				data = temp->Height();
				data+=17;
				ar.Write(&data, sizeof(WORD));
				temp = temp->m_pNext;
			}
		}
	}
	else
	{
		//版本检查
		char cT[5];
		ar.Read(cT, 4);
		cT[4] = 0;
		if (strcmp(cT, cTitle) != 0)
		{
			AfxMessageBox("文件格式错误!");
			::PostQuitMessage(-1);
		}
		DWORD dwV;
		ar.Read(&dwV, 4);
		if (dwV != dwVer)
		{
			AfxMessageBox("地图文件版本不对!");
			::PostQuitMessage(-1);
		}
		ar.Read(cPicName, 32);
		pView->m_csPicName = cPicName;
		ar.Read(&pView->m_lBkWidth, sizeof(DWORD));
		ar.Read(&pView->m_lBkHeight, sizeof(DWORD));
		SAFE_DELETE_ALL(pView->m_pArray);
		pView->m_pArray = new WORD[pView->m_lBkWidth/_BLOCK_SIZE * pView->m_lBkHeight/_BLOCK_SIZE];
		ar.Read(pView->m_pArray, (pView->m_lBkWidth/_BLOCK_SIZE * pView->m_lBkHeight/_BLOCK_SIZE)*sizeof(WORD));
		
		pView->ReleaseAllLayerRect();
		long i;
		for (i=0; i<0xff; i++)
		{
			DWORD count = 0;
			ar.Read(&count, sizeof(DWORD));
			long j;
			for (j=0; j<count; j++)
			{
				CRectList *temp = new CRectList;
				WORD data;
				ar.Read(&data, sizeof(WORD));
				temp->left = data;
				ar.Read(&data, sizeof(WORD));
				temp->top = data;
				ar.Read(&data, sizeof(WORD));
				temp->right = temp->left + data -17 - 1;
				ar.Read(&data, sizeof(WORD));
				temp->bottom = temp->top + data -17 - 1;

				temp->m_pNext = pView->m_pLayerRect[i];
				pView->m_pLayerRect[i] = temp;
			}
		}
		pView->m_bIsLoad = TRUE;
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CLaoMapEdtDoc diagnostics

#ifdef _DEBUG
void CLaoMapEdtDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CLaoMapEdtDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CLaoMapEdtDoc commands

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -