// MapEditDlg.cpp : implementation file//
#include "stdafx.h"#include "MapEdit.h"#include "MapEditDlg.h"#include "BaseSetDlg.h"
#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif#define NO_EXIST -1/// CAboutDlg dialog used for App AboutCString csMapName = "";CString csMapStyle = "";CString csMapFloor = "";CString csMapMusic = "";BaseSetDlg dlgBase;HDC hTempDC;HDC hBkDC;HDC hObjBKDC;HDC hFloorDC;HDC hObjDC;HDC hPalyerDC;
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
// Implementationprotected: //{{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_MAPEND_MESSAGE_MAP()
/// CMapEditDlg dialog
CMapEditDlg::CMapEditDlg(CWnd* pParent /*=NULL*/) : CDialog(CMapEditDlg::IDD, pParent){ //{{AFX_DATA_INIT(CMapEditDlg)
//}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);}
void CMapEditDlg::DoDataExchange(CDataExchange* pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CMapEditDlg) DDX_Control(pDX, IDC_STATIC_ATTR_BOX, m_csAttr); DDX_Control(pDX, IDC_STATIC_STATUS, m_csOutMsg); //}}AFX_DATA_MAP}
BEGIN_MESSAGE_MAP(CMapEditDlg, CDialog) //{{AFX_MSG_MAP(CMapEditDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew) ON_BN_CLICKED(IDC_BUTTON_EDIT, OnButtonEdit) ON_WM_RBUTTONDOWN() ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() ON_BN_CLICKED(IDC_BUTTON_HELP, OnButtonHelp) ON_WM_DRAWITEM() ON_WM_TIMER() //}}AFX_MSG_MAPEND_MESSAGE_MAP()
/// CMapEditDlg message handlers
BOOL CMapEditDlg::OnInitDialog(){ CDialog::OnInitDialog(); m_bNewFlag = false; MoveWindow(0,0,930,620); GetDlgItem(IDC_STATIC_MAP)->MoveWindow(0,0,650,575,TRUE);
GetDlgItem(IDC_STATIC_FLOOR)->MoveWindow(660,0,230,12,TRUE); GetDlgItem(IDC_STATIC_SMALLMAP)->MoveWindow(660,13,255,56,TRUE); GetDlgItem(IDC_STATIC_OBJECT)->MoveWindow(660,70,230,12,TRUE); GetDlgItem(IDC_STATIC_OBJECT_BOX)->MoveWindow(660,85,255,375,TRUE);
GetDlgItem(IDC_STATIC_PLAYER)->MoveWindow(660,462,50,12,TRUE); GetDlgItem(IDC_STATIC_PLAYER_BOX)->MoveWindow(660,475,75,75,TRUE);
GetDlgItem(IDC_STATIC_ATTR)->MoveWindow(740,462,50,12,TRUE); GetDlgItem(IDC_STATIC_ATTR_BOX)->MoveWindow(740,475,175,75,TRUE); GetDlgItem(IDC_BUTTON_NEW)->MoveWindow(664,553,80,19,TRUE); GetDlgItem(IDC_BUTTON_EDIT)->MoveWindow(749,553,80,19,TRUE); GetDlgItem(IDC_BUTTON_SAVE)->MoveWindow(833,553,80,19,TRUE); GetDlgItem(IDC_STATIC_STATUS)->MoveWindow(0,576,160,19,TRUE); GetDlgItem(IDC_PROGRESS)->MoveWindow(162,576,300,19,TRUE); GetDlgItem(IDC_BUTTON_HELP)->MoveWindow(470,576,60,19,TRUE); GetDlgItem(IDC_STATIC_COPYRIGHT)->MoveWindow(530,576,380,19,TRUE); m_nFloorNum = NO_EXIST; m_nObjNum = NO_EXIST; m_nRight = NO_EXIST; m_nObjTotalNum = NO_EXIST; m_bSelect = false; HDC hScrDC=CreateDC("DISPLAY", NULL, NULL, NULL); hBkDC =CreateCompatibleDC(hScrDC); hObjBKDC = CreateCompatibleDC(hScrDC); HBITMAP bitMap = CreateCompatibleBitmap(hScrDC,650,575); HBITMAP bitOBj = CreateCompatibleBitmap(hScrDC,255,375); SelectObject(hBkDC,bitMap); SelectObject(hObjBKDC,bitOBj); hTempDC = CreateCompatibleDC(0); hFloorDC = CreateCompatibleDC(hScrDC); hObjDC = CreateCompatibleDC(hScrDC); InitMapObject(); InitObject(); // 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
OnButtonNew();
return TRUE; // return TRUE unless you set the focus to a control}
void CMapEditDlg::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 CMapEditDlg::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 { //DrawLine(); CDialog::OnPaint(); }}
// The system calls this to obtain the cursor to display while the user drags// the minimized window.HCURSOR CMapEditDlg::OnQueryDragIcon(){ return (HCURSOR) m_hIcon;}
void CMapEditDlg::OnButtonNew() { // TODO: Add your control notification handler code here if (dlgBase.DoModal() == IDOK) { m_nFloorTotalNum = GetFilesNum("bao//Floor"); m_nObjTotalNum = GetFilesNum("bao//OBject"); m_nRight = 662 + 50 * m_nFloorTotalNum; m_bNewFlag = true; SetTimer(1,150,NULL); }}
void CMapEditDlg::OnButtonEdit() { // TODO: Add your control notification handler code here CFileDialog dlgFile(TRUE,"map",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"MAP File (*.map)|*.map||",this); dlgFile.DoModal();}
void CMapEditDlg::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default CDialog::OnRButtonDown(nFlags, point);}
void CMapEditDlg::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default int nPositionX = point.x; int nPositionY = point.y; if (true == m_bNewFlag) { if ((0 < nPositionX) && (650 > nPositionX) && ( 0 < nPositionY) && ( 575 > nPositionY)) { // main int nRow = (nPositionY -25)/50; int nCol = nPositionX / 50; int nPosX = nCol * 50; int nPosY = nRow * 50 + 25; // test CString csOutMsg = _T(""); csOutMsg.Format("Row = %d, Col = %d",nRow,nCol); CString csOutMsg1 = _T(""); csOutMsg1.Format("nPosX = %d, nPosY = %d",nPosX,nPosY); csOutMsg += csOutMsg1; MessageBox(csOutMsg); // TextOut(this,0,0,csOutMsg,sizeof(csOutMsg)); //operate obj[nRow][nCol] } else if((662 < nPositionX) && (m_nRight > nPositionX) && ( 13 < nPositionY) && ( 63 > nPositionY)) { //floor m_bSelect = true; for (int nIndex = 0; nIndex < m_nFloorTotalNum; nIndex ++) { if (((662 + 50*nIndex) < nPositionX) && ((712+50*nIndex) > nPositionX)) { m_nFloorNum = nIndex; } } CString csTemp = _T(""); csTemp.Format(_T("bao/Floor/dg%d.bmp"),m_nFloorNum); HBITMAP hTempBit = LoadPic(csTemp); SelectObject(hFloorDC, hTempBit); } else if((660 < nPositionX) && (910 > nPositionX) && ( 85 < nPositionY) && ( 485 > nPositionY)) { //object // MessageBox("object window"); CString csTemp = _T(""); csTemp.Format(_T(" Width = %d /r/n Height = %d /r/n Move = %d /r/n Bomb out = %d"),5,4,3,1); m_csAttr.SetWindowText(csTemp); } else if((660 < nPositionX) && (710 > nPositionX) && ( 500 < nPositionY) && ( 550 > nPositionY)) { //player MessageBox("Player window"); } } CDialog::OnLButtonDown(nFlags, point);}
void CMapEditDlg::OnMouseMove(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default if (true == m_bNewFlag) { int nPositionX = point.x; int nPositionY = point.y; int nRow = 0; int nCol = 0; CString csOutMsg = _T(""); if ((0 < nPositionX) && (650 > nPositionX) && ( 0 < nPositionY) && ( 575 > nPositionY)) { // main nRow = (nPositionY -25)/50; nCol = nPositionX / 50; csOutMsg.Format("Row = %d, Col = %d",nRow,nCol); } else { csOutMsg = "Row = OUT, Col = OUT"; } m_csOutMsg.SetWindowText(csOutMsg); } CDialog::OnMouseMove(nFlags, point);}void CMapEditDlg::DrawLine() { CClientDC dc(this); CDC* dcTemp = CDC::FromHandle (hBkDC); CPen pen(PS_SOLID,1,RGB(0,128,0)); CPen *pOldPen=dcTemp->SelectObject(&pen); for (int nRow = 0; nRow < 11; nRow++) { int nTempRow = nRow*50+25; dcTemp->MoveTo(0, nTempRow); dcTemp->LineTo(648, nTempRow); } for (int nCol = 0; nCol < 13; nCol++) { int nTempCol = nCol*50; dcTemp->MoveTo(nTempCol, 0); dcTemp->LineTo(nTempCol, 573); } dcTemp->SelectObject(pOldPen); CDC::DeleteTempMap(); BitBlt(dc.m_hDC,0,0,650,575,hBkDC,0,0,SRCCOPY);}
void CMapEditDlg::OnButtonHelp() { // TODO: Add your control notification handler code here CAboutDlg dlg_about; dlg_about.DoModal();}
int CMapEditDlg::GetFilesNum(CString pstr) { int nFileNum = 0; DecryptFile(pstr,0); CFileFind finder; if(pstr.IsEmpty()) { return nFileNum; } // build a string with wildcards CString strWildcard(pstr); strWildcard += _T("//*.bmp");//ÐÞ¸ÄÕâÀïËÑË÷²»Í¬µÄÀàÐÍ // start working for files BOOL bWorking = finder.FindFile(strWildcard); while (bWorking) { bWorking = finder.FindNextFile(); // skip . and .. files; otherwise, we'd // recur infinitely! if (finder.IsDots()) continue; // if it's a directory, recursively search it // if (finder.IsDirectory()) // { // DecryptFile(finder.GetFilePath(),0); // CString str = finder.GetFilePath(); // FindFiles(str); // } // else // { //ÔÚÕâÀïÌí¼Ó¶ÔËù²éÕÒÎļþµÄ´¦Àí´úÂë // CString s = finder.GetFileName();// m_combo.AddString(s);// DecryptFile(finder.GetFilePath(),0);// UpdateData(FALSE); nFileNum ++; // // } } finder.Close(); return nFileNum; } void CMapEditDlg::DrawFloorWindow(){ CClientDC dc(this); for (int i = 0; i < m_nFloorTotalNum; i++) { CString csTemp(_T("")); csTemp.Format(_T("bao/Floor/dg%d.bmp"),i); HBITMAP hFloorBIt = LoadPic(csTemp); SelectObject(hTempDC,hFloorBIt); BitBlt(dc.m_hDC,662+50*i,16,50,50,hTempDC,0,0,SRCCOPY); }}
void CMapEditDlg::OnTimer(UINT nIDEvent) { // TODO: Add your message handler code here and/or call default CClientDC dc(this); DrawFloorWindow(); if (false == m_bSelect) { DrawLine(); } else { DrawMapFloor(); } DrawMapOBject(); DrawOBject(); BitBlt(dc.m_hDC,0,0,650,575,hBkDC,0,0,SRCCOPY); BitBlt(dc.m_hDC,660,85,255,375,hObjBKDC,0,0,SRCCOPY); CDialog::OnTimer(nIDEvent);}void CMapEditDlg::DrawMapFloor(){ for (int nRow = 0; nRow < 11; nRow++) { for (int nCol = 0; nCol < 13; nCol++) { BitBlt(hBkDC,nCol * 50,nRow * 50 + 25,50,50,hFloorDC,0,0,SRCCOPY); } }}HBITMAP CMapEditDlg::LoadPic(CString csStr){ HBITMAP hBIt=(HBITMAP)LoadImage (AfxGetInstanceHandle(), csStr, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION ); return hBIt;}void CMapEditDlg::InitMapObject(){ for (int nRow = 0; nRow < 11; nRow++) { for (int nCol = 0; nCol < 13; nCol++) { m_stMapObj[nRow][nCol].Surface = NO_EXIST; m_stMapObj[nRow][nCol].mState = e_nullMove; } }}void CMapEditDlg::DrawMapOBject(){ for (int nRow = 0; nRow < 11; nRow++) { for (int nCol = 0; nCol < 13; nCol++) { if ( NO_EXIST == m_stMapObj[nRow][nCol].Surface) { continue; } else { CString csTemp = _T(""); csTemp.Format(_T("bao/OBject/obj%d.bmp"),m_stMapObj[nRow][nCol].Surface); HBITMAP hTempbit = LoadPic(csTemp); SelectObject(hObjDC, hTempbit); BitBlt(hBkDC,nCol*50,nRow*50+13,50,62,hObjDC,0,0,SRCCOPY); } } }}void CMapEditDlg::DrawOBject(){ CClientDC dc(this); for (int nRow = 0; nRow < 7; nRow++) { for (int nCol = 0; nCol < 5; nCol++) { if ( NO_EXIST == m_stObj[nRow][nCol].Surface) { continue; } else { CString csTemp = _T(""); csTemp.Format(_T("bao/OBject/obj%d.bmp"),m_stObj[nRow][nCol].Surface); HBITMAP hTempbit = LoadPic(csTemp); SelectObject(hObjDC, hTempbit); BitBlt(hObjBKDC,3+nCol*50,nRow*50+5,50,62,hObjDC,0,0,SRCCOPY); } } }}void CMapEditDlg::InitObject(){ for (int nRow = 0; nRow < 7; nRow++) { for (int nCol = 0; nCol < 5; nCol++) { m_stObj[nRow][nCol].Surface = 4; m_stObj[nRow][nCol].mState = e_nullMove; } }}