Пример #1
0
//-----------------------------------------------------------------------------
// Populate element choice lists
//-----------------------------------------------------------------------------
bool CVcdBlockDoc::GetElementChoiceList( const char *pChoiceListType, CDmElement *pElement, 
									 const char *pAttributeName, bool bArrayElement, ElementChoiceList_t &list )
{
	if ( !Q_stricmp( pChoiceListType, "allelements" ) )
	{
		AddElementsRecursively( m_hEditRoot, list );
		return true;
	}

	if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
	{
		const CDmrElementArray<> entities = GetEntityList();

		bool bFound = false;
		int nCount = entities.Count();
		for ( int i = 0; i < nCount; ++i )
		{
			CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
			if ( !V_stricmp( pNode->GetClassName(), "info_target" ) )
			{
				bFound = true;
				ElementChoice_t sChoice;
				sChoice.m_pValue = pNode;
				sChoice.m_pChoiceString = pNode->GetTargetName();
				list.AddToTail( sChoice );
			}
		}
		return bFound;
	}

	// by default, try to treat the choice list type as a Dme element type
	AddElementsRecursively( m_hEditRoot, list, pChoiceListType );

	return list.Count() > 0;
}
Пример #2
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &vecStart - 
//			&vecEnd - 
// Output : CDmeVMFEntity
//-----------------------------------------------------------------------------
CDmeVMFEntity *CVcdBlockDoc::GetInfoTargetForLocation( Vector &vecStart, Vector &vecEnd )
{
	Vector vecDelta;
	float flEndDist;

	vecDelta = vecEnd - vecStart;
	flEndDist = VectorNormalize( vecDelta );

	CDmeVMFEntity *pSelectedNode = NULL;
	float flMinDistFromLine = 1E30;

	const CDmrElementArray<CDmElement> entities = GetEntityList();
	int nCount = entities.Count();
	for ( int i = 0; i < nCount; ++i )
	{
		CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
		float flDistAway = DotProduct( pNode->GetRenderOrigin() - vecStart, vecDelta );

		if (flDistAway > 0.0 && flDistAway < flEndDist)
		{
			float flDistFromLine = (pNode->GetRenderOrigin() - vecStart - vecDelta * flDistAway).Length();
			if (flDistFromLine < flMinDistFromLine)
			{
				pSelectedNode = pNode;
				flMinDistFromLine = flDistFromLine;
			}
		}
	}
	return pSelectedNode;
}
Пример #3
0
//-----------------------------------------------------------------------------
// Populate string choice lists
//-----------------------------------------------------------------------------
bool CVcdBlockDoc::GetStringChoiceList( const char *pChoiceListType, CDmElement *pElement, 
									const char *pAttributeName, bool bArrayElement, StringChoiceList_t &list )
{
	if ( !Q_stricmp( pChoiceListType, "info_targets" ) )
	{
		const CDmrElementArray<> entities = GetEntityList();

		StringChoice_t sChoice;
		sChoice.m_pValue = "";
		sChoice.m_pChoiceString = "";
		list.AddToTail( sChoice );

		int nCount = entities.Count();
		for ( int i = 0; i < nCount; ++i )
		{
			CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
			if ( !V_stricmp( pNode->GetClassName(), "info_target" ) )
			{
				StringChoice_t sChoice;
				sChoice.m_pValue = pNode->GetTargetName();
				sChoice.m_pChoiceString = pNode->GetTargetName();
				list.AddToTail( sChoice );
			}
		}
		return true;
	}

	return false;
}
Пример #4
0
//---------------------------------------------------------------
// Purpose: 
//---------------------------------------------------------------
void CeditorDoc::DeleteSelectedEntity( void )
{
	CEditorEntityList *list = GetEntityList();

	for( UINT i = 0; i < m_selectedEnts.size(); i++ )
		list->RemoveEntity(m_selectedEnts[i], true);

	m_selectedEnts.clear();
	SetModified();
	UpdatePropertiesWnd();
	//UpdateAllViews(NULL);
}
Пример #5
0
//-----------------------------------------------------------------------------
// The server just loaded, populate the list with the entities is has
//-----------------------------------------------------------------------------
void CVcdBlockDoc::ServerLevelInitPostEntity( void )
{
	CDmrElementArray<> entityList = GetEntityList();

	if ( entityList.Count() )
	{
		VerifyAllEdits( entityList );
	}
	else
	{
		InitializeFromServer( entityList );
	}
}
Пример #6
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : &vecOrigin - 
//			&angAbsAngles - 
// Output : CDmeVMFEntity
//-----------------------------------------------------------------------------
CDmeVMFEntity *CVcdBlockDoc::GetInfoTargetForLocation( Vector &vecOrigin, QAngle &angAbsAngles )
{
	const CDmrElementArray<> entities = GetEntityList();
	int nCount = entities.Count();
	for ( int i = 0; i < nCount; ++i )
	{
		CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
		Vector &vecAngles = *(Vector*)(&pNode->GetRenderAngles());
		if ( pNode->GetRenderOrigin().DistTo( vecOrigin ) < 1e-3 && vecAngles.DistTo( *(Vector*)&angAbsAngles ) < 1e-1 )
			return pNode;
	}

	return NULL;
}
Пример #7
0
//-----------------------------------------------------------------------------
// Deletes a commentary node
//-----------------------------------------------------------------------------
void CVcdBlockDoc::DeleteInfoTarget( CDmeVMFEntity *pNode )
{
	CDmrElementArray<CDmElement> entities = GetEntityList();
	int nCount = entities.Count();
	for ( int i = 0; i < nCount; ++i )
	{
		if ( pNode == entities[i] )
		{
			CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Delete Info Target", "Delete Info Target" );
			CDmeVMFEntity *pNode = CastElement< CDmeVMFEntity >( entities[ i ] );
			pNode->DrawInEngine( false );
			entities.FastRemove( i );
			return;
		}
	}
}
Пример #8
0
BOOL CeditorDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	//SetModifiedFlag();
	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	Init();

	CEditorEntity *pEnt = GetEntityList()->InsertNewEntity( "world" );

	SetModified();

	return TRUE;
}
Пример #9
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CVcdBlockDoc::AddNewInfoTarget( const Vector &vecOrigin, const QAngle &angAngles )
{
	CDmrElementArray<> entities = GetEntityList();

	CDmeVMFEntity *pTarget;
	{
		CAppUndoScopeGuard guard( NOTIFY_SETDIRTYFLAG, "Add Info Target", "Add Info Target" );

		pTarget = CreateElement<CDmeVMFEntity>( "", entities.GetOwner()->GetFileId() );
		pTarget->SetValue( "classname", "info_target" );
		pTarget->SetRenderOrigin( vecOrigin );
		pTarget->SetRenderAngles( angAngles );

		entities.AddToTail( pTarget );
		pTarget->MarkDirty();
		pTarget->DrawInEngine( true );
	}

	g_pVcdBlockTool->GetInfoTargetBrowser()->SelectNode( pTarget );
}
Пример #10
0
//-----------------------------------------------------------------------------
// Load the VMF file, merge in all the edits, write it back out
//-----------------------------------------------------------------------------
bool CVcdBlockDoc::CopyEditsToVMF( )
{
	const CDmrElementArray<CDmElement> entityList = GetEntityList();
	
	CDmElement *pVMF = NULL;
	DmFileId_t fileid = g_pDataModel->FindOrCreateFileId( m_pVMFFileName );
	if ( g_pDataModel->RestoreFromFile( m_pVMFFileName, NULL, "vmf", &pVMF ) == DMFILEID_INVALID )
	{
		// needs some kind of error message
		return false;
	}

	CDmrElementArray<CDmElement> vmfEntities( pVMF, "entities" );

	int nVMFCount = vmfEntities.Count();
	for (int i = 0; i < nVMFCount; i++)
	{
		CDmElement *pVMFEntity = vmfEntities[i];

		char classname[256];
		pVMFEntity->GetValueAsString( "classname", classname, sizeof( classname ) );

		if ( Q_stricmp( "info_target", classname ) )
			continue;

		int nHammerID = atoi( pVMFEntity->GetName() );

		// find a match.
		int nCount = entityList.Count();
		for (int j = 0; j < nCount; j++)
		{
			CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[j] );

			if ( pEntity->IsDirty() && pEntity->GetEntityId() == nHammerID)
			{
				char text[256];
				pEntity->GetValueAsString( "targetname", text, sizeof( text ) );
				pVMFEntity->SetValueFromString( "targetname", text );
				pEntity->GetValueAsString( "origin", text, sizeof( text ) );
				pVMFEntity->SetValueFromString( "origin", text );
				pEntity->GetValueAsString( "angles", text, sizeof( text ) );
				pVMFEntity->SetValueFromString( "angles", text );

				pEntity->MarkDirty(false);
			}
		}
	}

	// add the new entities
	int nCount = entityList.Count();
	for (int j = 0; j < nCount; j++)
	{
		CDmeVMFEntity *pEntity = CastElement<CDmeVMFEntity>( entityList[j] );

		if ( pEntity->IsDirty())
		{
			CDmElement *pVMFEntity = CreateElement<CDmElement>( pEntity->GetName(), fileid );

			char text[256];
			pEntity->GetValueAsString( "classname", text, sizeof( text ) );
			pVMFEntity->SetValue( "classname", text );
			pEntity->GetValueAsString( "targetname", text, sizeof( text ) );
			pVMFEntity->SetValue( "targetname", text );
			pEntity->GetValueAsString( "origin", text, sizeof( text ) );
			pVMFEntity->SetValue( "origin", text );
			pEntity->GetValueAsString( "angles", text, sizeof( text ) );
			pVMFEntity->SetValue( "angles", text );

			vmfEntities.AddToTail( pVMFEntity );

			pEntity->MarkDirty(false);
		}
	}

	// currently, don't overwrite the vmf, not sure if this is serializing correctly yet
	char tmpname[ 256 ];
	Q_StripExtension( m_pVMFFileName, tmpname, sizeof(tmpname) );
	Q_SetExtension( tmpname, ".vme", sizeof(tmpname) );

	if (!g_pDataModel->SaveToFile( tmpname, NULL, "keyvalues", "vmf", pVMF ))
	{
		// needs some kind of error message
		return false;
	}

	/*
		// If we successfully read the file in, ask it for the max hammer id
		int nMaxHammerId = pVMF->GetAttributeValue<int>( "maxHammerId" );
		CDmeVMFEntity::SetNextEntityId( nMaxHammerId + 1 );
		m_hVMFRoot = pVMF;
	*/

	return true;
}