Ejemplo n.º 1
0
//-----------------------------------------------------------------------------
// Purpose: loads filter settings (from disk) from the keyvalues
//-----------------------------------------------------------------------------
void CBaseMapsPage::LoadFilterSettings()
{
    KeyValues *filter = MapSelectorDialog().GetFilterSaveData(GetName());

    //Game-mode selection
    m_iGameModeFilter = filter->GetInt("gamemode", 0);
    m_pGameModeFilter->ActivateItemByRow(m_iGameModeFilter);

    //"Map"
    Q_strncpy(m_szMapFilter, filter->GetString("map"), sizeof(m_szMapFilter));
    m_pMapFilter->SetText(m_szMapFilter);

    //Map layout
    m_iMapLayoutFilter = filter->GetInt("maplayout", 0);
    m_pMapLayoutFilter->ActivateItemByRow(m_iMapLayoutFilter);

    //HideCompleted maps
    m_bFilterHideCompleted = filter->GetBool("HideCompleted", false);
    m_pHideCompletedFilterCheck->SetSelected(m_bFilterHideCompleted);

    //Difficulty
    m_iDifficultyFilter = filter->GetInt("difficulty");
    if (m_iDifficultyFilter)
    {
        char buf[32];
        Q_snprintf(buf, sizeof(buf), "< %d", m_iDifficultyFilter);
        m_pDifficultyFilter->SetText(buf);
    }

    // apply to the controls
    OnLoadFilter(filter);
    UpdateFilterSettings();
    ApplyGameFilters();
}
void CRuleInstanceNodePanel::CreatePanelContents()
{
	KeyValues *pNodeKV = GetData();

	// If this rule instance is wrapped in a dummy key values node, move down a level.
	if ( HasDummyContainerNode() )
	{
		pNodeKV = pNodeKV->GetFirstSubKey();
	}

	m_bDisabled = pNodeKV->GetBool( "disabled", false );
	m_pChangeRuleButton = new Button( this, "ChangeRule", "Change", this, "ChangeRule" );
	AddHeadingElement( m_pChangeRuleButton, 0.0f );
	m_pDisableRuleButton = new Button( this, "DisableRule", m_bDisabled ? "Enable" : "Disable", this, "DisableRule" );
	AddHeadingElement( m_pDisableRuleButton, 0.0f );
	
	Assert( pNodeKV != NULL );

	const char *pRuleName = pNodeKV->GetString( "name", NULL );
	
	if ( pRuleName == NULL )
	{
		Q_snprintf( m_NodeLabel, m_nNameLength, "No Rule specified" );
	}
	else
	{
		const CTilegenMissionPreprocessor *pPreprocessor = GetEditor()->GetPreprocessor();
		const CTilegenRule *pRule = pPreprocessor->FindRule( pRuleName );
		if ( pRule != NULL )
		{
			GetTooltip()->SetText( pRule->GetDescription() );

			if ( !m_bDisabled )
			{
				for ( int i = 0; i < pRule->GetParameterCount(); ++ i )
				{
					// @TODO: need to error if a non-optional parameter is missing
					const char *pParameterName = pRule->GetParameterName( i );
					KeyValues *pInstanceParameterKV = pNodeKV->FindKey( pParameterName );
					CRuleInstanceParameterPanel *pPanel = new CRuleInstanceParameterPanel( this, "text_entry", pRule, i );
					pPanel->SetEditor( GetEditor() );
					pPanel->SetData( pInstanceParameterKV );
					AddChild( pPanel, 0 );
				}
			}

			Q_snprintf( m_NodeLabel, m_nNameLength, "%s", pRule->GetFriendlyName() );
		}
		else
		{
			Q_snprintf( m_NodeLabel, m_nNameLength, "Rule '%s' not found!", pRuleName );
		}
	}
}
Ejemplo n.º 3
0
//=============================================================================
bool Video::SetupRecommendedActivateData( void )
{
#ifdef _X360
	AssertMsg( false, "VideoCFG is not supported on 360." );
	return false;
#else
	KeyValues *pConfigKeys = new KeyValues( "VideoConfig" );
	if ( !pConfigKeys )
		return false;

	if ( !ReadCurrentVideoConfig( pConfigKeys, true ) )
	{
		pConfigKeys->deleteThis();
		return false;
	}

	m_iResolutionWidth = pConfigKeys->GetInt( "setting.defaultres", 640 );
	m_iResolutionHeight = pConfigKeys->GetInt( "setting.defaultresheight", 480 );
	m_iAspectRatio = GetScreenAspectMode( m_iResolutionWidth, m_iResolutionHeight );
	m_bWindowed = !pConfigKeys->GetBool( "setting.fullscreen", true );
	m_bNoBorder = pConfigKeys->GetBool( "setting.nowindowborder", false );
	m_iModelTextureDetail = clamp( pConfigKeys->GetInt( "setting.gpu_mem_level", 0 ), 0, 2 );
	m_iPagedPoolMem = clamp( pConfigKeys->GetInt( "setting.mem_level", 0 ), 0, 2 );
	m_nAASamples = pConfigKeys->GetInt( "setting.mat_antialias", 0 );
	m_nAAQuality = pConfigKeys->GetInt( "setting.mat_aaquality", 0 );
	m_iFiltering = pConfigKeys->GetInt( "setting.mat_forceaniso", 1 );
	m_bVSync = pConfigKeys->GetBool( "setting.mat_vsync", true );
	m_bTripleBuffered = pConfigKeys->GetBool( "setting.mat_triplebuffered", false );
	m_iGPUDetail = pConfigKeys->GetInt( "setting.gpu_level", 0 );
	m_iCPUDetail = pConfigKeys->GetInt( "setting.cpu_level", 0 );
	m_flFilmGrain = pConfigKeys->GetFloat( "setting.mat_grain_scale_override", 1.0f );
	m_iQueuedMode = pConfigKeys->GetInt( "setting.mat_queue_mode", -1 );
	m_bLockMouse = pConfigKeys->GetBool( "setting.in_lock_mouse_to_window", true );

	pConfigKeys->deleteThis();

	return true;
#endif
}
Ejemplo n.º 4
0
bool CMapzoneData::LoadFromFile(const char *szMapName)
{
    bool toReturn = false;
    char zoneFilePath[MAX_PATH];
    Q_strcpy(zoneFilePath, c_mapPath);
    Q_strcat(zoneFilePath, szMapName, MAX_PATH);
    Q_strncat(zoneFilePath, c_zoneFileEnding, MAX_PATH);
    DevLog("Looking for zone file: %s \n", zoneFilePath);
    KeyValues* zoneKV = new KeyValues(szMapName);
    if (zoneKV->LoadFromFile(filesystem, zoneFilePath, "MOD"))
    {
        // Go through checkpoints
        for (KeyValues *cp = zoneKV->GetFirstSubKey(); cp; cp = cp->GetNextKey())
        {
            // Load position information (will default to 0 if the keys don't exist)
            Vector* pos = new Vector(cp->GetFloat("xPos"), cp->GetFloat("yPos"), cp->GetFloat("zPos"));
            QAngle* rot = new QAngle(cp->GetFloat("xRot"), cp->GetFloat("yRot"), cp->GetFloat("zRot"));
            Vector* scaleMins = new Vector(cp->GetFloat("xScaleMins"), cp->GetFloat("yScaleMins"), cp->GetFloat("zScaleMins"));
            Vector* scaleMaxs = new Vector(cp->GetFloat("xScaleMaxs"), cp->GetFloat("yScaleMaxs"), cp->GetFloat("zScaleMaxs"));

            // Do specific things for different types of checkpoints
            // 0 = start, 1 = checkpoint, 2 = end, 3 = Onehop, 4 = OnehopReset, 5 = Checkpoint_teleport, 6 = Multihop, 7 = stage
            int zoneType = -1;
            int index = -1;
            bool shouldStop = false;
            bool shouldTilt = true;
            float holdTime = 1.0f;
            //int destinationIndex = -1;
            bool limitingspeed = true;
            float maxleavespeed = 290.0f;
            const char * linkedtrigger = NULL;

            if (Q_strcmp(cp->GetName(), "start") == 0)
            {
                zoneType = MOMZONETYPE_START;
                limitingspeed = cp->GetBool("limitingspeed");
                maxleavespeed = cp->GetFloat("leavespeed");
            }
            else if (Q_strcmp(cp->GetName(), "checkpoint") == 0)
            {
                zoneType = MOMZONETYPE_CP;
                index = cp->GetInt("number", -1);
            }
            else if (Q_strcmp(cp->GetName(), "end") == 0)
            {
                zoneType = MOMZONETYPE_STOP;
            }
            else if (Q_strcmp(cp->GetName(), "onehop") == 0)
            {
                zoneType = MOMZONETYPE_ONEHOP;
                shouldStop = cp->GetBool("stop", false);
                shouldTilt = cp->GetBool("resetang", true);
                holdTime = cp->GetFloat("hold", 1);
                //destinationIndex = cp->GetInt("destination", 1);
                linkedtrigger = cp->GetString("destinationname", NULL);
            }
            else if (Q_strcmp(cp->GetName(), "resetonehop") == 0)
            {
                zoneType = MOMZONETYPE_RESETONEHOP;
            }
            else if (Q_strcmp(cp->GetName(), "checkpoint_teleport") == 0)
            {
                zoneType = MOMZONETYPE_CPTELE;
                //destinationIndex = cp->GetInt("destination", -1);
                shouldStop = cp->GetBool("stop", false);
                shouldTilt = cp->GetBool("resetang", true);
                linkedtrigger = cp->GetString("destinationname", NULL);
            }
            else if (Q_strcmp(cp->GetName(), "multihop") == 0)
            {
                zoneType = MOMZONETYPE_MULTIHOP;
                shouldStop = cp->GetBool("stop", false);
                shouldTilt = cp->GetBool("resetang", true);
                holdTime = cp->GetFloat("hold", 1);
                //destinationIndex = cp->GetInt("destination", 1);
                linkedtrigger = cp->GetString("destinationname", NULL);
            }
            else if (Q_strcmp(cp->GetName(), "stage") == 0)
            {
                zoneType = MOMZONETYPE_STAGE;
                index = cp->GetInt("number", 0);
            }
            else
            {
                Warning("Error while reading zone file: Unknown mapzone type %s!\n", cp->GetName());
                continue;
            }

            // Add element
            m_zones.AddToTail(new CMapzone(zoneType, pos, rot, scaleMins, scaleMaxs, index, shouldStop, shouldTilt,
                holdTime, limitingspeed, maxleavespeed, MAKE_STRING(linkedtrigger)));
        }
        DevLog("Successfully loaded map zone file %s!\n", zoneFilePath);
        toReturn = true;
    }
    zoneKV->deleteThis();
    return toReturn;
}
Ejemplo n.º 5
0
//=============================================================================
void InGameChapterSelect::ApplySchemeSettings(vgui::IScheme *pScheme)
{
	BaseClass::ApplySchemeSettings(pScheme);

	SetPaintBackgroundEnabled( true );

	// Determine current game settings
	KeyValues *pGameSettings = g_pMatchFramework->GetMatchNetworkMsgController()->GetActiveServerGameDetails( NULL );
	KeyValues::AutoDelete autodelete_pGameSettings( pGameSettings );

	char const *szGameMode = pGameSettings->GetString( "game/mode", "campaign" );

	if ( !GameModeIsSingleChapter( szGameMode ) )
		pGameSettings->SetInt( "game/chapter", 1 );

	// Get mission and campaign info
	KeyValues *pInfoMission = NULL;
	KeyValues *pInfoChapter = g_pMatchExtSwarm->GetMapInfo( pGameSettings, &pInfoMission );

	// Check if this is a custom mission?
	if ( pInfoMission && !pInfoMission->GetBool( "builtin" ) )
		pInfoChapter = pInfoMission = NULL;	// trigger to use another builtin mission

	if ( !pInfoMission || !pInfoChapter )
	{
		KeyValues *pAllMissions = g_pMatchExtSwarm->GetAllMissions();
		for ( pInfoMission = pAllMissions ? pAllMissions->GetFirstTrueSubKey() : NULL;
			  pInfoMission; pInfoMission = pInfoMission->GetNextTrueSubKey() )
		{
			if ( !pInfoMission->GetBool( "builtin" ) )
				continue;

			pInfoChapter = pInfoMission->FindKey( CFmtStr( "modes/%s/1", szGameMode ) );
			if ( pInfoChapter )
				break;
		}
	}

	Assert( pInfoMission && pInfoChapter );

	// set the dropdowns
	DropDownMenu *pMissionDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpMission" ) );
	DropDownMenu *pChapterDropDown = dynamic_cast< DropDownMenu* >( FindChildByName( "DrpChapter" ) );
	if( pMissionDropDown && pChapterDropDown ) //missions change what the available campaigns are, we should listen on that flyout as well
	{
		pMissionDropDown->SetFlyout( CFmtStr( "FlmMission%s", szGameMode ) );

		if ( pInfoMission && pInfoChapter )
		{
			pMissionDropDown->SetCurrentSelection( CFmtStr( "cmd_campaign_%s", pInfoMission->GetString( "name" ) ) );
			Q_strncpy( m_chCampaign, pInfoMission->GetString( "name" ), ARRAYSIZE( m_chCampaign ) );

			// Set this after setting the mission dropdown, as that will default the chapter to the first in the campaign
			pChapterDropDown->SetCurrentSelection( CFmtStr( "#L4D360UI_Chapter_%d", pInfoChapter->GetInt( "chapter" ) ) );
			m_nChapter = pInfoChapter->GetInt( "chapter" );
		}

		FlyoutMenu *flyout = pMissionDropDown->GetCurrentFlyout();
		if( flyout )
		{
			flyout->CloseMenu( NULL );
		}

		flyout = pChapterDropDown->GetCurrentFlyout();
		if( flyout )
		{
			flyout->CloseMenu( NULL );
		}

		if ( m_ActiveControl )
		{
			m_ActiveControl->NavigateFrom( );
		}
		pMissionDropDown->NavigateTo();
		m_ActiveControl = pMissionDropDown;

		// Chapters are directly selectable only in some game modes
		pChapterDropDown->SetEnabled( GameModeIsSingleChapter( szGameMode ) );
	}

	SetPaintBackgroundEnabled( true );
	SetupAsDialogStyle();
}
Ejemplo n.º 6
0
// reads in current save data from a keyvalues file
bool CASW_Campaign_Save::LoadGameFromFile(const char *szFileName)
{
	// make sure the path and extension are correct
	char szFullFileName[256];
	char tempbuffer[256];
	Q_snprintf(tempbuffer, sizeof(tempbuffer), "%s", szFileName);	
	Q_SetExtension( tempbuffer, ".campaignsave", sizeof(tempbuffer) );
	const char *pszNoPathName = Q_UnqualifiedFileName(tempbuffer);	
	Q_snprintf(szFullFileName, sizeof(szFullFileName), "save/%s", pszNoPathName);	

	KeyValues *pSaveKeyValues = new KeyValues( szFileName );
	if (pSaveKeyValues->LoadFromFile(filesystem, szFullFileName))
	{
		m_CurrentSaveFileName = AllocPooledString(szFullFileName);

		m_iVersion = pSaveKeyValues->GetInt("Version");		
		m_iLowestSkillLevelPlayed = pSaveKeyValues->GetInt("SkillLevel");
		Q_strncpy( m_CampaignName.GetForModify(), pSaveKeyValues->GetString("CampaignName"), 255 );
		m_iCurrentPosition = pSaveKeyValues->GetInt("CurrentPosition");
		m_iNumMissionsComplete = pSaveKeyValues->GetInt("NumMissionsComplete");
		m_iInitialNumMissionsComplete = pSaveKeyValues->GetInt("InitialNumMissionsComplete");
		m_bMultiplayerGame = pSaveKeyValues->GetInt("Multiplayer") != 0;		
		Q_strncpy( m_DateTime.GetForModify(), pSaveKeyValues->GetString("DateTime"), 255 );		
		m_iNumDeaths = pSaveKeyValues->GetInt("NumDeaths");
		m_bFixedSkillPoints = !asw_custom_skill_points.GetBool(); //pSaveKeyValues->GetBool( "FixedSkillPoints", true );
		
		m_iNumPlayers = pSaveKeyValues->GetInt("NumPlayers");
		m_PlayerNames.Purge();
		m_PlayerIDs.Purge();

		// go through each sub section, adding the relevant details
		KeyValues *pkvSubSection = pSaveKeyValues->GetFirstSubKey();
		while ( pkvSubSection )
		{
			// mission details
			if (Q_stricmp(pkvSubSection->GetName(), "MISSION")==0)
			{
				int MissionID = pkvSubSection->GetInt("MissionID");
				if (MissionID >=0 && MissionID < ASW_MAX_MISSIONS_PER_CAMPAIGN)
				{
					m_MissionComplete.Set(MissionID, pkvSubSection->GetInt("MissionComplete"));
					m_NumRetries.Set(MissionID, pkvSubSection->GetInt("NumRetries"));
				}
			}

			// marine details
			if (Q_stricmp(pkvSubSection->GetName(), "MARINE")==0)
			{
				int MarineID = pkvSubSection->GetInt("MarineID");
				if (MarineID >=0 && MarineID < ASW_NUM_MARINE_PROFILES)
				{
					m_iMarineSkill[MarineID][ASW_SKILL_SLOT_0] = pkvSubSection->GetInt("SkillSlot0");
					m_iMarineSkill[MarineID][ASW_SKILL_SLOT_1] = pkvSubSection->GetInt("SkillSlot1");
					m_iMarineSkill[MarineID][ASW_SKILL_SLOT_2] = pkvSubSection->GetInt("SkillSlot2");
					m_iMarineSkill[MarineID][ASW_SKILL_SLOT_3] = pkvSubSection->GetInt("SkillSlot3");
					m_iMarineSkill[MarineID][ASW_SKILL_SLOT_4] = pkvSubSection->GetInt("SkillSlot4");
					m_iMarineSkill[MarineID][ASW_SKILL_SLOT_SPARE] = pkvSubSection->GetInt("SkillSlotSpare");

					m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_0] = pkvSubSection->GetInt("UndoSkillSlot0");
					m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_1] = pkvSubSection->GetInt("UndoSkillSlot1");
					m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_2] = pkvSubSection->GetInt("UndoSkillSlot2");
					m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_3] = pkvSubSection->GetInt("UndoSkillSlot3");
					m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_4] = pkvSubSection->GetInt("UndoSkillSlot4");
					m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_SPARE] = pkvSubSection->GetInt("UndoSkillSlotSpare");

					m_iParasitesKilled[MarineID] = pkvSubSection->GetInt("ParasitesKilled");

					m_MissionsCompleteNames.Set(MarineID, AllocPooledString(pkvSubSection->GetString("MissionsCompleted")));
					m_Medals.Set(MarineID, AllocPooledString(pkvSubSection->GetString("Medals")));

					m_bMarineWounded.Set(MarineID, (pkvSubSection->GetInt("Wounded") == 1));
					m_bMarineDead.Set(MarineID, (pkvSubSection->GetInt("Dead") == 1));

					//Ch1ckensCoop: Hack to give marines skill points for the first mission in a campaign. I'm too lazy to edit missionchooser.
					if (m_iCurrentPosition == 1)
					{
						m_iMarineSkill[MarineID][ASW_SKILL_SLOT_SPARE] = sk_asw_points_per_mission.GetInt();
						m_iPreviousMarineSkill[MarineID][ASW_SKILL_SLOT_SPARE] = sk_asw_points_per_mission.GetInt();
					}
				}					
			}

			// player name
			if (Q_stricmp(pkvSubSection->GetName(), "PLAYER")==0)
			{
				string_t stringName = AllocPooledString(pkvSubSection->GetString("PlayerName"));
				m_PlayerNames.AddToTail(stringName);				
			}
			// player ID
			if (Q_stricmp(pkvSubSection->GetName(), "DATA")==0)
			{
				string_t stringID = AllocPooledString(pkvSubSection->GetString("DataBlock"));
				m_PlayerIDs.AddToTail(stringID);								
			}
			// last commanders
			if (Q_stricmp(pkvSubSection->GetName(), "COMM")==0)
			{
				for (int i=0;i<ASW_NUM_MARINE_PROFILES;i++)
				{
					char buffer[16];
					Q_snprintf(buffer, sizeof(buffer), "Comm%d", i);
					string_t stringID = AllocPooledString(pkvSubSection->GetString(buffer));					
					m_LastCommanders[i] = stringID;
					Q_snprintf(buffer, sizeof(buffer), "Slot%d", i);
					m_LastMarineResourceSlot[i] = pkvSubSection->GetInt(buffer);

					//Ch1ckensCoop: Remember primary marines for each player, so we can handle reservations properly.
					Q_snprintf(buffer, sizeof(buffer), "Primary%d", i);
					m_LastPrimaryMarines[i] = pkvSubSection->GetBool(buffer);
				}				
			}
			
			pkvSubSection = pkvSubSection->GetNextKey();
		}
		return true;
	}
	Msg("Failed to load KeyValues from file %s\n", szFullFileName);
	return false;
}
Ejemplo n.º 7
0
void LoadObjectInfos( IBaseFileSystem *pFileSystem )
{
	const char *pFilename = "scripts/objects.txt";

	// Make sure this stuff hasn't already been loaded.
	Assert( !AreObjectInfosLoaded() );

	KeyValues *pValues = new KeyValues( "Object descriptions" );
	if ( !pValues->LoadFromFile( pFileSystem, pFilename, "GAME" ) )
	{
		Error( "Can't open %s for object info.", pFilename );
		pValues->deleteThis();
		return;
	}

	// Now read each class's information in.
	for ( int iObj=0; iObj < ARRAYSIZE( g_ObjectInfos ); iObj++ )
	{
		CObjectInfo *pInfo = &g_ObjectInfos[iObj];
		KeyValues *pSub = pValues->FindKey( pInfo->m_pObjectName );
		if ( !pSub )
		{
			Error( "Missing section '%s' from %s.", pInfo->m_pObjectName, pFilename );
			pValues->deleteThis();
			return;
		}

		// Read all the info in.
		if ( (pInfo->m_flBuildTime = pSub->GetFloat( "BuildTime", -999 )) == -999 ||
			(pInfo->m_nMaxObjects = pSub->GetInt( "MaxObjects", -999 )) == -999 ||
			(pInfo->m_Cost = pSub->GetInt( "Cost", -999 )) == -999 ||
			(pInfo->m_CostMultiplierPerInstance = pSub->GetFloat( "CostMultiplier", -999 )) == -999 ||
			(pInfo->m_UpgradeCost = pSub->GetInt( "UpgradeCost", -999 )) == -999 ||
			(pInfo->m_flUpgradeDuration = pSub->GetFloat( "UpgradeDuration", -999)) == -999 ||
			(pInfo->m_MaxUpgradeLevel = pSub->GetInt( "MaxUpgradeLevel", -999 )) == -999 ||
			(pInfo->m_SelectionSlot = pSub->GetInt( "SelectionSlot", -999 )) == -999 ||
			(pInfo->m_BuildCount = pSub->GetInt( "BuildCount", -999 )) == -999 ||
			(pInfo->m_SelectionPosition = pSub->GetInt( "SelectionPosition", -999 )) == -999 )
		{
			Error( "Missing data for object '%s' in %s.", pInfo->m_pObjectName, pFilename );
			pValues->deleteThis();
			return;
		}

		pInfo->m_pClassName = ReadAndAllocStringValue( pSub, "ClassName", pFilename );
		pInfo->m_pStatusName = ReadAndAllocStringValue( pSub, "StatusName", pFilename );
		pInfo->m_pBuilderWeaponName = ReadAndAllocStringValue( pSub, "BuilderWeaponName", pFilename );
		pInfo->m_pBuilderPlacementString = ReadAndAllocStringValue( pSub, "BuilderPlacementString", pFilename );
		pInfo->m_bSolidToPlayerMovement = pSub->GetInt( "SolidToPlayerMovement", 0 ) ? true : false;
		pInfo->m_pIconActive = ReadAndAllocStringValue( pSub, "IconActive", pFilename );
		pInfo->m_pIconInactive = ReadAndAllocStringValue( pSub, "IconInactive", pFilename );
		pInfo->m_pIconMenu = ReadAndAllocStringValue( pSub, "IconMenu", pFilename );
		pInfo->m_bUseItemInfo = pSub->GetInt( "UseItemInfo", 0 ) ? true : false;
		pInfo->m_pViewModel = ReadAndAllocStringValue( pSub, "Viewmodel", pFilename );
		pInfo->m_pPlayerModel = ReadAndAllocStringValue( pSub, "Playermodel", pFilename );
		pInfo->m_iDisplayPriority = pSub->GetInt( "DisplayPriority", 0 );
		pInfo->m_pHudStatusIcon = ReadAndAllocStringValue( pSub, "HudStatusIcon", pFilename );
		pInfo->m_bVisibleInWeaponSelection = ( pSub->GetInt( "VisibleInWeaponSelection", 1 ) > 0 );
		pInfo->m_pExplodeSound = ReadAndAllocStringValue( pSub, "ExplodeSound", pFilename );
		pInfo->m_pUpgradeSound = ReadAndAllocStringValue( pSub, "UpgradeSound", pFilename );
		pInfo->m_pExplosionParticleEffect = ReadAndAllocStringValue( pSub, "ExplodeEffect", pFilename );
		pInfo->m_bAutoSwitchTo = ( pSub->GetInt( "autoswitchto", 0 ) > 0 );

		pInfo->m_iMetalToDropInGibs = pSub->GetInt( "MetalToDropInGibs", 0 );
		pInfo->m_bRequiresOwnBuilder = pSub->GetBool( "RequiresOwnBuilder", 0 );
		// PistonMiner: Added Object Mode key
		KeyValues *pAltModes = pSub->FindKey("AltModes");
		if (pAltModes)
		{
			for (int i = 0; i < 4; ++i) // load at most 4 object modes
			{
				char altModeBuffer[256]; // Max size of 0x100
				V_snprintf(altModeBuffer, ARRAYSIZE(altModeBuffer), "AltMode%d", i);
				KeyValues *pCurAltMode = pAltModes->FindKey(altModeBuffer);
				if (!pCurAltMode)
					break;

				// Save logic here
				pInfo->m_AltModes.AddToTail(ReadAndAllocStringValue( pCurAltMode, "StatusName", pFilename ));
				pInfo->m_AltModes.AddToTail(ReadAndAllocStringValue( pCurAltMode, "ModeName", pFilename ));
				pInfo->m_AltModes.AddToTail(ReadAndAllocStringValue( pCurAltMode, "IconMenu", pFilename ));
			}
		}
	}

	pValues->deleteThis();
}
Ejemplo n.º 8
0
void GameModes::ApplySettings( KeyValues *pInResourceData )
{
	BaseClass::ApplySettings( pInResourceData );

	vgui::HScheme hScheme = vgui::scheme()->GetScheme( "SwarmScheme" );
	vgui::IScheme *pScheme = vgui::scheme()->GetIScheme( hScheme );
	if ( !pScheme )
		return;

	const char *pImageName = pInResourceData->GetString( "borderimage", "" );
	m_nBorderImageId = vgui::surface()->DrawGetTextureId( pImageName );
	if ( m_nBorderImageId == -1 )
	{
		m_nBorderImageId = vgui::surface()->CreateNewTextureID();
		vgui::surface()->DrawSetTextureFile( m_nBorderImageId, pImageName, true, false );	
	}

	pImageName = pInResourceData->GetString( "leftarrow", "" );
	m_nLeftArrowId = vgui::surface()->DrawGetTextureId( pImageName );
	if ( m_nLeftArrowId == -1 )
	{
		m_nLeftArrowId = vgui::surface()->CreateNewTextureID();
		vgui::surface()->DrawSetTextureFile( m_nLeftArrowId, pImageName, true, false );	
	}

	pImageName = pInResourceData->GetString( "rightarrow", "" );
	m_nRightArrowId = vgui::surface()->DrawGetTextureId( pImageName );
	if ( m_nRightArrowId == -1 )
	{
		m_nRightArrowId = vgui::surface()->CreateNewTextureID();
		vgui::surface()->DrawSetTextureFile( m_nRightArrowId, pImageName, true, false );	
	}

	m_nPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picoffsetx", 0 ) );
	m_nPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picwidth", 0 ) );
	m_nPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "picheight", 0 ) );

	m_nMenuTitleX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlex", 0 ) );
	m_nMenuTitleY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitley", 0 ) );
	m_nMenuTitleWide = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitlewide", 0 ) );
	m_nMenuTitleTall = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "menutitletall", 0 ) );

	m_nSubPics = pInResourceData->GetInt( "subpics", 0 );
	m_nSubPicGap = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicgap", 0 ) );
	m_nSubPicOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsetx", 0 ) );
	m_nSubPicOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicoffsety", 0 ) );
	m_nSubPicWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicwidth", 0 ) );
	m_nSubPicHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "subpicheight", 0 ) );
	m_bHideLabels = !!vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "hidelabels", 0 ) );

	m_nArrowWidth = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowwidth", 0 ) );
	m_nArrowHeight = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowheight", 0 ) );
	m_nArrowOffsetY = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "arrowoffsety", 0 ) );
	m_nRightArrowOffsetX = vgui::scheme()->GetProportionalScaledValue( pInResourceData->GetInt( "rightarrowoffsetx", 0 ) );

	m_hNameFont = pScheme->GetFont( pInResourceData->GetString( "subpicnamefont", "" ), true );
	m_nNameFontHeight = vgui::surface()->GetFontTall( m_hNameFont );

	const char *pNavUp = pInResourceData->GetString( "navUp", "" );
	const char *pNavDown = pInResourceData->GetString( "navDown", "" );

	int wideAtOpen = pInResourceData->GetInt( "wideatopen", 0 );

	// need to reset due to video mode change, alt+tab, etc
	m_GameModeInfos.Purge();

	// find all modes
	for ( KeyValues *pModeKey = pInResourceData->GetFirstTrueSubKey(); pModeKey; pModeKey = pModeKey->GetNextTrueSubKey() )
	{
		pImageName = pModeKey->GetString( "image", "" );
		int nImageId = vgui::surface()->DrawGetTextureId( pImageName );
		if ( nImageId == -1 )
		{
			nImageId = vgui::surface()->CreateNewTextureID();
			vgui::surface()->DrawSetTextureFile( nImageId, pImageName, true, false );	
		}

		int iIndex = m_GameModeInfos.AddToTail();

		m_GameModeInfos[iIndex].m_NameId = pModeKey->GetString( "id", "" );
		m_GameModeInfos[iIndex].m_NameText = pModeKey->GetString( "name", "" );
		m_GameModeInfos[iIndex].m_CommandText = pModeKey->GetString( "command", "" );
		m_GameModeInfos[iIndex].m_TitleText = pModeKey->GetString( "menutitle", "" );
		m_GameModeInfos[iIndex].m_HintText = pModeKey->GetString( "menuhint", "" );
		m_GameModeInfos[iIndex].m_HintTextDisabled = pModeKey->GetString( "menuhintdisabled", "" );
		m_GameModeInfos[iIndex].m_nImageId = nImageId;
		m_GameModeInfos[iIndex].m_bEnabled = pModeKey->GetBool( "enabled", true );

		m_GameModeInfos[iIndex].m_pHybridButton = new BaseModHybridButton( 
					this, 
					m_GameModeInfos[iIndex].m_NameId, 
					m_GameModeInfos[iIndex].m_TitleText, 
					this->GetParent(), 
					m_GameModeInfos[iIndex].m_CommandText );
		KeyValues *pKV = new KeyValues( "BtnGameMode" );

		int buttonX = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleX );
		int buttonY = vgui::scheme()->GetProportionalNormalizedValue( m_nPicHeight + m_nMenuTitleY );
		int buttonW = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleWide );
		int buttonH = vgui::scheme()->GetProportionalNormalizedValue( m_nMenuTitleTall );

		pKV->SetInt( "xpos", buttonX );
		pKV->SetInt( "ypos", buttonY );
		pKV->SetInt( "wide", buttonW );
		pKV->SetInt( "tall", buttonH );
		pKV->SetInt( "autoResize", 1 );
		pKV->SetInt( "pinCorner", 0 );
		pKV->SetInt( "visible", 0 );
		pKV->SetInt( "enabled", m_GameModeInfos[iIndex].m_bEnabled );
		pKV->SetInt( "tabPosition", 0 );
		if ( IsX360() )
		{
			pKV->SetString( "navUp", pNavUp );
			pKV->SetString( "navDown", pNavDown );
		}
		pKV->SetString( "tooltiptext", m_GameModeInfos[iIndex].m_HintText );
		pKV->SetString( "disabled_tooltiptext", m_GameModeInfos[iIndex].m_HintTextDisabled );
		pKV->SetString( "style", "GameModeButton" );
		pKV->SetInt( "ActivationType", 1 );
		pKV->SetString( "EnableCondition", pModeKey->GetString( "EnableCondition", "" ) );
		pKV->SetInt( "wideatopen", wideAtOpen );

		m_GameModeInfos[iIndex].m_pHybridButton->ApplySettings( pKV );
		pKV->deleteThis();
	}
	
	m_nMenuTitleActualTall = m_nMenuTitleTall;
	if ( m_GameModeInfos.Count() )
	{
		// get the real size
		m_nMenuTitleActualTall = m_GameModeInfos[0].m_pHybridButton->GetTall();

		// fixup the number of subpics to what we actually have
		// one active plus any subpics can only show the modes with no repeat
		m_nSubPics = MIN( m_nSubPics, m_GameModeInfos.Count() - 1 );
	}
	else
	{
		m_nSubPics = 0;
	}

	// exact size fixup width to get hardware clipping on rhs
	int panelWidth, panelHeight;
	GetSize( panelWidth, panelHeight );
	panelWidth = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX + ( m_nSubPics + 1 ) * m_nSubPicWidth + m_nSubPics * m_nSubPicGap;
	panelHeight = m_nPicHeight + m_nMenuTitleY + ( m_nMenuTitleActualTall - m_nMenuTitleTall )/2 + m_nMenuTitleTall;
	SetSize( panelWidth, panelHeight );

	// calc the arrow position for drawing and hit testing
	m_nSubPicX = m_nPicOffsetX + m_nPicWidth + m_nSubPicOffsetX;
	m_nSubPicY = ( m_nPicHeight + m_nMenuTitleY + m_nMenuTitleTall - m_nSubPicHeight )/2 + m_nSubPicOffsetY;
	m_nLeftArrowX = m_nPicOffsetX - m_nSubPicGap - m_nArrowWidth;
	m_nLeftArrowY = m_nSubPicY + m_nSubPicHeight - m_nArrowHeight + m_nArrowOffsetY;

	if ( m_nRightArrowOffsetX )
	{
		m_nRightArrowX = m_nPicOffsetX + m_nPicWidth + m_nSubPicGap + m_nRightArrowOffsetX;
	}
	else
	{
		m_nRightArrowX = m_nSubPicX + m_nSubPics * ( m_nSubPicWidth + m_nSubPicGap );
	}

	m_nRightArrowY = m_nLeftArrowY;

	// try to put back our last known game mode
	// this is to solve the navigation to children when the navigation has been lost
	// or alt+tab, video mode resize
	m_nActive = 0;
	if ( !g_CurrentModeIdSave.IsEmpty() )
	{
		m_nActive = NameIdToModeInfo( g_CurrentModeIdSave.String() );
		if ( m_nActive == -1 )
		{
			// no longer available
			g_CurrentModeIdSave = NULL;
			m_nActive = 0;
		}
	}

	SetActiveGameMode( m_nActive, true );
}