void CTileSetCont::build (CTileBank& bank, uint tileSet) { // TileSet ref CTileSet* set=bank.getTileSet (tileSet); // Find a main bitmap with a valid name if (set->getNumTile128()) { // Get the name std::string fileName=bank.getAbsPath()+bank.getTile (set->getTile128(0))->getRelativeFileName (CTile::diffuse); // Valid name? if (fileName!="") { // Create it MainBitmap=new CTextureFile (fileName); } } // Build group bitmaps for (int group=0; group<NL3D_CTILE_NUM_GROUP; group++) { int tile; // Look for a 128 tile in this group for (tile=0; tile<set->getNumTile128(); tile++) { // Tile pointer CTile* pTile=bank.getTile (set->getTile128 (tile)); // Look for a tile of the group if (pTile->getGroupFlags ()&(1<<group)) { // Get the name std::string fileName=bank.getAbsPath()+pTile->getRelativeFileName (CTile::diffuse); // Valid name? if (fileName!="") { // Create it if (GroupBitmap[group]==NULL) GroupBitmap[group]=new CTextureFile (fileName); // Add to the group list GroupTile128[group].push_back (tile); } } } // Look for a 256 tile in this group for (tile=0; tile<set->getNumTile256(); tile++) { // Tile pointer CTile* pTile=bank.getTile (set->getTile256 (tile)); // Look for a tile of the group if (pTile->getGroupFlags ()&(1<<group)) { // Get the name std::string fileName=bank.getAbsPath()+pTile->getRelativeFileName (CTile::diffuse); // Valid name? if (fileName!="") { // Create it if (GroupBitmap[group]==NULL) GroupBitmap[group]=new CTextureFile (fileName); // Add to the group list GroupTile256[group].push_back (tile); } } } } // Current index bool dmwarn = false; for (uint displace=0; displace<CTileSet::CountDisplace; displace++) { uint dispTile = set->getDisplacementTile((CTileSet::TDisplacement)displace); if (bank.getDisplacementMapCount() <= dispTile) { if (!dmwarn) { dmwarn = true; MessageBox(NULL, "Tile bank not loaded, or bad tile bank. Missing a displacement tile. Use the tile bank utility to load the correct tilebank.", "NeL Patch Paint", MB_OK | MB_ICONWARNING); } continue; // with next displace } // Get the name std::string fileName = bank.getDisplacementMap(dispTile); if (fileName=="EmptyDisplacementMap") fileName=""; // Valid name? if (fileName!="") { // Create it DisplaceBitmap[displace]=new CTextureFile (bank.getAbsPath()+fileName); DisplaceBitmap[displace]->loadGrayscaleAsAlpha (false); } } }
void CTile_edit_dlg::on_absolutePathPushButton_clicked() { // Build the struct QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly; QString directory = QFileDialog::getExistingDirectory(this, tr("Select the absolute base path of the bank"), ui.absolutePathPushButton->text(), options); // Select the path if (!directory.isEmpty()) { // Convert item into path string QString path = QDir::toNativeSeparators(directory); // Add a final back slash if (!path.endsWith(QDir::separator())) { // Add a '\' at the end path.append(QDir::separator()); } //// Last check QMessageBox::StandardButton reply; QString confirmMessage = tr("Do you really want to set %1 as base path of the bank?").arg(path); reply = QMessageBox::question(this, tr("Confirm Path"), confirmMessage, QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) { // Set as default path.. // Old path const char* oldPath=tileBank.getAbsPath ().c_str(); // Path are good bool goodPath=true; // If no absolute path, must check before use it if ((*oldPath)==0) { // Compute xref tileBank.computeXRef(); // For all tiles, check we can change the path for (int tiles=0; tiles<tileBank.getTileCount(); tiles++) { // Get tile xref int tileSet; int number; CTileBank::TTileType type; tileBank.getTileXRef (tiles, tileSet, number, type); // Is tile used ? if (tileSet!=-1) { // 3 types of bitmaps int type; for (type=CTile::diffuse; type<CTile::bitmapCount; type++) { // Bitmap string const std::string& bitmapPath=tileBank.getTile(tiles)->getRelativeFileName ((CTile::TBitmap)type); // not empty ? if (bitmapPath!="") { // Check the path if ( CheckPath( bitmapPath, path.toUtf8() ) == false ) { // Bad path goodPath=false; // Message QString continueMessage = tr("Path '%1' can't be found in bitmap '%2'. Continue ?").arg(path).arg(QString(bitmapPath.c_str())); reply = QMessageBox::question(this, tr("Continue"), continueMessage, QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::No) break; } } } if (type!=CTile::bitmapCount) break; } } // For all tiles, check we can change the path for (uint noise=1; noise<tileBank.getDisplacementMapCount (); noise++) { // Bitmap string const char *bitmapPath=tileBank.getDisplacementMap (noise); // not empty ? if (strcmp (bitmapPath, "")!=0) { // Check the path if (CheckPath( bitmapPath, path.toUtf8() )==false) { // Bad path goodPath=false; // Message QString continueMessage = tr("Path '%1' can't be found in bitmap '%2'. Continue ?").arg(path).arg(QString(bitmapPath)); reply = QMessageBox::question(this, tr("Continue"), continueMessage, QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::No) break; } } } // Good path ? if (goodPath) { // Ok change the path // For all tiles, check we can change the path for (int tiles=0; tiles<tileBank.getTileCount(); tiles++) { // Get tile xref int tileSet; int number; CTileBank::TTileType type; tileBank.getTileXRef (tiles, tileSet, number, type); // Is tile used ? if (tileSet!=-1) { // 3 types of bitmaps for (int type=CTile::diffuse; type<CTile::bitmapCount; type++) { // Bitmap string std::string bitmapPath=tileBank.getTile(tiles)->getRelativeFileName ((CTile::TBitmap)type); // not empty ? if (bitmapPath!="") { // Remove the absolute path bool res=RemovePath (bitmapPath, path.toUtf8()); nlassert (res); // Set the bitmap tileBank.getTile(tiles)->setFileName ((CTile::TBitmap)type, bitmapPath); } } } } // For all tiles, check we can change the path for (uint noise=1; noise<tileBank.getDisplacementMapCount (); noise++) { // Bitmap string std::string bitmapPath=tileBank.getDisplacementMap (noise); // not empty ? if (bitmapPath!="") { // Remove the absolute path bool res=RemovePath (bitmapPath, path.toUtf8()); nlassert (res); // Set the bitmap tileBank.setDisplacementMap (noise, bitmapPath.c_str()); } } } else { // Info message QMessageBox::information(this, tr("Error"), tr("Can't set the path.")); } } // Good path ? if (goodPath) { // Change the abs path of the bank tileBank.setAbsPath (path.toUtf8().constData()); // Change the bouton text ui.absolutePathPushButton->setText(path); } } // Remove path from all tiles //tileBank } }