From fed92a47d36e7f5749d71c23d02b0bb27f8a7390 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 28 Jul 2014 17:05:51 +0200 Subject: [PATCH] As it turns out, tilesets can be assigned to multiple lands... --- .../src/plugins/tile_editor/CMakeLists.txt | 6 +- .../plugins/tile_editor/land_edit_dialog.cpp | 77 +++++++++ .../plugins/tile_editor/land_edit_dialog.h | 32 ++++ .../plugins/tile_editor/land_edit_dialog.ui | 99 +++++++++++ .../tile_editor/tile_editor_main_window.cpp | 157 +++++++++--------- .../tile_editor/tile_editor_main_window.h | 12 +- .../plugins/tile_editor/tilebank_saver.cpp | 2 +- .../src/plugins/tile_editor/tilebank_saver.h | 2 +- 8 files changed, 299 insertions(+), 88 deletions(-) create mode 100644 code/studio/src/plugins/tile_editor/land_edit_dialog.cpp create mode 100644 code/studio/src/plugins/tile_editor/land_edit_dialog.h create mode 100644 code/studio/src/plugins/tile_editor/land_edit_dialog.ui diff --git a/code/studio/src/plugins/tile_editor/CMakeLists.txt b/code/studio/src/plugins/tile_editor/CMakeLists.txt index d546beba1..396522235 100644 --- a/code/studio/src/plugins/tile_editor/CMakeLists.txt +++ b/code/studio/src/plugins/tile_editor/CMakeLists.txt @@ -11,10 +11,12 @@ SET(OVQT_EXT_SYS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/../../extension_system/iplugin. SET(OVQT_TILE_EDITOR_PLUGIN_HDR tile_model.h tile_editor_main_window.h - tile_editor_plugin.h) + tile_editor_plugin.h + land_edit_dialog.h) SET(OVQT_TILE_EDITOR_PLUGIN_UIS - tile_editor_main_window.ui) + tile_editor_main_window.ui + land_edit_dialog.ui) SET(OVQT_PLUG_TILE_EDITOR_RCS tile_editor.qrc) diff --git a/code/studio/src/plugins/tile_editor/land_edit_dialog.cpp b/code/studio/src/plugins/tile_editor/land_edit_dialog.cpp new file mode 100644 index 000000000..f7f5c5ce6 --- /dev/null +++ b/code/studio/src/plugins/tile_editor/land_edit_dialog.cpp @@ -0,0 +1,77 @@ +#include "land_edit_dialog.h" + +LandEditDialog::LandEditDialog( QWidget *parent ) : +QDialog( parent ) +{ + setupUi( this ); + setupConnections(); +} + +LandEditDialog::~LandEditDialog() +{ +} + +void LandEditDialog::getSelectedTileSets( QStringList &l ) const +{ + int c = tilesetLV->count(); + for( int i = 0; i < c; i++ ) + { + l.push_back( tilesetLV->item( i )->text() ); + } +} + +void LandEditDialog::setTileSets( const QStringList &l ) +{ + tilesetCB->clear(); + + QStringListIterator itr( l ); + while( itr.hasNext() ) + { + tilesetCB->addItem( itr.next() ); + } +} + +void LandEditDialog::setupConnections() +{ + connect( okButton, SIGNAL( clicked( bool ) ), this, SLOT( onOkClicked() ) ); + connect( cancelButton, SIGNAL( clicked( bool ) ), this, SLOT( onCancelClicked() ) ); + connect( addButton, SIGNAL( clicked( bool ) ), this, SLOT( onAddClicked() ) ); + connect( removeButton, SIGNAL( clicked( bool ) ), this, SLOT( onRemoveClicked() ) ); +} + +void LandEditDialog::onOkClicked() +{ + accept(); +} + +void LandEditDialog::onCancelClicked() +{ + reject(); +} + +void LandEditDialog::onAddClicked() +{ + if( tilesetCB->currentIndex() < 0 ) + return; + + QString text = tilesetCB->currentText(); + + int c = tilesetLV->count(); + for( int i = 0; i < c; i++ ) + { + if( text == tilesetLV->item( i )->text() ) + return; + } + + tilesetLV->addItem( text ); +} + +void LandEditDialog::onRemoveClicked() +{ + if( tilesetLV->currentItem() == NULL ) + return; + + QListWidgetItem *item = tilesetLV->currentItem(); + delete item; +} + diff --git a/code/studio/src/plugins/tile_editor/land_edit_dialog.h b/code/studio/src/plugins/tile_editor/land_edit_dialog.h new file mode 100644 index 000000000..9b86a2d06 --- /dev/null +++ b/code/studio/src/plugins/tile_editor/land_edit_dialog.h @@ -0,0 +1,32 @@ +#ifndef LAND_EDIT_DLG_H +#define LAND_EDIT_DLG_H + + +#include "ui_land_edit_dialog.h" +#include + +class LandEditDialog : public QDialog, public Ui::LandEditDialog +{ + Q_OBJECT +public: + LandEditDialog( QWidget *parent = NULL ); + ~LandEditDialog(); + + void getSelectedTileSets( QStringList &l ) const; + void setTileSets( const QStringList &l ); + +private: + void setupConnections(); + + +private Q_SLOTS: + void onOkClicked(); + void onCancelClicked(); + void onAddClicked(); + void onRemoveClicked(); + +}; + + +#endif + diff --git a/code/studio/src/plugins/tile_editor/land_edit_dialog.ui b/code/studio/src/plugins/tile_editor/land_edit_dialog.ui new file mode 100644 index 000000000..7eb707528 --- /dev/null +++ b/code/studio/src/plugins/tile_editor/land_edit_dialog.ui @@ -0,0 +1,99 @@ + + + LandEditDialog + + + Qt::WindowModal + + + + 0 + 0 + 402 + 311 + + + + Editing land + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Add + + + + + + + + 0 + 0 + + + + Remove + + + + + + + + 0 + 0 + + + + OK + + + + + + + + 0 + 0 + + + + Cancel + + + + + + + + + + diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp index 75d2c31f4..0a30da403 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.cpp @@ -34,6 +34,8 @@ #include "tilebank_saver.h" +#include "land_edit_dialog.h" + TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::TileEditorMainWindow) @@ -96,15 +98,18 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) connect(m_ui->landAddTB, SIGNAL(clicked()), this, SLOT(onLandAdd())); connect(m_ui->landRemoveTB, SIGNAL(clicked()), this, SLOT(onLandRemove())); connect(m_ui->landEditTB, SIGNAL(clicked()), this, SLOT(onLandEdit())); - connect(m_ui->landLW, SIGNAL(currentRowChanged(int)), this, SLOT(onLandRowChanged(int))); connect(m_ui->chooseVegetPushButton, SIGNAL(clicked()), this, SLOT(onChooseVegetation())); connect(m_ui->resetVegetPushButton, SIGNAL(clicked()), this, SLOT(onResetVegetation())); connect(m_ui->tileBankTexturePathPB, SIGNAL(clicked()), this, SLOT(onChooseTexturePath())); + m_tileModel = createTileModel(); + m_ui->tileSetLV->setModel( m_tileModel ); + // 128x128 List View //m_ui->listView128->setItemDelegate(m_tileItemDelegate); + m_ui->listView128->setModel( m_tileModel ); m_ui->listView128->addAction(m_ui->actionAddTile); m_ui->listView128->addAction(m_ui->actionDeleteTile); m_ui->listView128->addAction(m_ui->actionReplaceImage); @@ -112,6 +117,7 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) // 256x256 List View //m_ui->listView256->setItemDelegate(m_tileItemDelegate); + m_ui->listView256->setModel( m_tileModel ); m_ui->listView256->addAction(m_ui->actionAddTile); m_ui->listView256->addAction(m_ui->actionDeleteTile); m_ui->listView256->addAction(m_ui->actionReplaceImage); @@ -119,11 +125,13 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) // Transition List View //m_ui->listViewTransition->setItemDelegate(m_tileItemDelegate); + m_ui->listViewTransition->setModel( m_tileModel ); m_ui->listViewTransition->addAction(m_ui->actionReplaceImage); m_ui->listViewTransition->addAction(m_ui->actionDeleteImage); // Displacement List View //m_ui->listViewDisplacement->setItemDelegate(m_tileItemDelegate); + m_ui->listViewDisplacement->setModel( m_tileModel ); m_ui->listViewDisplacement->addAction(m_ui->actionReplaceImage); m_ui->listViewDisplacement->addAction(m_ui->actionDeleteImage); @@ -135,6 +143,8 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) connect(m_ui->actionDeleteImage, SIGNAL(triggered(bool)), this, SLOT(onActionDeleteImage(bool))); //connect(m_ui->tileViewTabWidget, SIGNAL(currentChanged(int)), m_tileItemDelegate, SLOT(currentTab(int))); + connect( m_ui->tileSetLV->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), + this, SLOT( changeActiveTileSet( const QModelIndex &, const QModelIndex & ) ) ); // Connect the zoom buttons. connect(m_ui->actionZoom50, SIGNAL(triggered()), m_zoomSignalMapper, SLOT(map())); @@ -167,8 +177,8 @@ TileEditorMainWindow::~TileEditorMainWindow() delete m_zoomActionGroup; delete m_zoomSignalMapper; - qDeleteAll( m_tileModels ); - m_tileModels.clear(); + delete m_tileModel; + m_tileModel = NULL; } void TileEditorMainWindow::save() @@ -200,7 +210,7 @@ void TileEditorMainWindow::saveAs() } TileBankSaver saver; - bool ok = saver.save( m_fileName.toUtf8().constData(), m_tileModels, landNames ); + bool ok = saver.save( m_fileName.toUtf8().constData(), m_tileModel, landNames ); if( !ok ) { @@ -279,14 +289,6 @@ void TileEditorMainWindow::onActionDeleteImage(bool triggered) void TileEditorMainWindow::onTileSetAdd() { - if( m_ui->landLW->count() == 0 ) - { - QMessageBox::information( this, - tr( "Error adding tile set" ), - tr( "You need to add a land before adding a tileset!" ) ); - return; - } - bool ok; QString text = QInputDialog::getText(this, tr("Add Tile Set"), tr("Enter Tile Set name:"), QLineEdit::Normal, "", &ok); if (ok && !text.isEmpty()) @@ -323,8 +325,12 @@ void TileEditorMainWindow::onTileSetDelete() if( reply != QMessageBox::Yes ) return; + QString set = reinterpret_cast< TileSetNode* >( idx.internalPointer() )->getTileSetName(); + TileModel *model = static_cast(m_ui->tileSetLV->model()); bool ok = model->removeRow( idx.row() ); + + onTileSetRemoved( set ); } void TileEditorMainWindow::onTileSetEdit() @@ -357,8 +363,11 @@ void TileEditorMainWindow::onTileSetEdit() return; } + QString oldName = node->getTileSetName(); node->setTileSetName( newName ); m_ui->tileSetLV->reset(); + + onTileSetRenamed( oldName, newName ); } void TileEditorMainWindow::onTileSetUp() @@ -422,13 +431,10 @@ void TileEditorMainWindow::onLandAdd() } m_ui->landLW->addItem( name ); - - TileModel *m = createTileModel(); - - m_tileModels.push_back( m ); - - if( m_tileModels.count() == 1 ) - m_ui->landLW->setCurrentRow( 0 ); + + Land l; + l.name = name; + m_lands.push_back( l ); } void TileEditorMainWindow::onLandRemove() @@ -447,12 +453,10 @@ void TileEditorMainWindow::onLandRemove() if( reply != QMessageBox::Yes ) return; - QList< TileModel* >::iterator itr = m_tileModels.begin() + idx; - delete m_tileModels[ idx ]; - m_tileModels[ idx ] = NULL; - m_tileModels.erase( itr ); - delete item; + + QList< Land >::iterator itr = m_lands.begin() + idx; + m_lands.erase( itr ); } void TileEditorMainWindow::onLandEdit() @@ -461,58 +465,33 @@ void TileEditorMainWindow::onLandEdit() if( item == NULL ) return; - QString name = item->text(); - - QString newName = QInputDialog::getText( this, - tr( "Editing land" ), - tr( "Please specify the new name of the selected land" ), - QLineEdit::Normal, - name ); - - if( newName.isEmpty() ) - return; - if( newName == name ) - return; - item->setText( newName ); -} - -void TileEditorMainWindow::onLandRowChanged( int row ) -{ - m_ui->chooseVegetPushButton->setText( "..." ); - - if( row == -1 ) + QStringList ts; + int c = m_tileModel->rowCount(); + for( int i = 0; i < c; i++ ) { - disconnect( m_ui->tileSetLV->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), - this, SLOT( changeActiveTileSet( const QModelIndex &, const QModelIndex & ) ) ); + QModelIndex idx = m_tileModel->index( i, 0 ); + if( !idx.isValid() ) + continue; - m_ui->tileSetLV->setModel( NULL ); - m_ui->listView128->setModel( NULL ); - m_ui->listView256->setModel( NULL ); - m_ui->listViewTransition->setModel( NULL ); - m_ui->listViewDisplacement->setModel( NULL ); + TileSetNode *n = reinterpret_cast< TileSetNode* >( idx.internalPointer() ); + ts.push_back( n->getTileSetName() ); } - else - { - //disconnect( m_ui->tileSetLV->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), - // this, SLOT( changeActiveTileSet( const QModelIndex &, const QModelIndex & ) ) ); + + int r = m_ui->landLW->currentRow(); + Land &l = m_lands[ r ]; - m_ui->tileSetLV->setModel( m_tileModels[ row ] ); - m_ui->listView128->setModel( m_tileModels[ row ] ); - m_ui->listView256->setModel( m_tileModels[ row ] ); - m_ui->listViewTransition->setModel( m_tileModels[ row ] ); - m_ui->listViewDisplacement->setModel( m_tileModels[ row ] ); + LandEditDialog d; + d.setTileSets( ts ); + int result = d.exec(); - connect( m_ui->tileSetLV->selectionModel(), SIGNAL( currentChanged( const QModelIndex &, const QModelIndex & ) ), - this, SLOT( changeActiveTileSet( const QModelIndex &, const QModelIndex & ) ) ); + if( result != QDialog::Accepted ) + return; - if( m_ui->tileSetLV->model()->rowCount() != 0 ) - { - QModelIndex idx = m_ui->tileSetLV->model()->index( 0, 0 ); - m_ui->tileSetLV->setCurrentIndex( idx ); - } - } - - m_ui->tileSetLV->reset(); + // Update the tileset of the land + ts.clear(); + d.getSelectedTileSets( ts ); + l.tilesets.clear(); + l.tilesets = ts; } void TileEditorMainWindow::onChooseVegetation() @@ -579,15 +558,6 @@ void TileEditorMainWindow::onChooseTexturePath() void TileEditorMainWindow::onActionAddTile(int tabId) { - int land = m_ui->landLW->currentRow(); - if( land == -1 ) - { - QMessageBox::information( this, - tr( "Adding new tile" ), - tr( "You need to have a land and a tileset selected before you can add tiles!" ) ); - return; - } - QModelIndex idx = m_ui->tileSetLV->currentIndex(); if( !idx.isValid() ) { @@ -599,8 +569,7 @@ void TileEditorMainWindow::onActionAddTile(int tabId) int tileSet = idx.row(); - TileModel *model = static_cast< TileModel* >( m_tileModels[ land ] ); - idx = model->index( tileSet, 0 ); + idx = m_tileModel->index( tileSet, 0 ); if( !idx.isValid() ) return; @@ -622,7 +591,7 @@ void TileEditorMainWindow::onActionAddTile(int tabId) c++; } - QModelIndex rootIdx = model->index( tabId, 0, m_ui->tileSetLV->currentIndex()); + QModelIndex rootIdx = m_tileModel->index( tabId, 0, m_ui->tileSetLV->currentIndex()); QListView *lv = getListViewByTab( tabId ); @@ -693,6 +662,30 @@ void TileEditorMainWindow::onActionReplaceImage( int tabId ) n->setTileFilename( TileModel::TileDiffuse, fileName ); } +void TileEditorMainWindow::onTileSetRemoved( const QString &set ) +{ + int c = m_lands.count(); + for( int i = 0; i < c; i++ ) + { + Land &land = m_lands[ i ]; + land.tilesets.removeAll( set ); + } +} + +void TileEditorMainWindow::onTileSetRenamed( const QString &oldname, const QString &newname ) +{ + int c = m_lands.count(); + for( int i = 0; i < c; i++ ) + { + Land &land = m_lands[ i ]; + int idx = land.tilesets.indexOf( oldname ); + if( idx < 0 ) + continue; + + land.tilesets[ idx ] = newname; + } +} + TileModel* TileEditorMainWindow::createTileModel() { QStringList headers; diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h index c1fb662b0..5f015ad6a 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.h +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.h @@ -61,7 +61,6 @@ private Q_SLOTS: void onLandAdd(); void onLandRemove(); void onLandEdit(); - void onLandRowChanged( int row ); void onResetVegetation(); void onChooseVegetation(); @@ -77,6 +76,8 @@ private: void onActionDeleteImage(int tabId); void onActionReplaceImage(int tabId); + void onTileSetRemoved( const QString &set ); + void onTileSetRenamed( const QString &oldname, const QString &newname ); TileModel* createTileModel(); QListView* getListViewByTab( int tab ) const; @@ -94,7 +95,7 @@ private: TileItemDelegate *m_tileItemDelegate; - QList< TileModel* > m_tileModels; + TileModel *m_tileModel; QString m_texturePath; @@ -107,7 +108,14 @@ private: TAB_DETAILS = 4 }; + struct Land + { + QString name; + QStringList tilesets; + }; + QString m_fileName; + QList< Land > m_lands; }; #endif // TILE_EDITOR_MAIN_WINDOW_H diff --git a/code/studio/src/plugins/tile_editor/tilebank_saver.cpp b/code/studio/src/plugins/tile_editor/tilebank_saver.cpp index d149648ff..db281d161 100644 --- a/code/studio/src/plugins/tile_editor/tilebank_saver.cpp +++ b/code/studio/src/plugins/tile_editor/tilebank_saver.cpp @@ -28,7 +28,7 @@ TileBankSaver::~TileBankSaver() { } -bool TileBankSaver::save( const char *fileName, const QList< TileModel* > &models, const QList< QString > &lands ) +bool TileBankSaver::save( const char *fileName, const TileModel* model, const QList< QString > &lands ) { NL3D::CTileBank bank; diff --git a/code/studio/src/plugins/tile_editor/tilebank_saver.h b/code/studio/src/plugins/tile_editor/tilebank_saver.h index 80fb119d8..f86bfab60 100644 --- a/code/studio/src/plugins/tile_editor/tilebank_saver.h +++ b/code/studio/src/plugins/tile_editor/tilebank_saver.h @@ -29,7 +29,7 @@ public: TileBankSaver(); ~TileBankSaver(); - bool save( const char *filename, const QList< TileModel* > &models, const QList< QString > &lands ); + bool save( const char *filename, const TileModel* model, const QList< QString > &lands ); private: };