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

📄 dialog.cpp

📁 凌星科技_2004-5-17_《圣剑英雄传II》的源代码scr2
💻 CPP
📖 第 1 页 / 共 3 页
字号:
//********************************************
//	对话框 相关函数
//  创建于2000年3月17日
//********************************************
#include <windows.h>
#include "Shlwapi.h"
#include <stdio.h>
#include "shlobj.h"
#include "..\resource.h"
#include "..\gamelib\goldpoint2.h"
#include "..\main.h"
#include "..\cursor.h"
#include "..\map.h"
#include "..\fight\fight.h"
#include "mapedit.h"
#include "dialog.h"
#pragma comment(lib,"shlwapi.lib")

int CGetType;	//类型 0=字符串 1=数值 3=资源图片名
char *CGetDlgMessage;	//提示文字
char *CGetStringDlgBuffer;	//字符串
int CGetIntDlg;				//数值

char strHelp[]="\
[鼠标左键]	=填充图块\n\
[鼠标右键]	=弹出菜单\n\
\n\
--组合健--\n\
[Ctrl+左键]	=删除物体\n\
[Alt+左键]	=修改格子阻挡关系\n\
[Shift+左键]	=获取当前图块\n\
[Space+左健]	=修改图块层次\n\
[Ctrl+Z]	=反悔一步误操作\n\
\n\
  - 金点时空(www.gpgame.com) -\n\
 \n\
 主策划 : sleepd\n\
执行策划 : ended-man\n\
  程序 : softboy、LDH\n\
  美工 : ended-man、\n\
      sleepd、zrhspy、\n\
      星仔、qinyong";

/////////////////////////////////////////////////////////////////////
//
//************************
//创建模态对话框
void CreateDlg(int Templete, DLGPROC Proc)
{
	DialogBox( 	hInst, 
				MAKEINTRESOURCE(Templete),
				hWnd, 
				Proc);
}

/////////////////////////////////////////////////////////////////////
//
//************************
//创建非模态对话框
void CreateDlg2(int Templete, DLGPROC Proc)
{
	CreateDialog( 	hInst, 
					MAKEINTRESOURCE(Templete),
					hWnd, 
					Proc);
}

/////////////////////////////////////////////////////////////////////
//
//***********************
//输入一个字符串
char *GetStringDlg(char *Msg)
{
	CGetDlgMessage=Msg;
	CGetType=0;
	CreateDlg( IDD_DIALOG_GetString, (DLGPROC)CGetStringDlgProc );
	return CGetStringDlgBuffer;
}

/////////////////////////////////////////////////////////////////////
//
//***********************
//输入一个数值
int GetIntDlg(char *Msg)
{
	CGetDlgMessage=Msg;
	CGetType=1;
	CreateDlg( IDD_DIALOG_GetInt, (DLGPROC)CGetStringDlgProc );
	return CGetIntDlg;
}

/////////////////////////////////////////////////////////////////////
//
//*****************************
//输入窗口消息
BOOL APIENTRY CGetStringDlgProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	UINT idCommand;

    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);
			}

			//显示提示信息
			if( CGetDlgMessage==NULL )
			{
				if( CGetType==0 )
					SetDlgItemText( hDlg, IDC_EDIT_Message, "请输入一串字符:[结束按OK]");
				if( CGetType==1 )
					SetDlgItemText( hDlg, IDC_EDIT_Message, "请输入一个数字:[结束按OK]");
			}
			else
				SetDlgItemText( hDlg, IDC_EDIT_Message, CGetDlgMessage);

			ShowWindow(hDlg,SW_SHOW);
			UpdateWindow(hWnd);

            return TRUE;
            break;

		case WM_COMMAND:
			idCommand=LOWORD(wParam);
			switch( idCommand )
			{
			case IDOK:
				if( CGetType==0 )	//字符串
				{
					CGetStringDlgBuffer=(char *)malloc(65535);
					GetDlgItemText(hDlg, IDC_EDIT_String, CGetStringDlgBuffer, 65535);
				}
				else if( CGetType==1 )	//数值
				{
					CGetIntDlg=GetDlgItemInt(hDlg, IDC_EDIT_Int, NULL, true);
				}
				EndDialog(hDlg,false);
				return true;
			
			case IDCANCEL:
				if( CGetType==0 )	//字符串
				{
					CGetStringDlgBuffer=NULL;
				}
				else if( CGetType==1 )	//数值
				{
					CGetIntDlg=-9999;
				}
				PressKey(VK_ESCAPE, 1);
				EndDialog(hDlg,false);
				return true;
			}

	    case WM_DESTROY:
            return TRUE;
            break;

        default:
            return FALSE;
    }
return true;
}

/////////////////////////////////////////////////////////////////////
//
//*****************************
//处理主窗口消息
BOOL APIENTRY DialogProc( HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam )
{
	static char strBackBmp[128];
	UINT idCommand;
	Cell_Struct *tmp;

	HWND hComBoxLevel;
	hComBoxLevel=GetDlgItem(hDlg, IDC_COMBO_Level);

    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);
			
			//显示复选控件
			if( bShowBackGround )
				CheckDlgButton(hDlg, IDC_CHECK_ShowBackGround, 1);

			if( bShowCell )
				CheckDlgButton(hDlg, IDC_CHECK_ShowCell, 1);

			if( bShowBlock )
				CheckDlgButton(hDlg, IDC_CHECK_ShowBlock, 1);

			if( bShowObject )
				CheckDlgButton(hDlg, IDC_CHECK_ShowObject, 1);

			if( bShowCurrent )
				CheckDlgButton(hDlg, IDC_CHECK_ShowCurrent, 1);

			if( bShowEdit )
				CheckDlgButton(hDlg, IDC_CHECK_ShowEdit, 1);

			if( bShowOnlyObject )
				CheckDlgButton(hDlg, IDC_CHECK_ShowOnlyObject, 1);

			//设置地图信息
			SetDlgItemInt( hDlg, IDC_EDIT_Id, map.Id, TRUE);
			SetDlgItemText( hDlg, IDC_EDIT_Name, map.Name);
			SetDlgItemInt( hDlg, IDC_EDIT_Width, map.Width-1, TRUE);
			SetDlgItemInt( hDlg, IDC_EDIT_Height, map.Height-1, TRUE);
			SetDlgItemText( hDlg, IDC_EDIT_BackBmp, map.m_strBackBmpFilename);

			//初始化层次复选框
			for(int i=0; i<Max_Level; i++)
			{
				SendMessage(hComBoxLevel, CB_ADDSTRING, 0, (LPARAM)Level[i]);
			}
			SendMessage(hComBoxLevel, CB_SETCURSEL, Cur_Level, 0);

			//设置窗口为当前文件名
			SetWindowText(hDlg, map.CurrentMapFileName);

			ShowWindow(hDlg,SW_SHOW);
			UpdateWindow(hDlg);
			}

            return TRUE;
            break;

		case WM_COMMAND:
			idCommand=LOWORD(wParam);
			switch( idCommand )
			{
			case IDOK:
				//检查网格显示
				if( IsDlgButtonChecked(hDlg, IDC_CHECK_ShowBackGround) )
					bShowBackGround=true;
				else 
					bShowBackGround=false;

				if( IsDlgButtonChecked(hDlg, IDC_CHECK_ShowCell) )
					bShowCell=true;
				else 
					bShowCell=false;

				if( IsDlgButtonChecked(hDlg, IDC_CHECK_ShowBlock) )
					bShowBlock=true;
				else 
					bShowBlock=false;

				if( IsDlgButtonChecked(hDlg, IDC_CHECK_ShowObject) )
					bShowObject=true;
				else 
					bShowObject=false;

				if( IsDlgButtonChecked(hDlg, IDC_CHECK_ShowCurrent) )
					bShowCurrent=true;
				else 
					bShowCurrent=false;

				if( IsDlgButtonChecked(hDlg, IDC_CHECK_ShowEdit) )
					bShowEdit=true;
				else 
					bShowEdit=false;

				if( IsDlgButtonChecked(hDlg, IDC_CHECK_ShowOnlyObject) )
					bShowOnlyObject=true;
				else 
					bShowOnlyObject=false;

				// 读入背景图片
				if( strBackBmp[0] )
				{
					if( strcmp(strBackBmp, map.m_strBackBmpFilename) != 0 )
					{
						strcpy(map.m_strBackBmpFilename, strBackBmp);
						CreateBitmap(map.m_pBackBmp, 0,0, map.m_strBackBmpFilename);
					}
				}
				else
				{
					map.m_strBackBmpFilename[0] = 0;
					_RELEASE( map.m_pBackBmp );
				}
				
				EndDialog(hDlg,false);
				return true;

			//返回
			case IDCANCEL:
				EndDialog(hDlg,false);
				return true;

			//更新
			case IDC_EDIT_Name:
				switch( HIWORD(wParam) )
				{
					case EN_CHANGE:
						GetDlgItemText(hDlg, IDC_EDIT_Name, map.Name, 64);
						break;
				}
				break;

			//更新
			case IDC_EDIT_BackBmp:
				switch( HIWORD(wParam) )
				{
					case EN_CHANGE:
						GetDlgItemText(hDlg, IDC_EDIT_BackBmp, strBackBmp, 128);
						break;
				}
				break;

			//更新
			case IDC_EDIT_Id:
				switch( HIWORD(wParam) )
				{
					case EN_CHANGE:
						map.Id=GetDlgItemInt(hDlg, IDC_EDIT_Id, NULL, NULL);
						break;
				}
				break;

			//编辑层次
			case IDC_COMBO_Level:
				switch( HIWORD(wParam) )
				{
					case CBN_SELCHANGE:
						Cur_Level=SendMessage(hComBoxLevel, CB_GETCURSEL, 0,0);
						break;
				}
				break;

			//高级-陷阱
			case IDC_BUTTON_ChangePoint:
				CreateDlg( IDD_DIALOG_Hook, (DLGPROC)DialogChangePointListProc);
				break;

			//高级-格子属性
			case IDC_BUTTON_Object:
				CreateDlg( IDD_DIALOG_Object, (DLGPROC)DialogObjectProc);
				break;

			// 敌人设置
			case IDC_BUTTON_Enemy:
				CreateDlg(IDD_DIALOG_EnemySet, DialogEnemySetListProc);
				break;

			//导出地图
			case ID_MENUITEM_SaveFullMap:
				{
					char* str = GetFileDialog(false);
					if( str )
					{
						map.SaveFullMap(str, 1.f);
					}
					delete str;
				}
				break;

			//退出
			case ID_MENUITEM_Exit:
				if( MessageBox(hDlg, "确定吗?(注意保存地图)", "Exit", MB_OKCANCEL)==IDOK )
				{
					RunGame=false;
					EndDialog(hDlg,false);
					return true;
				}
				break;

			//帮助
			case ID_MENUITEM_Help:
				MessageBox(hDlg, strHelp, "Help", MB_OK);
				break;

			//新建地图
			case ID_MENUITEM_New:
				_NewMap(hDlg);
				EndDialog(hDlg,false);
				break;

			//重新读入当前地图
			case ID_MENUITEM_ReOpen:
				if( MessageBox(hWnd, "重新读入当前地图吗?","Reopen", MB_YESNO )==IDYES )
				{
					char strTemp1[MAX_PATH];
					char* strTemp2 = strTemp1;

					strcpy(strTemp1,map.CurrentMapFileName);				

					strTemp2 += strlen(CurrentPath)+1;			//跳过路径
					SetCurrentDirectory(CurrentPath);
					/*char strTemp1[256];				//保存当前路径名字
					strcpy(strTemp1,CurrentPath);

					char* strTemp2 = GetFilePath(map.CurrentMapFileName);	//得到文件路径
					SetCurrentDirectory(strTemp2);							//设为当前路径
					strTemp2[strlen(strTemp2)-1] = 0;

					strcpy(CurrentPath,strTemp2);
					_FREE(strTemp2);
					strTemp2 = GetFileName(map.CurrentMapFileName);			//得到文件名

⌨️ 快捷键说明

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