示例#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;
}
示例#2
0
文件: Browse.cpp 项目: mixxit/solinia
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);
			}
		}
	}
}
示例#3
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 ...") );
	}
}
示例#4
0
文件: Browse.cpp 项目: mixxit/solinia
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);
}
示例#5
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 ...") );
	}
}
示例#6
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 ...") );
		}
	}
}
示例#7
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() ) );
	}
}
示例#8
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 ...") );
		}
	}
}
示例#9
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 ...") );
	}
}
示例#10
0
文件: Browse.cpp 项目: mixxit/solinia
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 ();

	}
}
//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);
			}
		}
	}

}
示例#12
0
文件: Browse.cpp 项目: mixxit/solinia
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();
}
示例#13
0
文件: Browse.cpp 项目: mixxit/solinia
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;
}
示例#14
0
文件: Browse.cpp 项目: mixxit/solinia
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);
	}
}
示例#15
0
文件: Browse.cpp 项目: mixxit/solinia
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);
			}
		}
	}
}
//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::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();

}
示例#18
0
文件: Browse.cpp 项目: mixxit/solinia
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);
}
示例#19
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);
		}
	}
}
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();

	}
}