mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-18 21:26:12 +00:00
Most of the functionality works with the new code.
This commit is contained in:
parent
8d7c974be6
commit
fa9cd4af24
11 changed files with 513 additions and 875 deletions
|
@ -3,8 +3,10 @@
|
|||
|
||||
#include <QPixmap>
|
||||
|
||||
bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels )
|
||||
{
|
||||
namespace{
|
||||
|
||||
bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels )
|
||||
{
|
||||
QImage img = pixmap.toImage();
|
||||
if( img.format() != QImage::Format_ARGB32 )
|
||||
img = img.convertToFormat( QImage::Format_ARGB32 );
|
||||
|
@ -33,15 +35,141 @@ bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels )
|
|||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NL3D::CTile::TBitmap channelToTBitmap( TileConstants::TTileChannel channel )
|
||||
{
|
||||
return NL3D::CTile::TBitmap( int( channel ) );
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class TileBankPvt
|
||||
{
|
||||
public:
|
||||
|
||||
bool checkSize( TileConstants::TNodeTileType type, TileConstants::TTileChannel channel, int w, int h )
|
||||
{
|
||||
int width = -1;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128:
|
||||
width = 128;
|
||||
break;
|
||||
|
||||
case TileConstants::Tile256:
|
||||
width = 256;
|
||||
break;
|
||||
|
||||
case TileConstants::TileTransition:
|
||||
{
|
||||
if( channel == TileConstants::TileAlpha )
|
||||
width = 64;
|
||||
else
|
||||
width = 128;
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case TileConstants::TileDisplacement:
|
||||
width = 32;
|
||||
break;
|
||||
}
|
||||
|
||||
if( width == w )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
NL3D::CTileSet::TError checkTile( NL3D::CTileSet *set, int tile, TileConstants::TNodeTileType type, NL3D::CTileBorder &border, NL3D::CTile::TBitmap bitmap, QString &msg )
|
||||
{
|
||||
NL3D::CTileSet::TError error;
|
||||
|
||||
if( bitmap == NL3D::CTile::additive )
|
||||
return NL3D::CTileSet::ok;
|
||||
|
||||
if( type == TileConstants::TileDisplacement )
|
||||
return NL3D::CTileSet::ok;
|
||||
|
||||
int component;
|
||||
int pixel;
|
||||
int idx;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128:
|
||||
error = set->checkTile128( bitmap, border, pixel, component );
|
||||
break;
|
||||
|
||||
case TileConstants::Tile256:
|
||||
error = set->checkTile256( bitmap, border, pixel, component );
|
||||
break;
|
||||
|
||||
case TileConstants::TileTransition:
|
||||
{
|
||||
if( bitmap != NL3D::CTile::alpha )
|
||||
error = set->checkTile128( bitmap, border, pixel, component );
|
||||
else
|
||||
error = set->checkTileTransition( NL3D::CTileSet::TTransition( tile ), bitmap, border, idx, pixel, component );
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( ( error != NL3D::CTileSet::ok ) && ( error != NL3D::CTileSet::addFirstA128128 ) )
|
||||
{
|
||||
static const char* comp[]={"Red", "Green", "Blue", "Alpha", ""};
|
||||
|
||||
msg = NL3D::CTileSet::getErrorMessage( error );
|
||||
msg += "\n";
|
||||
msg += " pixel %1 component %2";
|
||||
msg = msg.arg( pixel );
|
||||
msg = msg.arg( comp[ component ] );
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
void setTile( NL3D::CTileSet *set, int tile, int rotation, const QString &name, NL3D::CTile::TBitmap bm, TileConstants::TNodeTileType type, NL3D::CTileBorder &border )
|
||||
{
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128:
|
||||
set->setTile128( tile, name.toUtf8().constData(), bm, m_bank );
|
||||
break;
|
||||
|
||||
case TileConstants::Tile256:
|
||||
set->setTile256( tile, name.toUtf8().constData(), bm, m_bank );
|
||||
break;
|
||||
|
||||
case TileConstants::TileTransition:
|
||||
if( bm != NL3D::CTile::alpha )
|
||||
set->setTileTransition( NL3D::CTileSet::TTransition( tile ), name.toUtf8().constData(), bm, m_bank, border );
|
||||
else
|
||||
set->setTileTransitionAlpha( NL3D::CTileSet::TTransition( tile ), name.toUtf8().constData(), m_bank, border, rotation );
|
||||
break;
|
||||
|
||||
case TileConstants::TileDisplacement:
|
||||
set->setDisplacement( NL3D::CTileSet::TDisplacement( tile ), name.toUtf8().constData(), m_bank );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void buildBorder( QPixmap &pm, NL3D::CTileBorder &border )
|
||||
{
|
||||
std::vector< NLMISC::CBGRA > pixels;
|
||||
pixmapToCBGRA( pm, pixels );
|
||||
border.set( pm.width(), pm.height(), pixels );
|
||||
}
|
||||
|
||||
NL3D::CTileBank m_bank;
|
||||
};
|
||||
|
||||
|
@ -52,6 +180,7 @@ public:
|
|||
TileBank::TileBank()
|
||||
{
|
||||
m_pvt = new TileBankPvt();
|
||||
resetError();
|
||||
}
|
||||
|
||||
TileBank::~TileBank()
|
||||
|
@ -65,11 +194,51 @@ void TileBank::addTileSet( const QString &name )
|
|||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( 0 );
|
||||
}
|
||||
|
||||
void TileBank::removeTileSet( int idx )
|
||||
{
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx );
|
||||
if( set == NULL )
|
||||
return;
|
||||
|
||||
int c = m_pvt->m_bank.getLandCount();
|
||||
for( int i = 0; i < c; i++ )
|
||||
{
|
||||
NL3D::CTileLand *land = m_pvt->m_bank.getLand( i );
|
||||
land->removeTileSet( set->getName() );
|
||||
}
|
||||
|
||||
m_pvt->m_bank.removeTileSet( idx );
|
||||
}
|
||||
|
||||
void TileBank::renameTileSet( int idx, const QString &newName )
|
||||
{
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx );
|
||||
if( set == NULL )
|
||||
return;
|
||||
|
||||
std::string oldName = set->getName();
|
||||
set->setName( newName.toUtf8().constData() );
|
||||
|
||||
int c = m_pvt->m_bank.getLandCount();
|
||||
for( int i = 0; i < c; i++ )
|
||||
{
|
||||
NL3D::CTileLand *land = m_pvt->m_bank.getLand( i );
|
||||
land->removeTileSet( oldName );
|
||||
land->addTileSet( newName.toUtf8().constData() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void TileBank::addLand( const QString &name )
|
||||
{
|
||||
m_pvt->m_bank.addLand( name.toUtf8().constData() );
|
||||
}
|
||||
|
||||
void TileBank::removeLand( int idx )
|
||||
{
|
||||
m_pvt->m_bank.removeLand( idx );
|
||||
}
|
||||
|
||||
void TileBank::setLandSets( int idx, const QStringList &l )
|
||||
{
|
||||
NL3D::CTileLand *land = m_pvt->m_bank.getLand( idx );
|
||||
|
@ -82,29 +251,145 @@ void TileBank::setLandSets( int idx, const QStringList &l )
|
|||
}
|
||||
}
|
||||
|
||||
bool TileBank::addTileToSet( int idx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type )
|
||||
void TileBank::getLandSets( int idx, QStringList &l )
|
||||
{
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( idx );
|
||||
NL3D::CTileLand *land = m_pvt->m_bank.getLand( idx );
|
||||
if( land == NULL )
|
||||
return;
|
||||
|
||||
l.clear();
|
||||
|
||||
std::set< std::string> sets = land->getTileSets();
|
||||
std::set< std::string >::const_iterator itr = sets.begin();
|
||||
while( itr != sets.end() )
|
||||
{
|
||||
l.push_back( itr->c_str() );
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
|
||||
bool TileBank::addTile( int setIdx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type )
|
||||
{
|
||||
resetError();
|
||||
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( setIdx );
|
||||
|
||||
int tile;
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128: set->addTile128( tile, m_pvt->m_bank ); break;
|
||||
case TileConstants::Tile256: set->addTile256( tile, m_pvt->m_bank ); break;
|
||||
}
|
||||
|
||||
bool b = setTile( setIdx, tile, name, pixmap, channel, type );
|
||||
if( b )
|
||||
return true;
|
||||
|
||||
// There was an error, roll back
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128: set->removeTile128( tile, m_pvt->m_bank ); break;
|
||||
case TileConstants::Tile256: set->removeTile128( tile, m_pvt->m_bank ); break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TileBank::removeTile( int ts, int type, int tile )
|
||||
{
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( ts );
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128: set->removeTile128( tile, m_pvt->m_bank ); break;
|
||||
case TileConstants::Tile256: set->removeTile256( tile, m_pvt->m_bank ); break;
|
||||
}
|
||||
}
|
||||
|
||||
bool TileBank::setTile( int tileset, int tile, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type )
|
||||
{
|
||||
resetError();
|
||||
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( tileset );
|
||||
if( set == NULL )
|
||||
return false;
|
||||
|
||||
QPixmap pm = pixmap.value< QPixmap >();
|
||||
if( pm.isNull() )
|
||||
{
|
||||
m_hasError = true;
|
||||
m_lastError = "Failed to load image.";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( pm.width() != pm.height() )
|
||||
{
|
||||
m_hasError = true;
|
||||
m_lastError = "Image isn't square.";
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector< NLMISC::CBGRA > pixels;
|
||||
pixmapToCBGRA( pm, pixels );
|
||||
|
||||
int tile;
|
||||
set->addTile128( tile, m_pvt->m_bank );
|
||||
if( !m_pvt->checkSize( type, channel, pm.width(), pm.height() ) )
|
||||
{
|
||||
m_hasError = true;
|
||||
m_lastError = "Invalid image size.";
|
||||
return false;
|
||||
}
|
||||
|
||||
NL3D::CTileBorder border;
|
||||
border.set( pm.width(), pm.height(), pixels );
|
||||
m_pvt->buildBorder( pm, border );
|
||||
|
||||
QString msg;
|
||||
NL3D::CTileSet::TError error = m_pvt->checkTile( set, tile, type, border, channelToTBitmap( channel ), msg );
|
||||
|
||||
// Tile checks out fine, set it
|
||||
if( ( error == NL3D::CTileSet::ok ) || ( error == NL3D::CTileSet::addFirstA128128 ) )
|
||||
{
|
||||
if( error == NL3D::CTileSet::addFirstA128128 )
|
||||
set->setBorder( channelToTBitmap( channel ), border );
|
||||
|
||||
m_pvt->setTile( set, tile, 0 /* rotation */, name, channelToTBitmap( channel ), type, border );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
setError( msg );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void TileBank::replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name, const QVariant &pixmap )
|
||||
{
|
||||
setTile( ts, tile, name, pixmap, channel, TileConstants::TNodeTileType( type ) );
|
||||
}
|
||||
|
||||
void TileBank::clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel )
|
||||
{
|
||||
NL3D::CTileSet *set = m_pvt->m_bank.getTileSet( ts );
|
||||
|
||||
int tileId;
|
||||
|
||||
NL3D::CTile::TBitmap bm = channelToTBitmap( channel );
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128:
|
||||
set->clearTile128( tile, bm, m_pvt->m_bank );
|
||||
break;
|
||||
|
||||
case TileConstants::Tile256:
|
||||
set->clearTile256( tile, bm, m_pvt->m_bank );
|
||||
break;
|
||||
|
||||
case TileConstants::TileTransition:
|
||||
set->clearTransition( NL3D::CTileSet::TTransition( tile ), bm, m_pvt->m_bank );
|
||||
break;
|
||||
|
||||
case TileConstants::TileDisplacement:
|
||||
set->clearDisplacement( NL3D::CTileSet::TDisplacement( tile ), m_pvt->m_bank );
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -16,13 +16,37 @@ public:
|
|||
~TileBank();
|
||||
|
||||
void addTileSet( const QString &name );
|
||||
void addLand( const QString &name );
|
||||
void setLandSets( int idx, const QStringList &l );
|
||||
void removeTileSet( int idx );
|
||||
void renameTileSet( int idx, const QString &newName );
|
||||
|
||||
bool addTileToSet( int idx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type );
|
||||
void addLand( const QString &name );
|
||||
void removeLand( int idx );
|
||||
void setLandSets( int idx, const QStringList &l );
|
||||
void getLandSets( int idx, QStringList &l );
|
||||
|
||||
bool addTile( int setIdx, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type );
|
||||
void removeTile( int ts, int type, int tile );
|
||||
bool setTile( int tileset, int tile, const QString &name, const QVariant &pixmap, TileConstants::TTileChannel channel, TileConstants::TNodeTileType type );
|
||||
void replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name, const QVariant &pixmap );
|
||||
void clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel );
|
||||
|
||||
bool hasError() const{ return m_hasError; }
|
||||
QString getLastError() const{ return m_lastError; }
|
||||
void resetError(){
|
||||
m_hasError = false;
|
||||
m_lastError = "";
|
||||
}
|
||||
|
||||
void setError( const QString &msg )
|
||||
{
|
||||
m_hasError = true;
|
||||
m_lastError = msg;
|
||||
}
|
||||
|
||||
private:
|
||||
TileBankPvt *m_pvt;
|
||||
QString m_lastError;
|
||||
bool m_hasError;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -110,8 +110,6 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
|||
connect(m_ui->tileSetAddTB, SIGNAL(clicked()), this, SLOT(onTileSetAdd()));
|
||||
connect(m_ui->tileSetDeleteTB, SIGNAL(clicked()), this, SLOT(onTileSetDelete()));
|
||||
connect(m_ui->tileSetEditTB, SIGNAL(clicked()), this, SLOT(onTileSetEdit()));
|
||||
connect(m_ui->tileSetUpTB, SIGNAL(clicked()), this, SLOT(onTileSetUp()));
|
||||
connect(m_ui->tileSetDownTB, SIGNAL(clicked()), this, SLOT(onTileSetDown()));
|
||||
|
||||
connect(m_ui->landAddTB, SIGNAL(clicked()), this, SLOT(onLandAdd()));
|
||||
connect(m_ui->landRemoveTB, SIGNAL(clicked()), this, SLOT(onLandRemove()));
|
||||
|
@ -251,7 +249,8 @@ void TileEditorMainWindow::saveAs( const QString &fn )
|
|||
}
|
||||
|
||||
TileBankSaver saver;
|
||||
bool ok = saver.save( fn.toUtf8().constData(), m_tileModel, m_lands );
|
||||
bool ok = true;
|
||||
//saver.save( fn.toUtf8().constData(), m_tileModel, m_lands );
|
||||
|
||||
if( !ok )
|
||||
{
|
||||
|
@ -272,7 +271,8 @@ void TileEditorMainWindow::open()
|
|||
return;
|
||||
|
||||
TileBankLoader loader;
|
||||
bool b = loader.load( fn.toUtf8().constData(), m_tileModel, m_lands );
|
||||
bool b = true;
|
||||
//loader.load( fn.toUtf8().constData(), m_tileModel, m_lands );
|
||||
|
||||
if( !b )
|
||||
{
|
||||
|
@ -398,10 +398,7 @@ void TileEditorMainWindow::onTileSetDelete()
|
|||
|
||||
QString set = reinterpret_cast< TileSetNode* >( idx.internalPointer() )->getTileSetName();
|
||||
|
||||
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||
bool ok = model->removeRow( idx.row() );
|
||||
|
||||
onTileSetRemoved( set );
|
||||
m_tileModel->removeTileSet( idx.row() );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileSetEdit()
|
||||
|
@ -438,46 +435,7 @@ void TileEditorMainWindow::onTileSetEdit()
|
|||
node->setTileSetName( newName );
|
||||
m_ui->tileSetLV->reset();
|
||||
|
||||
onTileSetRenamed( oldName, newName );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileSetUp()
|
||||
{
|
||||
QModelIndex idx = m_ui->tileSetLV->currentIndex();
|
||||
if( !idx.isValid() )
|
||||
return;
|
||||
|
||||
if( idx.row() == 0 )
|
||||
return;
|
||||
|
||||
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||
if( model->rowCount() < 2 )
|
||||
return;
|
||||
|
||||
int r = idx.row();
|
||||
model->swapRows( r, r - 1 );
|
||||
|
||||
m_ui->tileSetLV->reset();
|
||||
m_ui->tileSetLV->setCurrentIndex( model->index( r - 1, 0 ) );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileSetDown()
|
||||
{
|
||||
QModelIndex idx = m_ui->tileSetLV->currentIndex();
|
||||
if( !idx.isValid() )
|
||||
return;
|
||||
|
||||
TileModel *model = static_cast<TileModel*>(m_ui->tileSetLV->model());
|
||||
if( model->rowCount() < idx.row() )
|
||||
return;
|
||||
if( model->rowCount() < 2 )
|
||||
return;
|
||||
|
||||
int r = idx.row();
|
||||
model->swapRows( r, r + 1 );
|
||||
|
||||
m_ui->tileSetLV->reset();
|
||||
m_ui->tileSetLV->setCurrentIndex( model->index( r + 1, 0 ) );
|
||||
m_tileModel->renameTileSet( idx.row(), newName );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onLandAdd()
|
||||
|
@ -503,9 +461,7 @@ void TileEditorMainWindow::onLandAdd()
|
|||
|
||||
m_ui->landLW->addItem( name );
|
||||
|
||||
Land l;
|
||||
l.name = name;
|
||||
m_lands.push_back( l );
|
||||
m_tileModel->addLand( name );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onLandRemove()
|
||||
|
@ -526,8 +482,7 @@ void TileEditorMainWindow::onLandRemove()
|
|||
|
||||
delete item;
|
||||
|
||||
QList< Land >::iterator itr = m_lands.begin() + idx;
|
||||
m_lands.erase( itr );
|
||||
m_tileModel->removeLand( idx );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onLandEdit()
|
||||
|
@ -549,10 +504,12 @@ void TileEditorMainWindow::onLandEdit()
|
|||
}
|
||||
|
||||
int r = m_ui->landLW->currentRow();
|
||||
Land &l = m_lands[ r ];
|
||||
|
||||
QStringList sts;
|
||||
m_tileModel->getLandSets( r, sts );
|
||||
|
||||
LandEditDialog d;
|
||||
d.setSelectedTileSets( l.tilesets );
|
||||
d.setSelectedTileSets( sts );
|
||||
d.setTileSets( ts );
|
||||
int result = d.exec();
|
||||
|
||||
|
@ -560,10 +517,10 @@ void TileEditorMainWindow::onLandEdit()
|
|||
return;
|
||||
|
||||
// Update the tileset of the land
|
||||
ts.clear();
|
||||
d.getSelectedTileSets( ts );
|
||||
l.tilesets.clear();
|
||||
l.tilesets = ts;
|
||||
sts.clear();
|
||||
d.getSelectedTileSets( sts );
|
||||
|
||||
m_tileModel->setLandSets( r, sts );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onChooseVegetation()
|
||||
|
@ -720,30 +677,19 @@ void TileEditorMainWindow::onActionAddTile(int tabId)
|
|||
TileConstants::TNodeTileType type = tabToType( tabId );
|
||||
|
||||
QStringListIterator itr( fileNames );
|
||||
QString error;
|
||||
|
||||
while( itr.hasNext() )
|
||||
{
|
||||
TileItemNode *newNode = m_tileModel->createItemNode( setId, type, c, TileConstants::TileDiffuse, itr.next() );
|
||||
if( newNode == NULL )
|
||||
{
|
||||
int reply = QMessageBox::question( this,
|
||||
tr( "Error adding tile" ),
|
||||
tr( "Failed to create tile!\nContinue?" ),
|
||||
QMessageBox::Yes, QMessageBox::No );
|
||||
if( reply != QMessageBox::Yes )
|
||||
break;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
if( newNode->hasError() )
|
||||
{
|
||||
QString error = newNode->getLastError();
|
||||
error += "\nContinue?";
|
||||
if( m_tileModel->hasError() )
|
||||
error = m_tileModel->getLastError();
|
||||
|
||||
int reply = QMessageBox::question( this,
|
||||
tr( "Error adding tile" ),
|
||||
error,
|
||||
error + "\nContinue?",
|
||||
QMessageBox::Yes, QMessageBox::No );
|
||||
if( reply != QMessageBox::Yes )
|
||||
break;
|
||||
|
@ -777,12 +723,13 @@ void TileEditorMainWindow::onActionDeleteTile( int tabId )
|
|||
return;
|
||||
}
|
||||
|
||||
int row = idx.row();
|
||||
QModelIndex tsidx = m_ui->tileSetLV->currentIndex();
|
||||
if( !tsidx.isValid() )
|
||||
return;
|
||||
int ts = tsidx.row();
|
||||
int tile = idx.row();
|
||||
|
||||
QModelIndex parent = idx.parent();
|
||||
lv->model()->removeRow( row, parent );
|
||||
|
||||
//lv->reset();
|
||||
m_tileModel->removeTile( ts, tabId, tile );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onActionDeleteImage( int tabId )
|
||||
|
@ -798,14 +745,26 @@ void TileEditorMainWindow::onActionDeleteImage( int tabId )
|
|||
return;
|
||||
}
|
||||
|
||||
QModelIndex tsidx = m_ui->tileSetLV->currentIndex();
|
||||
if( !tsidx.isValid() )
|
||||
return;
|
||||
int ts = tsidx.row();
|
||||
|
||||
TileItemNode *n = reinterpret_cast< TileItemNode* >( idx.internalPointer() );
|
||||
n->setTileFilename( TileItemNode::displayChannel(), "" );
|
||||
int tile = n->id();
|
||||
|
||||
m_tileModel->clearImage( ts, tabId, tile, TileItemNode::displayChannel() );
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onActionReplaceImage( int tabId )
|
||||
{
|
||||
QListView *lv = getListViewByTab( tabId );
|
||||
|
||||
QModelIndex tsidx = m_ui->tileSetLV->currentIndex();
|
||||
if( !tsidx.isValid() )
|
||||
return;
|
||||
int set = tsidx.row();
|
||||
|
||||
QModelIndex idx = lv->currentIndex();
|
||||
if( !idx.isValid() )
|
||||
{
|
||||
|
@ -823,41 +782,22 @@ void TileEditorMainWindow::onActionReplaceImage( int tabId )
|
|||
return;
|
||||
|
||||
TileItemNode *n = reinterpret_cast< TileItemNode* >( idx.internalPointer() );
|
||||
n->setTileFilename( TileItemNode::displayChannel(), fileName );
|
||||
}
|
||||
int tile = n->id();
|
||||
|
||||
void TileEditorMainWindow::onTileSetRemoved( const QString &set )
|
||||
{
|
||||
int c = m_lands.count();
|
||||
for( int i = 0; i < c; i++ )
|
||||
m_tileModel->replaceImage( set, tabId, tile, TileItemNode::displayChannel(), fileName );
|
||||
if( m_tileModel->hasError() )
|
||||
{
|
||||
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;
|
||||
QString error = m_tileModel->getLastError();
|
||||
QMessageBox::information( this,
|
||||
tr( "Error replacing tile image" ),
|
||||
error );
|
||||
}
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileBankLoaded()
|
||||
{
|
||||
m_ui->landLW->clear();
|
||||
QListIterator< Land > itr( m_lands );
|
||||
while( itr.hasNext() )
|
||||
{
|
||||
m_ui->landLW->addItem( itr.next().name );
|
||||
}
|
||||
// load lands
|
||||
|
||||
m_ui->listView128->reset();
|
||||
m_ui->listView256->reset();
|
||||
|
|
|
@ -25,8 +25,6 @@
|
|||
#include <QtGui/QUndoStack>
|
||||
#include <QSignalMapper>
|
||||
|
||||
#include "land.h"
|
||||
|
||||
namespace Ui {
|
||||
class TileEditorMainWindow;
|
||||
}
|
||||
|
@ -59,8 +57,6 @@ private Q_SLOTS:
|
|||
void onTileSetAdd();
|
||||
void onTileSetDelete();
|
||||
void onTileSetEdit();
|
||||
void onTileSetUp();
|
||||
void onTileSetDown();
|
||||
|
||||
void onLandAdd();
|
||||
void onLandRemove();
|
||||
|
@ -89,8 +85,6 @@ private:
|
|||
void onActionDeleteImage(int tabId);
|
||||
void onActionReplaceImage(int tabId);
|
||||
|
||||
void onTileSetRemoved( const QString &set );
|
||||
void onTileSetRenamed( const QString &oldname, const QString &newname );
|
||||
void onTileBankLoaded();
|
||||
|
||||
void updateTab();
|
||||
|
@ -127,7 +121,6 @@ private:
|
|||
};
|
||||
|
||||
QString m_fileName;
|
||||
QList< Land > m_lands;
|
||||
};
|
||||
|
||||
#endif // TILE_EDITOR_MAIN_WINDOW_H
|
||||
|
|
|
@ -426,58 +426,6 @@
|
|||
<string>Tile Sets</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_5">
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tileSetUpTB">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="tile_editor.qrc">
|
||||
<normaloff>:/movementIcons/images/up.png</normaloff>:/movementIcons/images/up.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="tileSetDownTB">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="tile_editor.qrc">
|
||||
<normaloff>:/movementIcons/images/down.png</normaloff>:/movementIcons/images/down.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0" colspan="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
|
|
|
@ -18,12 +18,8 @@
|
|||
|
||||
#include "tile_item.h"
|
||||
|
||||
//#include "tile_widget.h"
|
||||
|
||||
#include <nel/misc/debug.h>
|
||||
|
||||
#include <nel/3d/tile_bank.h>
|
||||
|
||||
Node::Node() : m_parentItem(0)
|
||||
{
|
||||
}
|
||||
|
@ -266,208 +262,12 @@ void TileTypeNode::reindex()
|
|||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
NL3D::CTile::TBitmap channelToTBitmap( TileConstants::TTileChannel channel )
|
||||
{
|
||||
NL3D::CTile::TBitmap bm;
|
||||
|
||||
switch( channel )
|
||||
{
|
||||
case TileConstants::TileDiffuse: bm = NL3D::CTile::diffuse; break;
|
||||
case TileConstants::TileAdditive: bm = NL3D::CTile::additive; break;
|
||||
case TileConstants::TileAlpha: bm = NL3D::CTile::alpha; break;
|
||||
}
|
||||
|
||||
return bm;
|
||||
}
|
||||
|
||||
class TileItemNodePvt
|
||||
{
|
||||
public:
|
||||
|
||||
TileItemNodePvt()
|
||||
{
|
||||
for( int i = 0; i < TileConstants::TileChannelCount; i++ )
|
||||
m_borderFirst[ i ] = false;
|
||||
|
||||
m_id = -1;
|
||||
m_alphaRot = 0;
|
||||
}
|
||||
|
||||
bool pixmapToCBGRA( QPixmap &pixmap, std::vector< NLMISC::CBGRA >& pixels )
|
||||
{
|
||||
QImage img = pixmap.toImage();
|
||||
if( img.format() != QImage::Format_ARGB32 )
|
||||
img = img.convertToFormat( QImage::Format_ARGB32 );
|
||||
|
||||
if( img.format() != QImage::Format_ARGB32 )
|
||||
return false;
|
||||
|
||||
int c = img.width() * img.height();
|
||||
|
||||
const unsigned char *data = img.bits();
|
||||
const unsigned int *idata = reinterpret_cast< const unsigned int* >( data );
|
||||
|
||||
NLMISC::CBGRA bgra;
|
||||
pixels.clear();
|
||||
|
||||
int i = 0;
|
||||
while( i < c )
|
||||
{
|
||||
bgra.A = ( idata[ i ] & 0xFF000000 ) >> 24;
|
||||
bgra.R = ( idata[ i ] & 0x00FF0000 ) >> 16;
|
||||
bgra.G = ( idata[ i ] & 0x0000FF00 ) >> 8;
|
||||
bgra.B = ( idata[ i ] & 0x000000FF );
|
||||
pixels.push_back( bgra );
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int getWidthForType( TileConstants::TNodeTileType type, TileConstants::TTileChannel channel )
|
||||
{
|
||||
int width = -1;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128: width = 128; break;
|
||||
case TileConstants::Tile256: width = 256; break;
|
||||
case TileConstants::TileTransition:
|
||||
{
|
||||
if( channel != TileConstants::TileAlpha )
|
||||
width = 128;
|
||||
break;
|
||||
}
|
||||
|
||||
case TileConstants::TileDisplacement: width = 32; break;
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
NL3D::CTileSet::TError checkTile( TileConstants::TTileChannel channel )
|
||||
{
|
||||
if( m_type == TileConstants::TileDisplacement )
|
||||
return NL3D::CTileSet::ok;
|
||||
|
||||
if( channel == TileConstants::TileAdditive )
|
||||
return NL3D::CTileSet::ok;
|
||||
|
||||
int pixel;
|
||||
int component;
|
||||
int index;
|
||||
|
||||
NL3D::CTileSet set;
|
||||
NL3D::CTile::TBitmap bm = channelToTBitmap( channel );
|
||||
|
||||
NL3D::CTileSet::TError error = NL3D::CTileSet::ok;
|
||||
|
||||
switch( m_type )
|
||||
{
|
||||
case TileConstants::Tile128:
|
||||
error = set.checkTile128( bm, m_border[ channel ], pixel, component );
|
||||
break;
|
||||
case TileConstants::Tile256:
|
||||
error = set.checkTile256( bm, m_border[ channel ], pixel, component );
|
||||
break;
|
||||
case TileConstants::TileTransition:
|
||||
if( channel != TileConstants::TileAlpha )
|
||||
error = set.checkTile128( bm, m_border[ channel ], pixel, component );
|
||||
else
|
||||
error = set.checkTileTransition( NL3D::CTileSet::TTransition( m_id ), bm, m_border[ channel ], index, pixel, component );
|
||||
break;
|
||||
}
|
||||
|
||||
if( error == NL3D::CTileSet::ok )
|
||||
return NL3D::CTileSet::ok;
|
||||
if( error == NL3D::CTileSet::addFirstA128128 )
|
||||
return NL3D::CTileSet::addFirstA128128;
|
||||
|
||||
static const char* comp[]={"Red", "Green", "Blue", "Alpha", ""};
|
||||
|
||||
if( error != NL3D::CTileSet::ok )
|
||||
{
|
||||
m_lastError = "ERROR: ";
|
||||
m_lastError += NL3D::CTileSet::getErrorMessage( error );
|
||||
m_lastError += "\n";
|
||||
|
||||
switch( m_type )
|
||||
{
|
||||
case TileConstants::Tile128:
|
||||
case TileConstants::Tile256:
|
||||
m_lastError += QString( "pixel: %1 component: %2" ).arg( pixel ).arg( comp[ component ] );
|
||||
break;
|
||||
|
||||
case TileConstants::TileTransition:
|
||||
if( channel != TileConstants::TileAlpha )
|
||||
{
|
||||
m_lastError += QString( "pixel: %1 component: %2" ).arg( pixel ).arg( comp[ component ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((error==NL3D::CTileSet::topInterfaceProblem)||(error==NL3D::CTileSet::bottomInterfaceProblem)||
|
||||
(error==NL3D::CTileSet::leftInterfaceProblem)||(error==NL3D::CTileSet::rightInterfaceProblem)||
|
||||
(error==NL3D::CTileSet::topBottomNotTheSame)||(error==NL3D::CTileSet::rightLeftNotTheSame)
|
||||
||(error==NL3D::CTileSet::topInterfaceProblem))
|
||||
{
|
||||
if( index != -1 )
|
||||
{
|
||||
m_lastError += QString( "tile: %1 pixel: %2 component: %3" ).arg( index ).arg( pixel ).arg( comp[ component ] );
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastError += QString( "incompatible with a 128 tile, pixel: %1 component: %2" ).arg( pixel ).arg( comp[ component ] );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
bool checkPixmap( TileConstants::TTileChannel channel, QPixmap &pixmap )
|
||||
{
|
||||
int w = pixmap.width();
|
||||
int h = pixmap.height();
|
||||
|
||||
if( w != h )
|
||||
{
|
||||
m_lastError = QObject::tr( "Not a square texture." );
|
||||
return false;
|
||||
}
|
||||
|
||||
int width = getWidthForType( m_type, channel );
|
||||
|
||||
if( width != -1 )
|
||||
{
|
||||
if( width != w )
|
||||
{
|
||||
m_lastError = QObject::tr( "Not the proper size." );
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector< NLMISC::CBGRA > pixels;
|
||||
|
||||
pixmapToCBGRA( pixmap, pixels );
|
||||
|
||||
m_border[ channel ].set( w, h, pixels );
|
||||
|
||||
NL3D::CTileSet::TError error = checkTile( channel );
|
||||
if( error == NL3D::CTileSet::addFirstA128128 )
|
||||
{
|
||||
m_borderFirst[ channel ] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
if( error != NL3D::CTileSet::ok )
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool loadImage( TileConstants::TTileChannel channel, const QString &fn, bool empty = false )
|
||||
|
@ -477,20 +277,9 @@ public:
|
|||
|
||||
if( !b )
|
||||
{
|
||||
m_lastError = QObject::tr( "Cannot open file %1" ).arg( fn );
|
||||
return false;
|
||||
}
|
||||
|
||||
m_borderFirst[ channel ] = false;
|
||||
|
||||
/*
|
||||
if( !empty )
|
||||
{
|
||||
if( !checkPixmap( channel, temp ) )
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
pixmaps[ channel ] = temp;
|
||||
|
||||
return true;
|
||||
|
@ -505,26 +294,8 @@ public:
|
|||
return pixmaps[ channel ];
|
||||
}
|
||||
|
||||
void setType( TileConstants::TNodeTileType type ){ m_type = type; }
|
||||
void setId( int id ){ m_id = id; }
|
||||
int id() const{ return m_id; }
|
||||
|
||||
QString getLastError() const{ return m_lastError; }
|
||||
bool borderFirst( TileConstants::TTileChannel channel ) const{ return m_borderFirst[ channel ]; }
|
||||
|
||||
const NL3D::CTileBorder &border( TileConstants::TTileChannel channel ){ return m_border[ channel ]; }
|
||||
|
||||
int alphaRot() const{ return m_alphaRot; }
|
||||
void setAlphaRot( int rot ){ m_alphaRot = rot; }
|
||||
|
||||
private:
|
||||
QPixmap pixmaps[ TileConstants::TileChannelCount ];
|
||||
TileConstants::TNodeTileType m_type;
|
||||
NL3D::CTileBorder m_border[ TileConstants::TileChannelCount ];
|
||||
int m_id;
|
||||
QString m_lastError;
|
||||
bool m_borderFirst[ TileConstants::TileChannelCount ];
|
||||
int m_alphaRot;
|
||||
};
|
||||
|
||||
TileConstants::TTileChannel TileItemNode::s_displayChannel = TileConstants::TileDiffuse;
|
||||
|
@ -532,13 +303,11 @@ int TileItemNode::s_alphaRot = 0;
|
|||
|
||||
TileItemNode::TileItemNode( TileConstants::TNodeTileType type, int tileId, TileConstants::TTileChannel channel, QString filename, Node *parent)
|
||||
{
|
||||
m_id = tileId;
|
||||
m_parentItem = parent;
|
||||
//nlinfo("dispalying tile %d - %s", m_tileId, m_tileFilename[TileModel::TileDiffuse].toAscii().data());
|
||||
|
||||
pvt = new TileItemNodePvt();
|
||||
pvt->setType( type );
|
||||
pvt->setId( tileId );
|
||||
|
||||
m_hasError = false;
|
||||
|
||||
setTileFilename( channel, filename );
|
||||
|
@ -563,7 +332,6 @@ bool TileItemNode::setTileFilename(TileConstants::TTileChannel channel, QString
|
|||
empty = true;
|
||||
}
|
||||
|
||||
pvt->setAlphaRot( s_alphaRot );
|
||||
bool b = pvt->loadImage( channel, fn, empty );
|
||||
m_hasError = !b;
|
||||
if( !b )
|
||||
|
@ -583,36 +351,6 @@ QString TileItemNode::getTileFilename(TileConstants::TTileChannel channel)
|
|||
return itr.value();
|
||||
}
|
||||
|
||||
void TileItemNode::setId( int id )
|
||||
{
|
||||
pvt->setId( id );
|
||||
}
|
||||
|
||||
int TileItemNode::id() const
|
||||
{
|
||||
return pvt->id();
|
||||
}
|
||||
|
||||
QString TileItemNode::getLastError() const
|
||||
{
|
||||
return pvt->getLastError();
|
||||
}
|
||||
|
||||
bool TileItemNode::borderFirst( TileConstants::TTileChannel channel ) const
|
||||
{
|
||||
return pvt->borderFirst( channel );
|
||||
}
|
||||
|
||||
const NL3D::CTileBorder& TileItemNode::border( TileConstants::TTileChannel channel ) const
|
||||
{
|
||||
return pvt->border( channel );
|
||||
}
|
||||
|
||||
int TileItemNode::alphaRot() const
|
||||
{
|
||||
return pvt->alphaRot();
|
||||
}
|
||||
|
||||
QVariant TileItemNode::data(int column, int role) const
|
||||
{
|
||||
QString tileFilename = m_tileFilename[ TileItemNode::s_displayChannel ];
|
||||
|
@ -647,11 +385,11 @@ QVariant TileItemNode::data(int column, int role) const
|
|||
}
|
||||
else if(role == TileModel::TileIndexRole)
|
||||
{
|
||||
return QVariant("("+QString::number(pvt->id())+")");
|
||||
return QVariant("("+QString::number(m_id)+")");
|
||||
}
|
||||
else if(role == TileModel::TileFilenameIndexRole)
|
||||
{
|
||||
return QVariant(tileFilename + " ("+QString::number(pvt->id())+")");
|
||||
return QVariant(tileFilename + " ("+QString::number(m_id)+")");
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
|
|
@ -120,19 +120,13 @@ public:
|
|||
int columnCount() const;
|
||||
bool setTileFilename(TileConstants::TTileChannel channel, QString filename);
|
||||
QString getTileFilename(TileConstants::TTileChannel channel);
|
||||
void setId( int id );
|
||||
int id() const;
|
||||
QString getLastError() const;
|
||||
bool borderFirst( TileConstants::TTileChannel channel ) const;
|
||||
const NL3D::CTileBorder& border( TileConstants::TTileChannel channel ) const;
|
||||
int alphaRot() const;
|
||||
void setId( int id ){ m_id = id; }
|
||||
int id() const{ return m_id; }
|
||||
|
||||
static void setDisplayChannel( TileConstants::TTileChannel channel ){ s_displayChannel = channel; }
|
||||
static TileConstants::TTileChannel displayChannel(){ return s_displayChannel; }
|
||||
static void setAlphaRot( int rot ){ s_alphaRot = rot; }
|
||||
|
||||
bool hasError() const{ return m_hasError; }
|
||||
|
||||
QVariant pixmap( TileConstants::TTileChannel channel ) const;
|
||||
|
||||
private:
|
||||
|
@ -142,6 +136,8 @@ private:
|
|||
static TileConstants::TTileChannel s_displayChannel;
|
||||
static int s_alphaRot;
|
||||
|
||||
int m_id;
|
||||
|
||||
TileItemNodePvt *pvt;
|
||||
|
||||
bool m_hasError;
|
||||
|
|
|
@ -232,7 +232,7 @@ TileItemNode *TileModel::createItemNode( int idx, TileConstants::TNodeTileType t
|
|||
{
|
||||
TileItemNode *n = new TileItemNode( type, id, channel, fileName );
|
||||
|
||||
bool b = m_tileBank->addTileToSet( idx, fileName, n->pixmap( channel ), channel, type );
|
||||
bool b = m_tileBank->addTile( idx, fileName, n->pixmap( channel ), channel, type );
|
||||
if( !b )
|
||||
{
|
||||
delete n;
|
||||
|
@ -310,11 +310,101 @@ void TileModel::addLand( const QString &name )
|
|||
m_tileBank->addLand( name );
|
||||
}
|
||||
|
||||
void TileModel::removeLand( int idx )
|
||||
{
|
||||
m_tileBank->removeLand( idx );
|
||||
}
|
||||
|
||||
void TileModel::setLandSets( int idx, const QStringList &l )
|
||||
{
|
||||
m_tileBank->setLandSets( idx, l );
|
||||
}
|
||||
|
||||
void TileModel::getLandSets( int idx, QStringList &l )
|
||||
{
|
||||
m_tileBank->getLandSets( idx, l );
|
||||
}
|
||||
|
||||
void TileModel::removeTileSet( int idx )
|
||||
{
|
||||
TileSetNode *set = static_cast< TileSetNode* >( rootItem->child( idx ) );
|
||||
if( set == NULL )
|
||||
return;
|
||||
|
||||
removeRow( idx );
|
||||
|
||||
m_tileBank->removeTileSet( idx );
|
||||
}
|
||||
|
||||
void TileModel::renameTileSet( int idx, const QString &newName )
|
||||
{
|
||||
m_tileBank->renameTileSet( idx, newName );
|
||||
}
|
||||
|
||||
void TileModel::removeTile( int ts, int type, int tile )
|
||||
{
|
||||
TileSetNode *set = static_cast< TileSetNode* >( rootItem->child( ts ) );
|
||||
if( set == NULL )
|
||||
return;
|
||||
|
||||
TileTypeNode *typeNode = static_cast< TileTypeNode* >( set->child( type ) );
|
||||
if( typeNode == NULL )
|
||||
return;
|
||||
|
||||
TileItemNode *tileNode = static_cast< TileItemNode* >( typeNode->child( tile ) );
|
||||
if( tileNode == NULL )
|
||||
return;
|
||||
|
||||
QModelIndex tileIdx = createIndex( tile, 0, tileNode );
|
||||
removeRow( tile, tileIdx.parent() );
|
||||
|
||||
m_tileBank->removeTile( ts, type, tile );
|
||||
}
|
||||
|
||||
bool TileModel::replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name )
|
||||
{
|
||||
Node *set = rootItem->child( ts );
|
||||
Node *tn = set->child( type );
|
||||
Node *n = tn->child( tile );
|
||||
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( n );
|
||||
QString old = tin->getTileFilename( channel );
|
||||
|
||||
bool b = tin->setTileFilename( channel, name );
|
||||
if( !b )
|
||||
return false;
|
||||
|
||||
m_tileBank->replaceImage( ts, type, tile, channel, name, tin->pixmap( channel ) );
|
||||
if( m_tileBank->hasError() )
|
||||
{
|
||||
tin->setTileFilename( channel, old );
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void TileModel::clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel )
|
||||
{
|
||||
Node *set = rootItem->child( ts );
|
||||
Node *tn = set->child( type );
|
||||
Node *n = tn->child( tile );
|
||||
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( n );
|
||||
tin->setTileFilename( channel, "" );
|
||||
|
||||
m_tileBank->clearImage( ts, type, tile, channel );
|
||||
}
|
||||
|
||||
QString TileModel::getLastError() const{
|
||||
return m_tileBank->getLastError();
|
||||
}
|
||||
|
||||
bool TileModel::hasError() const
|
||||
{
|
||||
return m_tileBank->hasError();
|
||||
}
|
||||
|
||||
void TileModel::selectFilenameDisplay(bool selected)
|
||||
{
|
||||
m_fileDisplay = selected;
|
||||
|
|
|
@ -89,7 +89,17 @@ public:
|
|||
QString texturePath() const{ return m_texturePath; }
|
||||
|
||||
void addLand( const QString &name );
|
||||
void removeLand( int idx );
|
||||
void removeTileSet( int idx );
|
||||
void renameTileSet( int idx, const QString &newName );
|
||||
void setLandSets( int idx, const QStringList &l );
|
||||
void getLandSets( int idx, QStringList &l );
|
||||
void removeTile( int ts, int type, int tile );
|
||||
bool replaceImage( int ts, int type, int tile, TileConstants::TTileChannel channel, const QString &name );
|
||||
void clearImage( int ts, int type, int tile, TileConstants::TTileChannel channel );
|
||||
|
||||
QString getLastError() const;
|
||||
bool hasError() const;
|
||||
|
||||
public Q_SLOTS:
|
||||
void selectFilenameDisplay(bool selected);
|
||||
|
|
|
@ -26,138 +26,6 @@
|
|||
class TileBankLoaderPvt
|
||||
{
|
||||
public:
|
||||
NL3D::CTileBank bank;
|
||||
|
||||
static NL3D::CTile::TBitmap channelToTBitmap( TileConstants::TTileChannel channel )
|
||||
{
|
||||
NL3D::CTile::TBitmap b = NL3D::CTile::bitmapCount;
|
||||
|
||||
switch( channel )
|
||||
{
|
||||
case TileConstants::TileDiffuse: b = NL3D::CTile::diffuse; break;
|
||||
case TileConstants::TileAdditive: b = NL3D::CTile::additive; break;
|
||||
case TileConstants::TileAlpha: b = NL3D::CTile::alpha; break;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
void loadLands( QList< Land > &lands )
|
||||
{
|
||||
lands.clear();
|
||||
|
||||
Land l;
|
||||
|
||||
int c = bank.getLandCount();
|
||||
for( int i = 0; i < c; i++ )
|
||||
{
|
||||
NL3D::CTileLand *land = bank.getLand( i );
|
||||
l.name = land->getName().c_str();
|
||||
|
||||
|
||||
std::set< std::string > sets = land->getTileSets();
|
||||
std::set< std::string >::const_iterator itr = sets.begin();
|
||||
while( itr != sets.end() )
|
||||
{
|
||||
l.tilesets.push_back( itr->c_str() );
|
||||
++itr;
|
||||
}
|
||||
|
||||
lands.push_back( l );
|
||||
}
|
||||
}
|
||||
|
||||
void loadTiles128( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
int c = set->getNumTile128();
|
||||
for( int i = 0; i < c; i++ )
|
||||
{
|
||||
int idx = set->getTile128( i );
|
||||
NL3D::CTile *tile = bank.getTile( idx );
|
||||
|
||||
TileItemNode *tin = new TileItemNode( TileConstants::Tile128, i, TileConstants::TileDiffuse, "" );
|
||||
|
||||
for( int i = TileConstants::TileDiffuse; i < TileConstants::TileAlpha; i++ )
|
||||
{
|
||||
tin->setTileFilename( TileConstants::TTileChannel( i ), tile->getRelativeFileName( channelToTBitmap( TileConstants::TTileChannel( i ) ) ).c_str() );
|
||||
}
|
||||
|
||||
node->appendChild( tin );
|
||||
}
|
||||
}
|
||||
|
||||
void loadTiles256( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
int c = set->getNumTile256();
|
||||
for( int i = 0; i < c; i++ )
|
||||
{
|
||||
int idx = set->getTile256( i );
|
||||
NL3D::CTile *tile = bank.getTile( idx );
|
||||
|
||||
TileItemNode *tin = new TileItemNode( TileConstants::Tile256, i, TileConstants::TileDiffuse, "" );
|
||||
|
||||
for( int i = TileConstants::TileDiffuse; i < TileConstants::TileAlpha; i++ )
|
||||
{
|
||||
tin->setTileFilename( TileConstants::TTileChannel( i ), tile->getRelativeFileName( channelToTBitmap( TileConstants::TTileChannel( i ) ) ).c_str() );
|
||||
}
|
||||
|
||||
node->appendChild( tin );
|
||||
}
|
||||
}
|
||||
|
||||
void loadTilesTransition( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
for( int i = 0; i < NL3D::CTileSet::count; i++ )
|
||||
{
|
||||
const NL3D::CTileSetTransition *tr = set->getTransition( i );
|
||||
int idx = tr->getTile();
|
||||
NL3D::CTile *tile = bank.getTile( idx );
|
||||
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( node->child( i ) );
|
||||
|
||||
for( int j = TileConstants::TileDiffuse; j <= TileConstants::TileAlpha; j++ )
|
||||
{
|
||||
tin->setTileFilename( TileConstants::TTileChannel( i ), tile->getRelativeFileName( channelToTBitmap( TileConstants::TTileChannel( i ) ) ).c_str() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void loadTilesDisplacement( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
for( int i = 0; i < NL3D::CTileSet::CountDisplace; i++ )
|
||||
{
|
||||
uint did = set->getDisplacementTile( NL3D::CTileSet::TDisplacement( i ) );
|
||||
const char *fn = bank.getDisplacementMap( did );
|
||||
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( node->child( i ) );
|
||||
tin->setTileFilename( TileConstants::TileDiffuse, fn );
|
||||
}
|
||||
}
|
||||
|
||||
void loadTileSet( NL3D::CTileSet *set, TileSetNode *node )
|
||||
{
|
||||
loadTiles128( set, static_cast< TileTypeNode* >( node->child( 0 ) ) );
|
||||
loadTiles256( set, static_cast< TileTypeNode* >( node->child( 1 ) ) );
|
||||
loadTilesTransition( set, static_cast< TileTypeNode* >( node->child( 2 ) ) );
|
||||
loadTilesDisplacement( set, static_cast< TileTypeNode* >( node->child( 3 ) ) );
|
||||
|
||||
node->setOriented( set->getOriented() );
|
||||
|
||||
node->setVegetSet( set->getTileVegetableDescFileName().c_str() );
|
||||
}
|
||||
|
||||
void loadTileSets( TileModel *model )
|
||||
{
|
||||
model->clear();
|
||||
|
||||
int c = bank.getTileSetCount();
|
||||
for( int i = 0; i < c; i++ )
|
||||
{
|
||||
NL3D::CTileSet *set = bank.getTileSet( i );
|
||||
TileSetNode *node = model->createTileSetNode( set->getName().c_str() );
|
||||
loadTileSet( set, node );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
@ -178,12 +46,7 @@ bool TileBankLoader::load( const char *filename, TileModel *model, QList< Land >
|
|||
if( !file.open( filename, false ) )
|
||||
return false;
|
||||
|
||||
p->bank.serial( file );
|
||||
|
||||
p->loadLands( lands );
|
||||
p->loadTileSets( model );
|
||||
|
||||
model->setTexturePath( p->bank.getAbsPath().c_str() );
|
||||
//p->bank.serial( file );
|
||||
|
||||
file.close();
|
||||
|
||||
|
|
|
@ -25,251 +25,7 @@
|
|||
class TileBankSaverPvt
|
||||
{
|
||||
public:
|
||||
NL3D::CTileBank bank;
|
||||
|
||||
static NL3D::CTile::TBitmap channelToTBitmap( TileConstants::TTileChannel channel )
|
||||
{
|
||||
NL3D::CTile::TBitmap b = NL3D::CTile::bitmapCount;
|
||||
|
||||
switch( channel )
|
||||
{
|
||||
case TileConstants::TileDiffuse: b = NL3D::CTile::diffuse; break;
|
||||
case TileConstants::TileAdditive: b = NL3D::CTile::additive; break;
|
||||
case TileConstants::TileAlpha: b = NL3D::CTile::alpha; break;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
NL3D::CTile* addTileToSet( NL3D::CTileSet *set, TileConstants::TNodeTileType type )
|
||||
{
|
||||
int idx = -1;
|
||||
int bidx = -1;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case TileConstants::Tile128:
|
||||
{
|
||||
set->addTile128( idx, bank );
|
||||
bidx = set->getTile128( idx );
|
||||
break;
|
||||
}
|
||||
|
||||
case TileConstants::Tile256:
|
||||
{
|
||||
set->addTile256( idx, bank );
|
||||
bidx = set->getTile256( idx );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if( idx == -1 )
|
||||
return NULL;
|
||||
|
||||
return bank.getTile( bidx );
|
||||
}
|
||||
|
||||
void addTilesToSet( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
TileConstants::TNodeTileType type = node->getTileType();
|
||||
|
||||
for( int i = 0; i < node->childCount(); i++ )
|
||||
{
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( node->child( i ) );
|
||||
NL3D::CTile *tile = addTileToSet( set, type );
|
||||
|
||||
for( int j = TileConstants::TileDiffuse; j < TileConstants::TileAlpha; j++ )
|
||||
{
|
||||
QString fn = tin->getTileFilename( TileConstants::TTileChannel( j ) );
|
||||
tile->setFileName( channelToTBitmap( TileConstants::TTileChannel( j ) ) , fn.toUtf8().constData() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addTilesToSet( NL3D::CTileSet *set, TileSetNode *node )
|
||||
{
|
||||
for( int i = TileConstants::Tile128; i <= TileConstants::Tile256; i++ )
|
||||
{
|
||||
TileTypeNode *tn = static_cast< TileTypeNode* >( node->child( i ) );
|
||||
|
||||
addTilesToSet( set, tn );
|
||||
}
|
||||
}
|
||||
|
||||
void setupTiles128( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
TileItemNode *tileNode = NULL;
|
||||
for( int i = 0; i < node->childCount(); i++ )
|
||||
{
|
||||
tileNode = static_cast< TileItemNode* >( node->child( i ) );
|
||||
|
||||
for( int j = TileConstants::TileDiffuse; j < TileConstants::TileAlpha; j++ )
|
||||
{
|
||||
TileConstants::TTileChannel channel = TileConstants::TTileChannel( j );
|
||||
NL3D::CTile::TBitmap bm = channelToTBitmap( channel );
|
||||
const NL3D::CTileBorder &border = tileNode->border( channel );
|
||||
|
||||
if( tileNode->borderFirst( channel ) )
|
||||
set->setBorder( bm, border );
|
||||
|
||||
set->setTile128( i, tileNode->getTileFilename( channel ).toUtf8().constData(), bm, bank );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setupTiles256( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
TileItemNode *tileNode = NULL;
|
||||
for( int i = 0; i < node->childCount(); i++ )
|
||||
{
|
||||
tileNode = static_cast< TileItemNode* >( node->child( i ) );
|
||||
|
||||
for( int j = TileConstants::TileDiffuse; j < TileConstants::TileAlpha; j++ )
|
||||
{
|
||||
TileConstants::TTileChannel channel = TileConstants::TTileChannel( j );
|
||||
NL3D::CTile::TBitmap bm = channelToTBitmap( channel );
|
||||
const NL3D::CTileBorder &border = tileNode->border( channel );
|
||||
|
||||
if( tileNode->borderFirst( channel ) )
|
||||
set->setBorder( bm, border );
|
||||
|
||||
set->setTile256( i, tileNode->getTileFilename( channel ).toUtf8().constData(), bm, bank );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setupTransitionTile( NL3D::CTileSet *set, TileItemNode *node, int idx )
|
||||
{
|
||||
TileConstants::TTileChannel channel;
|
||||
NL3D::CTile::TBitmap bm;
|
||||
NL3D::CTileSet::TTransition tr;
|
||||
|
||||
// Diffuse, Additive
|
||||
for( int i = TileConstants::TileDiffuse; i < TileConstants::TileAlpha; i++ )
|
||||
{
|
||||
channel =TileConstants::TTileChannel( i );
|
||||
bm = channelToTBitmap( channel );
|
||||
tr = NL3D::CTileSet::TTransition( idx );
|
||||
const NL3D::CTileBorder &border = node->border( channel );
|
||||
|
||||
if( node->borderFirst( channel ) )
|
||||
set->setBorder( bm, border );
|
||||
set->setTileTransition( tr, node->getTileFilename( channel ).toUtf8().constData(), bm, bank, border );
|
||||
}
|
||||
|
||||
// Alpha
|
||||
{
|
||||
channel = TileConstants::TileAlpha;
|
||||
bm = channelToTBitmap( channel );
|
||||
tr = NL3D::CTileSet::TTransition( idx );
|
||||
const NL3D::CTileBorder &border = node->border( channel );
|
||||
int rot = node->alphaRot();
|
||||
|
||||
set->setTileTransitionAlpha( tr, node->getTileFilename( channel ).toUtf8().constData(), bank, border, rot );
|
||||
}
|
||||
}
|
||||
|
||||
void setupTransitionTiles( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
for( int i = 0; i < node->childCount(); i++ )
|
||||
{
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( node->child( i ) );
|
||||
setupTransitionTile( set, tin, i );
|
||||
}
|
||||
}
|
||||
|
||||
void setupTransitionTiles( NL3D::CTileSet *set, TileSetNode *node )
|
||||
{
|
||||
TileTypeNode *tn = static_cast< TileTypeNode* >( node->child( 2 ) );
|
||||
setupTransitionTiles( set, tn );
|
||||
}
|
||||
|
||||
void setupDisplacementTile( NL3D::CTileSet *set, TileItemNode *node, int idx )
|
||||
{
|
||||
set->setDisplacement( NL3D::CTileSet::TDisplacement( idx ),
|
||||
node->getTileFilename( TileConstants::TileDiffuse ).toUtf8().constData(),
|
||||
bank );
|
||||
}
|
||||
|
||||
void setupDisplacementTiles( NL3D::CTileSet *set, TileTypeNode *node )
|
||||
{
|
||||
for( int i = 0; i < node->childCount(); i++ )
|
||||
{
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( node->child( i ) );
|
||||
setupDisplacementTile( set, tin, i );
|
||||
}
|
||||
}
|
||||
|
||||
void setupDisplacementTiles( NL3D::CTileSet *set, TileSetNode *node )
|
||||
{
|
||||
TileTypeNode *tn = static_cast< TileTypeNode* >( node->child( 3 ) );
|
||||
setupDisplacementTiles( set, tn );
|
||||
}
|
||||
|
||||
void setupTiles( NL3D::CTileSet *set, TileSetNode *node )
|
||||
{
|
||||
TileTypeNode *tn128 = static_cast< TileTypeNode* >( node->child( 0 ) );
|
||||
TileTypeNode *tn256 = static_cast< TileTypeNode* >( node->child( 1 ) );
|
||||
|
||||
setupTiles128( set, tn128 );
|
||||
setupTiles256( set, tn256 );
|
||||
setupTransitionTiles( set, node );
|
||||
setupDisplacementTiles( set, node );
|
||||
}
|
||||
|
||||
void addLands( const QList< Land > &lands )
|
||||
{
|
||||
QListIterator< Land > itr( lands );
|
||||
while( itr.hasNext() )
|
||||
{
|
||||
bank.addLand( itr.next().name.toUtf8().constData() );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void addTileSets( const TileModel* model, const QList< Land > &lands )
|
||||
{
|
||||
// Add the tilesets
|
||||
for( int i = 0; i < model->rowCount(); i++ )
|
||||
{
|
||||
QModelIndex idx = model->index( i, 0 );
|
||||
if( !idx.isValid() )
|
||||
continue;
|
||||
|
||||
TileSetNode *n = reinterpret_cast< TileSetNode* >( idx.internalPointer() );
|
||||
QString set = n->getTileSetName();
|
||||
bank.addTileSet( set.toUtf8().constData() );
|
||||
}
|
||||
|
||||
// Set the data to tilesets
|
||||
for( int i = 0; i < bank.getTileSetCount(); i++ )
|
||||
{
|
||||
NL3D::CTileSet *set = bank.getTileSet( i );
|
||||
|
||||
QModelIndex idx = model->index( i, 0 );
|
||||
if( !idx.isValid() )
|
||||
continue;
|
||||
|
||||
TileSetNode *n = reinterpret_cast< TileSetNode* >( idx.internalPointer() );
|
||||
|
||||
addTilesToSet( set, n );
|
||||
setupTiles( set, n );
|
||||
set->setOriented( n->isOriented() );
|
||||
set->setTileVegetableDescFileName( n->vegetSet().toUtf8().constData() );
|
||||
}
|
||||
|
||||
// Add tilesets to lands
|
||||
for( int i = 0; i < bank.getLandCount(); i++ )
|
||||
{
|
||||
NL3D::CTileLand *land = bank.getLand( i );
|
||||
const Land &l = lands[ i ];
|
||||
|
||||
for( int j = 0; j < l.tilesets.count(); j++ )
|
||||
{
|
||||
land->addTileSet( l.tilesets[ j ].toUtf8().constData() );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TileBankSaver::TileBankSaver()
|
||||
|
@ -285,18 +41,13 @@ TileBankSaver::~TileBankSaver()
|
|||
|
||||
bool TileBankSaver::save( const char *fileName, const TileModel* model, const QList< Land > &lands )
|
||||
{
|
||||
p->addLands( lands );
|
||||
p->addTileSets( model, lands );
|
||||
|
||||
p->bank.setAbsPath( model->texturePath().toUtf8().constData() );
|
||||
|
||||
// Save to file
|
||||
NLMISC::COFile f;
|
||||
bool b = f.open( fileName, false, false, false );
|
||||
if( !b )
|
||||
return false;
|
||||
|
||||
p->bank.serial( f );
|
||||
//p->bank.serial( f );
|
||||
|
||||
f.flush();
|
||||
f.close();
|
||||
|
|
Loading…
Reference in a new issue