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

📄 genedit.cpp

📁 3D游戏场景编辑器
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************************/
/*  GenEdit.cpp                                                                          */
/*                                                                                      */
/*  Author:       Jim Mischel, Ken Baird, Jeff Lomax, John Moore, Bruce Cooner          */
/*  Description:  Top level mfc stuff here                                              */
/*                                                                                      */
/*  The contents of this file are subject to the Genesis3D Public License               */
/*  Version 1.01 (the "License"); you may not use this file except in                   */
/*  compliance with the License. You may obtain a copy of the License at                */
/*  http://www.genesis3d.com                                                            */
/*                                                                                      */
/*  Software distributed under the License is distributed on an "AS IS"                 */
/*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
/*  the License for the specific language governing rights and limitations              */
/*  under the License.                                                                  */
/*                                                                                      */
/*  The Original Code is Genesis3D, released March 25, 1999.                            */
/*Genesis3D Version 1.1 released November 15, 1999                            */
/*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
/*                                                                                      */
/*  Modified by Tom Morris for GenEdit-Classic ver. 0.5, Dec. 15, 2000					*/
/****************************************************************************************/

#include "stdafx.h"
#include "Globals.h"
#include "GenEdit.h"
#include "MainFrm.h"
#include "ChildFrm.h"
#include "GenEditView.h"
#include "PreferencesDialog.h"
#include "TextureDlg.h"
#include "about.h"
#include "FilePath.h"
#include "ram.h"
#include "util.h"
#include "Splash.h"
#include "TipDlg.h"

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


//#define TIME_OUT

/////////////////////////////////////////////////////////////////////////////
// CGenEditApp

BEGIN_MESSAGE_MAP(CGenEditApp, CWinApp)
	ON_COMMAND(CG_IDS_TIPOFTHEDAY, ShowTipOfTheDay)
	//{{AFX_MSG_MAP(CGenEditApp)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
	ON_COMMAND(ID_FILE_NEW, OnFileNew)
	ON_COMMAND(ID_FILE_OPEN, OnFileOpen)
	ON_COMMAND_EX_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnOpenRecentFile)
	ON_COMMAND(IDM_PREFERENCES, OnPreferences)
	ON_UPDATE_COMMAND_UI(IDM_PREFERENCES, OnUpdatePreferences)
	ON_COMMAND(ID_HELP_HOWDOI, OnHelpHowdoi)
	//}}AFX_MSG_MAP
	ON_COMMAND(ID_HELP_INDEX, OnHelpIndex)
	ON_COMMAND(ID_HELP, OnHelp)
	ON_COMMAND(ID_CONTEXT_HELP, OnContextHelp)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGenEditApp construction

CGenEditApp::CGenEditApp()
{
	// TODO: add construction code here,
	// Place all significant initialization in InitInstance
}

//	Destruction...
CGenEditApp::~CGenEditApp()
{
	if( pShutdownEvent != NULL )
	{
		pShutdownEvent->SetEvent();
		
		if( pWatcher != NULL )
			::WaitForSingleObject( pWatcher->m_hThread, INFINITE );

		delete pShutdownEvent;
		pShutdownEvent = NULL;
	}

	if( pNewInstanceEvent != NULL )
	{
		delete pNewInstanceEvent;
		pNewInstanceEvent = NULL;
	}

	CloseAllDocuments( TRUE );

	if (pPrefs != NULL)
	{
		Prefs_Save (pPrefs, m_pszProfileName);
		Prefs_Destroy (&pPrefs);
	}
	if (pResolvedPrefs != NULL)
	{
		Prefs_Destroy (&pResolvedPrefs);
	}
}

/////////////////////////////////////////////////////////////////////////////
// The one and only CGenEditApp object

CGenEditApp theApp;

#pragma warning (disable:4100)
static	LONG	__stdcall xxHandler(LPEXCEPTION_POINTERS xcpt)
{
static	int	nested;

	if	(!nested)
	{
		nested = 1;
		::MessageBeep(1);
		exit(0);
	}

	return EXCEPTION_EXECUTE_HANDLER;
}
#pragma warning (default:4100)

void CGenEditApp::ResolvePreferencesPaths (void)
{
	char AppDir[MAX_PATH];
	char WorkTxlSearch[2048];
	char Work[2048];	// hope that's big enough!!
	
	::Prefs_SetBackgroundColor (pResolvedPrefs, Prefs_GetBackgroundColor (pPrefs));
	::Prefs_SetGridColor (pResolvedPrefs, Prefs_GetGridColor (pPrefs));
	::Prefs_SetSnapGridColor (pResolvedPrefs, Prefs_GetSnapGridColor (pPrefs));
	::FilePath_GetNameAndExt (Prefs_GetTxlName (pPrefs), Work);
	::Prefs_SetTxlName (pResolvedPrefs, Work);

	WorkTxlSearch[0] = '\0';
	::GetCurrentDirectory (sizeof (WorkTxlSearch), WorkTxlSearch);
	if (::GetModuleFileName (NULL, AppDir, sizeof (AppDir)))
	{
		::FilePath_GetDriveAndDir (AppDir, AppDir);
	}
	else
	{
		AppDir[0] = '\0';
	}
	::FilePath_AppendSearchDir (WorkTxlSearch, AppDir);

	::FilePath_ResolveRelativePathList (Prefs_GetTxlSearchPath (pPrefs), Work);
	::FilePath_AppendSearchDir (WorkTxlSearch, Work);
	::Prefs_SetTxlSearchPath (pResolvedPrefs, WorkTxlSearch);

	::FilePath_ResolveRelativePath (Prefs_GetPreviewPath (pPrefs), Work);
	::Prefs_SetPreviewPath (pResolvedPrefs, Work);

	::FilePath_ResolveRelativePathList (Prefs_GetHeadersList (pPrefs), Work);
	::Prefs_SetHeadersList (pResolvedPrefs, Work);

	::FilePath_ResolveRelativePath (Prefs_GetObjectsDir (pPrefs), Work);
	::Prefs_SetObjectsDir (pResolvedPrefs, Work);
	
	::FilePath_ResolveRelativePath (Prefs_GetProjectDir (pPrefs), Work);
	::Prefs_SetProjectDir (pResolvedPrefs, Work);
}

BOOL CGenEditApp::InitInstance()
{
	// CG: The following block was added by the Splash Screen component.\	{\		CCommandLineInfo cmdInfo;\		ParseCommandLine(cmdInfo);\\		CSplashWnd::EnableSplashScreen(cmdInfo.m_bShowSplash);\	}
	char AppPath[MAX_PATH];
	
	::GetModuleFileName (NULL, AppPath, MAX_PATH);
	FilePath_GetDriveAndDir (AppPath, AppPath);

	//	set global directory path
	GetCurrentDirectory(CGlobals::m_dwNameSize, CGlobals::m_GlobalAppPath);

	SetUnhandledExceptionFilter(xxHandler);

	//	Setup global environment...

	{
		// set up the help file
		char HelpFilePath[MAX_PATH];

					//	post 0.57	update help path				
		FilePath_AppendName (AppPath, "GENEDITHELP.HLP", HelpFilePath);
		//First free the string allocated by MFC at CWinApp startup.
		//The string is allocated before InitInstance is called.
		free ((void *)m_pszHelpFilePath);

		//The CWinApp destructor will free the memory.
		m_pszHelpFilePath=_tcsdup(_T(HelpFilePath));
	}

	// Initialize OLE 2.0 libraries
	/*if (!AfxOleInit())
	{
		AfxMessageBox("Cannot load OLE");
		return FALSE;
	}*/

	// Standard initialization
	// If you are not using these features and wish to reduce the size
	//  of your final executable, you should remove from the following
	//  the specific initialization routines you do not need.

#ifdef _AFXDLL
	Enable3dControls();			// Call this when using MFC in a shared DLL
#else
	Enable3dControlsStatic();	// Call this when linking to MFC statically
#endif


	{
		char IniFilePath[MAX_PATH] ;

		FilePath_AppendName (AppPath, GenEdit_INIFILE_NAME, IniFilePath);

		// Set our INI file to GEDIT.INI
		free( (void*)m_pszProfileName ) ;
		m_pszProfileName = _tcsdup( IniFilePath ) ;

	}

	LoadStdProfileSettings();  // Load standard INI file options (including MRU)

	// load the preferences from the INI file, and resolve any relative paths
	pPrefs = Prefs_Read (m_pszProfileName);
	pResolvedPrefs = Prefs_Create ();

	ResolvePreferencesPaths ();

	// Register the application's document templates.  Document templates
	//  serve as the connection between documents, frame windows and views.

	pDocTemplate = new CMultiDocTemplate(
		IDR_GENEDITTYPE,
		RUNTIME_CLASS(CGenEditDoc),
		RUNTIME_CLASS(CChildFrame), // custom MDI child frame
		RUNTIME_CLASS(CGenEditView));
	AddDocTemplate(pDocTemplate);

	// create main MDI Frame window
	pMainFrame = new CMainFrame;
	if (!pMainFrame->LoadFrame(IDR_MAINFRAME))
		return FALSE;
	m_pMainWnd = pMainFrame;

	// Enable drag/drop open
	m_pMainWnd->DragAcceptFiles();

	// Enable DDE Execute open
	EnableShellOpen();
	RegisterShellFileTypes(TRUE);

	// Parse command line for standard shell commands, DDE, file open
	CCommandLineInfo cmdInfo;
	ParseCommandLine(cmdInfo);

	//	Preliminary command line error checking...

	//	Are there commands?
	int index = 0;
	CString CmdLine = m_lpCmdLine;
	CString Argument;
	if( ( index = CmdLine.Find( '-' )) != -1 )
	{
		//	Yep...

		//	Is there a .3dt file in there before the first command?
		Argument = CmdLine.Left( index - 1 );
		if( Argument.IsEmpty() )
		{
			//	Nope...
			AfxMessageBox( "Unable to process command line.  No .3DT file specified.", MB_OK );
			return FALSE;
		}
	}

	//	If there is a file name in cmdInfo, does it have a .3dt extension?
	//  If not, provide one...
	Argument = cmdInfo.m_strFileName;
	Argument.MakeLower();
	if( !Argument.IsEmpty() )
	{
		if( Argument.Find( ".3dt" ) == -1 )
		{
			//	Extension not present, add it to the end of file name
			Argument = Argument + ".3dt";
			cmdInfo.m_strFileName = Argument;
		}
	}

	// Dispatch commands specified on the command line
	if (!ProcessShellCommand(cmdInfo))
	{
		pMainFrame->IsDestroyingApp = 1;
		return FALSE;
	}

	//	Check to see if this is the first instance...
	if( !IsFirstInstance() )
		return FALSE;


						//	load up the disclaimer dialog
//	CDisclaimerDlg pDisclaimerDlg;
//	pDisclaimerDlg.DoModal();

	//	Let's setup the brush/entities tab...
//	pMainFrame->m_wndTabControls->UpdateTabs();		//	old GEdit

								// including fills in texture list box

	//	Let's grab the active document and save it...
	CChildFrame* pActiveChild =(CChildFrame *)pMainFrame->MDIGetActive();
	CGenEditDoc* pDoc;

	if (pActiveChild == NULL ||
	  (pDoc = (CGenEditDoc*) pActiveChild->GetActiveDocument()) == NULL)
	{
		TRACE0("Warning: No active document for tab update command.\n");
		AfxMessageBox(AFX_IDP_COMMAND_FAILURE);
		return FALSE;     // command failed
	}
	pGenEditDoc = pDoc;

⌨️ 快捷键说明

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