int
PAKViewer::OnLoadTexture (int pos)
{
	static char str2[256];
	char suffix[16] = "";

	if (strstr (d_currLumpName, ".tga"))
		sprintf (suffix, "%d%s", pos, ".tga");

	_makeTempFileName (str2, suffix);

	if (!pak_ExtractFile (d_pakFile, d_currLumpName, str2))
	{
		mxMessageBox (this, "Error extracting from PAK file.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
		return 1;
	}

	if (0 /* g_MDLViewer->getGlWindow ()->loadTexture (str2, pos) */)
	{
		if (pos == 0)
			g_ControlPanel->setShowBackground (true);
		else
			g_ControlPanel->setShowGround (true);
	}
	else
		mxMessageBox (this, "Error loading texture.",  g_appTitle, MX_MB_OK | MX_MB_ERROR);

	return 1;
}
int
PAKViewer::OnLoadModel ()
{
	static char str2[256];
	char suffix[16];

	strcpy (suffix, ".mdl");
	_makeTempFileName (str2, suffix);

	if (!pak_ExtractFile (d_pakFile, d_currLumpName, str2))
	{
		mxMessageBox (this, "Error extracting from PAK file.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
		return 1;
	}

	g_pStudioModel->FreeModel ();
	if( !g_pStudioModel->LoadModel (str2) )
	{
		mxMessageBox (this, "Error reading model header.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
		return 1;
	}

	studiohdr_t *hdr = g_pStudioModel->getStudioHeader();
		
	return 1;
}
Beispiel #3
0
//-----------------------------------------------------------------------------
// Purpose: Loads the file and updates the MRU list.
// Input  : pszFile - File to load.
//-----------------------------------------------------------------------------
void MDLViewer::LoadModelFile( const char *pszFile, int slot )
{
	// copy off name, pszFile may be point into recentFiles array
	char filename[1024];
	strcpy( filename, pszFile );

	LoadModelResult_t eLoaded = d_cpl->loadModel( filename, slot );

	if ( eLoaded != LoadModel_Success )
	{
		switch (eLoaded)
		{
			case LoadModel_LoadFail:
			{
				mxMessageBox (this, "Error loading model.", g_appTitle, MX_MB_ERROR | MX_MB_OK);
				break;
			}
			
			case LoadModel_PostLoadFail:
			{
				mxMessageBox (this, "Error post-loading model.", g_appTitle, MX_MB_ERROR | MX_MB_OK);
				break;
			}

			case LoadModel_NoModel:
			{
				mxMessageBox (this, "Error loading model. The model has no vertices.", g_appTitle, MX_MB_ERROR | MX_MB_OK);
				break;
			}
		}

		return;
	}

	if (slot == -1)
	{
		int i;
		for (i = 0; i < 8; i++)
		{
			if (!mx_strcasecmp( recentFiles[i], filename ))
				break;
		}

		// shift down existing recent files
		for (i = ((i > 7) ? 7 : i); i > 0; i--)
		{
			strcpy (recentFiles[i], recentFiles[i-1]);
		}

		strcpy( recentFiles[0], filename );

		initRecentFiles ();

		setLabel( "%s", filename );
	}
}
int
PAKViewer::OnPlaySound ()
{
#ifdef WIN32
	static char str2[256];
	char suffix[16] = "";

	// stop any playing sound
	PlaySound (0, 0, SND_FILENAME | SND_ASYNC);

	if (strstr (d_currLumpName, ".wav"))
		sprintf (suffix, "%d%s", 44, ".wav");

	_makeTempFileName (str2, suffix);

	if (!pak_ExtractFile (d_pakFile, d_currLumpName, str2))
	{
		mxMessageBox (this, "Error extracting from PAK file.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
		return 1;
	}

	PlaySound (str2, 0, SND_FILENAME | SND_ASYNC);

#endif
	return 1;
}
int
PAKViewer::OnExtract ()
{
	char *ptr = (char *) mxGetSaveFileName (this, "", "*.*");
	if (ptr)
	{
		if (!pak_ExtractFile (d_pakFile, d_currLumpName, ptr))
			mxMessageBox (this, "Error extracting from PAK file.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
	}

	return 1;
}
Beispiel #6
0
int
main (int argc, char *argv[])
{
	mx::init (argc, argv);

	FILE *file = fopen ("md2.cfg", "rb");
	if (!file)
	{
		mxMessageBox (0, "Error loading configuration", "MD2 Viewer", MX_MB_OK | MX_MB_ERROR);
		return 0;
	}

	int width, height;
	bool cds;
	float d_rotX, d_rotY;
	float d_transX, d_transY, d_transZ;
	int d_renderMode;
	float d_pol;
	int d_currFrame, d_currFrame2, d_startFrame, d_endFrame;
	float d_pitch;
	float d_bgColor[3];
	float d_fgColor[3];
	float d_wfColor[3];
	float d_lightColor[3];
	float d_bias;
	int d_flags;
	int d_textureLimit;


	fread (&width, sizeof (int), 1, file);
	fread (&height, sizeof (int), 1, file);
	fread (&cds, sizeof (bool), 1, file);

	fread (modelFile, 256, 1, file);
	fread (modelTexFile, 256, 1, file);
	fread (weaponFile, 256, 1, file);
	fread (weaponTexFile, 256, 1, file);
	fread (backgroundTexFile, 256, 1, file);
	fread (waterTexFile, 256, 1, file);

	fread (&d_rotX, sizeof (float), 1, file);
	fread (&d_rotY, sizeof (float), 1, file);
	fread (&d_transX, sizeof (float), 1, file);
	fread (&d_transY, sizeof (float), 1, file);
	fread (&d_transZ, sizeof (float), 1, file);

	fread (&d_renderMode, sizeof (int), 1, file);

	fread (&d_pol, sizeof (float), 1, file);
	fread (&d_currFrame, sizeof (int), 1, file);
	fread (&d_currFrame2, sizeof (int), 1, file);
	fread (&d_startFrame, sizeof (int), 1, file);
	fread (&d_endFrame, sizeof (int), 1, file);
	fread (&d_pitch, sizeof (float), 1, file);

	fread (d_bgColor, 3 * sizeof (float), 1, file);
	fread (d_fgColor, 3 * sizeof (float), 1, file);
	fread (d_wfColor, 3 * sizeof (float), 1, file);
	fread (d_lightColor, 3 * sizeof (float), 1, file);
	fread (&d_bias, sizeof (int), 1, file);
	fread (&d_flags, sizeof (int), 1, file);
	fread (&d_textureLimit, sizeof (int), 1, file);

	fclose (file);

	if (cds)
		mx::setDisplayMode (width, height, 16);

	mxGlWindow::setFormat (mxGlWindow::FormatDouble, 16, 16);

	GlWindow *glw = new GlWindow (0, 0, 0, width, height, "", mxWindow::Popup);

	glw->loadModel (modelFile, 0);
	glw->loadModel (weaponFile, 1);
	glw->loadTexture (modelTexFile, TEXTURE_MODEL);
	glw->loadTexture (weaponTexFile, TEXTURE_WEAPON);
	glw->loadTexture (backgroundTexFile, TEXTURE_BACKGROUND);
	glw->loadTexture (waterTexFile, TEXTURE_WATER);

	glw->setRot (d_rotX, d_rotY);
	glw->setTrans (d_transX, d_transY, d_transZ);
	glw->setRenderMode (d_renderMode);
	glw->setInterpolate (d_pol);
	glw->setCurrFrame (d_currFrame);
	glw->setCurrFrame2 (d_currFrame2);
	glw->setStartFrame (d_startFrame);
	glw->setEndFrame (d_endFrame);
	glw->setPitch (d_pitch);

	glw->setBGColor (d_bgColor[0], d_bgColor[1], d_bgColor[2]);
	glw->setFGColor (d_fgColor[0], d_fgColor[1], d_fgColor[2]);
	glw->setWFColor (d_wfColor[0], d_wfColor[1], d_wfColor[2]);
	glw->setLightColor (d_lightColor[0], d_lightColor[1], d_lightColor[2]);

	glw->setBrightness ((int) d_bias);
	glw->setFlags (d_flags);
	glw->setFlag (F_LIGHT, false);
	glw->setTextureLimit (d_textureLimit);

	int ret = mx::run ();

	if (cds)
		mx::setDisplayMode (0, 0, 0);

	delete glw;

	return ret;
}
Beispiel #7
0
int
MDLViewer::handleEvent (mxEvent *event)
{
	MDLCACHE_CRITICAL_SECTION_( g_pMDLCache );
	
	switch (event->event)
	{
	case mxEvent::Action:
	{
		switch (event->action)
		{
		case IDC_FILE_LOADMODEL:
		{
			const char *ptr = mxGetOpenFileName (this, 0, "*.mdl");
			if (ptr)
			{
				LoadModelFile( ptr );
			}
		}
		break;

		case IDC_FILE_LOADMODEL_STEAM:
		{
			const char *pFilename = SteamGetOpenFilename();
			if ( pFilename )
			{
				LoadModelFile( pFilename );
			}
		}
		break;

		case IDC_FILE_LOADMERGEDMODEL:
		{
			const char *ptr = mxGetOpenFileName (this, 0, "*.mdl");
			if (ptr)
			{
				strcpy( g_viewerSettings.mergeModelFile[0], ptr );
				LoadModelFile( ptr, 0 );
			}
		}
		break;

		case IDC_FILE_LOADMERGEDMODEL_STEAM:
		{
			const char *pFilename = SteamGetOpenFilename();
			if ( pFilename )
			{
				strcpy( g_viewerSettings.mergeModelFile[0], pFilename );
				LoadModelFile( pFilename, 0 );
			}
		}
		break;

		case IDC_FILE_UNLOADMERGEDMODEL:
		{
			// FIXME: move to d_cpl
			if (g_pStudioExtraModel[0])
			{
				strcpy( g_viewerSettings.mergeModelFile[0], "" );
				g_pStudioExtraModel[0]->FreeModel( false );
				delete g_pStudioExtraModel[0];
				g_pStudioExtraModel[0] = NULL;
			}
		}
		break;

		case IDC_FILE_REFRESH:
		{
			Refresh();
			break;
		}

		case IDC_FILE_LOADBACKGROUNDTEX:
		case IDC_FILE_LOADGROUNDTEX:
		{
			const char *ptr = mxGetOpenFileName (this, 0, "*.*");
			if (ptr)
			{
				if (0 /* d_MatSysWindow->loadTexture (ptr, event->action - IDC_FILE_LOADBACKGROUNDTEX) */)
				{
					if (event->action == IDC_FILE_LOADBACKGROUNDTEX)
						d_cpl->setShowBackground (true);
					else
						d_cpl->setShowGround (true);

				}
				else
					mxMessageBox (this, "Error loading texture.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
			}
		}
		break;

		case IDC_FILE_UNLOADGROUNDTEX:
		{
			// d_MatSysWindow->loadTexture (0, 1);
			d_cpl->setShowGround (false);
		}
		break;

		case IDC_FILE_RECENTMODELS1:
		case IDC_FILE_RECENTMODELS2:
		case IDC_FILE_RECENTMODELS3:
		case IDC_FILE_RECENTMODELS4:
		case IDC_FILE_RECENTMODELS5:
		case IDC_FILE_RECENTMODELS6:
		case IDC_FILE_RECENTMODELS7:
		case IDC_FILE_RECENTMODELS8:
		{
			int i = event->action - IDC_FILE_RECENTMODELS1;
			LoadModelFile( recentFiles[i] );
		}
		break;

		case IDC_FILE_EXIT:
		{
			redraw ();
			mx::quit ();
		}
		break;

		case IDC_OPTIONS_COLORBACKGROUND:
		case IDC_OPTIONS_COLORGROUND:
		case IDC_OPTIONS_COLORLIGHT:
		case IDC_OPTIONS_COLORAMBIENT:
		{
			float *cols[4] = { g_viewerSettings.bgColor, g_viewerSettings.gColor, g_viewerSettings.lColor, g_viewerSettings.aColor };
			float *col = cols[event->action - IDC_OPTIONS_COLORBACKGROUND];
			int r = (int) (col[0] * 255.0f);
			int g = (int) (col[1] * 255.0f);
			int b = (int) (col[2] * 255.0f);
			if (mxChooseColor (this, &r, &g, &b))
			{
				col[0] = (float) r / 255.0f;
				col[1] = (float) g / 255.0f;
				col[2] = (float) b / 255.0f;
			}
		}
		break;

		case IDC_OPTIONS_CENTERVIEW:
			d_cpl->centerView ();
			break;
		case IDC_OPTIONS_VIEWMODEL:
		{
			d_cpl->viewmodelView();
		}
		break;

		case IDC_OPTIONS_MAKESCREENSHOT:
		{
			char *ptr = (char *) mxGetSaveFileName (this, "", "*.tga");
			if (ptr)
			{
				if (!strstr (ptr, ".tga"))
					strcat (ptr, ".tga");
				d_MatSysWindow->dumpViewport (ptr);
			}
		}
		break;

		case IDC_OPTIONS_DUMP:
			d_cpl->dumpModelInfo ();
			break;

		case IDC_VIEW_FILEASSOCIATIONS:
			g_FileAssociation->setAssociation (0);
			g_FileAssociation->setVisible (true);
			break;

		case IDC_VIEW_ACTIVITIES:
			g_viewerSettings.showActivities = !g_viewerSettings.showActivities;
			menuView->setChecked( event->action, g_viewerSettings.showActivities );
			d_cpl->initSequenceChoices();
			d_cpl->resetControlPanel();
			break;

		case IDC_VIEW_HIDDEN:
			g_viewerSettings.showHidden = !g_viewerSettings.showHidden;
			menuView->setChecked( event->action, g_viewerSettings.showHidden );
			d_cpl->initSequenceChoices();
			d_cpl->resetControlPanel();
			break;

#ifdef WIN32
		case IDC_HELP_GOTOHOMEPAGE:
			ShellExecute (0, "open", "http://www.swissquake.ch/chumbalum-soft/index.html", 0, 0, SW_SHOW);
			break;
#endif

		case IDC_HELP_ABOUT:
			mxMessageBox (this,
				"Half-Life Model Viewer v2.0 (c) 2004 Valve Corp.\n"
				"Portions (c) 1999 by Mete Ciragan\n\n"
				"Left-drag inside circle to spin.\n"
				"Left-drag outside circle to rotate.\n"
				"Right-drag to zoom.\n"
				"Shift-left-drag to x-y-pan.\n"
				"Shift-right-drag to z-pan.\n"
				"Ctrl-left-drag to move light.\n\n"
				"Build:\t" __DATE__ ".\n"
				"Email:\[email protected]\n"
				"Web:\thttp://www.swissquake.ch/chumbalum-soft/", "About Half-Life Model Viewer",
				MX_MB_OK | MX_MB_INFORMATION);
			break;

		case IDC_ACCEL_WIREFRAME:
			d_cpl->setOverlayWireframe( !g_viewerSettings.overlayWireframe );
			break;

		case IDC_ACCEL_ATTACHMENTS:
			d_cpl->setShowAttachments( !g_viewerSettings.showAttachments );
			break;

		case IDC_ACCEL_GROUND:
			d_cpl->setShowGround( !g_viewerSettings.showGround );
			break;

		case IDC_ACCEL_HITBOXES:
			d_cpl->setShowHitBoxes( !g_viewerSettings.showHitBoxes );
			break;

		case IDC_ACCEL_BONES:
			d_cpl->setShowBones( !g_viewerSettings.showBones );
			break;

		case IDC_ACCEL_BACKGROUND:
			d_cpl->setShowBackground( !g_viewerSettings.showBackground );
			break;

		case IDC_ACCEL_MOVEMENT:
			d_cpl->setShowMovement( !g_viewerSettings.showMovement );
			break;

		case IDC_ACCEL_NORMALS:
			d_cpl->setShowNormals( !g_viewerSettings.showNormals );
			break;

		case IDC_ACCEL_TANGENTS:
			d_cpl->setShowTangentFrame( !g_viewerSettings.showTangentFrame );
			break;

		case IDC_ACCEL_SHADOW:
			d_cpl->setShowShadow( !g_viewerSettings.showShadow );
			break;

		} //switch (event->action)

	} // mxEvent::Action
	break;

	case mxEvent::Size:
	{
		g_viewerSettings.xpos = x();
		g_viewerSettings.ypos = y();
		g_viewerSettings.width = w();
		g_viewerSettings.height = h();

		int w = event->width;
		int h = event->height;
		int y = mb->getHeight ();
#ifdef WIN32
#define HEIGHT 240
#else
#define HEIGHT 140
		h -= 40;
#endif

		d_MatSysWindow->setBounds (0, y, w, h - HEIGHT); // !!
		d_cpl->setBounds (0, y + h - HEIGHT, w, HEIGHT);
	}
	break;


	case mxEvent::PosChanged:
	{
		g_viewerSettings.xpos = x();
		g_viewerSettings.ypos = y();
	}
	break;

	case KeyDown:
		d_MatSysWindow->handleEvent(event);
		d_cpl->handleEvent(event);
	break;

	case mxEvent::Activate:
	{
		if (event->action)
		{
			mx::setIdleWindow( getMatSysWindow() );
		}
		else
		{
			mx::setIdleWindow( 0 );
		}
	}
	break;

	} // event->event

	return 1;
}
int MDLViewer::handleEvent (mxEvent *event)
{
	int iret = 0;

	switch (event->event)
	{
	case mxEvent::Size:
		{
			int width = w2();
			int height = h2();

			workspace->setBounds( 0, 0, width, height - WINDOW_TAB_OFFSET );
			int gridsettingswide = 100;
			int gridstart = width - gridsettingswide - 5;
			int windowwide = gridstart * 0.6f;
			int modelwide = gridstart * 0.4f;

			gridsettings->setBounds( gridstart, height - WINDOW_TAB_OFFSET + 1, gridsettingswide, WINDOW_TAB_OFFSET - 2 );

			windowtab->setBounds( 0, height - WINDOW_TAB_OFFSET, windowwide, WINDOW_TAB_OFFSET );
			modeltab->setBounds( windowwide, height - WINDOW_TAB_OFFSET, modelwide, WINDOW_TAB_OFFSET );

			iret = 1;
		}
		break;
	case mxEvent::Action:
		{
			iret = 1;
			switch (event->action)
			{
			case IDC_WINDOW_TAB:
				{
					windowtab->HandleWindowSelect();
				}
				break;
			case IDC_MODEL_TAB:
				{
					modeltab->HandleModelSelect();
				}
				break;
			case IDC_EDIT_COPY:
				{
					Copy();
				}
				break;
				
			case IDC_EDIT_PASTE:
				{
					Paste();
				}
				break;
				
			case IDC_EDIT_UNDO:
				{
					Undo();
				}
				break;
				
			case IDC_EDIT_REDO:
				{
					Redo();
				}
				break;
				
			case IDC_FILE_LOADMODEL:
				{
					const char *ptr = mxGetOpenFileName(
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/models/", GetGameDirectory() ) ),
						"*.mdl");
					if (ptr)
					{
						LoadModelFile( ptr );
					}
				}
				break;
				
			case IDC_FILE_REFRESH:
				{
					Refresh();
					break;
				}
				
			case IDC_FILE_LOADBACKGROUNDTEX:
			case IDC_FILE_LOADGROUNDTEX:
				{
					const char *ptr = mxGetOpenFileName (this, 0, "*.*");
					if (ptr)
					{
						if (0 /* g_pMatSysWindow->loadTexture (ptr, event->action - IDC_FILE_LOADBACKGROUNDTEX) */)
						{
							if (event->action == IDC_FILE_LOADBACKGROUNDTEX)
								g_pControlPanel->setShowBackground (true);
							else
								g_pControlPanel->setShowGround (true);
							
						}
						else
							mxMessageBox (this, "Error loading texture.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
					}
				}
				break;
				
			case IDC_FILE_UNLOADGROUNDTEX:
				{
					// g_pMatSysWindow->loadTexture (0, 1);
					g_pControlPanel->setShowGround (false);
				}
				break;
				
			case IDC_FILE_RECENTMODELS1:
			case IDC_FILE_RECENTMODELS2:
			case IDC_FILE_RECENTMODELS3:
			case IDC_FILE_RECENTMODELS4:
				{
					int i = event->action - IDC_FILE_RECENTMODELS1;
					
					LoadModelFile( recentFiles[ i ] );
					
					char tmp[256];			
					strcpy (tmp, recentFiles[0]);
					strcpy (recentFiles[0], recentFiles[i]);
					strcpy (recentFiles[i], tmp);
					
					initRecentFiles ();
					
					redraw ();
				}
				break;
				
			case IDC_FILE_EXIT:
				{
					redraw ();
					mx::quit ();
				}
				break;
				
			case IDC_OPTIONS_COLORBACKGROUND:
			case IDC_OPTIONS_COLORGROUND:
			case IDC_OPTIONS_COLORLIGHT:
				{
					float *cols[3] = { g_viewerSettings.bgColor, g_viewerSettings.gColor, g_viewerSettings.lColor };
					float *col = cols[event->action - IDC_OPTIONS_COLORBACKGROUND];
					int r = (int) (col[0] * 255.0f);
					int g = (int) (col[1] * 255.0f);
					int b = (int) (col[2] * 255.0f);
					if (mxChooseColor (this, &r, &g, &b))
					{
						col[0] = (float) r / 255.0f;
						col[1] = (float) g / 255.0f;
						col[2] = (float) b / 255.0f;
					}
				}
				break;
				
			case IDC_OPTIONS_CENTERVIEW:
				g_pControlPanel->centerView ();
				break;
				
			case IDC_OPTIONS_CENTERONFACE:
				g_pControlPanel->CenterOnFace();
				break;
				
			case IDC_OPTIONS_MAKESCREENSHOT:
				{
					char *ptr = (char *) mxGetSaveFileName (this, "", "*.tga");
					if (ptr)
					{
						if (!strstr (ptr, ".tga"))
							strcat (ptr, ".tga");
						// g_pMatSysWindow->dumpViewport (ptr);
					}
				}
				break;
				
			case IDC_OPTIONS_DUMP:
				g_pControlPanel->dumpModelInfo ();
				break;
				
#ifdef WIN32
			case IDC_HELP_GOTOHOMEPAGE:
				ShellExecute (0, "open", "http://www.swissquake.ch/chumbalum-soft/index.html", 0, 0, SW_SHOW);
				break;
#endif
				
			case IDC_HELP_ABOUT:
				mxMessageBox (this,
					"v0.1 (c) 2001, Valve, LLC.  All rights reserved.\r\nBuild Date: "__DATE__"",
					"Valve Face Poser", 
					MX_MB_OK | MX_MB_INFORMATION);
				break;
				
			case IDC_EXPRESSIONS_REDOBITMAPS:
				{
					bool saveOverrides = g_pExpressionTrayTool->GetOverridesShowing();
					g_pExpressionTrayTool->SetOverridesShowing( false );
					CExpClass *active = expressions->GetActiveClass();
					if ( active )
					{
						for ( int i = 0; i < active->GetNumExpressions() ; i++ )
						{
							CExpression *exp = active->GetExpression( i );
							if ( !exp )
								continue;
							
							active->SelectExpression( i );
							exp->CreateNewBitmap( models->GetActiveModelIndex() );
							
							if ( ! ( i % 5 ) )
							{
								g_pExpressionTrayTool->redraw();
							}
						}
						
						if ( active->HasOverrideClass() )
						{
							
							g_pExpressionTrayTool->SetOverridesShowing( true );
							
							CExpClass *oc = active->GetOverrideClass();
							for ( int i = 0; i < oc->GetNumExpressions() ; i++ )
							{
								CExpression *exp = oc->GetExpression( i );
								if ( !exp )
									continue;
								
								oc->SelectExpression( i );
								exp->CreateNewBitmap( models->GetActiveModelIndex() );
								
								if ( ! ( i % 5 ) )
								{
									g_pExpressionTrayTool->redraw();
								}
							}
						}
						active->SelectExpression( 0 );
					}
					
					g_pExpressionTrayTool->SetOverridesShowing( saveOverrides );
				}
				break;
			case IDC_EXPRESSIONS_NEW:
				{
					const char *filename = mxGetSaveFileName( 
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/expressions/", GetGameDirectory() ) ), 
						"*.txt" );
					if ( filename && filename[ 0 ] )
					{
						char classfile[ 512 ];
						strcpy( classfile, filename );
						StripExtension( classfile );
						DefaultExtension( classfile, ".txt" );
						
						expressions->CreateNewClass( classfile );
					}
				}
				break;
			case IDC_EXPRESSIONS_LOAD:
				{
					const char *filename = NULL;
					
					filename = mxGetOpenFileName( 
						this, 
						FacePoser_MakeWindowsSlashes( va( "%s/expressions/", GetGameDirectory() ) ), 
						"*.txt" );
					if ( filename && filename[ 0 ] )
					{
						expressions->LoadClass( filename );
					}
				}
				break;
				
			case IDC_EXPRESSIONS_SAVE:
				{
					CExpClass *active = expressions->GetActiveClass();
					if ( active )
					{
						active->Save();
						active->Export();
					}
				}
				break;
			case IDC_EXPRESSIONS_EXPORT:
				{
					CExpClass *active = expressions->GetActiveClass();
					if ( active )
					{
						active->Export();
					}
				}
				break;
			case IDC_EXPRESSIONS_CLOSE:
				g_pControlPanel->Close();
				break;
			case IDC_EXPRESSIONS_CLOSEALL:
				g_pControlPanel->Closeall();
				break;
			case IDC_CHOREOSCENE_NEW:
				g_pChoreoView->New();
				break;
			case IDC_CHOREOSCENE_LOAD:
				g_pChoreoView->Load();
				break;
			case IDC_CHOREOSCENE_SAVE:
				g_pChoreoView->Save();
				break;
			case IDC_CHOREOSCENE_SAVEAS:
				g_pChoreoView->SaveAs();
				break;
			case IDC_CHOREOSCENE_CLOSE:
				g_pChoreoView->Close();
				break;
			case IDC_CHOREOSCENE_ADDACTOR:
				g_pChoreoView->NewActor();
				break;
			case IDC_WINDOW_TILE:
				{
					OnTile();
				}
				break;
			case IDC_WINDOW_TILE_HORIZ:
				{
					OnTileHorizontally();
				}
				break;
			case IDC_WINDOW_TILE_VERT:
				{
					OnTileVertically();
				}
				break;
			case IDC_WINDOW_CASCADE:
				{
					OnCascade();
				}
				break;
			case IDC_WINDOW_HIDEALL:
				{
					OnHideAll();
				}
				break;
			case IDC_WINDOW_SHOWALL:
				{
					OnShowAll();
				}
				break;
			default:
				{
					iret = 0;
					int tool_number = event->action - IDC_WINDOW_FIRSTTOOL;
					int max_tools = IDC_WINDOW_LASTTOOL - IDC_WINDOW_FIRSTTOOL;
					
					if ( tool_number >= 0 && 
						tool_number <= max_tools && 
						tool_number < IFacePoserToolWindow::GetToolCount() )
					{
						iret = 1;
						IFacePoserToolWindow *tool = IFacePoserToolWindow::GetTool( tool_number );
						if ( tool )
						{
							mxWindow *toolw = tool->GetMxWindow();
							
							bool wasvisible = toolw->isVisible();
							toolw->setVisible( !wasvisible );
							
							g_MDLViewer->UpdateWindowMenu();

						}
					}
				}
				break;
			} //switch (event->action)
		} // mxEvent::Action
		break;
	case KeyDown:
		{
			g_pMatSysWindow->handleEvent(event);
			iret = 1;
		}
		break;
	case mxEvent::Activate:
		{
			if (event->action)
			{
				mx::setIdleWindow( g_pMatSysWindow );
			}
			else
			{
				mx::setIdleWindow( 0 );
			}
			iret = 1;
		}
		break;
	} // event->event
	
	return iret;
}
Beispiel #9
0
int main(int argc, char* argv[])
{
    SpewOutputFunc( SceneManagerSpewFunc );

    //
    // make sure, we start in the right directory
    //
    char szName[256];

    strcpy (szName, mx::getApplicationPath ());

    if (argc > 1)
    {
        strcpy (cmdline, argv[1]);
        for (int i = 2; i < argc; i++)
        {
            strcat (cmdline, " ");
            strcat (cmdline, argv[i]);
        }
    }

    mx::init (argc, argv);

    FileSystem_Init( true );
    filesystem = (IFileSystem *)(FileSystem_GetFactory()( FILESYSTEM_INTERFACE_VERSION, NULL ));
    if ( !filesystem )
    {
        AssertMsg( 0, "Failed to create/get IFileSystem" );
        return 1;
    }

    char workingdir[ 256 ];
    workingdir[0] = 0;
    Q_getwd( workingdir );

    char *vproject = getenv("VPROJECT");
    if ( !vproject )
    {
        mxMessageBox( NULL, "You must set VPROJECT to run scenemanager.exe", "SceneManager", MB_OK );
        return -1;
    }

    // If they didn't specify -game on the command line, use VPROJECT.
    CmdLib_InitFileSystem( workingdir, true );

    sound->Init();

    CWorkspaceManager *sm = new CWorkspaceManager();

    bool workspace_loaded = false;
    for ( int i = 1; i < argc; i++ )
    {
        if ( !workspace_loaded && strstr (argv[i], ".vsw") )
        {
            workspace_loaded = true;

            // Strip game directory and slash
            char workspace_name[ 512 ];
            filesystem->FullPathToRelativePath( argv[ i ], workspace_name );

            sm->AutoLoad( workspace_name );
        }
    }

    if ( !workspace_loaded )
    {
        sm->AutoLoad( NULL );
    }

    int retval = mx::run ();

    sound->Shutdown();

    soundemitter->BaseShutdown();

    FileSystem_Term();

    return retval;
}
int
PAKViewer::handleEvent (mxEvent *event)
{
	switch (event->event)
	{
	case mxEvent::Action:
	{
		switch (event->action)
		{
		case IDC_PAKVIEWER: // tvPAK
			if (event->flags & mxEvent::RightClicked)
			{
				pmMenu->setEnabled (1, strstr (d_currLumpName, ".mdl") != 0);
				pmMenu->setEnabled (2, strstr (d_currLumpName, ".tga") != 0);
				pmMenu->setEnabled (3, strstr (d_currLumpName, ".tga") != 0);
				pmMenu->setEnabled (4, strstr (d_currLumpName, ".wav") != 0);
				int ret = pmMenu->popup (tvPAK, event->x, event->y);
				switch (ret)
				{
				case 1:
					OnLoadModel ();
					break;

				case 2:
					OnLoadTexture (0);
					break;

				case 3:
					OnLoadTexture (1);
					break;

				case 4:
					OnPlaySound ();
					break;

				case 5:
					OnExtract ();
					break;
				}
			}
			else if (event->flags & mxEvent::DoubleClicked)
			{
				OnPAKViewer ();
				char e[16];

				strncpy (e, mx_getextension (d_currLumpName), 16);
				int mode = g_FileAssociation->getMode (&e[1]);
				if (mode == -1)
					return 1;

				char *program = g_FileAssociation->getProgram (&e[1]);

#ifdef WIN32
				if (mode == 0)
				{
					char str[256];
					_makeTempFileName (str, e);
					if (!pak_ExtractFile (d_pakFile, d_currLumpName, str))
						mxMessageBox (this, "Error extracting from PAK file.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
					else
					{
						if (program)
						{
							char path[256];
							strcpy (path, program);
							strcat (path, " ");
							strcat (path, str);
							if ((int) WinExec (path, SW_SHOW) <= 32)
								mxMessageBox (this, "Error executing specified program.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
						}
					}
				}

				// associated program
				else if (mode == 1)
				{
					char str[256];
					_makeTempFileName (str, e);
					if (!pak_ExtractFile (d_pakFile, d_currLumpName, str))
						mxMessageBox (this, "Error extracting from PAK file.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
					else
						if ((int) ShellExecute ((HWND) getHandle (), "open", str, 0, 0, SW_SHOW) <= 32)
							mxMessageBox (this, "Error executing document with associated program.", g_appTitle, MX_MB_OK | MX_MB_ERROR);
				}

				// HLMV default
				else	
#endif
				if (mode == 2)
				{
					if (!strcmp (e, ".mdl"))
						OnLoadModel ();

					else if (!strcmp (e, ".tga"))
						OnLoadTexture (0);

					else if (!strcmp (e, ".wav"))
						OnPlaySound ();

					return 1;
				}
			}
			
			return OnPAKViewer ();
		} // event->action
	} // mxEvent::Action
	break;

	case mxEvent::Size:
	{
		tvPAK->setBounds (0, 0, event->width, event->height);
	} // mxEvent::Size
	break;

	} // event->event

	return 1;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : hwndDlg - 
//			uMsg - 
//			wParam - 
//			lParam - 
// Output : static BOOL CALLBACK
//-----------------------------------------------------------------------------
static BOOL CALLBACK SoundLookupDialogProc( HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam )  
{
	switch(uMsg)
	{
    case WM_INITDIALOG:
		// Insert code here to put the string (to find and replace with)
		// into the edit controls.
		// ...
		{
			g_Params.PositionSelf( hwndDlg );

			PopulateSoundEntryList( hwndDlg, &g_Params );

			SetDlgItemText( hwndDlg, IDC_STATIC_PROMPT, g_Params.m_szPrompt );

			SetWindowText( hwndDlg, g_Params.m_szDialogTitle );

			SetFocus( GetDlgItem( hwndDlg, IDC_SOUNDENTRYLIST ) );
		}
		return FALSE;  
		
    case WM_COMMAND:
		switch (LOWORD(wParam))
		{
		case IDOK:
			{
				int selindex = SendMessage( GetDlgItem( hwndDlg, IDC_SOUNDENTRYLIST ), LB_GETCURSEL, 0, 0 );
				if ( selindex == LB_ERR )
				{
					mxMessageBox( NULL, "You must select an entry from the list", g_appTitle, MB_OK );
					return TRUE;
				}

				int soundindex = SendMessage( GetDlgItem( hwndDlg, IDC_SOUNDENTRYLIST ), LB_GETITEMDATA, selindex, 0 );

				Assert( soundindex != LB_ERR );

				Q_strncpy( g_Params.m_szSoundName, soundemitter->GetSoundName( soundindex ), sizeof ( g_Params.m_szSoundName ) );
				EndDialog( hwndDlg, 1 );
			}
			break;
        case IDCANCEL:
			EndDialog( hwndDlg, 0 );
			break;
		case IDC_ADDENTRY:
			{
				// Create a new sound entry for this sound
				CAddSoundParams params;
				Q_memset( &params, 0, sizeof( params ) );
				Q_strcpy( params.m_szDialogTitle, "Add Sound Entry" );
				Q_strcpy( params.m_szWaveFile, g_Params.m_szWaveFile );

				if ( AddSound( &params, hwndDlg ) )
				{
					// Add it to soundemitter and check out script files
					if ( params.m_szSoundName[ 0 ] && 
						 params.m_szScriptName[ 0 ] )
					{
						Q_strcpy( g_Params.m_szSoundName, params.m_szSoundName );
						// Press the OK button for the user...
						EndDialog( hwndDlg, 1 );
					}
				}
			}
			break;
		}
		return TRUE;
	}
	return FALSE;
}