mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-23 23:36:18 +00:00
Implemented saving of the currently stored tilebank data.
This commit is contained in:
parent
d85d0b97d3
commit
1952d517b1
7 changed files with 234 additions and 11 deletions
14
code/studio/src/plugins/tile_editor/land.h
Normal file
14
code/studio/src/plugins/tile_editor/land.h
Normal file
|
@ -0,0 +1,14 @@
|
|||
#ifndef LAND_H
|
||||
#define LAND_H
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
struct Land
|
||||
{
|
||||
QString name;
|
||||
QStringList tilesets;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -210,7 +210,7 @@ void TileEditorMainWindow::saveAs()
|
|||
}
|
||||
|
||||
TileBankSaver saver;
|
||||
bool ok = saver.save( m_fileName.toUtf8().constData(), m_tileModel, landNames );
|
||||
bool ok = saver.save( m_fileName.toUtf8().constData(), m_tileModel, m_lands );
|
||||
|
||||
if( !ok )
|
||||
{
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <QtGui/QUndoStack>
|
||||
#include <QSignalMapper>
|
||||
|
||||
#include "land.h"
|
||||
|
||||
namespace Ui {
|
||||
class TileEditorMainWindow;
|
||||
}
|
||||
|
@ -108,12 +110,6 @@ private:
|
|||
TAB_DETAILS = 4
|
||||
};
|
||||
|
||||
struct Land
|
||||
{
|
||||
QString name;
|
||||
QStringList tilesets;
|
||||
};
|
||||
|
||||
QString m_fileName;
|
||||
QList< Land > m_lands;
|
||||
};
|
||||
|
|
|
@ -272,6 +272,16 @@ void TileItemNode::setTileFilename(TileModel::TTileChannel channel, QString file
|
|||
m_tileFilename[channel] = filename;
|
||||
}
|
||||
|
||||
QString TileItemNode::getTileFilename(TileModel::TTileChannel channel)
|
||||
{
|
||||
QMap< TileModel::TTileChannel, QString >::const_iterator itr
|
||||
= m_tileFilename.find( channel );
|
||||
if( itr == m_tileFilename.end() )
|
||||
return "";
|
||||
|
||||
return itr.value();
|
||||
}
|
||||
|
||||
QVariant TileItemNode::data(int column, int role) const
|
||||
{
|
||||
// find some way to know which file/bitmap to display
|
||||
|
|
|
@ -106,6 +106,7 @@ public:
|
|||
QVariant data(int column, int role) const;
|
||||
int columnCount() const;
|
||||
void setTileFilename(TileModel::TTileChannel channel, QString filename);
|
||||
QString getTileFilename(TileModel::TTileChannel channel);
|
||||
void setId( int id ){ m_tileId = id; }
|
||||
int id() const{ return m_tileId; }
|
||||
private:
|
||||
|
|
|
@ -17,21 +17,219 @@
|
|||
|
||||
#include "tilebank_saver.h"
|
||||
#include "tile_model.h"
|
||||
#include "tile_item.h"
|
||||
|
||||
#include "nel/3d/tile_bank.h"
|
||||
#include "nel/misc/file.h"
|
||||
|
||||
class TileBankSaverPvt
|
||||
{
|
||||
public:
|
||||
NL3D::CTileBank bank;
|
||||
|
||||
static NL3D::CTile::TBitmap channelToTBitmap( TileModel::TTileChannel channel )
|
||||
{
|
||||
NL3D::CTile::TBitmap b = NL3D::CTile::bitmapCount;
|
||||
|
||||
switch( channel )
|
||||
{
|
||||
case TileModel::TileDiffuse: b = NL3D::CTile::diffuse; break;
|
||||
case TileModel::TileAdditive: b = NL3D::CTile::additive; break;
|
||||
case TileModel::TileAlpha: b = NL3D::CTile::alpha; break;
|
||||
}
|
||||
|
||||
return b;
|
||||
}
|
||||
|
||||
NL3D::CTile* addTileToSet( NL3D::CTileSet *set, TileModel::TNodeTileType type )
|
||||
{
|
||||
int idx = -1;
|
||||
int bidx = -1;
|
||||
|
||||
switch( type )
|
||||
{
|
||||
case TileModel::Tile128:
|
||||
{
|
||||
set->addTile128( idx, bank );
|
||||
bidx = set->getTile128( idx );
|
||||
break;
|
||||
}
|
||||
|
||||
case TileModel::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 )
|
||||
{
|
||||
TileModel::TNodeTileType type = node->getTileType();
|
||||
|
||||
for( int i = 0; i < node->childCount(); i++ )
|
||||
{
|
||||
TileItemNode *tin = static_cast< TileItemNode* >( node->child( i ) );
|
||||
for( int j = TileModel::TileDiffuse; j <= TileModel::TileAlpha; j++ )
|
||||
{
|
||||
QString fn = tin->getTileFilename( TileModel::TTileChannel( j ) );
|
||||
|
||||
NL3D::CTile *tile = addTileToSet( set, type );
|
||||
tile->setFileName( channelToTBitmap( TileModel::TTileChannel( j ) ) , fn.toUtf8().constData() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void addTilesToSet( NL3D::CTileSet *set, TileSetNode *node )
|
||||
{
|
||||
for( int i = TileModel::Tile128; i <= TileModel::Tile256; i++ )
|
||||
{
|
||||
TileTypeNode *tn = static_cast< TileTypeNode* >( node->child( i ) );
|
||||
|
||||
addTilesToSet( set, tn );
|
||||
}
|
||||
}
|
||||
|
||||
void setupTransitionTile( NL3D::CTileSet *set, TileItemNode *node, int idx )
|
||||
{
|
||||
NL3D::CTileSetTransition *tr = set->getTransition( idx );
|
||||
int tid = tr->getTile();
|
||||
NL3D::CTile *tile = bank.getTile( tid );
|
||||
|
||||
if( tile == NULL )
|
||||
return;
|
||||
|
||||
for( int i = TileModel::TileDiffuse; i <= TileModel::TileAlpha; i++ )
|
||||
{
|
||||
QString fn = node->getTileFilename( TileModel::TTileChannel( i ) );
|
||||
tile->setFileName( channelToTBitmap( TileModel::TTileChannel( i ) ), fn.toUtf8().constData() );
|
||||
}
|
||||
}
|
||||
|
||||
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( TileModel::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 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 );
|
||||
setupTransitionTiles( set, n );
|
||||
setupDisplacementTiles( set, n );
|
||||
}
|
||||
|
||||
// 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()
|
||||
{
|
||||
p = new TileBankSaverPvt();
|
||||
}
|
||||
|
||||
TileBankSaver::~TileBankSaver()
|
||||
{
|
||||
delete p;
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
bool TileBankSaver::save( const char *fileName, const TileModel* model, const QList< QString > &lands )
|
||||
bool TileBankSaver::save( const char *fileName, const TileModel* model, const QList< Land > &lands )
|
||||
{
|
||||
NL3D::CTileBank bank;
|
||||
p->addLands( lands );
|
||||
p->addTileSets( model, lands );
|
||||
|
||||
return false;
|
||||
// Save to file
|
||||
NLMISC::COFile f;
|
||||
bool b = f.open( fileName, false, false, false );
|
||||
if( !b )
|
||||
return false;
|
||||
|
||||
p->bank.serial( f );
|
||||
|
||||
f.flush();
|
||||
f.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -20,18 +20,22 @@
|
|||
|
||||
#include <QString>
|
||||
#include <QList>
|
||||
#include "land.h"
|
||||
|
||||
class TileModel;
|
||||
|
||||
class TileBankSaverPvt;
|
||||
|
||||
class TileBankSaver
|
||||
{
|
||||
public:
|
||||
TileBankSaver();
|
||||
~TileBankSaver();
|
||||
|
||||
bool save( const char *filename, const TileModel* model, const QList< QString > &lands );
|
||||
bool save( const char *filename, const TileModel* model, const QList< Land > &lands );
|
||||
|
||||
private:
|
||||
TileBankSaverPvt *p;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue