From 7b1ee54427e53cc8c658d884028a67206d99fece Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 30 Jul 2014 14:28:17 +0200 Subject: [PATCH] Show the image that belongs to the channel that is selected. --HG-- branch : gsoc2014-dfighter --- .../tile_editor/tile_editor_main_window.cpp | 53 +++++++++++++++++++ .../tile_editor/tile_editor_main_window.h | 8 +++ .../tile_editor/tile_editor_main_window.ui | 14 ++--- .../src/plugins/tile_editor/tile_item.cpp | 4 +- .../src/plugins/tile_editor/tile_item.h | 5 ++ 5 files changed, 76 insertions(+), 8 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 5a77f54e7..66a73cfd1 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 @@ -168,6 +168,17 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent) connect( m_ui->actionOpenTileBank, SIGNAL( triggered() ), this, SLOT( open() ) ); connect( m_ui->orientedCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( onOrientedStateChanged( int ) ) ); + + connect( m_ui->diffuse128BT, SIGNAL( toggled( bool ) ), this, SLOT( onDiffuseToggled( bool ) ) ); + connect( m_ui->diffuse256BT, SIGNAL( toggled( bool ) ), this, SLOT( onDiffuseToggled( bool ) ) ); + connect( m_ui->diffuseTrBT, SIGNAL( toggled( bool ) ), this, SLOT( onDiffuseToggled( bool ) ) ); + connect( m_ui->additive128BT, SIGNAL( toggled( bool ) ), this, SLOT( onAdditiveToggled( bool ) ) ); + connect( m_ui->additive256BT, SIGNAL( toggled( bool ) ), this, SLOT( onAdditiveToggled( bool ) ) ); + connect( m_ui->additiveTrBT, SIGNAL( toggled( bool ) ), this, SLOT( onAdditiveToggled( bool ) ) ); + connect( m_ui->alphaTrBT, SIGNAL( toggled( bool ) ), this, SLOT( onAlphaToggled( bool ) ) ); + + connect( m_ui->tileViewTabWidget, SIGNAL( currentChanged( int ) ), this, SLOT( onTabChanged( int ) ) ); + } TileEditorMainWindow::~TileEditorMainWindow() @@ -601,6 +612,43 @@ void TileEditorMainWindow::onOrientedStateChanged( int state ) node->setOriented( false ); } +void TileEditorMainWindow::onDiffuseToggled( bool b ) +{ + if( !b ) + return; + + TileItemNode::setDisplayChannel( TileModel::TileDiffuse ); + updateTab(); +} + +void TileEditorMainWindow::onAdditiveToggled( bool b ) +{ + if( !b ) + return; + + TileItemNode::setDisplayChannel( TileModel::TileAdditive ); + updateTab(); +} + +void TileEditorMainWindow::onAlphaToggled( bool b ) +{ + if( !b ) + return; + + TileItemNode::setDisplayChannel( TileModel::TileAlpha ); + updateTab(); +} + +void TileEditorMainWindow::onTabChanged( int tab ) +{ + if( tab == -1 ) + return; + + m_ui->diffuse128BT->setChecked( true ); + m_ui->diffuse256BT->setChecked( true ); + m_ui->diffuseTrBT->setChecked( true ); +} + void TileEditorMainWindow::onActionAddTile(int tabId) { QModelIndex idx = m_ui->tileSetLV->currentIndex(); @@ -758,6 +806,11 @@ void TileEditorMainWindow::onTileBankLoaded() m_ui->landLW->setCurrentRow( 0 ); } +void TileEditorMainWindow::updateTab() +{ + m_ui->tileViewTabWidget->currentWidget()->repaint(); +} + 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 022348ab5..2c4286377 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 @@ -72,6 +72,12 @@ private Q_SLOTS: void onOrientedStateChanged( int state ); + void onDiffuseToggled( bool b ); + void onAdditiveToggled( bool b ); + void onAlphaToggled( bool b ); + + void onTabChanged( int tab ); + void changeActiveTileSet(const QModelIndex &newIndex, const QModelIndex &oldIndex); void onZoomFactor(int level); @@ -85,6 +91,8 @@ private: void onTileSetRenamed( const QString &oldname, const QString &newname ); void onTileBankLoaded(); + void updateTab(); + TileModel* createTileModel(); QListView* getListViewByTab( int tab ) const; diff --git a/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui b/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui index 2e936aa8b..f45951aba 100644 --- a/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui +++ b/code/studio/src/plugins/tile_editor/tile_editor_main_window.ui @@ -57,7 +57,7 @@ - + Diffuse @@ -67,7 +67,7 @@ - + Additive @@ -115,7 +115,7 @@ - + Diffuse @@ -128,7 +128,7 @@ - + Additive @@ -185,7 +185,7 @@ - + Diffuse @@ -195,14 +195,14 @@ - + Additive - + Alpha diff --git a/code/studio/src/plugins/tile_editor/tile_item.cpp b/code/studio/src/plugins/tile_editor/tile_item.cpp index 76bf7c67e..7ae177220 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.cpp +++ b/code/studio/src/plugins/tile_editor/tile_item.cpp @@ -264,6 +264,8 @@ void TileTypeNode::reindex() /////////////////////////////////////////////////// +TileModel::TTileChannel TileItemNode::s_displayChannel = TileModel::TileDiffuse; + TileItemNode::TileItemNode(int tileId, TileModel::TTileChannel channel, QString filename, Node *parent) : m_tileId(tileId) { m_tileFilename[channel] = filename; @@ -294,7 +296,7 @@ QString TileItemNode::getTileFilename(TileModel::TTileChannel channel) QVariant TileItemNode::data(int column, int role) const { // find some way to know which file/bitmap to display - QString tileFilename = m_tileFilename[TileModel::TileDiffuse]; + QString tileFilename = m_tileFilename[s_displayChannel]; if(role == TileModel::TilePixmapRole || role == Qt::DecorationRole) { diff --git a/code/studio/src/plugins/tile_editor/tile_item.h b/code/studio/src/plugins/tile_editor/tile_item.h index 3fad517c3..4e00c12c3 100644 --- a/code/studio/src/plugins/tile_editor/tile_item.h +++ b/code/studio/src/plugins/tile_editor/tile_item.h @@ -115,10 +115,15 @@ public: QString getTileFilename(TileModel::TTileChannel channel); void setId( int id ){ m_tileId = id; } int id() const{ return m_tileId; } + + static void setDisplayChannel( TileModel::TTileChannel channel ){ s_displayChannel = channel; } + private: int m_tileId; QMap m_tileFilename; QMap m_tileWidget; + + static TileModel::TTileChannel s_displayChannel; }; #endif // TILE_ITEM_H