From d7d7a35b9ada344e77929f9ef0ec9707d191b33b Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 13 Oct 2014 18:53:26 +0200 Subject: [PATCH] Map files can now be specified when creating a new GUI project. --- .../plugins/gui_editor/gui_editor_window.cpp | 20 ++++++++ .../src/plugins/gui_editor/nelgui_ctrl.cpp | 36 ++++++++------ .../src/plugins/gui_editor/nelgui_ctrl.h | 1 + .../src/plugins/gui_editor/new_gui_dlg.cpp | 37 +++++++++++++++ .../src/plugins/gui_editor/new_gui_dlg.h | 4 ++ .../src/plugins/gui_editor/new_gui_dlg.ui | 47 +++++++++++++++---- 6 files changed, 122 insertions(+), 23 deletions(-) diff --git a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp index aad19c2ac..002002abd 100644 --- a/code/studio/src/plugins/gui_editor/gui_editor_window.cpp +++ b/code/studio/src/plugins/gui_editor/gui_editor_window.cpp @@ -215,6 +215,9 @@ namespace GUIEditor _lastDir = dir.c_str(); std::string uiFile = "ui_" + proj + ".xml"; + QList< QString > mapList; + d.getMapList( mapList ); + bool b = GUICtrl->createNewGUI( proj, wnd ); if( !b ) { @@ -222,6 +225,7 @@ namespace GUIEditor tr( "Creating new GUI project" ), tr( "Failed to create new GUI project :(" ) ); reset(); + return; } hierarchyView->buildHierarchy( mg ); @@ -231,6 +235,22 @@ namespace GUIEditor projectFiles.activeGroup = std::string( "ui:" ) + proj + ":" + wnd; projectFiles.version = SProjectFiles::NEW; projectFiles.guiFiles.push_back( uiFile ); + + for( int i = 0; i < mapList.size(); i++ ) + { + projectFiles.mapFiles.push_back( mapList[ i ].toUtf8().constData() ); + } + + b = GUICtrl->loadMapFiles( projectFiles.mapFiles ); + if( !b ) + { + QMessageBox::information( this, + tr( "Creating new GUI project" ), + tr( "Failed to create new GUI project: Couldn't load map files. " ) ); + reset(); + return; + } + projectWindow->setupFiles( projectFiles ); currentProject = proj.c_str(); diff --git a/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp b/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp index c1e7af3df..e9712ce4e 100644 --- a/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp +++ b/code/studio/src/plugins/gui_editor/nelgui_ctrl.cpp @@ -89,20 +89,8 @@ namespace GUIEditor reset(); IParser *parser = CWidgetManager::getInstance()->getParser(); - std::vector< std::string >::iterator itr; - for( itr = files.mapFiles.begin(); itr != files.mapFiles.end(); ++itr ) - { - std::string &file = *itr; - std::string::size_type i = file.find_last_of( '.' ); - std::string mapFile = file.substr( 0, i ); - mapFile.append( ".txt" ); - - if( !CViewRenderer::getInstance()->loadTextures( file, mapFile, false ) ) - { - CViewRenderer::getInstance()->reset(); - return false; - } - } + if( !loadMapFiles( files.mapFiles ) ) + return false; if( !parser->parseInterface( files.guiFiles, false ) ) return false; @@ -119,6 +107,26 @@ namespace GUIEditor return true; } + bool NelGUICtrl::loadMapFiles( const std::vector< std::string > &v ) + { + std::vector< std::string >::const_iterator itr; + for( itr = v.begin(); itr != v.end(); ++itr ) + { + const std::string &file = *itr; + std::string::size_type i = file.find_last_of( '.' ); + std::string mapFile = file.substr( 0, i ); + mapFile.append( ".txt" ); + + if( !CViewRenderer::getInstance()->loadTextures( file, mapFile, false ) ) + { + CViewRenderer::getInstance()->reset(); + return false; + } + } + + return true; + } + bool NelGUICtrl::createNewGUI( const std::string &project, const std::string &window ) { reset(); diff --git a/code/studio/src/plugins/gui_editor/nelgui_ctrl.h b/code/studio/src/plugins/gui_editor/nelgui_ctrl.h index d7d157ccf..d54c78c7a 100644 --- a/code/studio/src/plugins/gui_editor/nelgui_ctrl.h +++ b/code/studio/src/plugins/gui_editor/nelgui_ctrl.h @@ -43,6 +43,7 @@ namespace GUIEditor void init(); bool parse( SProjectFiles &files ); + bool loadMapFiles( const std::vector< std::string > &v ); bool createNewGUI( const std::string &project, const std::string &window ); void draw(); void reset(); diff --git a/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp b/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp index 88d4a19fd..3c9208dfc 100644 --- a/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp +++ b/code/studio/src/plugins/gui_editor/new_gui_dlg.cpp @@ -28,6 +28,8 @@ QDialog( parent ) connect( m_ui.okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOKClicked() ) ); connect( m_ui.cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) ); connect( m_ui.projectDirTB, SIGNAL( clicked( bool ) ), this, SLOT( onProjectDirTBClicked() ) ); + connect( m_ui.addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + connect( m_ui.removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); } @@ -50,6 +52,16 @@ QString NewGUIDlg::getProjectDirectory() const return m_ui.projectDirEdit->text(); } +void NewGUIDlg::getMapList( QList< QString > &l ) +{ + l.clear(); + + for( int i = 0; i < m_ui.mapList->count(); i++ ) + { + l.push_back( m_ui.mapList->item( i )->text() ); + } +} + void NewGUIDlg::onOKClicked() { if( m_ui.projectEdit->text().isEmpty() ) @@ -95,4 +107,29 @@ void NewGUIDlg::onProjectDirTBClicked() m_ui.projectDirEdit->setText( dir ); } +void NewGUIDlg::onAddClicked() +{ + if( m_ui.mapEdit->text().isEmpty() ) + return; + + QList< QListWidgetItem* > l = m_ui.mapList->findItems( m_ui.mapEdit->text(), Qt::MatchContains ); + if( !l.isEmpty() ) + { + return; + } + + m_ui.mapList->addItem( m_ui.mapEdit->text() ); + m_ui.mapEdit->clear(); +} + +void NewGUIDlg::onRemoveClicked() +{ + QListWidgetItem *item = m_ui.mapList->currentItem(); + if( item == NULL ) + return; + + delete item; +} + + diff --git a/code/studio/src/plugins/gui_editor/new_gui_dlg.h b/code/studio/src/plugins/gui_editor/new_gui_dlg.h index f4bf474f7..0d878461c 100644 --- a/code/studio/src/plugins/gui_editor/new_gui_dlg.h +++ b/code/studio/src/plugins/gui_editor/new_gui_dlg.h @@ -20,6 +20,7 @@ #define NEW_GUI_DLG_H #include "ui_new_gui_dlg.h" +#include class NewGUIDlg : public QDialog { @@ -32,11 +33,14 @@ public: QString getProjectName() const; QString getWindowName() const; QString getProjectDirectory() const; + void getMapList( QList< QString > &l ); private Q_SLOTS: void onOKClicked(); void onCancelClicked(); void onProjectDirTBClicked(); + void onAddClicked(); + void onRemoveClicked(); private: Ui::NewGUIDialog m_ui; diff --git a/code/studio/src/plugins/gui_editor/new_gui_dlg.ui b/code/studio/src/plugins/gui_editor/new_gui_dlg.ui index 7dca6d2a3..bf22e8c6b 100644 --- a/code/studio/src/plugins/gui_editor/new_gui_dlg.ui +++ b/code/studio/src/plugins/gui_editor/new_gui_dlg.ui @@ -6,14 +6,14 @@ 0 0 - 332 - 125 + 399 + 354 New GUI - + @@ -21,7 +21,7 @@ - + @@ -31,7 +31,7 @@ - + @@ -41,17 +41,46 @@ - + - + ... - + + + + Map files + + + + + + Add + + + + + + + + + + Remove + + + + + + + + + + Qt::Horizontal @@ -64,7 +93,7 @@ - +