win_qe3.cpp

来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 660 行 · 第 1/2 页

CPP
660
字号
	 */ 
 
	strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "mapspath") );
  if (strlen(szDirName) == 0)
  {
	  strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "basepath") );
	  strcat (szDirName, "\\maps");
  }

	/* Place the terminating null character in the szFile. */ 
 
	szFile[0] = '\0'; 
 
	/* Set the members of the OPENFILENAME structure. */ 
 
	ofn.lStructSize = sizeof(OPENFILENAME); 
	ofn.hwndOwner = g_qeglobals.d_hwndCamera;
	ofn.lpstrFilter = szFilter; 
	ofn.nFilterIndex = 1; 
	ofn.lpstrFile = szFile; 
	ofn.nMaxFile = sizeof(szFile); 
	ofn.lpstrFileTitle = szFileTitle; 
	ofn.nMaxFileTitle = sizeof(szFileTitle); 
	ofn.lpstrInitialDir = szDirName; 
	ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | 
		OFN_FILEMUSTEXIST; 

	/* Display the Open dialog box. */ 
 
	if (!GetOpenFileName(&ofn))
		return;	// canceled
 
	// Add the file in MRU.
  //FIXME
	AddNewItem( g_qeglobals.d_lpMruMenu, ofn.lpstrFile);

	// Refresh the File menu.
  //FIXME
	PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0), 
			ID_FILE_EXIT);

	/* Open the file. */ 
 
	Map_LoadFile (ofn.lpstrFile);	
}

void ProjectDialog (void)
{
	/* 
	 * Obtain the system directory name and 
	 * store it in szDirName. 
	 */ 
 
	strcpy (szDirName, ValueForKey(g_qeglobals.d_project_entity, "basepath") );
	strcat (szDirName, "\\scripts");

	/* Place the terminating null character in the szFile. */ 
 
	szFile[0] = '\0'; 
 
	/* Set the members of the OPENFILENAME structure. */ 
 
	ofn.lStructSize = sizeof(OPENFILENAME); 
	ofn.hwndOwner = g_qeglobals.d_hwndCamera;
	ofn.lpstrFilter = szProjectFilter; 
	ofn.nFilterIndex = 1; 
	ofn.lpstrFile = szFile; 
	ofn.nMaxFile = sizeof(szFile); 
	ofn.lpstrFileTitle = szFileTitle; 
	ofn.nMaxFileTitle = sizeof(szFileTitle); 
	ofn.lpstrInitialDir = szDirName; 
	ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | 
		OFN_FILEMUSTEXIST; 

	/* Display the Open dialog box. */ 
 
	if (!GetOpenFileName(&ofn))
		return;	// canceled
 
	// Refresh the File menu.
	PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0), 
			ID_FILE_EXIT);

	/* Open the file. */ 
	if (!QE_LoadProject(ofn.lpstrFile))
		Error ("Couldn't load project file");
}


extern void AddSlash(CString& strPath);
void SaveAsDialog (bool bRegion)
{ 
	strcpy (szDirName, ValueForKey (g_qeglobals.d_project_entity, "basepath") );
  CString strPath = szDirName;
  AddSlash(strPath);
  strPath += "maps";

	/* Place the terminating null character in the szFile. */ 
 
	szFile[0] = '\0'; 
 
	/* Set the members of the OPENFILENAME structure. */ 
 
	ofn.lStructSize = sizeof(OPENFILENAME); 
	ofn.hwndOwner = g_qeglobals.d_hwndCamera;
	ofn.lpstrFilter = szFilter; 
	ofn.nFilterIndex = 1; 
	ofn.lpstrFile = szFile; 
	ofn.nMaxFile = sizeof(szFile); 
	ofn.lpstrFileTitle = szFileTitle; 
	ofn.nMaxFileTitle = sizeof(szFileTitle); 
	ofn.lpstrInitialDir = strPath; 
	ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | 
		OFN_FILEMUSTEXIST | OFN_OVERWRITEPROMPT; 

	/* Display the Open dialog box. */ 
 
	if (!GetSaveFileName(&ofn))
		return;	// canceled

  if (bRegion)
	  DefaultExtension (ofn.lpstrFile, ".reg");
  else
	  DefaultExtension (ofn.lpstrFile, ".map");

  if (!bRegion)
  {
	  strcpy (currentmap, ofn.lpstrFile);
    AddNewItem(g_qeglobals.d_lpMruMenu, ofn.lpstrFile);
	  PlaceMenuMRUItem(g_qeglobals.d_lpMruMenu,GetSubMenu(GetMenu(g_qeglobals.d_hwndMain),0),	ID_FILE_EXIT);
  }
	Map_SaveFile (ofn.lpstrFile, bRegion);	// ignore region
}

/*
=======================================================

Menu modifications

=======================================================
*/

/*
==================
FillBSPMenu

==================
*/
char	*bsp_commands[256];

void FillBSPMenu (void)
{
	HMENU	hmenu;
	epair_t	*ep;
	int		i;
	static int count;

	hmenu = GetSubMenu (GetMenu(g_qeglobals.d_hwndMain), MENU_BSP);

	for (i=0 ; i<count ; i++)
		DeleteMenu (hmenu, CMD_BSPCOMMAND+i, MF_BYCOMMAND);
	count = 0;

	if ( g_qeglobals.bBSPFrontendPlugin )
	{
		CString str = g_BSPFrontendTable.m_pfnGetBSPMenu();
		char cTemp[1024];
		strcpy(cTemp, str);
		char* token = strtok(cTemp, ",;");
		if (token && *token == ' ')
		{
			while (*token == ' ')
				token++;
		}
		i = 0;
		// first token is menu name
		ModifyMenu( GetMenu(g_qeglobals.d_hwndMain), MENU_BSP, MF_BYPOSITION, MENU_BSP, (LPCTSTR)token );
		// redraw the menu bar
		DrawMenuBar( g_qeglobals.d_hwndMain );
		token = strtok(NULL, ",;");
		while (token != NULL)
		{
			g_BSPFrontendCommands.Add(token);
			AppendMenu (hmenu, MF_ENABLED|MF_STRING, CMD_BSPCOMMAND+i, (LPCTSTR)token );
			token = strtok(NULL, ",;");
			i++;
		}
		count = i;
	}
	else
	{
		i = 0;
		for (ep = g_qeglobals.d_project_entity->epairs ; ep ; ep=ep->next)
		{
			if (ep->key[0] == 'b' && ep->key[1] == 's' && ep->key[2] == 'p')
			{
				bsp_commands[i] = ep->key;
				AppendMenu (hmenu, MF_ENABLED|MF_STRING,
					CMD_BSPCOMMAND+i, (LPCTSTR)ep->key);
				i++;
			}
		}
		count = i;
	}
}

//==============================================
void AddSlash(CString& strPath)
{
  if (strPath.GetLength() > 0)
  {
    if (strPath.GetAt(strPath.GetLength()-1) != '\\')
      strPath += '\\';
  }
}


bool ExtractPath_and_Filename(const char* pPath, CString& strPath, CString& strFilename)
{
  CString strPathName = pPath;
  int nSlash = strPathName.ReverseFind('\\');
  if (nSlash >= 0)
  {
    strPath = strPathName.Left(nSlash+1);
    strFilename = strPathName.Right(strPathName.GetLength() - nSlash - 1);
  }
  else strFilename = pPath;
  return true;
}


/*
===============
CheckBspProcess

See if the BSP is done yet
===============
*/
extern void FindReplace(CString& strContents, const char* pTag, const char* pValue);
extern CTime g_tBegin;

void CheckBspProcess (void)
{
	char	outputpath[1024];
	char	temppath[512];
	DWORD	exitcode;
	char	*out;
	BOOL	ret;

	if (!bsp_process)
		return;

	ret = GetExitCodeProcess (bsp_process, &exitcode);
	if (!ret)
		Error ("GetExitCodeProcess failed");
	if (exitcode == STILL_ACTIVE)
		return;

	bsp_process = 0;

	GetTempPath(512, temppath);
	sprintf (outputpath, "%sjunk.txt", temppath);

	LoadFile (outputpath, (void **)&out);
	Sys_Printf ("%s", out);
	Sys_Printf ("\ncompleted.\n");
	free (out);

	CTime tEnd = CTime::GetCurrentTime();
	CTimeSpan tElapsed = tEnd - g_tBegin;
	CString strElapsed;
	strElapsed.Format("Run time was %i hours, %i minutes and %i seconds", tElapsed.GetHours(), tElapsed.GetMinutes(), tElapsed.GetSeconds());
	Sys_Printf(strElapsed.GetBuffer(0));


	Sys_Beep ();
	Pointfile_Check();
	// run game if no PointFile and pref is set
	//++timo needs to stop after BSP if leaked .. does run through vis and light instead ..
	if (g_PrefsDlg.m_bRunQuake == TRUE  && !g_qeglobals.d_pointfile_display_list)
	{
		char cCurDir[1024];
		GetCurrentDirectory(1024, cCurDir);
		CString strExePath = g_PrefsDlg.m_strQuake2;
		CString strOrgPath;
		CString strOrgFile;
		ExtractPath_and_Filename(currentmap, strOrgPath, strOrgFile);
		if (g_PrefsDlg.m_bSetGame == TRUE) // run in place with set game.. don't copy map
		{
			CString strBasePath = ValueForKey(g_qeglobals.d_project_entity, "basepath");
			strExePath += " +set game ";
			strExePath += strBasePath;
			WinExec(strExePath, SW_SHOW);
		}
		else
		{
			CString strCopyPath = strExePath;
			char* pBuffer = strCopyPath.GetBufferSetLength(_MAX_PATH + 1);
			pBuffer[strCopyPath.ReverseFind('\\') + 1] = '\0';
			strCopyPath.ReleaseBuffer();
			SetCurrentDirectory(strCopyPath);
			CString strOrgPath;
			CString strOrgFile;
			ExtractPath_and_Filename(currentmap, strOrgPath, strOrgFile);
			AddSlash(strCopyPath);
			FindReplace(strOrgFile, ".map", ".bsp");
			//++timo modified for Quake3 !!
			strCopyPath += "baseq3\\maps\\";
			strCopyPath += strOrgFile;
			AddSlash(strOrgPath);
			strOrgPath += strOrgFile;
			bool bRun = (strOrgPath.CompareNoCase(strCopyPath) == 0);
			if (!bRun)
				bRun = (CopyFile(strOrgPath, strCopyPath, FALSE) == TRUE);
			if (bRun)
			{
				FindReplace(strOrgFile, ".bsp", "");
				strExePath += " +map ";
				strExePath += strOrgFile;
				WinExec(strExePath, SW_SHOW);
			}
		}
		SetCurrentDirectory(cCurDir);
	}
}

extern int	cambuttonstate;


⌨️ 快捷键说明

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