2010-03-13 10:39:22 +00:00
# include "main.h"
# include <stdexcept>
2010-03-13 22:00:01 +00:00
# include "model_gl.h"
2010-03-13 10:39:22 +00:00
# include "graphics_interface.h"
# include "util.h"
# include "conversion.h"
2010-05-25 18:06:42 +00:00
# include "platform_common.h"
# include "xml_parser.h"
2010-05-25 18:51:35 +00:00
# include <iostream>
2010-06-24 14:00:20 +00:00
# include <wx/event.h>
2010-08-25 18:26:17 +00:00
# include "game_constants.h"
2010-03-13 10:39:22 +00:00
using namespace Shared : : Platform ;
2010-05-25 18:06:42 +00:00
using namespace Shared : : PlatformCommon ;
2010-03-13 10:39:22 +00:00
using namespace Shared : : Graphics ;
using namespace Shared : : Graphics : : Gl ;
using namespace Shared : : Util ;
2010-05-25 18:06:42 +00:00
using namespace Shared : : Xml ;
2010-03-13 10:39:22 +00:00
using namespace std ;
2010-08-25 18:26:17 +00:00
using namespace Glest : : Game ;
2010-03-13 10:39:22 +00:00
2010-06-24 13:18:11 +00:00
# ifdef _WIN32
const char * folderDelimiter = " \\ " ;
# else
const char * folderDelimiter = " / " ;
# endif
2010-08-25 19:21:11 +00:00
int GameConstants : : updateFps = 40 ;
int GameConstants : : cameraFps = 100 ;
2010-08-25 18:26:17 +00:00
2010-03-13 10:39:22 +00:00
namespace Shared { namespace G3dViewer {
// ===============================================
// class Global functions
// ===============================================
wxString ToUnicode ( const char * str ) {
return wxString ( str , wxConvUTF8 ) ;
}
wxString ToUnicode ( const string & str ) {
return wxString ( str . c_str ( ) , wxConvUTF8 ) ;
}
// ===============================================
// class MainWindow
// ===============================================
2010-11-03 19:03:25 +00:00
const string g3dviewerVersionString = " v1.3.6 " ;
2010-12-03 05:07:42 +00:00
const string MainWindow : : winHeader = " G3D viewer " + g3dviewerVersionString ;
2010-03-13 10:39:22 +00:00
MainWindow : : MainWindow ( const string & modelPath )
: wxFrame ( NULL , - 1 , ToUnicode ( winHeader ) , wxPoint ( Renderer : : windowX , Renderer : : windowY ) ,
wxSize ( Renderer : : windowW , Renderer : : windowH ) )
{
//getGlPlatformExtensions();
renderer = Renderer : : getInstance ( ) ;
2010-05-25 18:06:42 +00:00
if ( modelPath ! = " " ) {
this - > modelPathList . push_back ( modelPath ) ;
}
2010-03-13 10:39:22 +00:00
model = NULL ;
playerColor = Renderer : : pcRed ;
speed = 0.025f ;
2010-12-03 05:07:42 +00:00
int args [ ] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER } ; // to prevent flicker
glCanvas = new GlCanvas ( this , args ) ;
2010-03-13 10:39:22 +00:00
//getGlPlatformExtensions();
//glCanvas->SetCurrent();
//renderer->init();
menu = new wxMenuBar ( ) ;
//menu
menuFile = new wxMenu ( ) ;
2010-11-03 19:03:25 +00:00
menuFile - > Append ( miFileLoad , wxT ( " &Load G3d model " ) , wxT ( " Load 3D model " ) ) ;
menuFile - > Append ( miFileLoadParticleXML , wxT ( " Load &Particle XML " ) , wxT ( " Press ctrl before menu for keeping current particles " ) ) ;
menuFile - > Append ( miFileLoadProjectileParticleXML , wxT ( " Load P&rojectile Particle XML " ) , wxT ( " Press ctrl before menu for keeping current projectile particles " ) ) ;
menuFile - > Append ( miFileLoadSplashParticleXML , wxT ( " Load &Splash Particle XML " ) , wxT ( " Press ctrl before menu for keeping current splash particles " ) ) ;
menuFile - > Append ( miFileClearAll , wxT ( " &Clear All " ) ) ;
2011-01-20 18:05:07 +00:00
menuFile - > Append ( miFileSaveScreenshot , wxT ( " Sa&ve a Screenshot " ) ) ;
2010-11-03 19:03:25 +00:00
menuFile - > AppendSeparator ( ) ;
menuFile - > Append ( wxID_EXIT ) ;
menu - > Append ( menuFile , wxT ( " &File " ) ) ;
2010-03-13 10:39:22 +00:00
//mode
menuMode = new wxMenu ( ) ;
2010-11-03 19:03:25 +00:00
menuMode - > AppendCheckItem ( miModeNormals , wxT ( " &Normals " ) ) ;
menuMode - > AppendCheckItem ( miModeWireframe , wxT ( " &Wireframe " ) ) ;
menuMode - > AppendCheckItem ( miModeGrid , wxT ( " &Grid " ) ) ;
menu - > Append ( menuMode , wxT ( " &Mode " ) ) ;
2010-03-13 10:39:22 +00:00
//mode
menuSpeed = new wxMenu ( ) ;
2010-11-03 19:03:25 +00:00
menuSpeed - > Append ( miSpeedSlower , wxT ( " &Slower \t - " ) ) ;
menuSpeed - > Append ( miSpeedFaster , wxT ( " &Faster \t + " ) ) ;
menuSpeed - > AppendSeparator ( ) ;
2010-12-05 01:33:28 +00:00
menuSpeed - > Append ( miRestart , wxT ( " &Restart particles \t R " ) , wxT ( " Restart particle animations, this also reloads model and particle files if they are changed " ) ) ;
2010-11-03 19:03:25 +00:00
menu - > Append ( menuSpeed , wxT ( " &Speed " ) ) ;
2010-03-13 10:39:22 +00:00
//custom color
menuCustomColor = new wxMenu ( ) ;
2011-01-20 18:05:07 +00:00
menuCustomColor - > AppendCheckItem ( miChangeBackgroundColor , wxT ( " Change Background Color " ) ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > AppendCheckItem ( miColorRed , wxT ( " &Red \t 0 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorBlue , wxT ( " &Blue \t 1 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorGreen , wxT ( " &Green \t 2 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorYellow , wxT ( " &Yellow \t 3 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorWhite , wxT ( " &White \t 4 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorCyan , wxT ( " &Cyan \t 5 " ) ) ;
menuCustomColor - > AppendCheckItem ( miColorOrange , wxT ( " &Orange \t 6 " ) ) ;
2010-12-03 05:07:42 +00:00
menuCustomColor - > AppendCheckItem ( miColorMagenta , wxT ( " &Pink \t 7 " ) ) ; // it is called Pink everywhere else so...
2010-11-03 19:03:25 +00:00
menu - > Append ( menuCustomColor , wxT ( " &Custom Color " ) ) ;
2010-03-13 10:39:22 +00:00
menuMode - > Check ( miModeGrid , true ) ;
menuCustomColor - > Check ( miColorRed , true ) ;
SetMenuBar ( menu ) ;
//misc
model = NULL ;
rotX = 0.0f ;
rotY = 0.0f ;
zoom = 1.0f ;
2010-12-03 05:07:42 +00:00
backBrightness = 0.3f ;
gridBrightness = 1.0f ;
lightBrightness = 0.3f ;
2010-03-13 10:39:22 +00:00
lastX = 0 ;
lastY = 0 ;
anim = 0.0f ;
2011-01-13 19:27:26 +00:00
statusbarText = " " ;
2010-03-13 10:39:22 +00:00
CreateStatusBar ( ) ;
2010-06-25 22:54:00 +00:00
wxInitAllImageHandlers ( ) ;
2010-06-25 22:04:40 +00:00
# ifdef WIN32
2010-12-08 20:03:15 +00:00
# if defined(__MINGW32__)
wxIcon icon ( ToUnicode ( " IDI_ICON1 " ) ) ;
# else
wxIcon icon ( " IDI_ICON1 " ) ;
# endif
2010-06-25 22:54:00 +00:00
# else
wxIcon icon ;
2010-10-07 18:13:17 +00:00
std : : ifstream testFile ( " g3dviewer.ico " ) ;
if ( testFile . good ( ) ) {
testFile . close ( ) ;
icon . LoadFile ( wxT ( " g3dviewer.ico " ) , wxBITMAP_TYPE_ICO ) ;
}
2010-06-25 22:04:40 +00:00
# endif
2010-06-25 22:54:00 +00:00
SetIcon ( icon ) ;
2010-06-25 22:04:40 +00:00
2010-03-13 10:39:22 +00:00
timer = new wxTimer ( this ) ;
timer - > Start ( 100 ) ;
glCanvas - > SetFocus ( ) ;
2011-01-18 21:17:48 +00:00
fileDialog = new wxFileDialog ( this ) ;
if ( modelPath ! = " " ) {
fileDialog - > SetPath ( ToUnicode ( modelPath ) ) ;
}
2010-03-13 10:39:22 +00:00
}
MainWindow : : ~ MainWindow ( ) {
delete renderer ;
delete model ;
delete timer ;
delete glCanvas ;
2010-06-25 22:04:40 +00:00
2010-03-13 10:39:22 +00:00
}
void MainWindow : : init ( ) {
glCanvas - > SetCurrent ( ) ;
renderer - > init ( ) ;
2010-05-25 18:06:42 +00:00
loadModel ( " " ) ;
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onPaint ( wxPaintEvent & event ) {
renderer - > reset ( GetClientSize ( ) . x , GetClientSize ( ) . y , playerColor ) ;
renderer - > transform ( rotX , rotY , zoom ) ;
renderer - > renderGrid ( ) ;
renderer - > renderTheModel ( model , anim ) ;
2010-05-25 18:06:42 +00:00
//int updateLoops = 100;
int updateLoops = 1 ;
for ( int i = 0 ; i < updateLoops ; + + i ) {
renderer - > updateParticleManager ( ) ;
}
renderer - > renderParticleManager ( ) ;
2010-03-13 10:39:22 +00:00
glCanvas - > SwapBuffers ( ) ;
}
void MainWindow : : onClose ( wxCloseEvent & event ) {
2010-11-03 19:03:25 +00:00
// release memory first (from onMenuFileClearAll)
modelPathList . clear ( ) ;
particlePathList . clear ( ) ;
particleProjectilePathList . clear ( ) ;
particleSplashPathList . clear ( ) ; // as above
timer - > Stop ( ) ;
renderer - > end ( ) ;
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
2010-12-03 05:07:42 +00:00
2010-11-03 19:03:25 +00:00
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
splashParticleSystems . clear ( ) ; // as above
splashParticleSystemTypes . clear ( ) ;
delete model ;
model = NULL ;
2010-03-13 10:39:22 +00:00
delete this ;
}
2010-12-03 05:07:42 +00:00
// for the mousewheel
2010-11-03 19:03:25 +00:00
void MainWindow : : onMouseWheelDown ( wxMouseEvent & event ) {
wxPaintEvent paintEvent ;
zoom * = 1.1f ;
zoom = clamp ( zoom , 0.1f , 10.0f ) ;
onPaint ( paintEvent ) ;
}
void MainWindow : : onMouseWheelUp ( wxMouseEvent & event ) {
wxPaintEvent paintEvent ;
zoom * = 0.90909f ;
zoom = clamp ( zoom , 0.1f , 10.0f ) ;
onPaint ( paintEvent ) ;
}
2010-03-13 10:39:22 +00:00
void MainWindow : : onMouseMove ( wxMouseEvent & event ) {
int x = event . GetX ( ) ;
int y = event . GetY ( ) ;
wxPaintEvent paintEvent ;
if ( event . LeftIsDown ( ) ) {
rotX + = clamp ( lastX - x , - 10 , 10 ) ;
rotY + = clamp ( lastY - y , - 10 , 10 ) ;
onPaint ( paintEvent ) ;
}
else if ( event . RightIsDown ( ) ) {
zoom * = 1.0f + ( lastX - x + lastY - y ) / 100.0f ;
zoom = clamp ( zoom , 0.1f , 10.0f ) ;
onPaint ( paintEvent ) ;
}
lastX = x ;
lastY = y ;
}
2011-01-20 18:05:07 +00:00
void MainWindow : : OnChangeColor ( wxCommandEvent & event ) {
//wxColour color = colorPicker->GetColour();
wxColourData data ;
data . SetChooseFull ( true ) ;
for ( int i = 0 ; i < 16 ; i + + )
{
wxColour colour ( i * 16 , i * 16 , i * 16 ) ;
data . SetCustomColour ( i , colour ) ;
}
wxColourDialog dialog ( this , & data ) ;
if ( dialog . ShowModal ( ) = = wxID_OK )
{
wxColourData retData = dialog . GetColourData ( ) ;
wxColour col = retData . GetColour ( ) ;
renderer - > setBackgroundColor ( col . Red ( ) / 255.0f , col . Green ( ) / 255.0f , col . Blue ( ) / 255.0f , col . Alpha ( ) / 255.0f ) ;
//wxBrush brush(col, wxSOLID);
//myWindow->SetBackground(brush);
//myWindow->Clear();
//myWindow->Refresh();
}
}
2010-03-13 10:39:22 +00:00
void MainWindow : : onMenuFileLoad ( wxCommandEvent & event ) {
string fileName ;
2010-06-24 17:47:28 +00:00
2011-01-18 21:17:48 +00:00
fileDialog - > SetWildcard ( wxT ( " G3D files (*.g3d)|*.g3d " ) ) ;
fileDialog - > SetMessage ( wxT ( " Selecting Glest Model for current view. " ) ) ;
2010-06-24 17:47:28 +00:00
2011-01-18 21:17:48 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
2010-05-25 18:06:42 +00:00
modelPathList . clear ( ) ;
2011-01-18 21:17:48 +00:00
loadModel ( ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ) ;
2010-05-25 18:06:42 +00:00
}
2010-12-03 05:07:42 +00:00
isControlKeyPressed = false ;
2010-05-25 18:06:42 +00:00
}
void MainWindow : : onMenuFileLoadParticleXML ( wxCommandEvent & event ) {
string fileName ;
2011-01-18 21:17:48 +00:00
fileDialog - > SetWildcard ( wxT ( " XML files (*.xml)|*.xml " ) ) ;
2010-06-24 17:47:28 +00:00
if ( isControlKeyPressed = = true ) {
2011-01-18 21:17:48 +00:00
fileDialog - > SetMessage ( wxT ( " Adding Mega-Glest particle to current view. " ) ) ;
2010-06-24 17:47:28 +00:00
}
else {
2011-01-18 21:17:48 +00:00
fileDialog - > SetMessage ( wxT ( " Selecting Mega-Glest particle for current view. " ) ) ;
2010-06-24 17:47:28 +00:00
}
2011-01-18 21:17:48 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
string path = ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ;
2010-05-25 18:06:42 +00:00
loadParticle ( path ) ;
}
2010-12-03 05:07:42 +00:00
isControlKeyPressed = false ;
2010-05-25 18:06:42 +00:00
}
2010-06-24 10:52:58 +00:00
void MainWindow : : onMenuFileLoadProjectileParticleXML ( wxCommandEvent & event ) {
string fileName ;
2011-01-18 21:17:48 +00:00
fileDialog - > SetWildcard ( wxT ( " XML files (*.xml)|*.xml " ) ) ;
2010-06-24 17:47:28 +00:00
if ( isControlKeyPressed = = true ) {
2011-01-18 21:17:48 +00:00
fileDialog - > SetMessage ( wxT ( " Adding Mega-Glest projectile particle to current view. " ) ) ;
2010-06-24 17:47:28 +00:00
}
else {
2011-01-18 21:17:48 +00:00
fileDialog - > SetMessage ( wxT ( " Selecting Mega-Glest projectile particle for current view. " ) ) ;
2010-06-24 17:47:28 +00:00
}
2011-01-18 21:17:48 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
string path = ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ;
2010-06-24 10:52:58 +00:00
loadProjectileParticle ( path ) ;
}
2010-12-03 05:07:42 +00:00
isControlKeyPressed = false ;
2010-06-24 10:52:58 +00:00
}
2010-11-03 19:03:25 +00:00
void MainWindow : : onMenuFileLoadSplashParticleXML ( wxCommandEvent & event ) {
string fileName ;
2011-01-18 21:17:48 +00:00
fileDialog - > SetWildcard ( wxT ( " XML files (*.xml)|*.xml " ) ) ;
2010-11-03 19:03:25 +00:00
if ( isControlKeyPressed = = true ) {
2011-01-18 21:17:48 +00:00
fileDialog - > SetMessage ( wxT ( " Adding Mega-Glest splash particle to current view. " ) ) ;
2010-11-03 19:03:25 +00:00
}
else {
2011-01-18 21:17:48 +00:00
fileDialog - > SetMessage ( wxT ( " Selecting Mega-Glest splash particle for current view. " ) ) ;
2010-11-03 19:03:25 +00:00
}
2011-01-18 21:17:48 +00:00
if ( fileDialog - > ShowModal ( ) = = wxID_OK ) {
string path = ( const char * ) wxFNCONV ( fileDialog - > GetPath ( ) . c_str ( ) ) ;
2010-11-03 19:03:25 +00:00
loadSplashParticle ( path ) ;
}
2010-12-03 05:07:42 +00:00
isControlKeyPressed = false ;
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
2010-11-03 19:03:25 +00:00
2011-01-20 18:05:07 +00:00
void MainWindow : : onMenuFileSaveScreenshot ( wxCommandEvent & event ) {
string path = " screens/ " ;
if ( isdir ( path . c_str ( ) ) = = true ) {
//Config &config= Config::getInstance();
//string fileFormat = config.getString("ScreenShotFileType","png");
string fileFormat = " png " ;
for ( int i = 0 ; i < 1000 ; + + i ) {
path = " screens/ " ;
path + = string ( " screen " ) + intToStr ( i ) + string ( " . " ) + fileFormat ;
FILE * f = fopen ( path . c_str ( ) , " rb " ) ;
if ( f = = NULL ) {
renderer - > saveScreen ( path ) ;
break ;
}
else {
fclose ( f ) ;
}
}
}
}
void MainWindow : : onMenuFileClearAll ( wxCommandEvent & event ) {
2010-11-03 19:03:25 +00:00
modelPathList . clear ( ) ;
particlePathList . clear ( ) ;
particleProjectilePathList . clear ( ) ;
particleSplashPathList . clear ( ) ; // as above
timer - > Stop ( ) ;
2010-06-24 14:00:20 +00:00
renderer - > end ( ) ;
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
2010-12-03 05:07:42 +00:00
2010-06-24 14:00:20 +00:00
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
2010-11-03 19:03:25 +00:00
splashParticleSystems . clear ( ) ; // as above
splashParticleSystemTypes . clear ( ) ;
2010-06-24 14:00:20 +00:00
delete model ;
model = NULL ;
loadModel ( " " ) ;
loadParticle ( " " ) ;
loadProjectileParticle ( " " ) ;
2010-11-03 19:03:25 +00:00
loadSplashParticle ( " " ) ; // as above
2010-06-24 14:00:20 +00:00
2011-01-13 19:27:26 +00:00
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusbarText . c_str ( ) ) ) ;
2010-06-24 14:00:20 +00:00
timer - > Start ( 100 ) ;
2010-12-03 05:07:42 +00:00
isControlKeyPressed = false ;
2010-06-24 14:00:20 +00:00
}
2010-11-03 19:03:25 +00:00
void MainWindow : : onMenuFileExit ( wxCommandEvent & event ) {
Close ( ) ;
}
2010-05-25 18:06:42 +00:00
void MainWindow : : loadModel ( string path ) {
if ( path ! = " " & & fileExists ( path ) = = true ) {
this - > modelPathList . push_back ( path ) ;
}
2010-12-03 05:07:42 +00:00
string titlestring = winHeader ;
2010-10-21 07:20:17 +00:00
for ( unsigned int idx = 0 ; idx < this - > modelPathList . size ( ) ; idx + + ) {
2010-05-25 18:06:42 +00:00
string modelPath = this - > modelPathList [ idx ] ;
2010-06-24 14:00:20 +00:00
timer - > Stop ( ) ;
2010-03-13 10:39:22 +00:00
delete model ;
Model * tmpModel = new ModelGl ( ) ;
2010-05-25 18:06:42 +00:00
renderer - > loadTheModel ( tmpModel , modelPath ) ;
2010-03-13 10:39:22 +00:00
model = tmpModel ;
2011-01-13 19:27:26 +00:00
statusbarText = getModelInfo ( ) ;
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2010-06-24 14:00:20 +00:00
timer - > Start ( 100 ) ;
2010-12-03 05:07:42 +00:00
titlestring = extractFileFromDirectoryPath ( modelPath ) + " - " + titlestring ;
2010-03-13 10:39:22 +00:00
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( titlestring ) ) ;
2010-03-13 10:39:22 +00:00
}
2010-05-25 18:06:42 +00:00
void MainWindow : : loadParticle ( string path ) {
2010-06-24 17:47:28 +00:00
timer - > Stop ( ) ;
2010-05-25 18:06:42 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
2010-06-24 17:47:28 +00:00
renderer - > end ( ) ;
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 14:00:20 +00:00
if ( isControlKeyPressed = = true ) {
2010-12-03 05:07:42 +00:00
// std::cout << "Adding to list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particlePathList . push_back ( path ) ;
}
else {
2010-12-03 05:07:42 +00:00
// std::cout << "Clearing list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particlePathList . clear ( ) ;
this - > particlePathList . push_back ( path ) ;
}
2010-06-24 17:47:28 +00:00
}
2010-05-25 18:06:42 +00:00
2010-11-03 19:03:25 +00:00
try {
2010-06-24 17:47:28 +00:00
if ( this - > particlePathList . size ( ) > 0 ) {
2010-12-03 05:07:42 +00:00
string titlestring = winHeader ;
2010-10-21 07:20:17 +00:00
for ( unsigned int idx = 0 ; idx < this - > particlePathList . size ( ) ; idx + + ) {
2010-06-24 17:47:28 +00:00
string particlePath = this - > particlePathList [ idx ] ;
string dir = extractDirectoryPathFromFile ( particlePath ) ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
size_t pos = dir . find_last_of ( folderDelimiter ) ;
if ( pos = = dir . length ( ) - 1 ) {
dir . erase ( dir . length ( ) - 1 ) ;
}
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
particlePath = extractFileFromDirectoryPath ( particlePath ) ;
2010-12-03 05:07:42 +00:00
titlestring = particlePath + " - " + titlestring ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
std : : string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath ( dir ) + " .xml " ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
int size = - 1 ;
int height = - 1 ;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
if ( fileExists ( unitXML ) = = true ) {
XmlTree xmlTree ;
xmlTree . load ( unitXML ) ;
const XmlNode * unitNode = xmlTree . getRootNode ( ) ;
const XmlNode * parametersNode = unitNode - > getChild ( " parameters " ) ;
//size
size = parametersNode - > getChild ( " size " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
//height
height = parametersNode - > getChild ( " height " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
2010-05-25 18:06:42 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
UnitParticleSystemType * unitParticleSystemType = new UnitParticleSystemType ( ) ;
unitParticleSystemType - > load ( dir , dir + folderDelimiter + particlePath , renderer ) ;
unitParticleSystemTypes . push_back ( unitParticleSystemType ) ;
for ( std : : vector < UnitParticleSystemType * > : : const_iterator it = unitParticleSystemTypes . begin ( ) ; it ! = unitParticleSystemTypes . end ( ) ; + + it ) {
UnitParticleSystem * ups = new UnitParticleSystem ( 200 ) ;
( * it ) - > setValues ( ups ) ;
if ( size > 0 ) {
//getCurrVectorFlat() + Vec3f(0.f, type->getHeight()/2.f, 0.f);
Vec3f vec = Vec3f ( 0.f , height / 2.f , 0.f ) ;
ups - > setPos ( vec ) ;
2010-05-25 18:06:42 +00:00
}
2010-06-24 17:47:28 +00:00
//ups->setFactionColor(getFaction()->getTexture()->getPixmap()->getPixel3f(0,0));
ups - > setFactionColor ( renderer - > getPlayerColorTexture ( playerColor ) - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ) ;
unitParticleSystems . push_back ( ups ) ;
renderer - > manageParticleSystem ( ups ) ;
ups - > setVisible ( true ) ;
}
2010-05-25 18:06:42 +00:00
2010-06-24 17:47:28 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > initModelManager ( ) ;
2010-06-24 14:00:20 +00:00
renderer - > initTextureManager ( ) ;
2010-05-25 18:06:42 +00:00
}
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( titlestring ) ) ;
2010-05-25 18:06:42 +00:00
}
2010-11-03 19:03:25 +00:00
}
2010-12-03 05:07:42 +00:00
catch ( std : : runtime_error e ) {
2010-11-03 19:03:25 +00:00
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageBox ( ToUnicode ( e . what ( ) ) , wxT ( " Not a Mega-Glest particle XML file, or broken " ) , wxICON_ERROR ) ;
}
2010-06-24 17:47:28 +00:00
timer - > Start ( 100 ) ;
2010-05-25 18:06:42 +00:00
}
2010-06-24 10:52:58 +00:00
void MainWindow : : loadProjectileParticle ( string path ) {
2010-06-24 17:47:28 +00:00
timer - > Stop ( ) ;
2010-06-24 10:52:58 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
2010-06-24 17:47:28 +00:00
renderer - > end ( ) ;
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 14:00:20 +00:00
if ( isControlKeyPressed = = true ) {
2010-12-03 05:07:42 +00:00
// std::cout << "Adding to list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particleProjectilePathList . push_back ( path ) ;
}
else {
2010-12-03 05:07:42 +00:00
// std::cout << "Clearing list..." << std::endl;
2010-06-24 14:00:20 +00:00
this - > particleProjectilePathList . clear ( ) ;
this - > particleProjectilePathList . push_back ( path ) ;
}
2010-06-24 17:47:28 +00:00
}
2010-06-24 10:52:58 +00:00
2010-11-03 19:03:25 +00:00
try {
2010-06-24 17:47:28 +00:00
if ( this - > particleProjectilePathList . size ( ) > 0 ) {
2010-12-03 05:07:42 +00:00
string titlestring = winHeader ;
2010-10-21 07:20:17 +00:00
for ( unsigned int idx = 0 ; idx < this - > particleProjectilePathList . size ( ) ; idx + + ) {
2010-06-24 17:47:28 +00:00
string particlePath = this - > particleProjectilePathList [ idx ] ;
string dir = extractDirectoryPathFromFile ( particlePath ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
size_t pos = dir . find_last_of ( folderDelimiter ) ;
if ( pos = = dir . length ( ) - 1 ) {
dir . erase ( dir . length ( ) - 1 ) ;
}
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
particlePath = extractFileFromDirectoryPath ( particlePath ) ;
2010-12-03 05:07:42 +00:00
titlestring = particlePath + " - " + titlestring ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
std : : string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath ( dir ) + " .xml " ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
int size = - 1 ;
int height = - 1 ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
if ( fileExists ( unitXML ) = = true ) {
2010-06-24 14:00:20 +00:00
XmlTree xmlTree ;
2010-06-24 17:47:28 +00:00
xmlTree . load ( unitXML ) ;
const XmlNode * unitNode = xmlTree . getRootNode ( ) ;
const XmlNode * parametersNode = unitNode - > getChild ( " parameters " ) ;
//size
size = parametersNode - > getChild ( " size " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
//height
height = parametersNode - > getChild ( " height " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
2010-06-24 10:52:58 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
XmlTree xmlTree ;
xmlTree . load ( dir + folderDelimiter + particlePath ) ;
const XmlNode * particleSystemNode = xmlTree . getRootNode ( ) ;
2010-06-24 10:52:58 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "Loaded successfully, loading values..." << std::endl;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
ParticleSystemTypeProjectile * projectileParticleSystemType = new ParticleSystemTypeProjectile ( ) ;
projectileParticleSystemType - > load ( dir , dir + folderDelimiter + particlePath , renderer ) ;
2010-06-24 10:52:58 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "Values loaded, about to read..." << std::endl;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
projectileParticleSystemTypes . push_back ( projectileParticleSystemType ) ;
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
for ( std : : vector < ParticleSystemTypeProjectile * > : : const_iterator it = projectileParticleSystemTypes . begin ( ) ; it ! = projectileParticleSystemTypes . end ( ) ; + + it ) {
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
ProjectileParticleSystem * ps = ( * it ) - > create ( ) ;
2010-06-24 10:52:58 +00:00
2010-06-24 17:47:28 +00:00
if ( size > 0 ) {
Vec3f vec = Vec3f ( 0.f , height / 2.f , 0.f ) ;
//ps->setPos(vec);
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
Vec3f vec2 = Vec3f ( size * 2.f , height * 2.f , height * 2.f ) ;
ps - > setPath ( vec , vec2 ) ;
2010-06-24 14:00:20 +00:00
}
2010-06-24 17:47:28 +00:00
ps - > setFactionColor ( renderer - > getPlayerColorTexture ( playerColor ) - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ) ;
2010-06-24 14:00:20 +00:00
2010-06-24 17:47:28 +00:00
projectileParticleSystems . push_back ( ps ) ;
ps - > setVisible ( true ) ;
renderer - > manageParticleSystem ( ps ) ;
//MessageBox(NULL,"hi","hi",MB_OK);
//psProj= pstProj->create();
//psProj->setPath(startPos, endPos);
//psProj->setObserver(new ParticleDamager(unit, this, gameCamera));
//psProj->setVisible(visible);
//psProj->setFactionColor(unit->getFaction()->getTexture()->getPixmap()->getPixel3f(0,0));
//renderer.manageParticleSystem(psProj, rsGame);
2010-06-24 14:00:20 +00:00
}
2010-06-24 10:52:58 +00:00
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( titlestring ) ) ;
2010-06-24 17:47:28 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > initModelManager ( ) ;
renderer - > initTextureManager ( ) ;
}
2010-06-24 10:52:58 +00:00
}
2010-11-03 19:03:25 +00:00
}
2010-12-03 05:07:42 +00:00
catch ( std : : runtime_error e ) {
2010-11-03 19:03:25 +00:00
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageBox ( ToUnicode ( e . what ( ) ) , wxT ( " Not a Mega-Glest projectile particle XML file, or broken " ) , wxICON_ERROR ) ;
}
timer - > Start ( 100 ) ;
}
void MainWindow : : loadSplashParticle ( string path ) { // uses ParticleSystemTypeSplash::load (and own list...)
timer - > Stop ( ) ;
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > end ( ) ;
splashParticleSystems . clear ( ) ;
2010-12-03 05:07:42 +00:00
splashParticleSystemTypes . clear ( ) ;
2010-11-03 19:03:25 +00:00
if ( isControlKeyPressed = = true ) {
2010-12-03 05:07:42 +00:00
// std::cout << "Adding to list..." << std::endl;
2010-11-03 19:03:25 +00:00
this - > particleSplashPathList . push_back ( path ) ;
}
else {
2010-12-03 05:07:42 +00:00
// std::cout << "Clearing list..." << std::endl;
2010-11-03 19:03:25 +00:00
this - > particleSplashPathList . clear ( ) ;
this - > particleSplashPathList . push_back ( path ) ;
}
}
try {
if ( this - > particleSplashPathList . size ( ) > 0 ) {
2010-12-03 05:07:42 +00:00
string titlestring = winHeader ;
2010-11-03 19:03:25 +00:00
for ( unsigned int idx = 0 ; idx < this - > particleSplashPathList . size ( ) ; idx + + ) {
string particlePath = this - > particleSplashPathList [ idx ] ;
string dir = extractDirectoryPathFromFile ( particlePath ) ;
size_t pos = dir . find_last_of ( folderDelimiter ) ;
if ( pos = = dir . length ( ) - 1 ) {
dir . erase ( dir . length ( ) - 1 ) ;
}
particlePath = extractFileFromDirectoryPath ( particlePath ) ;
2010-12-03 05:07:42 +00:00
titlestring = particlePath + " - " + titlestring ;
2010-11-03 19:03:25 +00:00
std : : string unitXML = dir + folderDelimiter + extractFileFromDirectoryPath ( dir ) + " .xml " ;
int size = - 1 ;
int height = - 1 ;
if ( fileExists ( unitXML ) = = true ) {
XmlTree xmlTree ;
xmlTree . load ( unitXML ) ;
const XmlNode * unitNode = xmlTree . getRootNode ( ) ;
const XmlNode * parametersNode = unitNode - > getChild ( " parameters " ) ;
//size
size = parametersNode - > getChild ( " size " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
//height
height = parametersNode - > getChild ( " height " ) - > getAttribute ( " value " ) - > getIntValue ( ) ;
}
2010-12-03 05:07:42 +00:00
// std::cout << "About to load [" << particlePath << "] from [" << dir << "] unit [" << unitXML << "]" << std::endl;
2010-11-03 19:03:25 +00:00
XmlTree xmlTree ;
xmlTree . load ( dir + folderDelimiter + particlePath ) ;
const XmlNode * particleSystemNode = xmlTree . getRootNode ( ) ;
2010-12-03 05:07:42 +00:00
// std::cout << "Loaded successfully, loading values..." << std::endl;
2010-11-03 19:03:25 +00:00
2010-12-03 05:07:42 +00:00
ParticleSystemTypeSplash * splashParticleSystemType = new ParticleSystemTypeSplash ( ) ;
2010-11-03 19:03:25 +00:00
splashParticleSystemType - > load ( dir , dir + folderDelimiter + particlePath , renderer ) ; // <---- only that must be splash...
2010-12-03 05:07:42 +00:00
// std::cout << "Values loaded, about to read..." << std::endl;
2010-11-03 19:03:25 +00:00
splashParticleSystemTypes . push_back ( splashParticleSystemType ) ;
//ParticleSystemTypeSplash
for ( std : : vector < ParticleSystemTypeSplash * > : : const_iterator it = splashParticleSystemTypes . begin ( ) ; it ! = splashParticleSystemTypes . end ( ) ; + + it ) {
SplashParticleSystem * ps = ( * it ) - > create ( ) ;
if ( size > 0 ) {
Vec3f vec = Vec3f ( 0.f , height / 2.f , 0.f ) ;
//ps->setPos(vec);
//Vec3f vec2 = Vec3f(size * 2.f, height * 2.f, height * 2.f); // <------- removed relative projectile
//ps->setPath(vec, vec2); // <------- removed relative projectile
}
ps - > setFactionColor ( renderer - > getPlayerColorTexture ( playerColor ) - > getPixmap ( ) - > getPixel3f ( 0 , 0 ) ) ;
splashParticleSystems . push_back ( ps ) ;
ps - > setVisible ( true ) ;
renderer - > manageParticleSystem ( ps ) ;
}
}
2010-12-03 05:07:42 +00:00
SetTitle ( ToUnicode ( titlestring ) ) ;
2010-11-03 19:03:25 +00:00
if ( path ! = " " & & fileExists ( path ) = = true ) {
renderer - > initModelManager ( ) ;
renderer - > initTextureManager ( ) ;
}
}
}
2010-12-03 05:07:42 +00:00
catch ( std : : runtime_error e ) {
2010-11-03 19:03:25 +00:00
std : : cout < < e . what ( ) < < std : : endl ;
wxMessageBox ( ToUnicode ( e . what ( ) ) , wxT ( " Not a Mega-Glest splash particle XML file, or broken " ) , wxICON_ERROR ) ;
}
2010-06-24 17:47:28 +00:00
timer - > Start ( 100 ) ;
2010-06-24 10:52:58 +00:00
}
2010-03-13 10:39:22 +00:00
void MainWindow : : onMenuModeNormals ( wxCommandEvent & event ) {
renderer - > toggleNormals ( ) ;
menuMode - > Check ( miModeNormals , renderer - > getNormals ( ) ) ;
}
void MainWindow : : onMenuModeWireframe ( wxCommandEvent & event ) {
renderer - > toggleWireframe ( ) ;
menuMode - > Check ( miModeWireframe , renderer - > getWireframe ( ) ) ;
}
void MainWindow : : onMenuModeGrid ( wxCommandEvent & event ) {
renderer - > toggleGrid ( ) ;
menuMode - > Check ( miModeGrid , renderer - > getGrid ( ) ) ;
}
void MainWindow : : onMenuSpeedSlower ( wxCommandEvent & event ) {
2011-01-13 19:27:26 +00:00
speed / = 1.5f ;
if ( speed < 0 ) {
speed = 0 ;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onMenuSpeedFaster ( wxCommandEvent & event ) {
2011-01-13 19:27:26 +00:00
speed * = 1.5f ;
if ( speed > 1 ) {
speed = 1 ;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
2010-03-13 10:39:22 +00:00
}
2010-11-03 19:03:25 +00:00
// set menu checkboxes to what player color is used
2010-03-13 10:39:22 +00:00
void MainWindow : : onMenuColorRed ( wxCommandEvent & event ) {
playerColor = Renderer : : pcRed ;
menuCustomColor - > Check ( miColorRed , true ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onMenuColorBlue ( wxCommandEvent & event ) {
playerColor = Renderer : : pcBlue ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , true ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
void MainWindow : : onMenuColorGreen ( wxCommandEvent & event ) {
playerColor = Renderer : : pcGreen ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , true ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
2010-03-13 10:39:22 +00:00
}
void MainWindow : : onMenuColorYellow ( wxCommandEvent & event ) {
playerColor = Renderer : : pcYellow ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > Check ( miColorGreen , false ) ;
2010-03-13 10:39:22 +00:00
menuCustomColor - > Check ( miColorYellow , true ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
void MainWindow : : onMenuColorWhite ( wxCommandEvent & event ) {
playerColor = Renderer : : pcWhite ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
2010-03-13 10:39:22 +00:00
menuCustomColor - > Check ( miColorGreen , false ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , true ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
2010-03-13 10:39:22 +00:00
}
2010-11-03 19:03:25 +00:00
void MainWindow : : onMenuColorCyan ( wxCommandEvent & event ) {
playerColor = Renderer : : pcCyan ;
2010-03-13 10:39:22 +00:00
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > Check ( miColorGreen , false ) ;
2010-03-13 10:39:22 +00:00
menuCustomColor - > Check ( miColorYellow , false ) ;
2010-11-03 19:03:25 +00:00
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , true ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
}
void MainWindow : : onMenuColorOrange ( wxCommandEvent & event ) {
playerColor = Renderer : : pcOrange ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , true ) ;
menuCustomColor - > Check ( miColorMagenta , false ) ;
2010-03-13 10:39:22 +00:00
}
2010-11-03 19:03:25 +00:00
void MainWindow : : onMenuColorMagenta ( wxCommandEvent & event ) {
playerColor = Renderer : : pcMagenta ;
menuCustomColor - > Check ( miColorRed , false ) ;
menuCustomColor - > Check ( miColorBlue , false ) ;
menuCustomColor - > Check ( miColorGreen , false ) ;
menuCustomColor - > Check ( miColorYellow , false ) ;
menuCustomColor - > Check ( miColorWhite , false ) ;
menuCustomColor - > Check ( miColorCyan , false ) ;
menuCustomColor - > Check ( miColorOrange , false ) ;
menuCustomColor - > Check ( miColorMagenta , true ) ;
}
2010-03-13 10:39:22 +00:00
void MainWindow : : onTimer ( wxTimerEvent & event ) {
wxPaintEvent paintEvent ;
2011-01-13 19:27:26 +00:00
anim = anim + speed ;
if ( anim > 1.0f ) {
anim - = 1.f ;
2010-03-13 10:39:22 +00:00
}
onPaint ( paintEvent ) ;
}
string MainWindow : : getModelInfo ( ) {
string str ;
if ( model ! = NULL ) {
str + = " Meshes: " + intToStr ( model - > getMeshCount ( ) ) ;
str + = " , Vertices: " + intToStr ( model - > getVertexCount ( ) ) ;
str + = " , Triangles: " + intToStr ( model - > getTriangleCount ( ) ) ;
str + = " , Version: " + intToStr ( model - > getFileVersion ( ) ) ;
}
return str ;
}
2010-05-25 18:06:42 +00:00
void MainWindow : : onKeyDown ( wxKeyEvent & e ) {
2010-06-24 17:47:28 +00:00
2010-12-03 05:07:42 +00:00
// std::cout << "e.ControlDown() = " << e.ControlDown() << " e.GetKeyCode() = " << e.GetKeyCode() << " isCtrl = " << (e.GetKeyCode() == WXK_CONTROL) << std::endl;
2010-06-24 17:47:28 +00:00
2010-12-03 05:07:42 +00:00
// Note: This ctrl-key handling is buggy since it never resests when ctrl is released later, so I reset it at end of loadcommands for now.
2010-06-24 17:47:28 +00:00
if ( e . ControlDown ( ) = = true | | e . GetKeyCode ( ) = = WXK_CONTROL ) {
2010-06-24 14:00:20 +00:00
isControlKeyPressed = true ;
}
else {
isControlKeyPressed = false ;
}
2010-12-03 05:07:42 +00:00
// std::cout << "isControlKeyPressed = " << isControlKeyPressed << std::endl;
2010-06-24 17:47:28 +00:00
2010-12-03 05:07:42 +00:00
// here also because + and - hotkeys don't work for numpad automaticly
2011-01-13 19:27:26 +00:00
if ( e . GetKeyCode ( ) = = 388 ) {
speed * = 1.5f ; //numpad+
if ( speed > 1.0 ) {
speed = 1.0 ;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
}
else if ( e . GetKeyCode ( ) = = 390 ) {
speed / = 1.5f ; //numpad-
if ( speed < 0 ) {
speed = 0 ;
}
string statusTextValue = statusbarText + " animation speed: " + floatToStr ( speed * 1000.0 ) ;
GetStatusBar ( ) - > SetStatusText ( ToUnicode ( statusTextValue . c_str ( ) ) ) ;
}
2010-12-03 05:07:42 +00:00
else if ( e . GetKeyCode ( ) = = 87 ) {
glClearColor ( 0.6f , 0.6f , 0.6f , 1.0f ) ; //w key //backgroundcolor constant 0.3 -> 0.6
}
// some posibility to adjust brightness:
/*
else if ( e . GetKeyCode ( ) = = 322 ) { // Ins - Grid
gridBrightness + = 0.1f ; if ( gridBrightness > 1.0 ) gridBrightness = 1.0 ;
}
else if ( e . GetKeyCode ( ) = = 127 ) { // Del
gridBrightness - = 0.1f ; if ( gridBrightness < 0 ) gridBrightness = 0 ;
}
*/
else if ( e . GetKeyCode ( ) = = 313 ) { // Home - Background
backBrightness + = 0.1f ; if ( backBrightness > 1.0 ) backBrightness = 1.0 ;
glClearColor ( backBrightness , backBrightness , backBrightness , 1.0f ) ;
}
else if ( e . GetKeyCode ( ) = = 312 ) { // End
backBrightness - = 0.1f ; if ( backBrightness < 0 ) backBrightness = 0 ;
glClearColor ( backBrightness , backBrightness , backBrightness , 1.0f ) ;
}
else if ( e . GetKeyCode ( ) = = 366 ) { // PgUp - Lightning of model
lightBrightness + = 0.1f ; if ( lightBrightness > 1.0 ) lightBrightness = 1.0 ;
Vec4f ambientNEW = Vec4f ( lightBrightness , lightBrightness , lightBrightness , 1.0f ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambientNEW . ptr ( ) ) ;
}
else if ( e . GetKeyCode ( ) = = 367 ) { // pgDn
lightBrightness - = 0.1f ; if ( lightBrightness < 0 ) lightBrightness = 0 ;
Vec4f ambientNEW = Vec4f ( lightBrightness , lightBrightness , lightBrightness , 1.0f ) ;
glLightfv ( GL_LIGHT0 , GL_AMBIENT , ambientNEW . ptr ( ) ) ;
}
2010-11-03 19:03:25 +00:00
}
2010-05-25 18:06:42 +00:00
2010-11-03 19:03:25 +00:00
void MainWindow : : onMenuRestart ( wxCommandEvent & event ) {
2010-12-03 05:07:42 +00:00
// std::cout << "pressed R (restart particle animation)" << std::endl;
2010-11-03 19:03:25 +00:00
renderer - > end ( ) ;
2010-06-24 17:47:28 +00:00
2010-11-03 19:03:25 +00:00
unitParticleSystems . clear ( ) ;
unitParticleSystemTypes . clear ( ) ;
projectileParticleSystems . clear ( ) ;
projectileParticleSystemTypes . clear ( ) ;
splashParticleSystems . clear ( ) ; // as above
splashParticleSystemTypes . clear ( ) ;
2010-05-25 18:06:42 +00:00
2010-11-03 19:03:25 +00:00
loadModel ( " " ) ;
loadParticle ( " " ) ;
loadProjectileParticle ( " " ) ;
loadSplashParticle ( " " ) ; // as above
2010-06-24 17:47:28 +00:00
2010-11-03 19:03:25 +00:00
renderer - > initModelManager ( ) ;
renderer - > initTextureManager ( ) ;
2010-05-25 18:06:42 +00:00
}
2010-03-13 10:39:22 +00:00
BEGIN_EVENT_TABLE ( MainWindow , wxFrame )
EVT_TIMER ( - 1 , MainWindow : : onTimer )
EVT_CLOSE ( MainWindow : : onClose )
EVT_MENU ( miFileLoad , MainWindow : : onMenuFileLoad )
2010-05-25 18:06:42 +00:00
EVT_MENU ( miFileLoadParticleXML , MainWindow : : onMenuFileLoadParticleXML )
2010-06-24 10:52:58 +00:00
EVT_MENU ( miFileLoadProjectileParticleXML , MainWindow : : onMenuFileLoadProjectileParticleXML )
2010-11-03 19:03:25 +00:00
EVT_MENU ( miFileLoadSplashParticleXML , MainWindow : : onMenuFileLoadSplashParticleXML )
2010-06-24 14:00:20 +00:00
EVT_MENU ( miFileClearAll , MainWindow : : onMenuFileClearAll )
2011-01-20 18:05:07 +00:00
EVT_MENU ( miFileSaveScreenshot , MainWindow : : onMenuFileSaveScreenshot )
2010-11-03 19:03:25 +00:00
EVT_MENU ( wxID_EXIT , MainWindow : : onMenuFileExit )
2010-03-13 10:39:22 +00:00
EVT_MENU ( miModeWireframe , MainWindow : : onMenuModeWireframe )
EVT_MENU ( miModeNormals , MainWindow : : onMenuModeNormals )
EVT_MENU ( miModeGrid , MainWindow : : onMenuModeGrid )
EVT_MENU ( miSpeedFaster , MainWindow : : onMenuSpeedFaster )
EVT_MENU ( miSpeedSlower , MainWindow : : onMenuSpeedSlower )
2010-11-03 19:03:25 +00:00
EVT_MENU ( miRestart , MainWindow : : onMenuRestart )
2010-03-13 10:39:22 +00:00
EVT_MENU ( miColorRed , MainWindow : : onMenuColorRed )
EVT_MENU ( miColorBlue , MainWindow : : onMenuColorBlue )
EVT_MENU ( miColorGreen , MainWindow : : onMenuColorGreen )
2010-11-03 19:03:25 +00:00
EVT_MENU ( miColorYellow , MainWindow : : onMenuColorYellow )
EVT_MENU ( miColorWhite , MainWindow : : onMenuColorWhite )
EVT_MENU ( miColorCyan , MainWindow : : onMenuColorCyan )
EVT_MENU ( miColorOrange , MainWindow : : onMenuColorOrange )
EVT_MENU ( miColorMagenta , MainWindow : : onMenuColorMagenta )
2011-01-20 18:05:07 +00:00
EVT_MENU ( miChangeBackgroundColor , MainWindow : : OnChangeColor )
2010-03-13 10:39:22 +00:00
END_EVENT_TABLE ( )
// =====================================================
// class GlCanvas
// =====================================================
2010-05-25 18:06:42 +00:00
void translateCoords ( wxWindow * wnd , int & x , int & y ) {
# ifdef WIN32
int cx , cy ;
wnd - > GetPosition ( & cx , & cy ) ;
x + = cx ;
y + = cy ;
# endif
}
2010-03-13 10:39:22 +00:00
GlCanvas : : GlCanvas ( MainWindow * mainWindow ) :
wxGLCanvas ( mainWindow , - 1 , wxDefaultPosition )
{
this - > mainWindow = mainWindow ;
}
2010-12-03 05:07:42 +00:00
// to prevent flicker
GlCanvas : : GlCanvas ( MainWindow * mainWindow , int * args )
: wxGLCanvas ( mainWindow , - 1 , wxDefaultPosition , wxDefaultSize , 0 , wxT ( " GLCanvas " ) , args ) {
this - > mainWindow = mainWindow ;
}
2010-11-03 19:03:25 +00:00
// for the mousewheel
void GlCanvas : : onMouseWheel ( wxMouseEvent & event ) {
if ( event . GetWheelRotation ( ) > 0 ) mainWindow - > onMouseWheelDown ( event ) ;
else mainWindow - > onMouseWheelUp ( event ) ;
}
2010-03-13 10:39:22 +00:00
void GlCanvas : : onMouseMove ( wxMouseEvent & event ) {
mainWindow - > onMouseMove ( event ) ;
}
2010-05-25 18:06:42 +00:00
void GlCanvas : : onKeyDown ( wxKeyEvent & event ) {
int x , y ;
event . GetPosition ( & x , & y ) ;
translateCoords ( this , x , y ) ;
mainWindow - > onKeyDown ( event ) ;
}
2010-11-03 19:03:25 +00:00
// EVT_SPIN_DOWN(GlCanvas::onMouseDown)
// EVT_SPIN_UP(GlCanvas::onMouseDown)
// EVT_MIDDLE_DOWN(GlCanvas::onMouseWheel)
// EVT_MIDDLE_UP(GlCanvas::onMouseWheel)
2010-03-13 10:39:22 +00:00
BEGIN_EVENT_TABLE ( GlCanvas , wxGLCanvas )
2010-11-03 19:03:25 +00:00
EVT_MOUSEWHEEL ( GlCanvas : : onMouseWheel )
2010-03-13 10:39:22 +00:00
EVT_MOTION ( GlCanvas : : onMouseMove )
2010-05-25 18:06:42 +00:00
EVT_KEY_DOWN ( GlCanvas : : onKeyDown )
2010-03-13 10:39:22 +00:00
END_EVENT_TABLE ( )
// ===============================================
// class App
// ===============================================
bool App : : OnInit ( ) {
std : : string modelPath ;
if ( argc = = 2 ) {
2010-11-03 19:03:25 +00:00
if ( argv [ 1 ] [ 0 ] = = ' - ' ) { // any flag gives help and exits program.
2010-12-03 05:07:42 +00:00
std : : cout < < " G3D viewer " < < g3dviewerVersionString < < std : : endl < < std : : endl ;
std : : cout < < " glest_g3dviewer [G3D 3D-MODEL FILE] " < < std : : endl < < std : : endl ;
2010-11-03 19:03:25 +00:00
std : : cout < < " Displays glest 3D-models and unit/projectile/splash particle systems. " < < std : : endl ;
2010-12-03 05:07:42 +00:00
std : : cout < < " rotate with left mouse button, zoom with right mouse button or mousewheel. " < < std : : endl ;
2010-12-05 01:33:28 +00:00
std : : cout < < " Use ctrl to load more than one particle system. " < < std : : endl ;
std : : cout < < " Press R to restart particles, this also reloads all files if they are changed. " < < std : : endl < < std : : endl ;
2010-11-03 19:03:25 +00:00
exit ( 0 ) ;
}
2010-12-08 20:03:15 +00:00
# if defined(__MINGW32__)
const wxWX2MBbuf tmp_buf = wxConvCurrent - > cWX2MB ( wxFNCONV ( argv [ 1 ] ) ) ;
modelPath = tmp_buf ;
# else
modelPath = wxFNCONV ( argv [ 1 ] ) ;
# endif
2010-03-13 10:39:22 +00:00
}
mainWindow = new MainWindow ( modelPath ) ;
mainWindow - > Show ( ) ;
mainWindow - > init ( ) ;
return true ;
}
int App : : MainLoop ( ) {
try {
return wxApp : : MainLoop ( ) ;
}
catch ( const exception & e ) {
wxMessageDialog ( NULL , ToUnicode ( e . what ( ) ) , ToUnicode ( " Exception " ) , wxOK | wxICON_ERROR ) . ShowModal ( ) ;
return 0 ;
}
}
int App : : OnExit ( ) {
return 0 ;
}
} } //end namespace
IMPLEMENT_APP ( Shared : : G3dViewer : : App )