Exemplo n.º 1
0
void FindReplaceTextures( const char* pFind, const char* pReplace, bool bSelected, bool bForce )
{
	brush_s* pList = ( bSelected ) ? &selected_brushes : &active_brushes;
	if ( !bSelected )
	{
		Select_Deselect();
	}
	
	for ( brush_s* pBrush = pList->next ; pBrush != pList; pBrush = pBrush->next )
	{
		if ( pBrush->patchBrush )
		{
			Patch_FindReplaceTexture( pBrush, pFind, pReplace, bForce );
		}
		
		for ( face_s* pFace = pBrush->brush_faces; pFace; pFace = pFace->next )
		{
			if ( bForce || strcmpi( pFace->texdef.name, pFind ) == 0 )
			{
				pFace->d_texture = Texture_ForName( pReplace );
				//strcpy(pFace->texdef.name, pReplace);
				pFace->texdef.SetName( pReplace );
			}
		}
		Brush_Build( pBrush );
	}
	Sys_UpdateWindows( W_CAMERA );
}
Exemplo n.º 2
0
// return is simply a count of how many texture replacements took place, only used for friendly-stats on completion...
//
// the arg list for this is getting pretty gay now, the reason being that the various update-windows routines that
//	radiant has don't work like windows ones, where paint messages are just issued then it returns instantly 
//	(and eliminates dup paint calls), radiant actually goes off and performs them, so I need to stop it doing that 
//	when calling this in the middle of a loop...
//
int FindReplaceTextures(const char* pFind, const char* pReplace, bool bSelected, bool bForce, bool bReScale, bool bSelectOnlyNoReplace,
						bool bInhibitCameraUpdate /*= false*/,
						bool bCalledDuringLoopAndNotFirstTime /*= false*/	// sigh, but saves an update-all-windows call
						)
{
	int iReplacedCount = 0;

	if (bSelectOnlyNoReplace)
	{
		bSelected = false;
		bForce = false;
	}
	
	const brush_t* const pList = (bSelected) ? &selected_brushes : &active_brushes;
	if (!bSelected)
	{
		if (!bCalledDuringLoopAndNotFirstTime)
			Select_Deselect();
	}
	
	const qtexture_t * const pReplaceTex = Texture_ForName(pReplace);


	// count them first, so I can show progress..
	//
	int iBrushCount = 0;
	for (brush_t* pBrush = pList->next ; pBrush != pList; pBrush = pBrush->next)
	{
		iBrushCount++;
	}

	Sys_Printf("\n");
	brush_t* pNextBrush = pList->next->prev;	// doesn't matter what value assigned here really. Note sneaky workaround here because can't point at non-const item, so use next->prev
	for (pBrush = pList->next ; pBrush != pList; pBrush = pNextBrush)
	{
		pNextBrush = pBrush->next;

		// just so they don't think it's locked up...
		//
		if ( !((iBrushCount--) & 15))
		{
			Sys_Printf(".");
		}
		OutputDebugString(va("iBrushCount = %d\n",iBrushCount));
		

		if (pBrush->patchBrush)
		{
			if (bSelectOnlyNoReplace)
			{
				if (!stricmp(pFind,Patch_FromBrush_GetTextureName(pBrush)))
				{
					g_bScreenUpdates = false;	// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
					Select_Brush(pBrush, false);
					g_bScreenUpdates = true;	// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
					continue;
				}
			}
			else
			{
				iReplacedCount += (Patch_FindReplaceTexture(pBrush, pFind, pReplace, bForce))?1:0;
			}
		}
		
		for (face_t* pFace = pBrush->brush_faces; pFace; pFace = pFace->next)
		{
			if(bForce || strcmpi(pFace->texdef.name, pFind) == 0)
			{
				iReplacedCount++;
				if (bSelectOnlyNoReplace)
				{
					g_bScreenUpdates = false;	// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
					Select_Brush(pBrush, false);
					g_bScreenUpdates = true;	// !!!!!!!!!!!!!!!!!!!!!!!!!!!!
					break;
				}
				else
				{
					if (bReScale)
					{
						if (pFace->d_texture == pReplaceTex)
						{//not changing textures, so reset the scale instead
							const float fXAspect = fTEXTURE_SCALE / (float) pFace->texdef.scale[0];
							const float fYAspect = fTEXTURE_SCALE / (float) pFace->texdef.scale[1];
							
							pFace->texdef.scale[0] = fTEXTURE_SCALE;
							pFace->texdef.scale[1] = fTEXTURE_SCALE;
							
							pFace->texdef.shift[0] /= fXAspect;
							pFace->texdef.shift[1] /= fYAspect;
						}
						else
						{
							const float fXAspect = (float)(pFace->d_texture->width)  / (float) pReplaceTex->width;
							const float fYAspect = (float)(pFace->d_texture->height) / (float) pReplaceTex->height;
							
							pFace->texdef.scale[0] *= fXAspect;
							pFace->texdef.scale[1] *= fYAspect;
							
							pFace->texdef.shift[0] /= fXAspect;
							pFace->texdef.shift[1] /= fYAspect;
						}
					}
					strcpy(pFace->texdef.name, pReplace);
					pFace->d_texture = (qtexture_t *)pReplaceTex;
				}
			}
		}
		if (!bSelectOnlyNoReplace)
		{
			Brush_Build(pBrush);
		}
	}
	Sys_Printf("\n");
	
	if (!bInhibitCameraUpdate)
	{
		Sys_UpdateWindows (W_CAMERA);
	}

	return iReplacedCount;
}