Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Process commands
//-----------------------------------------------------------------------------
void CSaveDocumentQuery::OnCommand( char const *cmd )
{
	if ( !Q_stricmp( cmd, "yes" ) )
	{
		KeyValues *kv = new KeyValues( "OnSaveFile" );
		kv->SetString( "filename", m_szFileName );
		kv->SetString( "filetype", m_szFileType );
		kv->SetInt( "context", m_nContext );
		kv->SetPtr( "actionTarget", m_pActionSignalTarget );
		if ( m_pPostSaveKeyValues )
		{
			kv->AddSubKey( m_pPostSaveKeyValues->MakeCopy() );
		}
		vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), kv, 0 );
		MarkForDeletion();
	}
	else if ( !Q_stricmp( cmd, "no" ) )
	{
		PostCommand( "OnMarkNotDirty" );
		if ( m_pPostSaveKeyValues )
		{
			vgui::ivgui()->PostMessage( m_pActionSignalTarget->GetVPanel(), m_pPostSaveKeyValues->MakeCopy(), 0 );
		}
		MarkForDeletion();
	}
	else if ( !Q_stricmp( cmd, "cancel" ) )
	{
		PostCommand( "OnCancelSaveDocument" );
		MarkForDeletion();
	}
	else
	{
		BaseClass::OnCommand( cmd );
	}
}
Ejemplo n.º 2
0
//-----------------------------------------------------------------------------
// Purpose: Loads filter settings from disk
//-----------------------------------------------------------------------------
void CMapSelectorDialog::LoadUserData()
{
    // free any old filters
    if (m_pSavedData)
    {
        m_pSavedData->deleteThis();
    }

    m_pSavedData = new KeyValues("Filters");
    if (!m_pSavedData->LoadFromFile(g_pFullFileSystem, "cfg/MapSelector.vdf", "MOD"))
    {
        // doesn't matter if the file is not found, defaults will work successfully and file will be created on exit
    }

    KeyValues *filters = m_pSavedData->FindKey("Filters", false);
    if (filters)
    {
        m_pFilterData = filters->MakeCopy();
        m_pSavedData->RemoveSubKey(filters);
    }
    else
    {
        m_pFilterData = new KeyValues("Filters");
    }

    int wide, tall;
    surface()->GetScreenSize(wide, tall);

    SetPos(wide / 2, tall / 3);

    InvalidateLayout();
    Repaint();
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CModelPanel::OnAddAnimation( KeyValues *pData )
{
	if ( !pData )
		return;

	CModelPanelModelAnimation *pAnimation = new CModelPanelModelAnimation;

	if ( pAnimation )
	{
		pAnimation->m_pszName = ReadAndAllocStringValue( pData, "name" );
		pAnimation->m_pszSequence = ReadAndAllocStringValue( pData, "sequence" );
		pAnimation->m_pszActivity = ReadAndAllocStringValue( pData, "activity" );
		pAnimation->m_bDefault = ( pData->GetInt( "default", 0 ) == 1 );

		for ( KeyValues *pAnimData = pData->GetFirstSubKey(); pAnimData != NULL; pAnimData = pAnimData->GetNextKey() )
		{
			if ( !Q_stricmp( pAnimData->GetName(), "pose_parameters" ) )
			{
				pAnimation->m_pPoseParameters = pAnimData->MakeCopy();
			}
		}

		m_pModelInfo->m_Animations.AddToTail( pAnimation );
		if ( pAnimation->m_bDefault )
		{
			m_iDefaultAnimation = m_pModelInfo->m_Animations.Find( pAnimation );
		}
	}
}
Ejemplo n.º 4
0
bool VMFExporter::AddLevelContainer()
{
    KeyValues *pLevelContainerKeys = new KeyValues( "LevelContainer" );
    if ( !pLevelContainerKeys->LoadFromFile( g_pFullFileSystem, "tilegen/roomtemplates/levelcontainer.vmf.no_func_detail", "GAME" ) )
        return false;

    m_bWritingLevelContainer = true;

    // set the extents of the map
    m_pMapLayout->GetExtents(m_iMapExtents_XMin, m_iMapExtents_XMax, m_iMapExtents_YMin, m_iMapExtents_YMax);
    Msg( "Layout extents: Topleft: %f %f - Lower right: %f %f\n", m_iMapExtents_XMin, m_iMapExtents_YMin, m_iMapExtents_XMax, m_iMapExtents_YMax );
    // adjust to be relative to the centre of the map
    int half_map_size = MAP_LAYOUT_TILES_WIDE * 0.5f;
    m_iMapExtents_XMin -= half_map_size;
    m_iMapExtents_XMax -= half_map_size;
    m_iMapExtents_YMin -= half_map_size;
    m_iMapExtents_YMax -= half_map_size;
    // pad them by 2 blocks, so the player doesn't move his camera into the wall when at an edge block
    m_iMapExtents_XMin -= 2;
    m_iMapExtents_XMax += 2;
    m_iMapExtents_YMin -= 2;
    m_iMapExtents_YMax += 2;

    Msg( "   Adjusted to: Topleft: %d %d - Lower right: %d %d\n", m_iMapExtents_XMin, m_iMapExtents_YMin, m_iMapExtents_XMax, m_iMapExtents_YMax );

    // find world keys
    KeyValues *pWorldKeys = NULL;
    for ( KeyValues *pKeys = pLevelContainerKeys; pKeys; pKeys = pKeys->GetNextKey() )
    {
        const char *szName = pKeys->GetName();
        if ( !Q_stricmp( szName, "world" ) )
        {
            pWorldKeys = pKeys;
            break;
        }
    }
    if ( !pWorldKeys || !ProcessWorld( pWorldKeys ) )
    {
        Q_snprintf( m_szLastExporterError, sizeof(m_szLastExporterError), "Failed to copy level container\n" );
        return false;
    }

    m_bWritingLevelContainer = false;

    for ( KeyValues *pKeys = pWorldKeys->GetFirstSubKey(); pKeys; pKeys = pKeys->GetNextKey() )
    {
        const char *szName = pKeys->GetName();
        if ( !Q_stricmp( szName, "solid" ) )
        {
            m_pExportWorldKeys->AddSubKey( pKeys->MakeCopy() );
        }
    }
    pLevelContainerKeys->deleteThis();

    m_pTemplateKeys->deleteThis();
    m_pTemplateKeys = NULL;

    return true;
}
Ejemplo n.º 5
0
bool VMFExporter::AddRoomTemplateSolids( const CRoomTemplate *pRoomTemplate )
{
    // open its vmf file
    char roomvmfname[MAX_PATH];
    Q_snprintf(roomvmfname, sizeof(roomvmfname), "tilegen/roomtemplates/%s/%s.vmf",
               pRoomTemplate->m_pLevelTheme->m_szName,
               pRoomTemplate->GetFullName() );
    m_pTemplateKeys = new KeyValues( "RoomTemplateVMF" );
    m_pTemplateKeys->LoadFromFile( g_pFullFileSystem, roomvmfname, "GAME" );

    // look for world key
    for ( KeyValues *pKeys = m_pTemplateKeys; pKeys; pKeys = pKeys->GetNextKey() )
    {
        if ( !Q_stricmp( pKeys->GetName(), "world" ) )		// find the world key in our room template
        {
            if ( !ProcessWorld( pKeys ) )					// fix up solid positions
            {
                Q_snprintf( m_szLastExporterError, sizeof(m_szLastExporterError), "Failed to copy world from room %s\n", pRoomTemplate->GetFullName() );
                return false;
            }
            for ( KeyValues *pSubKey = pKeys->GetFirstSubKey(); pSubKey; pSubKey = pSubKey->GetNextKey() )		// convert each solid to a func_detail entity
            {
                if ( !Q_stricmp( pSubKey->GetName(), "solid" ) )
                {
                    if ( IsDisplacementBrush( pSubKey ) )
                    {
                        // add to world section
                        m_pExportWorldKeys->AddSubKey( pSubKey->MakeCopy() );
                    }
                    else
                    {
                        // put into entity section as a func_detail
                        KeyValues *pFuncDetail = new KeyValues( "entity" );
                        pFuncDetail->SetInt( "id", ++m_iEntityCount );
                        pFuncDetail->SetString( "classname", "func_detail" );
                        pFuncDetail->AddSubKey( pSubKey->MakeCopy() );
                        m_pExportKeys->AddSubKey( pFuncDetail );
                    }
                }
            }
        }
    }
    m_pTemplateKeys->deleteThis();
    m_pTemplateKeys = NULL;
    return true;
}
Ejemplo n.º 6
0
void CTileGenDialog::GenerateMission( const char *szMissionFile )
{
	m_pPropertySheet->SetActivePage( m_pPropertySheet->GetPage( 0 ) );
	m_pGenerationOptions->Clear();
	m_pGenerationOptions->LoadFromFile( g_pFullFileSystem, szMissionFile, "GAME" );
	
	if ( IsGenerating() )
	{
		MessageBox *pMessage = new MessageBox ("Error", "Already generating a layout.  Please wait for this to finish before starting a new one.", this);
		pMessage->DoModal();
		return;
	}
	
	delete m_pLayoutSystem;
	m_pLayoutSystem = NULL;
	// Preprocess the mission file (i.e. apply rules)
	if ( m_pLayoutSystemPage->GetPreprocessor()->SubstituteRules( m_pGenerationOptions ) )
	{
		KeyValues *pMissionSettings = m_pGenerationOptions->FindKey( "mission_settings" ); 

		if ( pMissionSettings == NULL )
		{
			MessageBox *pMessage = new MessageBox( "Error", "Mission is missing a Global Options block.", this );
			pMessage->DoModal();
			return;
		}
		// Copy the filename key over
		pMissionSettings->SetString( "Filename", m_pGenerationOptions->GetString( "Filename", "invalid_filename" ) );

		if ( tilegen_preprocess_mission.GetBool() )
		{
			m_pGenerationOptions->SaveToFile( g_pFullFileSystem, "preprocessed_mission.txt", "GAME" );
		}
		
		m_pLayoutSystem = new CLayoutSystem();
		
		AddListeners( m_pLayoutSystem );
		if ( !m_pLayoutSystem->LoadFromKeyValues( m_pGenerationOptions ) )
		{
			MessageBox *pMessage = new MessageBox( "Error", "Failed to load mission from pre-processed key-values.", this );
			pMessage->DoModal();
			return;
		}

		// Clear the current layout
		// @TODO: check the current map is saved, print a warning if not?
		delete m_pMapLayout;
		m_pMapLayout = new CMapLayout( pMissionSettings->MakeCopy() );

		m_pLayoutSystem->BeginGeneration( m_pMapLayout );
	}
	else
	{
		MessageBox *pMessage = new MessageBox ("Error", "Failed to pre-process layout system definition.", this);
		pMessage->DoModal();
		return;
	}
}
Ejemplo n.º 7
0
bool CMapLayout::LoadMapLayout(const char *filename)
{
	// open our output layout file
	KeyValues *pLayoutKeys = new KeyValues( "LayoutKeys" );
	if ( !pLayoutKeys->LoadFromFile( g_pFullFileSystem, filename, "GAME" ) )
	{
		//Msg( "Failed to load map layout %s\n", filename );
		pLayoutKeys->deleteThis();
		return false;
	}

	while ( pLayoutKeys )
	{
		if ( !Q_stricmp( pLayoutKeys->GetName(), "room" ) )
		{
			if ( !CRoom::LoadRoomFromKeyValues( pLayoutKeys, this ) )
				return false;
		}
		else if ( !Q_stricmp( pLayoutKeys->GetName(), "logical_room" ) )
		{
			LoadLogicalRoom( pLayoutKeys );
		}
		else if ( !Q_stricmp( pLayoutKeys->GetName(), "mapmisc" ) )
		{
			m_iPlayerStartTileX = pLayoutKeys->GetInt( "PlayerStartX" );
			m_iPlayerStartTileY = pLayoutKeys->GetInt( "PlayerStartY" );
		}
		else if ( Q_stricmp( pLayoutKeys->GetName(), "mission_settings" ) == 0 )
		{
			m_pGenerationOptions = pLayoutKeys->MakeCopy();
		}
		else if ( Q_stricmp( pLayoutKeys->GetName(), "instance_spawn" ) == 0 )
		{
			m_InstanceSpawns[m_InstanceSpawns.AddToTail()].LoadFromKeyValues( pLayoutKeys );
		}
		else if ( Q_stricmp( pLayoutKeys->GetName(), "npc_encounter" ) == 0 )
		{
			CASW_Encounter *pEncounter = new CASW_Encounter();
			pEncounter->LoadFromKeyValues( pLayoutKeys );
			m_Encounters.AddToTail( pEncounter );
		}
		pLayoutKeys = pLayoutKeys->GetNextKey();
	}

	MarkEncounterRooms();

	SetCurrentFilename(filename);

	pLayoutKeys->deleteThis();

	return true;
}
Ejemplo n.º 8
0
void RadioButton::InternalSetSelected(bool state, bool bFireEvents)
{
	if (state == true)
	{
		if (!IsEnabled())
			return;

		// restore our tab position
		SetTabPosition(_oldTabPosition);

		// Should we send notifications?
		if ( bFireEvents )
		{
			// send a message
			KeyValues *msg = new KeyValues("RadioButtonChecked");
			msg->SetPtr("panel", this);
			msg->SetInt("tabposition", _oldTabPosition);

			// send a message to all other panels on the same level as heirarchy, 
			// so that other radio buttons know to shut off
			VPANEL radioParent = GetVParent();
			if (radioParent)
			{
				for (int i = 0; i < ipanel()->GetChildCount(radioParent); i++)
				{
					VPANEL child = ipanel()->GetChild(radioParent, i);
					if (child != GetVPanel())
					{
						ivgui()->PostMessage(child, msg->MakeCopy(), GetVPanel());
					}
				}
			}

			RequestFocus();
			PostActionSignal(msg);
		}
	}
	else
	{
		// remove ourselves from the tab order
		if (GetTabPosition())
		{
			_oldTabPosition = GetTabPosition();
		}
		SetTabPosition(0);
	}

	InvalidateLayout();
	Repaint();

	ToggleButton::SetSelected(state);
}
Ejemplo n.º 9
0
void KeyValues::CopySubkeys(KeyValues *pParent) const
{
	KeyValues *pPrev = NULL;

	for (KeyValues *sub = m_pSub; sub != NULL; sub = sub->m_pPeer)
	{
		KeyValues *dat = sub->MakeCopy();

		if (pPrev)
			pPrev->m_pPeer = dat;
		else
			pParent->m_pSub = dat;

		dat->m_pPeer = NULL;
		pPrev = dat;
	}
}
Ejemplo n.º 10
0
void BuildGroup::ProcessConditionalKeys( KeyValues *pData, KeyValues *pConditions )
{
	// for each condition, look for it in keys
	// if its a positive condition, promote all of its children, replacing values

	if ( pData )
	{
		KeyValues *pSubKey = pData->GetFirstSubKey();
		if ( !pSubKey )
		{
			// not a block
			return;
		}

		for ( ; pSubKey != nullptr; pSubKey = pSubKey->GetNextKey() )
		{
			// recursively descend each sub block
			ProcessConditionalKeys( pSubKey, pConditions );

			KeyValues *pCondition = pConditions->GetFirstSubKey();
			for ( ; pCondition != nullptr; pCondition = pCondition->GetNextKey() )
			{
				// if we match any conditions in this sub block, copy up
				KeyValues *pConditionBlock = pSubKey->FindKey( pCondition->GetName() );
				if ( pConditionBlock )
				{
					KeyValues *pOverridingKey;
					for ( pOverridingKey = pConditionBlock->GetFirstSubKey(); pOverridingKey != nullptr; pOverridingKey = pOverridingKey->GetNextKey() )
					{
						KeyValues *pExistingKey = pSubKey->FindKey( pOverridingKey->GetName() );
						if ( pExistingKey )
						{
							pExistingKey->SetStringValue( pOverridingKey->GetString() );
						}
						else
						{
							KeyValues *copy = pOverridingKey->MakeCopy();
							pSubKey->AddSubKey( copy );
						}
					}				
				}
			}			
		}		
	}
}
CASW_VGUI_Computer_Weather::CASW_VGUI_Computer_Weather( vgui::Panel *pParent, const char *pElementName, C_ASW_Hack_Computer* pHackComputer )
    :	vgui::Panel( pParent, pElementName ),
      CASW_VGUI_Ingame_Panel(),
      m_pHackComputer( pHackComputer )
{
    CASW_VGUI_Computer_Frame *pComputerFrame = dynamic_cast< CASW_VGUI_Computer_Frame* >( GetClientMode()->GetPanelFromViewport( "ComputerContainer/VGUIComputerFrame" ) );
    if ( pComputerFrame )
    {
        pComputerFrame->m_bHideLogoffButton = true;
    }

    m_pBackButton = new ImageButton(this, "BackButton", "#asw_SynTekBackButton");
    m_pBackButton->SetContentAlignment(vgui::Label::a_center);
    m_pBackButton->AddActionSignalTarget(this);
    KeyValues *msg = new KeyValues("Command");
    msg->SetString("command", "Back");
    m_pBackButton->SetCommand(msg->MakeCopy());
    m_pBackButton->SetCancelCommand(msg);
    m_pBackButton->SetAlpha(0);
    m_pTitleLabel = new vgui::Label(this, "TitleLabel", "#asw_SynTekAtmospherics");
    m_pTitleIcon = new vgui::ImagePanel(this, "TitleIcon");
    m_pTitleIconShadow = new vgui::ImagePanel(this, "TitleIconShadow");
    m_pWarningLabel = new vgui::WrappedLabel(this, "Warning", "#asw_weather_warning");

    for (int i=0; i<ASW_WEATHER_ENTRIES; i++)
    {
        m_pWeatherLabel[i] = new vgui::Label(this, "WLabel", "");
        m_pWeatherValue[i] = new vgui::Label(this, "WValue", "");
    }

    SetWeatherLabels();

    if (GetControllerFocus())
    {
        GetControllerFocus()->AddToFocusList(m_pBackButton);
        GetControllerFocus()->SetFocusPanel(m_pBackButton);
    }

    m_bSetAlpha = false;
}
Ejemplo n.º 12
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CBaseModelPanel::ParseModelAnimInfo( KeyValues *inResourceData )
{
	if ( !inResourceData )
		return;

	int iAnim = m_BMPResData.m_aAnimations.AddToTail();
	if ( iAnim == m_BMPResData.m_aAnimations.InvalidIndex() )
		return;

	m_BMPResData.m_aAnimations[iAnim].m_pszName = ReadAndAllocStringValue( inResourceData, "name" );
	m_BMPResData.m_aAnimations[iAnim].m_pszSequence = ReadAndAllocStringValue( inResourceData, "sequence" );
	m_BMPResData.m_aAnimations[iAnim].m_pszActivity = ReadAndAllocStringValue( inResourceData, "activity" );
	m_BMPResData.m_aAnimations[iAnim].m_bDefault = ( inResourceData->GetInt( "default", 0 ) == 1 );

	for ( KeyValues *pAnimData = inResourceData->GetFirstSubKey(); pAnimData != NULL; pAnimData = pAnimData->GetNextKey() )
	{
		if ( !Q_stricmp( pAnimData->GetName(), "pose_parameters" ) )
		{
			m_BMPResData.m_aAnimations[iAnim].m_pPoseParameters = pAnimData->MakeCopy();
		}
	}
}
Ejemplo n.º 13
0
bool VMFExporter::AddRoomTemplateEntities( const CRoomTemplate *pRoomTemplate )
{
    m_SideTranslations.PurgeAndDeleteElements();
    m_NodeTranslations.PurgeAndDeleteElements();

    // reopen the source vmf
    char roomvmfname[MAX_PATH];
    Q_snprintf( roomvmfname, sizeof(roomvmfname), "tilegen/roomtemplates/%s/%s.vmf",
                pRoomTemplate->m_pLevelTheme->m_szName,
                pRoomTemplate->GetFullName() );
    m_pTemplateKeys = new KeyValues( "RoomTemplateVMF" );
    m_pTemplateKeys->LoadFromFile( g_pFullFileSystem, roomvmfname, "GAME" );

    // make all node IDs unique
    MakeNodeIDsUnique();

    // sets priority of objective entities based on the generation options
    ReorderObjectives( pRoomTemplate, m_pTemplateKeys );

    // look for entity keys
    for ( KeyValues *pKeys = m_pTemplateKeys; pKeys; pKeys = pKeys->GetNextKey() )
    {
        if ( !Q_stricmp( pKeys->GetName(), "entity" ) )
        {
            if ( !ProcessEntity( pKeys ) )
            {
                Q_snprintf( m_szLastExporterError, sizeof(m_szLastExporterError), "Failed to copy entity from room %s\n", pRoomTemplate->GetFullName());
                return false;
            }
            m_pExportKeys->AddSubKey( pKeys->MakeCopy() );
        }
    }

    m_pTemplateKeys->deleteThis();
    m_pTemplateKeys = NULL;
    return true;
};
Ejemplo n.º 14
0
	virtual void OnValuesChanged( KeyValues **pValues, int iCount )
	{
		bool bFoundAnything = false;
		bool bWasMultiSelected = m_bMultiSelection;
		m_bMultiSelection = false;

		for ( int i = 0; i < iCount; i++ )
		{
			bool bFoundValue = false;
			for ( KeyValues *pValue = pValues[i]->GetFirstValue(); pValue; pValue = pValue->GetNextValue() )
			{
				if ( !Q_stricmp( m_pValue->GetName(), pValue->GetName() ) )
				{
					if ( i > 0 )
					{
						if ( Q_stricmp( m_pValue->GetString(), pValue->GetString() ) )
							m_bMultiSelection = true;
					}

					m_pValue->deleteThis();
					m_pValue = pValue->MakeCopy();
					bFoundAnything = true;
					bFoundValue = true;
					break;
				}
			}

			if ( !bFoundValue && bFoundAnything )
				m_bMultiSelection = true;
		}

		if ( !bFoundAnything )
			m_bMultiSelection = bWasMultiSelected;

		ReadValue();
	};
Ejemplo n.º 15
0
void KeyValues::RecursiveMergeKeyValues(KeyValues *baseKV)
{
	for (KeyValues *baseChild = baseKV->m_pSub; baseChild != NULL; baseChild = baseChild->m_pPeer)
	{
		bool bFoundMatch = false;

		for (KeyValues *newChild = m_pSub; newChild != NULL; newChild = newChild->m_pPeer)
		{
			if (!Q_strcmp(baseChild->GetName(), newChild->GetName()))
			{
				newChild->RecursiveMergeKeyValues(baseChild);
				bFoundMatch = true;
				break;
			}
		}

		if (!bFoundMatch)
		{
			KeyValues *dat = baseChild->MakeCopy();
			Assert(dat);
			AddSubKey(dat);
		}
	}
}
Ejemplo n.º 16
0
bool CEngineSprite::Init( const char *pName )
{
	m_VideoMaterial = NULL;
	for ( int i = 0; i < kRenderModeCount; ++i )
	{
		m_material[ i ] = NULL;
	}

	m_width = m_height = m_numFrames = 1;

	Assert( g_pVideo != NULL );
	
	if ( g_pVideo != NULL && g_pVideo->LocateVideoSystemForPlayingFile( pName ) != VideoSystem::NONE ) 
	{
		m_VideoMaterial = g_pVideo->CreateVideoMaterial( pName, pName, "GAME", VideoPlaybackFlags::DEFAULT_MATERIAL_OPTIONS, VideoSystem::DETERMINE_FROM_FILE_EXTENSION, false ); 
		
		if ( m_VideoMaterial == NULL )
			return false;

		IMaterial *pMaterial = m_VideoMaterial->GetMaterial();
		m_VideoMaterial->GetVideoImageSize( &m_width, &m_height );
		m_numFrames = m_VideoMaterial->GetFrameCount();
		for ( int i = 0; i < kRenderModeCount; ++i )
		{
			m_material[i] = pMaterial;
			pMaterial->IncrementReferenceCount();
		}
	}
	else
	{
		char pTemp[MAX_PATH];
		char pMaterialName[MAX_PATH];
		char pMaterialPath[MAX_PATH];
		Q_StripExtension( pName, pTemp, sizeof(pTemp) );
		Q_strlower( pTemp );
		Q_FixSlashes( pTemp, '/' );

		// Check to see if this is a UNC-specified material name
		bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/';
		if ( !bIsUNC )
		{
			Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) );
			Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS );
		}
		else
		{
			Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) );
		}
		Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) );
		Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) );

		KeyValues *kv = new KeyValues( "vmt" );
		if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) )
		{
			Warning( "Unable to load sprite material %s!\n", pMaterialPath );
			return false;
		}

		for ( int i = 0; i < kRenderModeCount; ++i )
		{	
			if ( i == kRenderNone || i == kRenderEnvironmental )
			{
				m_material[i] = NULL;
				continue;
			}

			Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName, i );
			KeyValues *pMaterialKV = kv->MakeCopy();
			pMaterialKV->SetInt( "$spriteRenderMode", i );
			m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV );
			m_material[ i ]->IncrementReferenceCount();
		}

		kv->deleteThis();

		m_width = m_material[0]->GetMappingWidth();
		m_height = m_material[0]->GetMappingHeight();
		m_numFrames = m_material[0]->GetNumAnimationFrames();
	}

	for ( int i = 0; i < kRenderModeCount; ++i )
	{
		if ( i == kRenderNone || i == kRenderEnvironmental )
			continue;

		if ( !m_material[i] )
			return false;
	}

	IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache );
	m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT;

	IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache );
	Vector origin, originVarValue;
	if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) )
	{
		origin[0] = -m_width * 0.5f;
		origin[1] = m_height * 0.5f;
	}
	else
	{
		originVar->GetVecValue( &originVarValue[0], 3 );
		origin[0] = -m_width * originVarValue[0];
		origin[1] = m_height * originVarValue[1];
	}

	up = origin[1];
	down = origin[1] - m_height;
	left = origin[0];
	right = m_width + origin[0];

	return true;
}
Ejemplo n.º 17
0
bool CEngineSprite::Init( const char *pName )
{
	m_hAVIMaterial = AVIMATERIAL_INVALID;
	m_hBIKMaterial = BIKMATERIAL_INVALID;
	m_width = m_height = m_numFrames = 1;

	const char *pExt = Q_GetFileExtension( pName );
	bool bIsAVI = pExt && !Q_stricmp( pExt, "avi" );
#if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 )
	bool bIsBIK = pExt && !Q_stricmp( pExt, "bik" );
#endif
	if ( bIsAVI && IsPC() )
	{
		m_hAVIMaterial = avi->CreateAVIMaterial( pName, pName, "GAME" );
		if ( m_hAVIMaterial == AVIMATERIAL_INVALID )
			return false;

		IMaterial *pMaterial = avi->GetMaterial( m_hAVIMaterial );
		avi->GetFrameSize( m_hAVIMaterial, &m_width, &m_height );
		m_numFrames = avi->GetFrameCount( m_hAVIMaterial );
		for ( int i = 0; i < kRenderModeCount; ++i )
		{
			m_material[i] = pMaterial;
			pMaterial->IncrementReferenceCount();
		}
	}
#if !defined( _X360 ) || defined( BINK_ENABLED_FOR_X360 )
	else if ( bIsBIK )
	{
		m_hBIKMaterial = bik->CreateMaterial( pName, pName, "GAME" );
		if ( m_hBIKMaterial == BIKMATERIAL_INVALID )
			return false;

		IMaterial *pMaterial = bik->GetMaterial( m_hBIKMaterial );
		bik->GetFrameSize( m_hBIKMaterial, &m_width, &m_height );
		m_numFrames = bik->GetFrameCount( m_hBIKMaterial );
		for ( int i = 0; i < kRenderModeCount; ++i )
		{
			m_material[i] = pMaterial;
			pMaterial->IncrementReferenceCount();
		}
	}
#endif
	else
	{
		char pTemp[MAX_PATH];
		char pMaterialName[MAX_PATH];
		char pMaterialPath[MAX_PATH];
		Q_StripExtension( pName, pTemp, sizeof(pTemp) );
		Q_strlower( pTemp );
		Q_FixSlashes( pTemp, '/' );

		// Check to see if this is a UNC-specified material name
		bool bIsUNC = pTemp[0] == '/' && pTemp[1] == '/' && pTemp[2] != '/';
		if ( !bIsUNC )
		{
			Q_strncpy( pMaterialName, "materials/", sizeof(pMaterialName) );
			Q_strncat( pMaterialName, pTemp, sizeof(pMaterialName), COPY_ALL_CHARACTERS );
		}
		else
		{
			Q_strncpy( pMaterialName, pTemp, sizeof(pMaterialName) );
		}
		Q_strncpy( pMaterialPath, pMaterialName, sizeof(pMaterialPath) );
		Q_SetExtension( pMaterialPath, ".vmt", sizeof(pMaterialPath) );

		for ( int i = 0; i < kRenderModeCount; ++i )
		{	
			m_material[i] = NULL;
		}

		KeyValues *kv = new KeyValues( "vmt" );
		if ( !kv->LoadFromFile( g_pFullFileSystem, pMaterialPath, "GAME" ) )
		{
			Warning( "Unable to load sprite material %s!\n", pMaterialPath );
			return false;
		}

		for ( int i = 0; i < kRenderModeCount; ++i )
		{	
			if ( i == kRenderNone || i == kRenderEnvironmental )
			{
				continue;
			}

			// strip possible materials/
			Q_snprintf( pMaterialPath, sizeof(pMaterialPath), "%s_rendermode_%d", pMaterialName + ( bIsUNC ? 0 : 10 ), i );
			KeyValues *pMaterialKV = kv->MakeCopy();
			pMaterialKV->SetInt( "$spriteRenderMode", i );
			m_material[i] = g_pMaterialSystem->FindProceduralMaterial( pMaterialPath, TEXTURE_GROUP_CLIENT_EFFECTS, pMaterialKV );
			m_material[i]->IncrementReferenceCount();	
		}

		kv->deleteThis();

		m_width = m_material[0]->GetMappingWidth();
		m_height = m_material[0]->GetMappingHeight();
		m_numFrames = m_material[0]->GetNumAnimationFrames();
	}

	for ( int i = 0; i < kRenderModeCount; ++i )
	{
		if ( i == kRenderNone || i == kRenderEnvironmental )
			continue;

		if ( !m_material[i] )
			return false;
	}

	IMaterialVar *orientationVar = m_material[0]->FindVarFast( "$spriteorientation", &spriteOrientationCache );
	m_orientation = orientationVar ? orientationVar->GetIntValue() : C_SpriteRenderer::SPR_VP_PARALLEL_UPRIGHT;

	IMaterialVar *originVar = m_material[0]->FindVarFast( "$spriteorigin", &spriteOriginCache );
	Vector origin, originVarValue;
	if( !originVar || ( originVar->GetType() != MATERIAL_VAR_TYPE_VECTOR ) )
	{
		origin[0] = -m_width * 0.5f;
		origin[1] = m_height * 0.5f;
	}
	else
	{
		originVar->GetVecValue( &originVarValue[0], 3 );
		origin[0] = -m_width * originVarValue[0];
		origin[1] = m_height * originVarValue[1];
	}

	up = origin[1];
	down = origin[1] - m_height;
	left = origin[0];
	right = m_width + origin[0];

	return true;
}
Ejemplo n.º 18
0
//=============================================================================
void FoundPublicGames::OnCommand( const char *command )
{
	if( V_strcmp( command, "CreateGame" ) == 0 )
	{
		if ( !CanCreateGame() )
		{
			CBaseModPanel::GetSingleton().PlayUISound( UISOUND_INVALID );
			return;
		}

		KeyValues *pSettings = KeyValues::FromString(
			"settings",
			" system { "
			" network LIVE "
			" access friends "
			" } "
			" game { "
			" mode = "
			" campaign = "
			" mission = "
			" } "
			" options { "
			" action create "
			" } "
			);
		KeyValues::AutoDelete autodelete( pSettings );

		char const *szGameMode = "campaign";
		pSettings->SetString( "game/mode", szGameMode );
		pSettings->SetString( "game/campaign", "jacob" );
		pSettings->SetString( "game/mission", "asi-jac1-landingbay_01" );

		if ( !CUIGameData::Get()->SignedInToLive() )
		{
			pSettings->SetString( "system/network", "lan" );
			pSettings->SetString( "system/access", "public" );
		}

		if ( StringHasPrefix( szGameMode, "team" ) )
		{
			pSettings->SetString( "system/netflag", "teamlobby" );
		}
		else if ( !Q_stricmp( "custommatch", m_pDataSettings->GetString( "options/action", "" ) ) )
		{
			pSettings->SetString( "system/access", "public" );
		}

		// TCR: We need to respect the default difficulty
		pSettings->SetString( "game/difficulty", GameModeGetDefaultDifficulty( szGameMode ) );

		CBaseModPanel::GetSingleton().PlayUISound( UISOUND_ACCEPT );
		CBaseModPanel::GetSingleton().CloseAllWindows();
		CBaseModPanel::GetSingleton().OpenWindow( WT_GAMESETTINGS, NULL, true, pSettings );
	}
	else if ( !Q_stricmp( command, "StartCustomMatchSearch" ) )
	{
		if ( CheckAndDisplayErrorIfNotLoggedIn() ||
			CUIGameData::Get()->CheckAndDisplayErrorIfNotSignedInToLive( this ) )
		{
			CBaseModPanel::GetSingleton().PlayUISound( UISOUND_DENY );
			return;
		}

		KeyValues *pSettings = NULL;
		bool bDefaultSettings = true;
		if ( FoundGameListItem* gameListItem = static_cast<FoundGameListItem*>( m_GplGames->GetSelectedPanelItem() ) )
		{
			pSettings = gameListItem->GetFullInfo().mpGameDetails;
		}

		if ( !pSettings )
		{
			pSettings = new KeyValues( "settings" );
		}
		else
		{
			pSettings = pSettings->MakeCopy();
			bDefaultSettings = false;
		}

		// Take ownership of allocated/copied keyvalues
		KeyValues::AutoDelete autodelete( pSettings );
		char const *szGameMode = m_pDataSettings->GetString( "game/mode", "campaign" );

		pSettings->SetString( "system/network", "LIVE" );
		pSettings->SetString( "system/access", "public" );
		pSettings->SetString( "game/mode", szGameMode );
		pSettings->SetString( "options/action", "custommatch" );

		// TCR: We need to respect the default difficulty
		if ( bDefaultSettings && GameModeHasDifficulty( szGameMode ) )
			pSettings->SetString( "game/difficulty", GameModeGetDefaultDifficulty( szGameMode ) );

		CBaseModPanel::GetSingleton().PlayUISound( UISOUND_ACCEPT );
		CBaseModPanel::GetSingleton().CloseAllWindows();
		CBaseModPanel::GetSingleton().OpenWindow( WT_GAMESETTINGS, NULL, true, pSettings );
	}
	else if ( char const *filterDifficulty = StringAfterPrefix( command, "filter_difficulty_" ) )
	{
		ui_public_lobby_filter_difficulty2.SetValue( filterDifficulty );
		StartSearching();
	}
	else if ( char const *filterOnslaught = StringAfterPrefix( command, "filter_onslaught_" ) )
	{
		ui_public_lobby_filter_onslaught.SetValue( filterOnslaught );
		StartSearching();
	}
	else if ( char const *filterCampaign = StringAfterPrefix( command, "filter_campaign_" ) )
	{
		ui_public_lobby_filter_campaign.SetValue( filterCampaign );
		StartSearching();
	}
	else if ( char const *filterGamestatus = StringAfterPrefix( command, "filter_status_" ) )
	{
		ui_public_lobby_filter_status.SetValue( filterGamestatus );
		StartSearching();
	}
	else if ( !Q_stricmp( command, "InstallSupport" ) )
	{
		// install the add-on support package
#ifdef IS_WINDOWS_PC
		// App ID for the legacy addon data is 564
		ShellExecute ( 0, "open", "steam://install/564", NULL, 0, SW_SHOW );
#endif		
	}
	else
	{
		BaseClass::OnCommand( command );
	}
}
Ejemplo n.º 19
0
//=============================================================================
void FoundPublicGames::AddServersToList( void )
{
	if ( !m_pSearchManager )
		return;

	int numItems = m_pSearchManager->GetNumResults();
	for ( int i = 0; i < numItems; ++ i )
	{
		IMatchSearchResult *item = m_pSearchManager->GetResultByIndex( i );
		KeyValues *pGameDetails = item->GetGameDetails();
		if ( !pGameDetails )
			continue;
		if ( !ShouldShowPublicGame( pGameDetails ) )
			continue;

		FoundGameListItem::Info fi;

		fi.mInfoType = FoundGameListItem::FGT_PUBLICGAME;
		char const *szGameMode = pGameDetails->GetString( "game/mode", "campaign" );
		bool bGameModeChapters = GameModeIsSingleChapter( szGameMode );
		const char *szDisplayName = pGameDetails->GetString( "game/missioninfo/displaytitle" );
		if ( !szDisplayName || !szDisplayName[0] )
		{
			szDisplayName = "Unknown Mission";
		}
		Q_strncpy( fi.Name, szDisplayName, sizeof( fi.Name ) );

		fi.mIsJoinable = item->IsJoinable();
		fi.mbInGame = true;

		fi.miPing = pGameDetails->GetInt( "server/ping", 0 );
		fi.mPing = fi.GP_HIGH;
		if ( !Q_stricmp( "lan", pGameDetails->GetString( "system/network", "" ) ) )
			fi.mPing = fi.GP_SYSTEMLINK;

		fi.mpGameDetails = pGameDetails->MakeCopy();
		KeyValues::AutoDelete autodelete_fi_mpGameDetails( fi.mpGameDetails );

		// Force the chapter to 1 in case there is no chapter specified
		int iChapter = fi.mpGameDetails->GetInt( "game/chapter", 0 );
		if ( !iChapter )
		{
			fi.mpGameDetails->SetInt( "game/chapter", 1 );
			fi.mpGameDetails->SetBool( "UI/nochapter", 1 );
		}

		if ( IsX360() )
		{
			// For X360 titles do not transmit campaign display title, so client needs to resolve locally
			KeyValues *pMissionInfo = NULL;
			KeyValues *pChapterInfo = NULL; //GetMapInfoRespectingAnyChapter( fi.mpGameDetails, &pMissionInfo );
			if ( pMissionInfo && pChapterInfo )
			{
				if ( bGameModeChapters )
					Q_strncpy( fi.Name, pChapterInfo->GetString( "displayname", "#L4D360UI_LevelName_Unknown" ), sizeof( fi.Name ) );
				else
					Q_strncpy( fi.Name, pMissionInfo->GetString( "displaytitle", "#L4D360UI_CampaignName_Unknown" ), sizeof( fi.Name ) );
			}
			else
			{
				Q_strncpy( fi.Name, "#L4D360UI_CampaignName_Unknown", sizeof( fi.Name ) );
				fi.mbDLC = true;
			}
		}

		fi.mFriendXUID = item->GetOnlineId();

		// Check if this is actually a non-joinable game
		if ( fi.IsDLC() )
		{
			fi.mIsJoinable = false;
		}
		else if ( fi.IsDownloadable() )
		{
			fi.mIsJoinable = false;
		}
		else if ( fi.mbInGame )
		{
			char const *szHint = fi.GetNonJoinableShortHint();
			if ( !*szHint )
			{
				fi.mIsJoinable = true;
				fi.mpfnJoinGame = HandleJoinPublicGame;
			}
			else
			{
				fi.mIsJoinable = false;
			}
		}

		AddGameFromDetails( fi );
	}
}