Example #1
0
void CTile_edit_dlg::on_tileSetListWidget_itemSelectionChanged()
{
	tileSetSelectionChanging = true;

	int nindex = ui.tileSetListWidget->currentRow();
	if (nindex != -1) 
	{
		if ( !tileBank.getTileSet(nindex)->getTileVegetableDescFileName().empty() )
			ui.chooseVegetPushButton->setText( QString( tileBank.getTileSet(nindex)->getTileVegetableDescFileName().c_str() ) );
		else
			ui.chooseVegetPushButton->setText("...");

		ui.surfaceDataLineEdit->setText( QString::number( tileBank.getTileSet(nindex)->SurfaceData) );
		ui.orientedCheckBox->setChecked( tileBank.getTileSet(nindex)->getOriented() );
		
		ui.selectedTileSetGroupBox->setEnabled(true);
		ui.editTileSetPushButton->setEnabled(true);
		ui.deleteTileSetPushButton->setEnabled(true);
	}
	else
	{
		//TODO titegus: Init DetailFrame Method
		ui.chooseVegetPushButton->setText("...");
		ui.surfaceDataLineEdit->clear();
		ui.orientedCheckBox->setChecked(false);

		ui.selectedTileSetGroupBox->setEnabled(false);
		ui.editTileSetPushButton->setEnabled(false);
		ui.deleteTileSetPushButton->setEnabled(false);
	}

	tileSetSelectionChanging = false;
}
Example #2
0
int main(int argc, char* argv[])
{
	// Arg ?
	if (argc<3)
	{
		// Doc
		printf ("build_smallbank [input.bank] [output.smallbank] [new_absolute_path]\n");
	}
	else
	{
		try
		{
			// Load the bank
			CTileBank bank;

			// Input file
			CIFile input;
			if (input.open (argv[1]))
			{
				// Serial the bank
				bank.serial (input);

				// Make a small bank
				bank.cleanUnusedData ();

				// Absolute path ?
				if (argc>3)
					bank.setAbsPath (argv[3]);

				// Output file
				COFile output;
				if (output.open (argv[2]))
				{
					// Serial the bank
					bank.serial (output);
				}
				else
				{
					// Error
					nlwarning ("ERROR can't open the file %s for writing", argv[2]);
				}
			}
			else
			{
				// Error
				nlwarning ("ERROR can't open the file %s for reading", argv[1]);
			}

		}
		catch (const Exception& e)
		{
			// Error
			nlwarning ("ERROR fatal error: %s", e.what());
		}
	}
	return 0;
}
Example #3
0
void Browse::Flags (int flagNumber, bool go)
{
	// For each 
	for (int i=0;i<m_ctrl.InfoList.GetSize(m_128x128);i++)
	{
		// Selected ?
		if (m_ctrl.InfoList.theList[m_128x128][i].Selected)
		{
			// Tile index
			sint index;

			// get flags
			switch (m_128x128)
			{
			case 0:
				// Tile index
				index=tileBank2.getTileSet (land)->getTile128 (i);
				break;
			case 1:
				// Tile index
				index=tileBank2.getTileSet (land)->getTile256 (i);
				break;
			case 2:
				// Tile index
				index=tileBank2.getTileSet (land)->getTransition (i)->getTile ();
				break;
			default:
				nlassert (0);	// no!
			}

			// valid flags
			if (index!=-1)
			{
				// Get flags
				uint value=tileBank2.getTile (index)->getGroupFlags ();

				// Clear flag
				value&=~(1<<flagNumber);

				// Set the flag
				if (go)
					value|=(1<<flagNumber);

				// Setup
				tileBank2.getTile (index)->setGroupFlags (value);
			}
		}
	}
}
Example #4
0
void CTile_edit_dlg::on_deleteTileSetPushButton_clicked()
{
	int nindex = ui.tileSetListWidget->currentRow();
	if (nindex != -1) 
	{

		//WORKAROUND : Qt 4.4 Behaviour (when removing at row 0 and currentRow equals to 0, currentRow is set to 1, it mess with the selectionChanged event
		if (nindex == 0)
		{
			if ( ui.tileSetListWidget->count() > 1)
				ui.tileSetListWidget->setCurrentRow(1);
			else
				ui.tileSetListWidget->setCurrentRow(-1);
		}
		//

		tileBank.removeTileSet( nindex );

		QListWidgetItem* item = ui.tileSetListWidget->takeItem(nindex);
		delete item;
	}
	else
	{
		QMessageBox::information( this, tr("No Tile Set Selected"), tr("Please, select a Tile Set to delete first ...") );
	}
}
Example #5
0
void CTile_edit_dlg::on_saveAsPushButton_clicked()
{
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getSaveFileName(this, tr("Save Bank"), this->mainFile.absoluteFilePath(), tr("NeL tile bank files (*.bank);;All Files (*.*);;"), &selectedFilter, options);
	if (!fileName.isEmpty())
	{
		// Set MainFile
		mainFile = QFileInfo(fileName);
		ui.savePushButton->setEnabled(true);


		string fullPath = this->mainFile.absoluteFilePath().toUtf8();
		if ( !fullPath.empty() )
		{
			COFile stream;
			if ( stream.open( fullPath.c_str() ) )
			{
				tileBank.serial (stream);
				QString s = tr("Bank %1 saved").arg( QString( fullPath.c_str() ) );
				QMessageBox::information(this, tr("Bank Saved"), s);
				return;
			}
		}

		QMessageBox::information(this, tr("Error"), tr("Can't Save Bank, check the path"));

	}

}
Example #6
0
CBankCont::CBankCont (CTileBank& bank, HINSTANCE hInstance)
{
	// Allocate bitmaps
	_smallBitmap	=	new CTextureMem ((uint8*)_small, _smallSize, false);
	mediumBitmap	=	new CTextureMem ((uint8*)medium, mediumSize, false);
	largeBitmap		=	new CTextureMem ((uint8*)large, largeSize, false);
	_256Bitmap		=	new CTextureMem ((uint8*)_256, _256Size, false);
	_128Bitmap		=	new CTextureMem ((uint8*)_128, _128Size, false);
	_0Bitmap		=	new CTextureMem ((uint8*)_0, _0Size, false);
	_1Bitmap		=	new CTextureMem ((uint8*)_1, _1Size, false);
	_2Bitmap		=	new CTextureMem ((uint8*)_2, _2Size, false);
	_3Bitmap		=	new CTextureMem ((uint8*)_3, _3Size, false);
	_4Bitmap		=	new CTextureMem ((uint8*)_4, _4Size, false);
	_5Bitmap		=	new CTextureMem ((uint8*)_5, _5Size, false);
	_6Bitmap		=	new CTextureMem ((uint8*)_6, _6Size, false);
	_7Bitmap		=	new CTextureMem ((uint8*)_7, _7Size, false);
	_8Bitmap		=	new CTextureMem ((uint8*)_8, _8Size, false);
	_9Bitmap		=	new CTextureMem ((uint8*)_9, _9Size, false);
	_10Bitmap		=	new CTextureMem ((uint8*)_10, _10Size, false);
	_11Bitmap		=	new CTextureMem ((uint8*)_11, _11Size, false);
	allBitmap		=	new CTextureMem ((uint8*)all, allSize, false);
	lightBitmap		=	new CTextureMem ((uint8*)light, lightSize, false);
	lockBitmap		=	new CTextureMem ((uint8*)lock, lockSize, false);
	orientedBitmap	=	new CTextureMem ((uint8*)oriented, orientedSize, false);
	nothingBitmap	=	new CTextureMem ((uint8*)nothing, nothingSize, false);
	regularBitmap	=	new CTextureMem ((uint8*)regular, regularSize, false);
	goofyBitmap		=	new CTextureMem ((uint8*)goofy, goofySize, false);

	// Resize the tileset array
	TileSet.resize (bank.getTileSetCount());

	// For each tileSet, build the cont
	for (int tileSet=0; tileSet<bank.getTileSetCount(); tileSet++)
		TileSet[tileSet].build (bank, tileSet);

	// Load cursors
	HInspect = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_INSPECT));
	HCur = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_PICK_COLOR));
	HFill = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_FILL));
	HTrick = LoadCursor(hInstance, MAKEINTRESOURCE(IDC_TRICK));
}
Example #7
0
void CTile_edit_dlg::on_resetVegetPushButton_clicked()
{
	int nindex = ui.tileSetListWidget->currentRow();
	if (nindex != -1) 
	{
		tileBank.getTileSet (nindex)->setTileVegetableDescFileName ("");
		ui.chooseVegetPushButton->setText("...");
	}
	else
	{
		QMessageBox::information( this, tr("No Tile Set Selected"), tr("Please, select a Tile Set first ...") );
	}
}
Example #8
0
void CTile_edit_dlg::on_deleteLandPushButton_clicked()
{
	int nindex = ui.landListWidget->currentRow();
	if (nindex != -1) 
	{
		tileBank.removeLand (nindex);
		QListWidgetItem* item = ui.landListWidget->takeItem(nindex);
		delete item;
	}
	else
	{
		QMessageBox::information( this, tr("No Land Selected"), tr("Please, select the Land to delete first ...") );
	}
}
Example #9
0
void Browse::OnOk() 
{
	// TODO: Add your control notification handler code here
	if (thread_actif) return;

	// trap - Don't know if this is the right place to do this
	UpdateData ();
	CTileSet *tileSet=tileBank2.getTileSet (land);
	tileSet->setOriented(Oriented?true:false);


	this->SendMessage(WM_CLOSE);
	EndDialog(1);
}
Example #10
0
void CTile_edit_dlg::on_orientedCheckBox_stateChanged ( int state )
{
	if (!tileSetSelectionChanging)
	{
		int nindex = ui.tileSetListWidget->currentRow();
		if (nindex != -1) 
		{
			tileBank.getTileSet (nindex)->setOriented(ui.orientedCheckBox->isChecked());
		}
		else
		{
			QMessageBox::information( this, tr("No Tile Set Selected"), tr("Please, select a Tile Set first ...") );
		}
	}
}
Example #11
0
void CTile_edit_dlg::on_savePushButton_clicked()
{
	string fullPath = this->mainFile.absoluteFilePath().toUtf8();
	if ( !fullPath.empty() )
	{
		COFile stream;
		if ( stream.open( fullPath.c_str() ) )
		{
			tileBank.serial (stream);
			QString s = tr("Bank %1 saved").arg( QString( fullPath.c_str() ) );
			QMessageBox::information(this, tr("Bank Saved"), s);
			return;
		}
	}

	QMessageBox::information(this, tr("Error"), tr("Can't Save Bank, check the path"));
}
Example #12
0
void CTile_edit_dlg::on_editLandPushButton_clicked()
{
	int nindex = ui.landListWidget->currentRow();
	if (nindex != -1) 
	{
		QStringList availableTileSetList;
		QStringList landTileSetList;
		for (int i=0; i<tileBank.getTileSetCount(); i++)
		{
			if (tileBank.getLand(nindex)->isTileSet (tileBank.getTileSet(i)->getName()))
				landTileSetList.append( QString( tileBank.getTileSet(i)->getName().c_str() ) );
			else
				availableTileSetList.append( QString( tileBank.getTileSet(i)->getName().c_str() ) );
		}

		bool ok = false;
		QStringList items = CItems_edit_dlg::getItems(this, tr("Edit Land"), ui.landListWidget->item(nindex)->text(), availableTileSetList, landTileSetList, &ok);

		if (ok)
		{
			for (int i=0; i<tileBank.getTileSetCount(); i++)
			{
				// remove tile set
				tileBank.getLand(nindex)->removeTileSet (tileBank.getTileSet(i)->getName());
			}
			for (int i=0; i<items.count(); i++)
			{
				QString rString = items[i];
				tileBank.getLand(nindex)->addTileSet( rString.toUtf8().constData() );
			}
		}
	}
	else
	{
		QMessageBox::information( this, tr("No Land Selected"), tr("Please, select the Land to edit first ...") );
	}
}
Example #13
0
void CTile_edit_dlg::on_upPushButton_clicked()
{
	int nindex = ui.tileSetListWidget->currentRow();
	if (nindex != -1) 
	{
		if (nindex > 0 )
		{
			tileBank.xchgTileset (nindex, nindex-1);
			QListWidgetItem* item = ui.tileSetListWidget->takeItem(nindex);
			ui.tileSetListWidget->insertItem(nindex - 1, item);

			ui.tileSetListWidget->setCurrentRow(nindex - 1);
		}
	}
	else
	{
		QMessageBox::information( this, tr("No Tile Set Selected"), tr("Please, select a Tile Set first ...") );
	}
}
Example #14
0
void CTile_edit_dlg::on_addLandPushButton_clicked()
{
    bool ok;
    QString text = QInputDialog::getText(this, tr("Add Land"), tr("Enter land name:"), QLineEdit::Normal, "", &ok);
    if (ok && !text.isEmpty())
	{
		if (ui.landListWidget->findItems(text, Qt::MatchExactly).count() > 0)
		{
			QMessageBox::information( this, tr("Error Adding Land"), tr("This name already exists") );
		}
		else
		{
			tileBank.addLand( text.toUtf8().constData() );

			ui.landListWidget->addItem(text);
			ui.landListWidget->setCurrentRow(ui.landListWidget->count() - 1);
		}
	}
}
Example #15
0
void CTile_edit_dlg::on_surfaceDataLineEdit_textChanged()
{
	if (!tileSetSelectionChanging)
	{
		int nindex = ui.tileSetListWidget->currentRow();
		if (nindex != -1) 
		{
			bool ok;
			uint intValue = ui.surfaceDataLineEdit->text().toUInt( &ok, 10 );
			if (ok)
			{
				tileBank.getTileSet (nindex)->SurfaceData = (uint32)intValue;
			}
		}
		else
		{
			QMessageBox::information( this, tr("No Tile Set Selected"), tr("Please, select a Tile Set first ...") );
		}
	}
}
Example #16
0
void CTile_edit_dlg::on_chooseVegetPushButton_clicked()
{
	int nindex = ui.tileSetListWidget->currentRow();
	if (nindex != -1) 
	{
		QFileDialog::Options options;
		QString selectedFilter;
		QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Veget Set"), ui.chooseVegetPushButton->text() , tr("NeL VegetSet Files (*.vegetset);;All Files (*.*);;"), &selectedFilter, options);
		
		if (!fileName.isEmpty())
		{
			QFileInfo fi(fileName);
			tileBank.getTileSet (nindex)->setTileVegetableDescFileName (fi.fileName().toUtf8().constData());
			ui.chooseVegetPushButton->setText(fi.fileName());
		}
	}
	else
	{
		QMessageBox::information( this, tr("No Tile Set Selected"), tr("Please, select a Tile Set first ...") );
	}
}
Example #17
0
void CTile_edit_dlg::on_loadPushButton_clicked()
{
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getOpenFileName(this, tr("Open Bank"), ui.absolutePathPushButton->text() , tr("NeL tile bank files (*.bank);;All Files (*.*);;"), &selectedFilter, options);
	
	if (!fileName.isEmpty())
	{
		CIFile stream;
		if ( stream.open( fileName.toUtf8().constData() ) )
		{
			ui.landListWidget->clear();
			ui.tileSetListWidget->clear();
			tileBank.clear();
			tileBank.serial (stream);
		}
		
		int i;
		QStringList lands;
		for (i=0; i<tileBank.getLandCount(); i++)
		{
			// Add to the list
			lands.append( QString(tileBank.getLand(i)->getName().c_str()) );
		}
		ui.landListWidget->addItems(lands);


		QStringList tileSets;
		for (i=0; i<tileBank.getTileSetCount(); i++)
		{
			// Add to the list
			tileSets.append( QString( tileBank.getTileSet(i)->getName().c_str() ) );
		}
		ui.tileSetListWidget->addItems(tileSets);

		// Set MainFile
		mainFile = QFileInfo(fileName);

		ui.savePushButton->setEnabled(true);
		ui.absolutePathPushButton->setText( QString( tileBank.getAbsPath().c_str() ) );
	}
}
Example #18
0
void Browse::UpdateFlags ()
{
	SubGroup0=0;
	SubGroup1=0;
	SubGroup2=0;
	SubGroup3=0;
	SubGroup4=0;
	SubGroup5=0;
	SubGroup6=0;
	SubGroup7=0;
	SubGroup8=0;
	SubGroup9=0;
	SubGroup10=0;
	SubGroup11=0;

	// Flags
	uint or=0, and=0xffffffff;
	bool find=false;

	// For each 
	for (int i=0;i<m_ctrl.InfoList.GetSize(m_128x128);i++)
	{
		// Selected ?
		if (m_ctrl.InfoList.theList[m_128x128][i].Selected)
		{
			// Tile index
			sint index;

			// get flags
			switch (m_128x128)
			{
			case 0:
				// Tile index
				index=tileBank2.getTileSet (land)->getTile128 (i);
				break;
			case 1:
				// Tile index
				index=tileBank2.getTileSet (land)->getTile256 (i);
				break;
			case 2:
				// Tile index
				index=tileBank2.getTileSet (land)->getTransition (i)->getTile ();
				break;
			case 3:
				// not found
				index=-1;
				break;
			default:
				nlassert (0);	// no!
			}

			// valid flags
			if (index!=-1)
			{
				// Get flags
				or|=tileBank2.getTile (index)->getGroupFlags ();
				and&=tileBank2.getTile (index)->getGroupFlags ();

				// Find one
				find=true;
			}
		}
	}

	// Valid ctrl
	GetDlgItem (IDC_SUBGROUP0)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP1)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP2)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP3)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP4)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP5)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP6)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP7)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP8)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP9)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP10)->EnableWindow (find?TRUE:FALSE);
	GetDlgItem (IDC_SUBGROUP11)->EnableWindow (find?TRUE:FALSE);

	// Find at least one tile ?
	if (find)
	{
		// Set UI
		SubGroup0=(and&0x1)?1:(or&0x1)?2:0;
		SubGroup1=(and&0x2)?1:(or&0x2)?2:0;
		SubGroup2=(and&0x4)?1:(or&0x4)?2:0;
		SubGroup3=(and&0x8)?1:(or&0x8)?2:0;
		SubGroup4=(and&0x10)?1:(or&0x10)?2:0;
		SubGroup5=(and&0x20)?1:(or&0x20)?2:0;
		SubGroup6=(and&0x40)?1:(or&0x40)?2:0;
		SubGroup7=(and&0x80)?1:(or&0x80)?2:0;
		SubGroup8=(and&0x100)?1:(or&0x100)?2:0;
		SubGroup9=(and&0x200)?1:(or&0x200)?2:0;
		SubGroup10=(and&0x400)?1:(or&0x400)?2:0;
		SubGroup11=(and&0x800)?1:(or&0x800)?2:0;
	}

	// Update UI data
	UpdateData (FALSE);
}
Example #19
0
void Browse::OnBatchLoad ()
{
	CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING,
		"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);

	if (sFile.DoModal()==IDOK)
	{
		char sDrive[256];
		char sPath[256];
		char sName[256];
		char sExt[256];
		_splitpath (sFile.GetPathName(), sDrive, sPath, sName, sExt);

		// look for some numbers..
		char *sNumber=sName+strlen(sName)-1;
		while ((sNumber>sName)&&(*sNumber>='0')&&(*sNumber<='9'))
		{
			sNumber--;
		}
		sNumber[1]=0;

		bool rotate=false;
		if (::MessageBox (NULL, "Do you want to use rotation to reuse alpha tiles ?", "Import rotated tiles", MB_OK|MB_ICONQUESTION|MB_YESNO)==IDYES)
			rotate=true;

		for (int i=0; i<CTileSet::count; i++)
		{
			if (m_ctrl.Texture==3)
			{
				// Current transition
				CTileSet::TTransition transition=(CTileSet::TTransition)i;

				// Transition to patch
				CTileSetTransition* trans=tileBank2.getTileSet (land)->getTransition (transition);
				if (tileBank2.getTile (trans->getTile())->getRelativeFileName (CTile::alpha)=="")
				{
					// Continue ?
					int ok;

					// Try to load transition with rotation
					for (int rot=0; rot<4; rot++)
					{
						// Try to load a tile with a file name like /tiletransition0.tga
						char sName2[256];
						char sFinal[256];
						sprintf (sName2, "%s%02d", sName, (int)transition);
						_makepath (sFinal, sDrive, sPath, sName2, sExt);
						FILE *pFile=fopen (sFinal, "rb");

						// Close the file and add the tile if opened
						if (pFile)
						{
							fclose (pFile);
							ok=m_ctrl.InfoList.setTileTransitionAlpha (i, sFinal, (4-rot)%4);

							// End
							break;
						}

						// Rotate the transition
						transition=CTileSet::rotateTransition (transition);

						if (!rotate)
							break;
					}
					if (!ok)
						break;
				}
			}
			else
			{
				// Current transition
				CTileSet::TTransition transition=(CTileSet::TTransition)i;

				// Transition to patch
				CTileSetTransition* trans=tileBank2.getTileSet (land)->getTransition (transition);
				if (tileBank2.getTile (trans->getTile())->getRelativeFileName (m_ctrl.Texture==1?CTile::diffuse:CTile::additive)=="")
				{
					// Try to load a tile with a file name like /tiletransition0.tga
					char sName2[256];
					char sFinal[256];
					sprintf (sName2, "%s%02d", sName, (int)transition);
					_makepath (sFinal, sDrive, sPath, sName2, sExt);
					FILE *pFile=fopen (sFinal, "rb");

					// Close the file and add the tile if opened
					if (pFile)
					{
						fclose (pFile);
						if (!m_ctrl.InfoList.setTileTransition (i, sFinal, m_ctrl.Texture==1?CTile::diffuse:CTile::additive))
							break;
					}
				}
			}
		}
		m_ctrl.Invalidate ();

	}
}
void CTile_browser_dlg::initDialog(const int& tileSetIndex)
{
	this->tileSetIndex = tileSetIndex;


	//GroupBox Creation
	tileTypeButtonGroup = new QButtonGroup;
    tileTypeButtonGroup->setExclusive(true);
	tileTypeButtonGroup->addButton(ui._128x128RadioButton, _128x128);
	tileTypeButtonGroup->addButton(ui._256x256RadioButton, _256x256);
	tileTypeButtonGroup->addButton(ui.transitionRadioButton, Transition);
	tileTypeButtonGroup->addButton(ui.displaceRadioButton, Displace);

	tileTextureButtonGroup = new QButtonGroup;
    tileTextureButtonGroup->setExclusive(true);
	tileTextureButtonGroup->addButton(ui.diffuseRadioButton, Diffuse);
	tileTextureButtonGroup->addButton(ui.additiveRadioButton, Additive);
	tileTextureButtonGroup->addButton(ui.alphaRadioButton, Alpha);

	tileLabelButtonGroup = new QButtonGroup;
    tileLabelButtonGroup->setExclusive(true);
	tileLabelButtonGroup->addButton(ui.indexRadioButton, CTile_browser_dlg::Index);
	tileLabelButtonGroup->addButton(ui.fileNameRadioButton, CTile_browser_dlg::FileName);

	tileZoomButtonGroup = new QButtonGroup;
    tileZoomButtonGroup->setExclusive(true);
	tileZoomButtonGroup->addButton(ui.smallRadioButton, CTile_browser_dlg::Small);
	tileZoomButtonGroup->addButton(ui.normalRadioButton, CTile_browser_dlg::Normal);
	tileZoomButtonGroup->addButton(ui.bigRadioButton, CTile_browser_dlg::Big);

	//Contextual Actions Creation
	ui.tileBrowserListView->addAction(ui.actionAddTile);
	ui.tileBrowserListView->addAction(ui.actionDeleteTile);
	ui.tileBrowserListView->addAction(ui.actionReplaceImage);
	ui.tileBrowserListView->addAction(ui.actionDeleteImage);


	//Layout
    QHBoxLayout *mainLayout = new QHBoxLayout;
	mainLayout->addWidget(ui.buttonFrame);
    mainLayout->addWidget(ui.tileBrowserListView);
    setLayout(mainLayout);

	//Apply Settings
	int width = settings.value("browser/width").toInt();
	int height = settings.value("browser/height").toInt();
	if (width > 0 && height > 0)
		this->resize(width, height);

	if ( settings.contains("browser/TileType") )
		tileTypeButtonGroup->button(settings.value("browser/TileType").toInt())->setChecked(true);

	if ( settings.contains("browser/TileTexture") )
		tileTextureButtonGroup->button(settings.value("browser/TileTexture").toInt())->setChecked(true);

	if ( settings.contains("browser/TileLabel") )
		tileLabelButtonGroup->button(settings.value("browser/TileLabel").toInt())->setChecked(true);

	if ( settings.contains("browser/TileZoom") )
		tileZoomButtonGroup->button(settings.value("browser/TileZoom").toInt())->setChecked(true);

	//GroupBox checkedIdChanged subscription
    connect(tileTypeButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(on_tileTypeButtonGroup_clicked(int)));
	connect(tileTextureButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(on_tileTextureButtonGroup_clicked(int)));
    connect(tileLabelButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(on_tileLabelButtonGroup_clicked(int)));
    connect(tileZoomButtonGroup, SIGNAL(buttonClicked(int)), this, SLOT(on_tileZoomButtonGroup_clicked(int)));

	//Tile View Model
	tileViewModel = new tiles_model(this);
    ui.tileBrowserListView->setModel(tileViewModel);
	connect(ui.tileBrowserListView->selectionModel(), SIGNAL(selectionChanged( const QItemSelection &, const QItemSelection & )), this, SLOT(on_tiles_model_selectionChanged(const QItemSelection &, const QItemSelection & )));

	// Tile Set
	browserModel._tileSet = tileSetIndex;

	// 128 Tiles
	int _128Count = tileBankBrowser.getTileSet (tileSetIndex)->getNumTile128 ();
	browserModel.theList128.resize (_128Count);
	for (int i=0; i<_128Count; i++)
	{
		browserModel.theList128[i].Init(i, _128x128);
	}
	browserModel.Reload (0, _128Count, _128x128);

	// 256 Tiles
	int _256Count = tileBankBrowser.getTileSet (tileSetIndex)->getNumTile256 ();
	browserModel.theList256.resize (_256Count);
	for (int i=0; i<_256Count; i++)
	{
		browserModel.theList256[i].Init(i, _256x256);
	}
	browserModel.Reload (0, _256Count, _256x256);

	// Transition Tiles
	for (int i=0; i<CTileSet::count; i++)
	{
		browserModel.theListTransition[i].Init(i, Transition);
	}
	browserModel.Reload (0, CTileSet::count, Transition);

	// Displacement Tiles
	for (int i=0; i<CTileSet::CountDisplace; i++)
	{
		browserModel.theListDisplacement[i].Init(i, Displace);
	}
	browserModel.Reload (0, CTileSet::CountDisplace, Displace);


	LoadInThread();

}
Example #21
0
void Browse::Init()
{		
	UpdateData ();
	lbutton = 0;
	selection = 0;
	control = 0;
	m_ctrl.lockInsertion = 0; oldsel = -1;
	HKEY regkey; 
	unsigned long value; 
	unsigned long type; 
	int cx=-1,cy=-1,x=-1,y=-1;
	char sWindowpl[256];

	if (RegOpenKey(HKEY_CURRENT_USER,REGKEY_TILEDIT,&regkey)==ERROR_SUCCESS)
	{		
		value=256;
		type=REG_SZ;
		if (RegQueryValueEx(regkey,REGKEY_WNDPL,0,&type,(unsigned char *)&sWindowpl,&value)==ERROR_SUCCESS)
		{
			WINDOWPLACEMENT wndpl;
			sscanf(sWindowpl,"%d %d %d %d %d %d %d %d %d %d",
						&wndpl.flags,
						&wndpl.ptMaxPosition.x,&wndpl.ptMaxPosition.y,
						&wndpl.ptMinPosition.x,&wndpl.ptMinPosition.y,
						&wndpl.rcNormalPosition.bottom,&wndpl.rcNormalPosition.left,&wndpl.rcNormalPosition.right,&wndpl.rcNormalPosition.top,
						&wndpl.showCmd);
			wndpl.length = sizeof(WINDOWPLACEMENT);
			this->SetWindowPlacement(&wndpl);
		}
		value=256;
		type=REG_SZ;
		if (RegQueryValueEx(regkey,REGKEY_LASTPATH,0,&type,(unsigned char *)&sWindowpl,&value)!=ERROR_SUCCESS)
			m_ctrl.LastPath="";
		else
			m_ctrl.LastPath=(const char*)sWindowpl;
		value=4;
		type=REG_DWORD;
		if (RegQueryValueEx(regkey,REGKEY_BUTTONZOOM,0,&type,(unsigned char *)&m_ctrl.Zoom,&value)!=ERROR_SUCCESS) 
			m_ctrl.Zoom = 3;
		value=4;
		type=REG_DWORD;
		if (RegQueryValueEx(regkey,REGKEY_BUTTONVARIETY,0,&type,(unsigned char *)&m_128x128,&value)!=ERROR_SUCCESS) 
			m_128x128 = 0;
		value=4;
		type=REG_DWORD;
		if (RegQueryValueEx(regkey,REGKEY_BUTTONTEXTURE,0,&type,(unsigned char *)&m_ctrl.Texture,&value)!=ERROR_SUCCESS) 
			m_ctrl.Texture = 1;
		value=4;
		type=REG_DWORD;
		if (RegQueryValueEx(regkey,REGKEY_BUTTONTEXTINFO,0,&type,(unsigned char *)&m_ctrl.InfoTexte,&value)!=ERROR_SUCCESS) 
			m_ctrl.InfoTexte = 1;
		RegCloseKey(regkey);
	}		
	CButton *button = (CButton*)GetDlgItem(IDC_ZOOM1 + m_ctrl.Zoom -1);
	button->SetCheck(1);
	button = (CButton*)GetDlgItem(IDC_JOUR + m_ctrl.Texture -1);
	button->SetCheck(1);
	button = (CButton*)GetDlgItem(IDC_INFONUM + m_ctrl.InfoTexte -1);
	button->SetCheck(1);	
	if (cx!=-1 && cy!=-1 && x!=-1 && y!=-1) SetWindowPos(0,x,y,cx,cy,0);

	m_ctrl.Init(land, m_128x128);
	SelectionTerritoire *slt = (SelectionTerritoire*)GetParent();
	ccount=1;
	
	RECT rect;
	this->GetWindowRect(&rect);
	SendMessage(WM_SIZE,rect.right - rect.left,rect.bottom - rect.top); //force resize

	SelectionTerritoire *parent = (SelectionTerritoire*)GetParent();

	// The land	
	CTileSet *tileSet=tileBank2.getTileSet (land);

	if (tileSet->getOriented())
		Oriented = 1;
	else
		Oriented = 0;
	
	// 128
	m_ctrl.InfoList.theList128.resize (tileSet->getNumTile128 ());
	int i;
	for (i=0; i<tileSet->getNumTile128 (); i++)
	{
		m_ctrl.InfoList.theList128[i].id=i;
		m_ctrl.InfoList.theList128[i].Selected=0;
		m_ctrl.InfoList.theList128[i].loaded=0;
		m_ctrl.InfoList.theList128[i].nightLoaded=0;
		m_ctrl.InfoList.theList128[i].alphaLoaded=0;
	}
	m_ctrl.InfoList.Reload (0, tileSet->getNumTile128 (), 0);

	// 256
	m_ctrl.InfoList.theList256.resize (tileSet->getNumTile256 ());
	for (i=0; i<tileSet->getNumTile256 (); i++)
	{
		m_ctrl.InfoList.theList256[i].id=i;
		m_ctrl.InfoList.theList256[i].Selected=0;
		m_ctrl.InfoList.theList256[i].loaded=0;
		m_ctrl.InfoList.theList256[i].nightLoaded=0;
		m_ctrl.InfoList.theList256[i].alphaLoaded=0;
	}
	m_ctrl.InfoList.Reload (0, tileSet->getNumTile256 (), 1);

	// Transition
	for (i=0; i<CTileSet::count; i++)
	{
		m_ctrl.InfoList.theListTransition[i].id=i;
		m_ctrl.InfoList.theListTransition[i].Selected=0;
		m_ctrl.InfoList.theListTransition[i].loaded=0;
		m_ctrl.InfoList.theListTransition[i].nightLoaded=0;
		m_ctrl.InfoList.theListTransition[i].alphaLoaded=0;
	}
	m_ctrl.InfoList.Reload (0, CTileSet::count, 2);

	// Displacement
	for (i=0; i<CTileSet::CountDisplace; i++)
	{
		m_ctrl.InfoList.theListDisplacement[i].id=i;
		m_ctrl.InfoList.theListDisplacement[i].Selected=0;
		m_ctrl.InfoList.theListDisplacement[i].loaded=0;
		m_ctrl.InfoList.theListDisplacement[i].nightLoaded=0;
		m_ctrl.InfoList.theListDisplacement[i].alphaLoaded=0;
	}
	m_ctrl.InfoList.Reload (0, CTileSet::CountDisplace, 3);

	CString fullpath = parent->DefautPath + parent->CurrentTerritory;
	
	LoadInThread();
	UpdateData (FALSE);
	
	OnChangeVariety();
}
Example #22
0
unsigned long Browse::MyControllingFunction( void* pParam )
{
	thread_actif = 1;
	Browse *br = (Browse*)pParam;
	br->m_ctrl.lockInsertion = 1;
	int iFV,iLV;
	br->m_ctrl.GetVisibility(iFV, iLV, br->m_128x128);
	br->m_ctrl.UpdateBar(iFV, iLV, br->m_128x128);
	tilelist::iterator p = br->m_ctrl.InfoList.GetFirst(br->m_128x128);
	tilelist::iterator plast = p;
	for (int i=0;i<br->m_ctrl.InfoList.GetSize(br->m_128x128);i++)
	{
		int *ld; 
		int rot=0;
		std::string path;
		LPBITMAPINFO pBmp; 
		std::vector<NLMISC::CBGRA>* bits;

		switch (br->m_128x128)
		{
		case 0:
			path = tileBank2.getTile (tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getTile128 (i))->
				getRelativeFileName ((CTile::TBitmap)(br->m_ctrl.Texture-1));
			break;
		case 1:
			path = tileBank2.getTile (tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getTile256 (i))->
				getRelativeFileName ((CTile::TBitmap)(br->m_ctrl.Texture-1));
			break;
		case 2:
			{
				int index=tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getTransition (i)->getTile();
				if (index!=-1)
				{
					path = tileBank2.getTile (index)->getRelativeFileName ((CTile::TBitmap)(br->m_ctrl.Texture-1));
					if (br->m_ctrl.Texture==3)
						rot = tileBank2.getTile (index)->getRotAlpha ();
				}
				else
					path = "";
			}
			break;
		case 3:
			// Get diplacement filename
			path = tileBank2.getDisplacementMap (tileBank2.getTileSet (br->m_ctrl.InfoList._tileSet)->getDisplacementTile ((CTileSet::TDisplacement)i));
			break;
		}
		std::vector<NLMISC::CBGRA>* pAlpha=NULL;
		switch (br->m_ctrl.Texture)
		{
		case 1:
			ld = &p->loaded;
			pBmp = &p->BmpInfo;
			bits = &p->Bits;
			pAlpha = &p->alphaBits;
			break;
		case 2:
			ld = &p->nightLoaded;
			pBmp = &p->nightBmpInfo;
			bits = &p->nightBits;
			pAlpha = &p->alphaBits;
			break;
		case 3:
			ld = &p->alphaLoaded;
			pBmp = &p->alphaBmpInfo;
			bits = &p->alphaBits;
			break;
		}

		if ((path!="") && _LoadBitmap(tileBank2.getAbsPath() + path, pBmp, *bits, pAlpha, rot))
		{			
			*ld=1;
			int iFV,iLV; br->m_ctrl.GetVisibility(iFV, iLV, br->m_128x128);
			if (i<=iLV && i>=iFV) 
			{
				CDC *pDC = br->m_ctrl.GetDC();
				br->m_ctrl.DrawTile(p,pDC,1,br->m_128x128);
				::ReleaseDC(*br,*pDC);
			}
		}
		p++;
	}
	br->m_ctrl.lockInsertion = 0;
	thread_actif = 0;
	return 1;
}
Example #23
0
void Browse::OnImportBorder() 
{
	// Select a file
	CFileDialog sFile (true, NULL, NULL, OFN_ENABLESIZING,
		"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
	if (sFile.DoModal()==IDOK)
	{
		// Get the border of the bank
		std::vector<NLMISC::CBGRA> array(128*128);

		// The bitmap
		NLMISC::CBitmap bitmap;

		// Read the bitmap
		bool error=false;
		CString pathName=sFile.GetPathName();
		try
		{
			CIFile file;
			if (file.open ((const char*)pathName))
			{
				// Export
				bitmap.load (file);
			}
			else
				error=true;
		}
		catch (Exception& e)
		{
			const char *toto=e.what ();
			error=true;
		}

		// Error during import ?
		if (error)
		{
			// Error message
			char tmp[512];
			sprintf (tmp, "Can't read bitmap %s", (const char*)pathName);
			MessageBox (tmp, "Import border", MB_OK|MB_ICONEXCLAMATION);
		}

		// Get pixel
		CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];

		// Good size
		if ((bitmap.getWidth()==128)&&(bitmap.getHeight()==128))
		{
			// Make a copy
			for (int i=0; i<128*128; i++)
			{
				// Copy the pixel
				array[i].R=pPixel->R;
				array[i].G=pPixel->G;
				array[i].B=pPixel->B;
				array[i].A=pPixel->A;
				pPixel++;
			}
		}
		else
		{
			// Error message
			char tmp[512];
			sprintf (tmp, "The bitmap must have a size of 128x128 (%s)", (const char*)pathName);
			MessageBox (tmp, "Import border", MB_OK|MB_ICONEXCLAMATION);
		}

		// 256 or 128 ?
		CTileBorder border;
		border.set (128, 128, array);
		tileBank2.getTileSet (land)->setBorder (m_ctrl.Texture==1?CTile::diffuse:CTile::additive, border);

		// Message
		MessageBox ("The border has been changed.", "Import border", MB_OK|MB_ICONINFORMATION);
	}
}
Example #24
0
void Browse::OnExportBorder() 
{
	// Select a file
	CFileDialog sFile (false, NULL, NULL, OFN_ENABLESIZING,
		"Targa bitmap (*.tga)|*.tga|All files (*.*)|*.*||",NULL);
	if (sFile.DoModal()==IDOK)
	{
		// Get the border of the bank
		std::vector<NLMISC::CBGRA> array;

		// 256 or 128 ?
		int width, height;
		tileBank2.getTileSet (land)->getBorder128 (m_ctrl.Texture==1?CTile::diffuse:CTile::additive)->get (width, height, array);

		// Make a bitmap
		if (width&&height)
		{
			NLMISC::CBitmap bitmap;
			bitmap.resize (width, height, NLMISC::CBitmap::RGBA);

			// Get pixel
			CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];

			// Make a copy
			for (int i=0; i<width*height; i++)
			{
				// Copy the pixel
				pPixel->R=array[i].R;
				pPixel->G=array[i].G;
				pPixel->B=array[i].B;
				pPixel->A=array[i].A;
				pPixel++;
			}

			// Write the bitmap
			bool error=false;
			CString pathName=sFile.GetPathName();
			try
			{
				COFile file;
				if (file.open ((const char*)pathName))
				{
					// Export
					bitmap.writeTGA (file, 32);
				}
				else
					error=true;
			}
			catch (Exception& e)
			{
				const char *toto=e.what ();
				error=true;
			}

			// Error during export ?
			if (error)
			{
				// Error message
				char tmp[512];
				sprintf (tmp, "Can't write bitmap %s", (const char*)pathName);
				MessageBox (tmp, "Export border", MB_OK|MB_ICONEXCLAMATION);
			}
		}
	}
}
Example #25
0
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);
		}
	}
}
Example #26
0
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
	}
}
//TODO titegus: What's the point in Importing a new border if there is no Pixel Compatibility check ?
void CTile_browser_dlg::on_importBorderPushButton_clicked()
{
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
	
	if (!fileName.isEmpty())
	{
		fileName = QDir::toNativeSeparators(fileName);
		// Get the border of the bank
		std::vector<NLMISC::CBGRA> array(128*128);

		// The bitmap
		NLMISC::CBitmap bitmap;

		// Read the bitmap
		bool error=false;
		try
		{
			CIFile file;
			if (file.open (fileName.toStdString().c_str()))
			{
				// Export
				bitmap.load (file);
			}
			else
				error=true;
		}
		catch (Exception& e)
		{
			const char *toto=e.what ();
			error=true;
		}

		// Error during import ?
		if (error)
		{
			// Error message
			QString s = tr("Can't read bitmap %1").arg(fileName);
			QMessageBox::information (this, tr("Import border"), s);
		}

		// Get pixel
		CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];

		// Good size
		if ((bitmap.getWidth()==128)&&(bitmap.getHeight()==128))
		{
			// Make a copy
			for (int i=0; i<128*128; i++)
			{
				// Copy the pixel
				array[i].R=pPixel->R;
				array[i].G=pPixel->G;
				array[i].B=pPixel->B;
				array[i].A=pPixel->A;
				pPixel++;
			}
		}
		else
		{
			// Error message
			QString s = tr("The bitmap must have a size of 128x128 (%1)").arg(fileName);
			QMessageBox::information (this, tr("Import border"), s);
		}

		// 256 or 128 ?
		CTileBorder border;
		border.set (128, 128, array);
		tileBankBrowser.getTileSet (tileSetIndex)->setBorder ((CTile::TBitmap) tileTextureButtonGroup->checkedId(), border);

		// Message
		QMessageBox::information (this, tr("Import border"), tr("The border has been changed."));
	}

}
void CTile_browser_dlg::on_batchLoadPushButton_clicked()
{
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getOpenFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , tr("Targa Bitmap (*.tga);;PNG Image (*.png);;All Files (*.*);;"), &selectedFilter, options);
	QFileInfo fi(fileName);
	QString baseName = fi.baseName() ;


	if (!fileName.isEmpty())
	{
		QRegExp rx("\\d{2}$");
		baseName = baseName.remove(rx);
	
		
		//TODO titegus: What's the point in asking for rotation if Texture != Alpha ???
		bool rotate = (QMessageBox::Yes == QMessageBox::question(this, tr("Import rotated tiles"), tr("Do you want to use rotation to reuse alpha tiles?"), QMessageBox::Yes | QMessageBox::No ));

		for (int i=0; i<CTileSet::count; i++)
		{
			if (tileTextureButtonGroup->checkedId() == Alpha)
			{
				// Current transition
				CTileSet::TTransition transition=(CTileSet::TTransition)i;



				// Transition to patch
				CTileSetTransition* trans=tileBankBrowser.getTileSet (tileSetIndex)->getTransition (transition);
				if (tileBankBrowser.getTile (trans->getTile())->getRelativeFileName (CTile::alpha)=="")
				{
					// Continue ?
					int ok;

					// Try to load transition with rotation
					for (int rot=0; rot<4; rot++)
					{
						// Try to load a tile with a file name like /tiletransition0.tga
						QString transitionNumber = QString::number(transition);
						QString batchNumber = transitionNumber.rightJustified(2, '0');
						QString nextBaseName = baseName + batchNumber;
						QString nextFileName = QDir::toNativeSeparators(fi.absolutePath()) + QDir::separator() + nextBaseName + QString(".") + fi.suffix();
						FILE *pFile=fopen (nextFileName.toStdString().c_str(), "rb");

						// Close the file and add the tile if opened
						if (pFile)
						{
							fclose (pFile);
							ok=browserModel.setTileTransitionAlpha (i, nextFileName.toStdString().c_str(), (4-rot)%4);

							// End
							break;
						}

						// Rotate the transition
						transition=CTileSet::rotateTransition (transition);

						if (!rotate)
							break;
					}
					if (!ok)
						break;
				}
			}
			else
			{

				//TODO titegus: Check that, Batch Load seems useless
				// Current transition
				CTileSet::TTransition transition=(CTileSet::TTransition)i;

				// Transition to patch
				//CTileSetTransition* trans=tileBankBrowser.getTileSet (tileSetIndex)->getTransition (transition);
				//if (tileBankBrowser.getTile (trans->getTile())->getRelativeFileName ((CTile::TBitmap)tileTextureButtonGroup->checkedId())=="")
				//{
				//	// Try to load a tile with a file name like /tiletransition0.tga
				//	char sName2[256];
				//	char sFinal[256];
				//	sprintf (sName2, "%s%02d", sName, (int)transition);
				//	_makepath (sFinal, sDrive, sPath, sName2, sExt);
				//	FILE *pFile=fopen (sFinal, "rb");

				//	// Close the file and add the tile if opened
				//	if (pFile)
				//	{
				//		fclose (pFile);
				//		if (!infoList.setTileTransition (i, sFinal, (CTile::TBitmap) tileTextureButtonGroup->checkedId()))
				//			break;
				//	}
				//}
			}
		}
		

		LoadInThread();

	}
}
void CTile_browser_dlg::on_actionReplaceImage_triggered(bool checked)
{
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getOpenFileName(this, "Choose Bitmap", QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
	
	if (!fileName.isEmpty())
	{
		bool ok = false;
		fileName = QDir::toNativeSeparators(fileName);
		switch (tileTypeButtonGroup->checkedId())
		{
			case _128x128:
				for (int i=0; i<ui.tileBrowserListView->selectionModel()->selectedRows().count(); i++)
				{
					int tileId = (ui.tileBrowserListView->selectionModel()->selectedRows().at(i).data(Qt::UserRole + 1)).toInt();
					
					if ( ! browserModel.setTile128 ( tileId, fileName.toStdString(), (CTile::TBitmap) tileTextureButtonGroup->checkedId()) )
						break;
				}
				break;
			case _256x256:
				for (int i=0; i<ui.tileBrowserListView->selectionModel()->selectedRows().count(); i++)
				{
					int tileId = (ui.tileBrowserListView->selectionModel()->selectedRows().at(i).data(Qt::UserRole + 1)).toInt();
					if ( ! browserModel.setTile256 (tileId, fileName.toStdString(), (CTile::TBitmap) tileTextureButtonGroup->checkedId()) )
						break;
				}
				break;
			case Transition:
				for (int i=0; i<ui.tileBrowserListView->selectionModel()->selectedRows().count(); i++)
				{
					int tileId = (ui.tileBrowserListView->selectionModel()->selectedRows().at(i).data(Qt::UserRole + 1)).toInt();
					if ( tileTextureButtonGroup->checkedId() != Alpha )
					{
						if ( ! browserModel.setTileTransition (tileId, fileName.toStdString(), (CTile::TBitmap) tileTextureButtonGroup->checkedId()) )
							break;
					}
					else
					{
						bool rotationOk = false;
						int rot = CTile_rotation_dlg::getRotation(this, &rotationOk);
						if (rotationOk)
						{
							if ( ! browserModel.setTileTransitionAlpha (tileId, fileName.toStdString(), rot) )
								break;
						}
					}
				}
				break;
			case Displace:
				for (int i=0; i<ui.tileBrowserListView->selectionModel()->selectedRows().count(); i++)
				{
					int tileId = (ui.tileBrowserListView->selectionModel()->selectedRows().at(i).data(Qt::UserRole + 1)).toInt();
					if ( ! browserModel.setDisplacement (tileId, fileName.toStdString(), (CTile::TBitmap) tileTextureButtonGroup->checkedId()) )
						break;
				}
				break;
			default:
				nlassert (0); // no!
		}

		LoadInThread();
	}
}
//TODO titegus: replace that by 4 buttons Export128Diffuse, Export128Additive, Export256Diffuse, Export256Diffuse ?
void CTile_browser_dlg::on_exportBorderPushButton_clicked()
{
	// Select a file
	QFileDialog::Options options;
	QString selectedFilter;
	QString fileName = QFileDialog::getSaveFileName(this, tr("Choose Bitmap"), QString(tileBankBrowser.getAbsPath().c_str()) , "Targa Bitmap(*.tga);;All Files (*.*);;", &selectedFilter, options);
	
	if (!fileName.isEmpty())
	{
		fileName = QDir::toNativeSeparators(fileName);
		// Get the border of the bank
		std::vector<NLMISC::CBGRA> array;

		// 256 or 128 ?
		int width, height;
		//TODO titegus: And So what if Alpha ??? and what about border256 ???
		tileBankBrowser.getTileSet (tileSetIndex)->getBorder128 ((CTile::TBitmap)tileTextureButtonGroup->checkedId())->get (width, height, array);

		// Make a bitmap
		if (width&&height)
		{
			NLMISC::CBitmap bitmap;
			bitmap.resize (width, height, NLMISC::CBitmap::RGBA);

			// Get pixel
			CRGBA *pPixel=(CRGBA*)&bitmap.getPixels()[0];

			// Make a copy
			for (int i=0; i<width*height; i++)
			{
				// Copy the pixel
				pPixel->R=array[i].R;
				pPixel->G=array[i].G;
				pPixel->B=array[i].B;
				pPixel->A=array[i].A;
				pPixel++;
			}

			// Write the bitmap
			bool error=false;
			try
			{
				COFile file;
				if (file.open (fileName.toStdString().c_str()))
				{
					// Export
					bitmap.writeTGA (file, 32);
				}
				else
					error=true;
			}
			catch (Exception& e)
			{
				const char *toto=e.what ();
				error=true;
			}

			// Error during export ?
			if (error)
			{
				// Error message
				QString s = tr("Can't write bitmap %1").arg(fileName);
				QMessageBox::information (this, tr("Export border"), s);
			}
		}
	}

}