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

📄 dialog.cpp

📁 凌星科技_2004-5-17_《圣剑英雄传II》的源代码scr2
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			case IDCANCEL:
				EndDialog(hDlg,false);
				return true;				
			
			//添加
			case IDC_BUTTON_Add:
				{
					Sel=SendMessage(hListBoxAllEnemy, LB_GETCURSEL, 0, 0 );
					if( Sel != LB_ERR )
					{
						char strTemp[32];
						SendMessage(hListBoxAllEnemy, LB_GETTEXT, Sel, (LPARAM)&strTemp );
						SendMessage(hListBoxEnemy, LB_INSERTSTRING, 0, (LPARAM)strTemp);
						SendMessage(hListBoxAllEnemy, LB_DELETESTRING, Sel, 0);
					}
				}
				break;

			//删除
			case IDC_BUTTON_Delete:
				{
					Sel=SendMessage(hListBoxEnemy, LB_GETCURSEL, 0, 0 );
					if( Sel != LB_ERR )
					{
						char strTemp[32];
						SendMessage(hListBoxEnemy, LB_GETTEXT, Sel, (LPARAM)&strTemp );
						SendMessage(hListBoxAllEnemy, LB_INSERTSTRING, 0, (LPARAM)strTemp);
						SendMessage(hListBoxEnemy, LB_DELETESTRING, Sel, 0);
					}
				}
				break;

			//列表框事件
			case IDC_LIST_AllEnemy:
				switch( HIWORD(wParam) )
				{
				//改变列表选择
				case LBN_SELCHANGE:
					Sel=SendMessage(hListBoxAllEnemy, LB_GETCURSEL, 0, 0 );
					EnableWindow(GetDlgItem(hDlg, IDC_BUTTON_Add),true);
					break;

				//双击鼠标
				case LBN_DBLCLK:
					return true;
				}
				break;
			}
			break;

	    case WM_DESTROY:
            return TRUE;
            break;

        default:
            return FALSE;
    }
return true;
}

/////////////////////////////////////////////////////////////////////
//
//*****************************
//物体属性窗口消息
BOOL APIENTRY DialogObjectProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	UINT idCommand;
	static int Sel=-1, Sel2=-1;

	HWND hComBoxMouseType;
	hComBoxMouseType=GetDlgItem(hDlg, IDC_COMBO_CPType);

    switch (message)
    {
        case WM_INITDIALOG:
			{

			//定位到中心点
			RECT rect;
			GetWindowRect(hDlg, &rect);
			int w=rect.right-rect.left;
			int h=rect.bottom-rect.top;
			if( WindowMode==1 )	//窗口
				MoveWindow(hDlg, RectWindow.left+(ScreenWidth-w)/2, RectWindow.top+(ScreenHeight-h)/2, w, h, TRUE);
			else
				MoveWindow(hDlg, (ScreenWidth-w)/2, (ScreenHeight-h)/2, w, h, TRUE);
			
			//坐标
			SetDlgItemInt(hDlg, IDC_EDIT_ox, cx, true);
			SetDlgItemInt(hDlg, IDC_EDIT_oy, cy, true);

			//地面材质
			SetDlgItemInt(hDlg, IDC_EDIT_Ground, map.Cell[map.Width*cy+cx].Ground, true);
			SetDlgItemInt(hDlg, IDC_EDIT_GroundPage, map.Cell[map.Width*cy+cx].GroundPic, true);
			SetDlgItemInt(hDlg, IDC_EDIT_Object, map.Cell[map.Width*cy+cx].Obj, true);
			SetDlgItemInt(hDlg, IDC_EDIT_ObjectPage, map.Cell[map.Width*cy+cx].ObjPic, true);
			SetDlgItemInt(hDlg, IDC_EDIT_Object2, map.Cell[map.Width*cy+cx].Obj2, true);
			SetDlgItemInt(hDlg, IDC_EDIT_ObjectPage2, map.Cell[map.Width*cy+cx].Obj2Pic, true);

			//Hook
			SetDlgItemInt(hDlg, IDC_EDIT_Hook, map.Cell[map.Width*cy+cx].CP, true);

			//能否通过
			if( map.Cell[map.Width*cy+cx].Block )
				CheckDlgButton(hDlg, IDC_CHECK_Block, 1);

			//初始化物体层次
			Sel=map.Cell[map.Width*cy+cx].Level;
			switch( Sel )
			{
			case CMap::OL_NORMAL:
				CheckDlgButton(hDlg, IDC_RADIO_Normal, 1);
				break;

			case CMap::OL_UP:
				CheckDlgButton(hDlg, IDC_RADIO_Up, 1);
				break;
			}

			//初始化陷阱类型复选框
			for(int i=0; i<CCursor::GetCursorNum(); i++)
			{
				SendMessage(hComBoxMouseType, CB_ADDSTRING, 0, (LPARAM)CCursor::GetCursor(i).strName);
			}
			SendMessage(hComBoxMouseType, CB_SETCURSEL, map.Cell[map.Width*cy+cx].MouseType, 0);

			Sel2=map.Cell[map.Width*cy+cx].Level2;
			switch( Sel2 )
			{
			case CMap::OL_NORMAL:
				CheckDlgButton(hDlg, IDC_RADIO_Normal2, 1);
				break;

			case CMap::OL_UP:
				CheckDlgButton(hDlg, IDC_RADIO_Up2, 1);
				break;
			}

			ShowWindow(hDlg,SW_SHOW);
			UpdateWindow(hWnd);
			
			}
            return TRUE;
            break;

		case WM_COMMAND:
			idCommand=LOWORD(wParam);
			switch( idCommand )
			{
			//确定
			case IDOK:
				if( IsDlgButtonChecked(hDlg, IDC_CHECK_Block) )
					map.Cell[map.Width*cy+cx].Block=1;
				else
					map.Cell[map.Width*cy+cx].Block=0;

				map.Cell[map.Width*cy+cx].Level=Sel;
				map.Cell[map.Width*cy+cx].Level2=Sel2;
				Cur_MouseType = SendMessage(hComBoxMouseType, CB_GETCURSEL, 0, 0);
				map.Cell[map.Width*cy+cx].MouseType = Cur_MouseType;
				memcpy(UndoMap, map.Cell, sizeof(Cell_Struct)*map.Width*map.Height);
				EndDialog(hDlg,false);
				return true;

			//取消
			case IDCANCEL:
				EndDialog(hDlg,false);
				return true;

			//地面层次
			case IDC_RADIO_Normal:
				Sel=CMap::OL_NORMAL;
				break;

			//地面层次
			case IDC_RADIO_Up:
				Sel=CMap::OL_UP;
				break;

			//地面层次2
			case IDC_RADIO_Normal2:
				Sel2=CMap::OL_NORMAL;
				break;

			//地面层次2
			case IDC_RADIO_Up2:
				Sel2=CMap::OL_UP;
				break;
			}

	    case WM_DESTROY:
            return TRUE;
            break;

        default:
            return FALSE;
    }
return true;
}

//---------------------------------------------------------

//新建地图
void _NewMap(HWND hWnd)
{
	if( MessageBox(hWnd, "新建地图吗?(注意保存当前地图)", "Exit", MB_OKCANCEL)==IDOK )
	{
		int w=GetIntDlg("请输入地图宽度(单位:格子 >= 20)");
		while( w<20 )
		{
			w=GetIntDlg("请输入地图宽度(单位:格子 >= 20)");
		}
		int h=GetIntDlg("请输入地图高度(单位:格子 >= 15)");
		while( h<15 )
		{
			h=GetIntDlg("请输入地图高度(单位:格子 >= 15)");
		}
		map.InitMap(w, h);

		// 初始鼠标状态
		map.RestoreMouseType(CCursor::CS_NORMAL);

		//取消当前选择的物体
		strcpy(map.CurrentMapFileName,"Unknow");	//当前编辑的地图文件名
		strcpy(map.CurrentMapFilePath,"Unknow");	//当前编辑的地图文件名

		//初始化UNDO功能
		_DELETE( UndoMap );
		UndoMap=new Cell_Struct[map.Width*map.Height];
		memcpy(UndoMap, map.Cell, sizeof(Cell_Struct)*map.Width*map.Height);
	}
}

//读入地图
bool _LoadMap(HWND hWnd)
{
	char tmp[256]="*.map";
	OPENFILENAME ofn;
	ZeroMemory(&ofn,sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hWnd;
	ofn.hInstance = hInst;
	ofn.lpstrFilter = "地图文件(*.map)";
	ofn.lpstrCustomFilter = NULL;
	ofn.nFilterIndex = 0;
	ofn.nMaxCustFilter = 0;	
	ofn.lpstrFile = tmp;
	ofn.nMaxFile = 1024;
	ofn.lpstrTitle = NULL;
	ofn.lpstrFileTitle = NULL;
	ofn.lpstrInitialDir = CurrentPath;
	ofn.Flags = OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST 
							| OFN_FILEMUSTEXIST | OFN_SHAREAWARE;
	ofn.lpstrDefExt = "";
	ofn.lpfnHook = NULL;
	if( GetOpenFileName((LPOPENFILENAME)&ofn)==0 )
	{
		//设置当前路径
		SetCurrentDirectory(CurrentPath);
		return false;
	}
	char strTemp1[MAX_PATH];
	char* strTemp2 = strTemp1;

	strcpy(strTemp1,ofn.lpstrFile);				

	strTemp2 += strlen(CurrentPath)+1;			//跳过路径
	SetCurrentDirectory(CurrentPath);
	if( map.LoadMap(strTemp2) )					//读入地图
	{
		//人物位置复位
		role[0].State.x = 16;
		role[0].State.y = 16;
		role[0].State.X = 0;
		role[0].State.Y = 0;

		//初始化UNDO功能
		_DELETE(UndoMap);
		UndoMap=new Cell_Struct[map.Width*map.Height];
		memcpy(UndoMap, map.Cell, sizeof(Cell_Struct)*map.Width*map.Height);
		return true;
	}
	return false;
}

//保存地图
void _SaveMap(HWND hWnd)
{
	if( strcmp(map.CurrentMapFileName, "Unknow") !=0 )
	{
		if( map.SaveMap(map.CurrentMapFileName) )
		{
			char* str = GetFilePath(map.CurrentMapFileName);
			strcpy(map.CurrentMapFilePath, str);
			_FREE( str );
			MessageBox(hWnd, "地图文件已保存", "Heroland", MB_OK );

			//设置当前路径
			SetCurrentDirectory(CurrentPath);
		}
	}
	else
		MessageBox(hWnd, "请使用'SaveAs'。", "Heroland", MB_OK );

}

//另存为
bool _SaveAsMap(HWND hWnd)
{
	char tmp[256]="*.map";
	OPENFILENAME ofn;
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hWnd;
	ofn.hInstance = hInst;
	ofn.lpstrFilter = "地图文件(*.map)";
	ofn.lpstrCustomFilter = NULL;
	ofn.nFilterIndex = 0;
	ofn.nMaxCustFilter = 0;	
	ofn.lpstrFile = tmp;
	ofn.nMaxFile = 1024;
	ofn.lpstrTitle = NULL;
	ofn.lpstrFileTitle = NULL;
	ofn.lpstrInitialDir = CurrentPath;
	ofn.Flags = OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST 
						| OFN_FILEMUSTEXIST | OFN_SHAREAWARE;
	ofn.lpstrDefExt = "";
	ofn.lpfnHook = NULL;
	if( GetSaveFileName((LPOPENFILENAME)&ofn)==0 )
	{
		//设置当前路径
		SetCurrentDirectory(CurrentPath);
		return false;
	}

	if( map.SaveMap(ofn.lpstrFile) )
	{
		strcpy(map.CurrentMapFileName,ofn.lpstrFile);
		char* str = GetFilePath(map.CurrentMapFileName);
		strcpy(map.CurrentMapFilePath, str);
		_FREE( str );
		MessageBox(hWnd, "地图文件已保存", "Heroland", MB_OK );

		//设置当前路径
		SetCurrentDirectory(CurrentPath);
		return true;
	}

	return false;
}

//***************************
//打开文件对话框
char *GetFileDialog(bool Load)
{
	char tmp[MAX_PATH]="*.*";
	char* strRet = new char[MAX_PATH];

	OPENFILENAME ofn;
	memset(&ofn, 0, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = hWnd;
	ofn.hInstance = hInst;
	ofn.lpstrFilter = "*.*";		
	ofn.lpstrCustomFilter = NULL;
	ofn.nFilterIndex = 0;		
	ofn.nMaxCustFilter = 0;	
	ofn.lpstrFile = tmp;		
	ofn.nMaxFile = 1024;
	ofn.lpstrTitle = NULL;		
	ofn.lpstrFileTitle = NULL;
	ofn.lpstrInitialDir = CurrentPath;   
	ofn.Flags = OFN_SHOWHELP | OFN_HIDEREADONLY | OFN_PATHMUSTEXIST 
					| OFN_FILEMUSTEXIST | OFN_SHAREAWARE;
	ofn.lpstrDefExt = "*";		
	ofn.lpfnHook = NULL;

	if( Load )	//打开
	{
		if( GetOpenFileName((LPOPENFILENAME)&ofn)==0 ) 
		{
			return NULL;
		}
		strcpy(strRet, ofn.lpstrFile);
		return strRet;
	}
	else	//保存
	{
		if( GetSaveFileName((LPOPENFILENAME)&ofn)==0 ) 
		{
			return NULL;
		}
		strcpy(strRet, ofn.lpstrFile);
		return strRet;
	}
}

//***************************
//取得路径
char *GetPathDialog()
{
	BROWSEINFO bi;
	char diskname[MAX_PATH], *path = new char[MAX_PATH];
	ITEMIDLIST *pidl;
	bi.hwndOwner=0;
	bi.pidlRoot=0;
	bi.pszDisplayName=diskname;
	bi.lpszTitle="你要显示的话";
	bi.ulFlags=0;
	bi.lpfn=0;
	bi.lParam=0;
	bi.iImage=0;

	if( pidl = SHBrowseForFolder(&bi) )
	{
		SHGetPathFromIDList(pidl, path);
		return path;
	}

	return NULL;
}

⌨️ 快捷键说明

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