From a1b87377768742b695e66a737e47bb368f105565 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Sat, 26 Jul 2014 00:29:37 +0200 Subject: [PATCH] Implemented Tile addition. --- .../tile_editor/tile_editor_main_window.cpp | 54 +++++++++++++++++++ .../tile_editor/tile_editor_main_window.h | 12 ++++- .../src/plugins/tile_editor/tile_model.cpp | 5 ++ .../src/plugins/tile_editor/tile_model.h | 1 + 4 files changed, 70 insertions(+), 2 deletions(-) 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 7b255ce2d..1ad0e8a45 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 @@ -527,9 +527,63 @@ 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() ) + { + QMessageBox::information( this, + tr( "Adding new tiles" ), + tr( "You need to have a tileset selected before you can add tiles!" ) ); + return; + } + + int tileSet = idx.row(); + + TileModel *model = static_cast< TileModel* >( m_tileModels[ land ] ); + idx = model->index( tileSet, 0 ); + if( !idx.isValid() ) + return; + + TileSetNode *tsn = reinterpret_cast< TileSetNode* >( idx.internalPointer() ); + + int tabIdx = m_ui->tileViewTabWidget->currentIndex(); + Node *n = tsn->child( tabIdx ); + QFileDialog::Options options; QString selectedFilter; QStringList fileNames = QFileDialog::getOpenFileNames(this, "Choose Tile Texture", "." , "Images (*.png);;All Files (*.*)", &selectedFilter, options); + + int c = n->childCount(); + + QStringListIterator itr( fileNames ); + while( itr.hasNext() ) + { + Node *newNode = TileModel::createItemNode( c, TileModel::TileDiffuse, itr.next() ); + n->appendRow( newNode ); + c++; + } + + QModelIndex rootIdx = model->index( tabIdx, 0, m_ui->tileSetLV->currentIndex()); + + QListView *lv = NULL; + + switch( tabIdx ) + { + case TAB_128: lv = m_ui->listView128; break; + case TAB_256: lv = m_ui->listView256; break; + } + + lv->reset(); + lv->setRootIndex( rootIdx ); + lv->setCurrentIndex( lv->model()->index( 0, 0, rootIdx ) ); } TileModel* TileEditorMainWindow::createTileModel() 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 a66d6d993..9dff9fc3e 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 @@ -42,7 +42,7 @@ public: QUndoStack *getUndoStack() { return m_undoStack; } -public Q_SLOTS: +private Q_SLOTS: void onActionAddTile(bool triggered); void onActionDeleteTile(bool triggered); void onActionReplaceImage(bool triggered); @@ -69,7 +69,6 @@ public Q_SLOTS: private: void onActionAddTile(int tabId); - TileModel* createTileModel(); Ui::TileEditorMainWindow *m_ui; @@ -88,6 +87,15 @@ private: QList< TileModel* > m_tileModels; QString m_texturePath; + + enum Tabs + { + TAB_128 = 0, + TAB_256 = 1, + TAB_TRANSITION = 2, + TAB_DISPLACEMENT = 3, + TAB_DETAILS = 4 + }; }; #endif // TILE_EDITOR_MAIN_WINDOW_H diff --git a/code/studio/src/plugins/tile_editor/tile_model.cpp b/code/studio/src/plugins/tile_editor/tile_model.cpp index 4b6d2113d..d7ead6ac3 100644 --- a/code/studio/src/plugins/tile_editor/tile_model.cpp +++ b/code/studio/src/plugins/tile_editor/tile_model.cpp @@ -203,6 +203,11 @@ TileSetNode *TileModel::createTileSetNode(QString tileSetName) return tileSet; } +Node *TileModel::createItemNode( int id, TTileChannel channel, const QString &fileName ) +{ + return new TileItemNode( id, channel, fileName ); +} + const char *TileModel::getTileTypeName(TileModel::TNodeTileType type) { switch(type) diff --git a/code/studio/src/plugins/tile_editor/tile_model.h b/code/studio/src/plugins/tile_editor/tile_model.h index e2be8da57..56d7b792b 100644 --- a/code/studio/src/plugins/tile_editor/tile_model.h +++ b/code/studio/src/plugins/tile_editor/tile_model.h @@ -84,6 +84,7 @@ public: void swapRows( int a, int b ); TileSetNode *createTileSetNode(QString tileSetName); + static Node *createItemNode( int id, TTileChannel channel, const QString &fileName ); static const char *getTileTypeName(TNodeTileType type); static uint32 getTileTypeSize(TileModel::TNodeTileType type);