Implemented Tile addition.

--HG--
branch : gsoc2014-dfighter
This commit is contained in:
dfighter1985 2014-07-26 00:29:37 +02:00
parent 78f4654063
commit d2a414edb4
4 changed files with 70 additions and 2 deletions

View file

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

View file

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

View file

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

View file

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