Map files can now be specified when creating a new GUI project.

This commit is contained in:
dfighter1985 2014-10-13 18:53:26 +02:00
parent 284de64589
commit 3511589f2f
6 changed files with 122 additions and 23 deletions

View file

@ -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();

View file

@ -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();

View file

@ -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();

View file

@ -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;
}

View file

@ -20,6 +20,7 @@
#define NEW_GUI_DLG_H
#include "ui_new_gui_dlg.h"
#include <QList>
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;

View file

@ -6,14 +6,14 @@
<rect>
<x>0</x>
<y>0</y>
<width>332</width>
<height>125</height>
<width>399</width>
<height>354</height>
</rect>
</property>
<property name="windowTitle">
<string>New GUI</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -21,7 +21,7 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="1" colspan="2">
<widget class="QLineEdit" name="projectEdit"/>
</item>
<item row="1" column="0">
@ -31,7 +31,7 @@
</property>
</widget>
</item>
<item row="1" column="1">
<item row="1" column="1" colspan="2">
<widget class="QLineEdit" name="windowEdit"/>
</item>
<item row="2" column="0">
@ -41,17 +41,46 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="1" colspan="2">
<widget class="QLineEdit" name="projectDirEdit"/>
</item>
<item row="2" column="2">
<item row="2" column="3">
<widget class="QToolButton" name="projectDirTB">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="0">
<item row="3" column="0" colspan="4">
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Map files</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="1">
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLineEdit" name="mapEdit"/>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item row="1" column="0" rowspan="2">
<widget class="QListWidget" name="mapList"/>
</item>
</layout>
</widget>
</item>
<item row="4" column="0" colspan="2">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
@ -64,7 +93,7 @@
</property>
</spacer>
</item>
<item row="3" column="1" colspan="2">
<item row="4" column="2" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QPushButton" name="okButton">