mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-30 15:45:58 +00:00
TileBank loading.
This commit is contained in:
parent
f25200c966
commit
47b85c3f8a
10 changed files with 268 additions and 1 deletions
|
@ -161,6 +161,9 @@ public:
|
|||
{
|
||||
return _Name;
|
||||
};
|
||||
|
||||
std::set<std::string> getTileSets() const{ return _TileSet; }
|
||||
|
||||
void setName (const std::string& name);
|
||||
void addTileSet (const std::string& name);
|
||||
void removeTileSet (const std::string& name);
|
||||
|
|
|
@ -33,6 +33,7 @@
|
|||
#include "tile_item_delegate.h"
|
||||
|
||||
#include "tilebank_saver.h"
|
||||
#include "tilebank_loader.h"
|
||||
|
||||
#include "land_edit_dialog.h"
|
||||
|
||||
|
@ -159,9 +160,12 @@ TileEditorMainWindow::TileEditorMainWindow(QWidget *parent)
|
|||
saveAction->setEnabled( true );
|
||||
QAction *saveAsAction = Core::ICore::instance()->menuManager()->action( Core::Constants::SAVE_AS );
|
||||
saveAsAction->setEnabled( true );
|
||||
QAction *openAction = Core::ICore::instance()->menuManager()->action( Core::Constants::OPEN );
|
||||
openAction->setEnabled( true );
|
||||
|
||||
connect( m_ui->actionSaveTileBank, SIGNAL( triggered() ), this, SLOT( save() ) );
|
||||
connect( m_ui->actionSaveTileBankAs, SIGNAL( triggered() ), this, SLOT( saveAs() ) );
|
||||
connect( m_ui->actionOpenTileBank, SIGNAL( triggered() ), this, SLOT( open() ) );
|
||||
|
||||
connect( m_ui->orientedCheckBox, SIGNAL( stateChanged( int ) ), this, SLOT( onOrientedStateChanged( int ) ) );
|
||||
}
|
||||
|
@ -222,6 +226,30 @@ void TileEditorMainWindow::saveAs()
|
|||
}
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::open()
|
||||
{
|
||||
QString fn = QFileDialog::getOpenFileName( this,
|
||||
tr( "Loading tilebank" ),
|
||||
"",
|
||||
tr( "tilebank files (*.tilebank)" ) );
|
||||
|
||||
if( fn.isEmpty() )
|
||||
return;
|
||||
|
||||
TileBankLoader loader;
|
||||
bool b = loader.load( fn.toUtf8().constData(), m_tileModel, m_lands );
|
||||
|
||||
if( !b )
|
||||
{
|
||||
QMessageBox::critical( this,
|
||||
tr( "Loading tilebank" ),
|
||||
tr( "Failed to load tilebank %1" ).arg( fn ) );
|
||||
}
|
||||
|
||||
// Put the loaded data into the GUI
|
||||
onTileBankLoaded();
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onZoomFactor(int level)
|
||||
{
|
||||
int tile128Scaled=TileModel::TILE_128_BASE_SIZE;
|
||||
|
@ -307,7 +335,6 @@ void TileEditorMainWindow::onTileSetAdd()
|
|||
TileSetNode *tileSet = model->createTileSetNode(text);
|
||||
|
||||
// Retrieve how many rows there currently are and set the current index using that.
|
||||
m_ui->tileSetLV->reset();
|
||||
uint32 rows = model->rowCount();
|
||||
m_ui->tileSetLV->setCurrentIndex(model->index(rows-1, 0));
|
||||
}
|
||||
|
@ -703,6 +730,20 @@ void TileEditorMainWindow::onTileSetRenamed( const QString &oldname, const QStri
|
|||
}
|
||||
}
|
||||
|
||||
void TileEditorMainWindow::onTileBankLoaded()
|
||||
{
|
||||
m_ui->landLW->clear();
|
||||
QListIterator< Land > itr( m_lands );
|
||||
while( itr.hasNext() )
|
||||
{
|
||||
m_ui->landLW->addItem( itr.next().name );
|
||||
}
|
||||
|
||||
m_ui->listView128->reset();
|
||||
m_ui->listView256->reset();
|
||||
m_ui->listViewTransition->reset();
|
||||
}
|
||||
|
||||
TileModel* TileEditorMainWindow::createTileModel()
|
||||
{
|
||||
QStringList headers;
|
||||
|
@ -749,6 +790,8 @@ void TileEditorMainWindow::changeActiveTileSet(const QModelIndex &newIndex, cons
|
|||
m_ui->chooseVegetPushButton->setText( vegetSet );
|
||||
else
|
||||
m_ui->chooseVegetPushButton->setText( "..." );
|
||||
|
||||
m_ui->orientedCheckBox->setChecked( newNode->isOriented() );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -47,6 +47,7 @@ public:
|
|||
public Q_SLOTS:
|
||||
void save();
|
||||
void saveAs();
|
||||
void open();
|
||||
|
||||
private Q_SLOTS:
|
||||
void onActionAddTile(bool triggered);
|
||||
|
@ -82,6 +83,7 @@ private:
|
|||
|
||||
void onTileSetRemoved( const QString &set );
|
||||
void onTileSetRenamed( const QString &oldname, const QString &newname );
|
||||
void onTileBankLoaded();
|
||||
|
||||
TileModel* createTileModel();
|
||||
QListView* getListViewByTab( int tab ) const;
|
||||
|
|
|
@ -93,6 +93,7 @@ public:
|
|||
|
||||
virtual void open()
|
||||
{
|
||||
m_tileEditorMainWindow->open();
|
||||
}
|
||||
|
||||
void save()
|
||||
|
|
|
@ -40,6 +40,7 @@ Node::~Node()
|
|||
|
||||
void Node::appendChild(Node *item)
|
||||
{
|
||||
item->setParent( this );
|
||||
m_childItems.append(item);
|
||||
}
|
||||
|
||||
|
@ -162,6 +163,13 @@ void Node::swapRows( int a, int b )
|
|||
m_childItems[ b ] = temp;
|
||||
}
|
||||
|
||||
void Node::clear()
|
||||
{
|
||||
qDeleteAll( m_childItems );
|
||||
m_childItems.clear();
|
||||
m_itemData.clear();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
TileSetNode::TileSetNode(QString tileSetName, Node *parent) : m_tileSetName(tileSetName)
|
||||
|
|
|
@ -55,6 +55,8 @@ public:
|
|||
|
||||
void swapRows( int a, int b );
|
||||
|
||||
void clear();
|
||||
|
||||
protected:
|
||||
QList<Node*> m_childItems;
|
||||
QVector<QVariant> m_itemData;
|
||||
|
|
|
@ -137,7 +137,13 @@ void TileModel::appendRow(const QList<Node*> &items)
|
|||
|
||||
void TileModel::appendRow(Node *item)
|
||||
{
|
||||
int c = rootItem->childCount();
|
||||
|
||||
beginInsertRows( QModelIndex(), c, c );
|
||||
|
||||
rootItem->appendRow(item);
|
||||
|
||||
endInsertRows();
|
||||
}
|
||||
|
||||
bool TileModel::removeRows( int row, int count, const QModelIndex &parent )
|
||||
|
@ -272,6 +278,15 @@ bool TileModel::hasTileSet( const QString &name )
|
|||
return false;
|
||||
}
|
||||
|
||||
void TileModel::clear()
|
||||
{
|
||||
int c = rootItem->childCount();
|
||||
if( c == 0 )
|
||||
return;
|
||||
|
||||
removeRows( 0, c );
|
||||
}
|
||||
|
||||
void TileModel::selectFilenameDisplay(bool selected)
|
||||
{
|
||||
m_fileDisplay = selected;
|
||||
|
|
|
@ -93,6 +93,8 @@ public:
|
|||
|
||||
bool hasTileSet( const QString &name );
|
||||
|
||||
void clear();
|
||||
|
||||
public Q_SLOTS:
|
||||
void selectFilenameDisplay(bool selected);
|
||||
void selectIndexDisplay(bool selected);
|
||||
|
|
168
code/studio/src/plugins/tile_editor/tilebank_loader.cpp
Normal file
168
code/studio/src/plugins/tile_editor/tilebank_loader.cpp
Normal file
|
@ -0,0 +1,168 @@
|
|||
#include "tilebank_loader.h"
|
||||
|
||||
#include "tile_model.h"
|
||||
#include "tile_item.h"
|
||||
|
||||
#include "nel/3d/tile_bank.h"
|
||||
#include "nel/misc/file.h"
|
||||
|
||||
class TileBankLoaderPvt
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
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( i, TileModel::TileDiffuse, "" );
|
||||
|
||||
for( int i = TileModel::TileDiffuse; i <= TileModel::TileAlpha; i++ )
|
||||
{
|
||||
tin->setTileFilename( TileModel::TTileChannel( i ), tile->getRelativeFileName( channelToTBitmap( TileModel::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( i, TileModel::TileDiffuse, "" );
|
||||
|
||||
for( int i = TileModel::TileDiffuse; i <= TileModel::TileAlpha; i++ )
|
||||
{
|
||||
tin->setTileFilename( TileModel::TTileChannel( i ), tile->getRelativeFileName( channelToTBitmap( TileModel::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 = TileModel::TileDiffuse; j <= TileModel::TileAlpha; j++ )
|
||||
{
|
||||
tin->setTileFilename( TileModel::TTileChannel( i ), tile->getRelativeFileName( channelToTBitmap( TileModel::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( TileModel::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() );
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
TileBankLoader::TileBankLoader()
|
||||
{
|
||||
p = new TileBankLoaderPvt;
|
||||
}
|
||||
|
||||
TileBankLoader::~TileBankLoader()
|
||||
{
|
||||
delete p;
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
bool TileBankLoader::load( const char *filename, TileModel *model, QList< Land > &lands )
|
||||
{
|
||||
NLMISC::CIFile file;
|
||||
if( !file.open( filename, false ) )
|
||||
return false;
|
||||
|
||||
p->bank.serial( file );
|
||||
|
||||
p->loadLands( lands );
|
||||
p->loadTileSets( model );
|
||||
|
||||
return false;
|
||||
}
|
23
code/studio/src/plugins/tile_editor/tilebank_loader.h
Normal file
23
code/studio/src/plugins/tile_editor/tilebank_loader.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef TILEBANK_LOADER_H
|
||||
#define TILEBANK_LOADER_H
|
||||
|
||||
#include "land.h"
|
||||
|
||||
class TileModel;
|
||||
class TileBankLoaderPvt;
|
||||
|
||||
class TileBankLoader
|
||||
{
|
||||
public:
|
||||
TileBankLoader();
|
||||
~TileBankLoader();
|
||||
|
||||
bool load( const char *filename, TileModel *model, QList< Land > &lands );
|
||||
|
||||
private:
|
||||
TileBankLoaderPvt *p;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in a new issue