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

📄 角色编辑器dlg.cpp

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

#include "stdafx.h"
#include "角色编辑器.h"
#include "角色编辑器Dlg.h"
#include <afx.h>
#include <afxwin.h>
#include <afxdlgs.h>

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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog

CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlg)
	m_szName = _T("");
	m_Status = 0;
	m_Flag = 0;
	m_szScript = _T("");
	m_szGraph = _T("");
	m_CellWidth = 0;
	m_GraphWidth = 0;
	m_GraphHeight = 0;
	m_CellHeight = 0;
	m_KeyPos_X = 0;
	m_KeyPos_Y = 0;
	m_InsideRECT_X1 = 0;
	m_InsideRECT_X2 = 0;
	m_InsideRECT_Y1 = 0;
	m_InsideRECT_Y2 = 0;
	m_MoveFrames = 0;
	m_MoveDelay = 0;
	m_MoveSwapFrame = 0;
	m_MoveSpeed = 0;
	m_MoveGrpahLine_1 = 0;
	m_MoveGrpahLine_2 = 0;
	m_MoveGrpahLine_3 = 0;
	m_MoveGrpahLine_4 = 0;
	m_MoveGrpahLine_5 = 0;
	m_MoveGrpahLine_6 = 0;
	m_MoveGrpahLine_7 = 0;
	m_MoveGrpahLine_8 = 0;
	m_FightFrames = 0;
	m_FightGrpahLine = 0;
	m_Direction_STR= _T("");
	m_DP = 0;
	m_AP = 0;
	m_DEX = 0;
	m_MP = 0;
	m_MP_MAX = 0;
	m_HP = 0;
	m_HP_MAX = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlg)
	DDX_Control(pDX, IDC_Direction, m_Direction);
	DDX_Text(pDX, IDC_szName, m_szName);
	DDV_MaxChars(pDX, m_szName, 16);
	DDX_Text(pDX, IDC_Status, m_Status);
	DDX_Text(pDX, IDC_Flag, m_Flag);
	DDX_Text(pDX, IDC_szScript, m_szScript);
	DDX_Text(pDX, IDC_szGraph, m_szGraph);
	DDX_Text(pDX, IDC_CellWidth, m_CellWidth);
	DDX_Text(pDX, IDC_GraphWidth, m_GraphWidth);
	DDX_Text(pDX, IDC_GraphHeight, m_GraphHeight);
	DDX_Text(pDX, IDC_CellHeight, m_CellHeight);
	DDX_Text(pDX, IDC_KeyPos_X, m_KeyPos_X);
	DDX_Text(pDX, IDC_KeyPos_Y, m_KeyPos_Y);
	DDX_Text(pDX, IDC_InsideRECT_X1, m_InsideRECT_X1);
	DDX_Text(pDX, IDC_InsideRECT_X2, m_InsideRECT_X2);
	DDX_Text(pDX, IDC_InsideRECT_Y1, m_InsideRECT_Y1);
	DDX_Text(pDX, IDC_InsideRECT_Y2, m_InsideRECT_Y2);
	DDX_Text(pDX, IDC_MoveFrames, m_MoveFrames);
	DDX_Text(pDX, IDC_MoveDelay, m_MoveDelay);
	DDX_Text(pDX, IDC_MoveSwapFrame, m_MoveSwapFrame);
	DDX_Text(pDX, IDC_MoveSpeed, m_MoveSpeed);
	DDX_Text(pDX, IDC_MoveGrpahLine_1, m_MoveGrpahLine_1);
	DDX_Text(pDX, IDC_MoveGrpahLine_2, m_MoveGrpahLine_2);
	DDX_Text(pDX, IDC_MoveGrpahLine_3, m_MoveGrpahLine_3);
	DDX_Text(pDX, IDC_MoveGrpahLine_4, m_MoveGrpahLine_4);
	DDX_Text(pDX, IDC_MoveGrpahLine_5, m_MoveGrpahLine_5);
	DDX_Text(pDX, IDC_MoveGrpahLine_6, m_MoveGrpahLine_6);
	DDX_Text(pDX, IDC_MoveGrpahLine_7, m_MoveGrpahLine_7);
	DDX_Text(pDX, IDC_MoveGrpahLine_8, m_MoveGrpahLine_8);
	DDX_Text(pDX, IDC_FightFrames, m_FightFrames);
	DDX_Text(pDX, IDC_FightGrpahLine, m_FightGrpahLine);
	DDX_CBString(pDX, IDC_Direction, m_Direction_STR);
	DDX_Text(pDX, IDC_DP, m_DP);
	DDX_Text(pDX, IDC_AP, m_AP);
	DDX_Text(pDX, IDC_DEX, m_DEX);
	DDX_Text(pDX, IDC_MP, m_MP);
	DDX_Text(pDX, IDC_MP_MAX, m_MP_MAX);
	DDX_Text(pDX, IDC_HP, m_HP);
	DDX_Text(pDX, IDC_HP_MAX, m_HP_MAX);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
	//{{AFX_MSG_MAP(CMyDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_BUILD, OnButtonBuild)
	ON_BN_CLICKED(IDC_BUTTON_S, OnButtonS)
	ON_BN_CLICKED(IDC_BUTTON_G, OnButtonG)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers

BOOL CMyDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_Direction.AddString ("0下");
	m_Direction.AddString ("1左下");
	m_Direction.AddString ("2左");
	m_Direction.AddString ("3左上");
	m_Direction.AddString ("4上");
	m_Direction.AddString ("5右上");
	m_Direction.AddString ("6右");
	m_Direction.AddString ("7右下");
	m_Direction.SetCurSel (0);
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMyDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMyDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMyDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
void CMyDlg::DelStr(CHAR *tempchar,int strlong,int size)	//将掉字串后面多余的内容变成0
{
	for (int i=strlong;i<size;i++)
	{
		tempchar[i]=0;
	}
}

void CMyDlg::OnButtonBuild() 
{
	// TODO: Add your control notification handler code here
	UpdateData(true);
	if (m_szName=="")
	{
		CFileDialog dlg(FALSE,_T("*.ROL"),_T("*.ROL"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("角色文件(*.ROL)|*.ROL|"));	
		if (dlg.DoModal ()==IDOK)
		{
			m_szName=dlg.GetFileTitle();		
			UpdateData(false);
		}
		else return;
	}
	else
	{
		CFileDialog dlg(FALSE,_T("*.ROL"),_T(m_szName+".ROL"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("角色文件(*.ROL)|*.ROL|"));	
		if (dlg.DoModal ()==IDOK)
		{
			m_szName=dlg.GetFileTitle();		
			UpdateData(false);
		}
		else return;
	}

	CFile file;
	if (file.Open (m_szName+".rol",CFile::modeCreate|CFile::modeWrite,NULL)) //m_szName
	{	
		DWORD tempdword;
		CHAR *tempchar;
		SHORT tempshort;
		long templong;
		int	 strlong;

		CPoint temppoint(m_KeyPos_X,m_KeyPos_Y);
		CRect  temprect(m_InsideRECT_X1,m_InsideRECT_Y1,m_InsideRECT_X2,m_InsideRECT_Y2);

		tempdword='LORG';			
		file.Write (&tempdword,sizeof (tempdword));		//标识
		tempdword=0x0103;
		file.Write (&tempdword,sizeof (tempdword));		//版本号(当前为v1.3)
		tempchar=m_szName.GetBuffer (16);
		strlong=m_szName.GetLength ();
		DelStr(tempchar,strlong,16);					//将掉字串后面多余的内容变成0
		file.Write (tempchar,16);						//角色名称
		m_szName.ReleaseBuffer (16);
		tempshort=m_Status;
		file.Write (&tempshort,sizeof (tempshort));		//角色状态
		tempshort=m_Flag;
		file.Write (&tempshort,sizeof (tempshort));		//角色类型
		tempshort=SHORT(atol(m_Direction_STR.Left(1)));
		file.Write (&tempshort,sizeof (tempshort));		//站立方向(从正下放开始顺时针0-7)

		if (m_szScript!="")							//角色脚本文件	
		{
			tempchar=m_szScript.GetBuffer (32);			
			strlong=m_szScript.GetLength ();
			DelStr(tempchar,strlong,32);				//将掉字串后面多余的内容变成0
			file.Write (tempchar,32);					
			m_szScript.ReleaseBuffer (32);
		}
		else		//(如果没有脚本文件则设定为全0,下同)
		{
			tempdword=0;
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
		}
		if (m_szGraph!="")							//角色图片文件	
		{
			tempchar=m_szGraph.GetBuffer (32);
			strlong=m_szGraph.GetLength ();
			DelStr(tempchar,strlong,32);				//将掉字串后面多余的内容变成0
			file.Write (tempchar,32);						
			m_szGraph.ReleaseBuffer (32);
		}
		else		//(如果没有脚本文件则设定为全0,下同)
		{
			tempdword=0;
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
			file.Write (&tempdword,sizeof (tempdword));		
		}
		tempdword=m_GraphWidth;
		file.Write (&tempdword,sizeof (tempdword));		//图片文件宽度(由图片文件设定)
		tempdword=m_GraphHeight;
		file.Write (&tempdword,sizeof (tempdword));		//图片文件高度(由图片文件设定)
		tempdword=m_CellWidth;
		file.Write (&tempdword,sizeof (tempdword));		//图片分割单元宽度
		tempdword=m_CellHeight;
		file.Write (&tempdword,sizeof (tempdword));		//图片分割单元高度
		file.Write (&temppoint,sizeof (temppoint));		//角色脚底坐标(用来定位角色)
		file.Write (&temprect,sizeof (temprect));		//用于检测碰撞的内部矩形框

		tempshort=m_MoveFrames;
		file.Write (&tempshort,sizeof (tempshort));		//运动帧数(第0帧是站立静止)
		tempshort=m_MoveDelay;
		file.Write (&tempshort,sizeof (tempshort));		//运动延时(毫秒)
		tempshort=m_MoveSwapFrame;
		file.Write (&tempshort,sizeof (tempshort));		//运动交换帧速率(一般为2或者3)
		tempshort=m_MoveSpeed;
		file.Write (&tempshort,sizeof (tempshort));		//运动速度(像素/步)

		tempshort=m_MoveGrpahLine_1;
		file.Write (&tempshort,sizeof (tempshort));		//数组 																									
		tempshort=m_MoveGrpahLine_2;							//纪录对应方向i的运动帧在图像中的行数
		file.Write (&tempshort,sizeof (tempshort));		//(行数从0开始计算)
		tempshort=m_MoveGrpahLine_3;
		file.Write (&tempshort,sizeof (tempshort));
		tempshort=m_MoveGrpahLine_4;
		file.Write (&tempshort,sizeof (tempshort));
		tempshort=m_MoveGrpahLine_5;
		file.Write (&tempshort,sizeof (tempshort));
		tempshort=m_MoveGrpahLine_6;
		file.Write (&tempshort,sizeof (tempshort));
		tempshort=m_MoveGrpahLine_7;
		file.Write (&tempshort,sizeof (tempshort));
		tempshort=m_MoveGrpahLine_8;
		file.Write (&tempshort,sizeof (tempshort));

		tempshort=m_FightFrames;
		file.Write (&tempshort,sizeof (tempshort));		//战斗帧数
		tempshort=m_FightGrpahLine;
		file.Write (&tempshort,sizeof (tempshort));		//战斗分解帧在图像中的行数
		templong=m_HP;
		file.Write (&templong,sizeof (templong));		//体力
		templong=m_HP_MAX;
		file.Write (&templong,sizeof (templong));		//体力最大值
		templong=m_MP;
		file.Write (&templong,sizeof (templong));		//魔法
		templong=m_MP_MAX;
		file.Write (&templong,sizeof (templong));		//魔法最大值
		templong=m_AP;
		file.Write (&templong,sizeof (templong));		//攻击力
		templong=m_DP;
		file.Write (&templong,sizeof (templong));		//防御力
		templong=m_DEX;
		file.Write (&templong,sizeof (templong));		//灵敏

		file.Close ();

	}
	else
		AfxMessageBox("文件存盘错误!");
}

void CMyDlg::OnButtonS() 
{
	// TODO: Add your control notification handler code here
	CString FilePathname;
	CString FileName;
	
	UpdateData(true);
	CFileDialog dlg(TRUE,NULL,_T("*.*"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("所有文件(*.*)|*.*|"));	
	if (dlg.DoModal ()==IDOK)
	{
		FilePathname=dlg.GetPathName ();
		FileName=dlg.GetFileName ();
		m_szScript=FileName;
		UpdateData(false);
	}
}

void CMyDlg::OnButtonG() 
{
	// TODO: Add your control notification handler code here
	CString FilePathname;
	CString FileName;

	UpdateData(true);
	CFileDialog dlg(TRUE,NULL,_T("*.*"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,_T("所有文件(*.*)|*.*|"));	
	if (dlg.DoModal ()==IDOK)
	{
		FilePathname=dlg.GetPathName ();
		FileName=dlg.GetFileName ();
		m_szGraph=FileName;
		UpdateData(false);
	}
	
}

⌨️ 快捷键说明

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