00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "newprojectdialogpage.h"
00022
00023 #include <QtGui/QWidget>
00024 #include <QtGui/QGroupBox>
00025 #include <QtGui/QVBoxLayout>
00026 #include <QtGui/QFormLayout>
00027 #include <QtGui/QLabel>
00028 #include <QtCore/QScopedPointer>
00029
00030 #include <KDE/KLocalizedString>
00031 #include <KDE/KIcon>
00032 #include <KDE/KLineEdit>
00033 #include <KDE/KUrlRequester>
00034 #include <KDE/KMessageBox>
00035
00036 #include <engine/gameproject.h>
00037 #include <engine/scene.h>
00038 #include <engine/game.h>
00039 #include <engine/gameobject.h>
00040 #include <engine/component.h>
00041
00042 using namespace GluonCreator;
00043
00044 class NewProjectDialogPage::NewProjectDialogPagePrivate
00045 {
00046 public:
00047 NewProjectDialogPagePrivate( NewProjectDialogPage* qq )
00048 : name( 0 ),
00049 location( 0 ),
00050 q( qq )
00051 {
00052 }
00053 public:
00054 KLineEdit* name;
00055 KUrlRequester* location;
00056 private:
00057 NewProjectDialogPage* q;
00058 };
00059
00060 NewProjectDialogPage::NewProjectDialogPage()
00061 : KPageWidgetItem( new QWidget, i18n( "New Project" ) ),
00062 d( new NewProjectDialogPagePrivate( this ) )
00063 {
00064 setIcon( KIcon( "document-new" ) );
00065
00066 QVBoxLayout* layout = new QVBoxLayout( widget() );
00067 QGroupBox* box = new QGroupBox( i18n( "General Information" ), widget() );
00068
00069 widget()->setLayout( layout );
00070 layout->addWidget( box );
00071
00072 QFormLayout* boxLayout = new QFormLayout( box );
00073 box->setLayout( boxLayout );
00074
00075 d->name = new KLineEdit( box );
00076 boxLayout->addRow( i18n( "Project Name" ), d->name );
00077
00078 d->location = new KUrlRequester( box );
00079 d->location->setMode( KFile::Directory );
00080 boxLayout->addRow( i18n( "Project Location" ), d->location );
00081 }
00082
00083 NewProjectDialogPage::~NewProjectDialogPage()
00084 {
00085 delete d;
00086 }
00087
00088 QString NewProjectDialogPage::createProject() const
00089 {
00090 if( d->name->text().isEmpty() || d->location->url().isEmpty() )
00091 {
00092 KMessageBox::error( 0, i18n( "You need to enter a name and location to continue" ) );
00093 return QString();
00094 }
00095
00096 QScopedPointer<GluonEngine::GameProject> project( new GluonEngine::GameProject( GluonEngine::Game::instance() ) );
00097 if( project.isNull() )
00098 {
00099 return QString();
00100 }
00101
00102 project->setName( d->name->text() );
00103
00104 GluonEngine::Scene* root = new GluonEngine::Scene( project.data() );
00105 root->setName( i18n( "New Scene" ) );
00106 root->savableDirty = true;
00107
00108 project->addChild( root );
00109 project->setEntryPoint( root );
00110
00111 GluonEngine::GameObject* camera = new GluonEngine::GameObject( root );
00112 camera->setName( i18n( "Camera" ) );
00113 camera->setPosition( 0.0f, 0.0f, 50.0f );
00114 root->sceneContents()->addChild( camera );
00115
00116 GluonCore::GluonObject* cameraController =
00117 GluonCore::GluonObjectFactory::instance()->instantiateObjectByName( "GluonEngine::CameraControllerComponent" );
00118 cameraController->setName( "CameraController" );
00119 camera->addComponent( qobject_cast<GluonEngine::Component*>( camera ) );
00120
00121 GluonEngine::GameObject* sprite = new GluonEngine::GameObject( root );
00122 sprite->setName( i18n( "Sprite" ) );
00123 root->sceneContents()->addChild( sprite );
00124
00125 GluonCore::GluonObject* spriteComponent =
00126 GluonCore::GluonObjectFactory::instance()->instantiateObjectByName( "GluonEngine::SpriteRendererComponent" );
00127 spriteComponent->setName( "SpriteRenderer" );
00128 sprite->addComponent( qobject_cast<GluonEngine::Component*>( spriteComponent ) );
00129
00130 KUrl location = d->location->url();
00131 QString projectFileName = project->fullyQualifiedFileName();
00132 location.addPath( projectFileName.left( projectFileName.indexOf( '.' ) ) + ".gluon" );
00133 project->setFilename( location );
00134
00135 QDir::setCurrent( d->location->url().toLocalFile() );
00136 project->saveToFile();
00137
00138 return location.toLocalFile();
00139 }
00140
00141 bool NewProjectDialogPage::isModified() const
00142 {
00143 return ( !d->name->text().isEmpty() || !d->location->url().isEmpty() );
00144 }