bool CommandMenu::LoadFromKeyValues( KeyValues * params ) { if ( !params ) return false; V_snprintf( m_CurrentTeam, 4, "%i", GetLocalPlayerTeam() ); V_FileBase( engine->GetLevelName(), m_CurrentMap, sizeof(m_CurrentMap) ); if ( params != m_MenuKeys ) { if ( m_MenuKeys ) m_MenuKeys->deleteThis(); m_MenuKeys = params->MakeCopy(); // save keyvalues } // iterate through all menu items KeyValues * subkey = m_MenuKeys->GetFirstSubKey(); while ( subkey ) { if ( subkey->GetDataType() == KeyValues::TYPE_NONE ) { if ( !LoadFromKeyValuesInternal( subkey, 0 ) ) // recursive call return false; } subkey = subkey->GetNextKey(); } UpdateMenu(); return true; }
void CHudAnimationInfo::PaintMappingInfo( int& x, int& y, Panel *element, PanelAnimationMap *map ) { if ( !map ) return; // Draw label surface()->DrawSetTextFont( m_LabelFont ); surface()->DrawSetTextColor( m_LabelColor ); surface()->DrawSetTextPos( x, y ); const char *className = ""; if ( map->pfnClassName ) { className = (*map->pfnClassName)(); } const char *p = className; while ( *p ) { surface()->DrawUnicodeChar( *p ); p++; } y += surface()->GetFontTall( m_LabelFont ) + 1; x += 10; int c = map->entries.Count(); for ( int i = 0; i < c; i++ ) { PanelAnimationMapEntry *e = &map->entries[ i ]; char sz[ 512 ]; char value[ 256 ]; Color col( 0, 0, 0, 0 ); Color *pColor = NULL; KeyValues *kv = new KeyValues( e->name() ); if ( element->RequestInfo( kv ) ) { KeyValues *dat = kv->FindKey(e->name()); if ( dat && dat->GetDataType() == KeyValues::TYPE_COLOR ) { col = dat->GetColor(); Q_snprintf( value, sizeof( value ), "%i, %i, %i, %i", col[0], col[1], col[2], col[3] ); pColor = &col; } else { Q_snprintf( value, sizeof( value ), "%s", dat->GetString() ); } } else { Q_strncpy( value, "???", sizeof( value ) ); } Q_snprintf( sz, sizeof( sz ), "%-30s %-20s (%s)", e->name(), e->type(), value ); kv->deleteThis(); PaintString( x, y, sz, pColor ); } x -= 10; if ( map->baseMap ) { PaintMappingInfo( x, y, element, map->baseMap ); } }
void CheckMaterial( KeyValues *pKeyValues, const char *pRoot, const char *pFileName, CUtlVector<VTFInfo_t> &vtf ) { const char *pShaderName = pKeyValues->GetName(); /* if ( Q_stristr( pShaderName, "Water" ) || Q_stristr( pShaderName, "Eyeball" ) || Q_stristr( pShaderName, "Shadow" ) || Q_stristr( pShaderName, "Refract" ) || Q_stristr( pShaderName, "Predator" ) || Q_stristr( pShaderName, "ParticleSphere" ) || Q_stristr( pShaderName, "DebugLuxels" ) || Q_stristr( pShaderName, "GooInGlass" ) || Q_stristr( pShaderName, "Modulate" ) || Q_stristr( pShaderName, "UnlitTwoTexture" ) || Q_stristr( pShaderName, "Cloud" ) || Q_stristr( pShaderName, "WorldVertexTransition" ) || Q_stristr( pShaderName, "DecalModulate" ) || Q_stristr( pShaderName, "DecalBaseTimesLightmapAlphaBlendSelfIllum" ) || Q_stristr( pShaderName, "Sprite" ) ) { return; } // Check for alpha channels const char *pBaseTextureName = pKeyValues->GetString( "$basetexture", NULL ); if ( pBaseTextureName != NULL ) { if ( DoesTextureUseAlpha( pBaseTextureName, pFileName ) ) { float flAlpha = MaterialFloatKeyValue( pKeyValues, "$alpha", 1.0f ); bool bHasVertexAlpha = DoesMaterialHaveKey( pKeyValues, "$vertexalpha" ); // Modulation always happens here whether we want it to or not bool bHasAlphaTest = DoesMaterialHaveKey( pKeyValues, "$alphatest" ); bool bHasTranslucent = DoesMaterialHaveKey( pKeyValues, "$translucent" ); bool bHasSelfIllum = DoesMaterialHaveKey( pKeyValues, "$selfillum" ); bool bHasBaseAlphaEnvMapMask = DoesMaterialHaveKey( pKeyValues, "$basealphaenvmapmask" ); if ( (flAlpha == 1.0f) && !bHasVertexAlpha && !bHasAlphaTest && !bHasTranslucent && !bHasSelfIllum && !bHasBaseAlphaEnvMapMask ) { Warning("Material \"%s\": BASETEXTURE \"%s\"\n", pFileName, pBaseTextureName ); } } } */ /* // Check for bump, spec, and no normalmapalphaenvmapmask const char *pBumpmapName = pKeyValues->GetString( "$bumpmap", NULL ); if ( pBumpmapName != NULL ) { if ( DoesTextureUseAlpha( pBumpmapName, pFileName ) ) { bool bHasEnvmap = DoesMaterialHaveKey( pKeyValues, "$envmap" ); bool bHasNormalMapAlphaEnvMapMask = DoesMaterialHaveKey( pKeyValues, "$normalmapalphaenvmapmask" ); if ( !bHasEnvmap || !bHasNormalMapAlphaEnvMapMask ) { Warning("Material \"%s\": BUMPMAP \"%s\"\n", pFileName, pBumpmapName ); } } } */ /* if ( !Q_stristr( pShaderName, "LightmappedGeneric" ) && !Q_stristr( pShaderName, "VertexLitGeneric" ) ) { return; } if ( DoesMaterialHaveKey( pKeyValues, "$envmap" ) && DoesMaterialHaveKey( pKeyValues, "$bumpmap" ) ) { int nDim; float retVal[4]; float defaultVal[4] = { 1, 1, 1, 1 }; if ( MaterialVectorKeyValue( pKeyValues, "$envmaptint", 3, defaultVal, &nDim, retVal ) ) { Warning("ENVMAP + ENVMAPTINT : Material \"%s\"\n", pFileName ); } // else // { // Warning("ENVMAP only: Material \"%s\"\n", pFileName ); // } } */ /* if ( !Q_stristr( pShaderName, "Refract" ) ) { return; } if ( !DoesMaterialHaveKey( pKeyValues, "$envmap" ) ) { bool bUsesAlpha, bIsCompressed, bIsPalettized; int nSizeInBytes; if ( DoesTextureUseNormal( pKeyValues->GetString( "$normalmap" ), pFileName, bUsesAlpha, bIsCompressed, bIsPalettized, nSizeInBytes ) ) { if ( bIsCompressed ) { Warning("Bad : Material compressed \"%s\"\n", pFileName ); } else { Warning("Bad : Material \"%s\"\n", pFileName ); } } } */ /* if ( !Q_stristr( pShaderName, "WorldTwoTextureBlend" ) ) { return; } if ( DoesMaterialHaveKey( pKeyValues, "$envmap" ) || DoesMaterialHaveKey( pKeyValues, "$parallaxmap" ) || DoesMaterialHaveKey( pKeyValues, "$bumpmap" ) || DoesMaterialHaveKey( pKeyValues, "$vertexcolor" ) || DoesMaterialHaveKey( pKeyValues, "$basetexture2" ) ) { Warning("Bad : Material \"%s\"\n", pFileName ); } */ for ( KeyValues *pSubKey = pKeyValues->GetFirstValue(); pSubKey; pSubKey = pSubKey->GetNextValue() ) { // Msg( " Checking %s\n", pSubKey->GetString() ); if ( pSubKey->GetDataType() != KeyValues::TYPE_STRING ) continue; bool bUsesAlpha, bIsCompressed; int nSizeInBytes; if ( DoesTextureUseNormal( pSubKey->GetString(), pFileName, bUsesAlpha, bIsCompressed, nSizeInBytes ) ) { if ( bUsesAlpha ) { if ( bIsCompressed ) { s_nNormalWithAlphaCompressedBytes += nSizeInBytes; } else { s_nNormalWithAlphaBytes += nSizeInBytes; Msg( "Normal texture w alpha uncompressed %s\n", pSubKey->GetString() ); } } else { if ( bIsCompressed ) { s_nNormalCompressedBytes += nSizeInBytes; } else { s_nNormalBytes += nSizeInBytes; } } } } /* if ( !Q_stristr( pShaderName, "VertexLitGeneric" ) ) return; if ( !DoesMaterialHaveKey( pKeyValues, "$envmap" ) && DoesMaterialHaveKey( pKeyValues, "$bumpmap" ) ) { Warning("BUMPMAP + no ENVMAP : Material \"%s\"\n", pFileName ); } */ // CheckKeyValues( pKeyValues, vtf ); }
static bool MaterialVectorKeyValue( KeyValues *pKeyValues, const char *pKeyName, int nDefaultDim, float *pDefault, int *pDim, float *pVector ) { int nDim; float retVal[4]; KeyValues *pValue = pKeyValues->FindKey( pKeyName ); if ( pValue ) { switch( pValue->GetDataType() ) { case KeyValues::TYPE_INT: { int nInt = pValue->GetInt(); for ( int i = 0; i < 4; ++i ) { retVal[i] = nInt; } if ( !AsVectorsEqual( nDefaultDim, pDefault, nDefaultDim, retVal ) ) { *pDim = nDefaultDim; memcpy( pVector, retVal, nDefaultDim * sizeof(float) ); return true; } } break; case KeyValues::TYPE_FLOAT: { float flFloat = pValue->GetFloat(); for ( int i = 0; i < 4; ++i ) { retVal[i] = flFloat; } if ( !AsVectorsEqual( nDefaultDim, pDefault, nDefaultDim, retVal ) ) { *pDim = nDefaultDim; memcpy( pVector, retVal, nDefaultDim * sizeof(float) ); return true; } } break; case KeyValues::TYPE_STRING: { nDim = ParseVectorFromKeyValueString( pValue, "", retVal ); if ( !AsVectorsEqual( nDefaultDim, pDefault, nDim, retVal ) ) { *pDim = nDim; memcpy( pVector, retVal, nDim * sizeof(float) ); return true; } } break; } } for( KeyValues *pSubKey = pKeyValues->GetFirstTrueSubKey(); pSubKey; pSubKey = pSubKey->GetNextTrueSubKey() ) { if ( MaterialVectorKeyValue( pSubKey, pKeyName, nDefaultDim, pDefault, &nDim, retVal ) ) { *pDim = nDim; memcpy( pVector, retVal, nDim * sizeof(float) ); return true; } } *pDim = nDefaultDim; memcpy( pVector, pDefault, nDefaultDim * sizeof(float) ); return false; }
int CPhysicsSurfaceProps::ParseSurfaceData(const char* pFilename, const char* pTextfile) { if (!AddFileToDatabase(pFilename)) return 0; KeyValues* surfprops = new KeyValues(""); surfprops->LoadFromBuffer(pFilename, pTextfile); for (KeyValues* surface = surfprops; surface; surface = surface->GetNextKey()) { CSurface prop; int baseMaterial = GetSurfaceIndex("default"); memset(&prop.data, 0, sizeof(prop.data)); prop.m_name = m_strings->AddString(surface->GetName()); prop.data.game.material = 0; prop.data.game.maxSpeedFactor = 1.0f; prop.data.game.jumpFactor = 1.0f; prop.data.game.climbable = 0.0f; CopyPhysicsProperties(&prop, baseMaterial); for (KeyValues* data = surface->GetFirstSubKey(); data; data = data->GetNextKey()) { const char* key = data->GetName(); if (!strcmpi(key, "base")) { baseMaterial = GetSurfaceIndex(data->GetString()); CopyPhysicsProperties(&prop, baseMaterial); } else if (!strcmpi(key, "thickness")) { prop.data.physics.thickness = data->GetFloat(); } else if (!strcmpi(key, "density")) { prop.data.physics.density = data->GetFloat(); } else if (!strcmpi(key, "elasticity")) { prop.data.physics.elasticity = data->GetFloat(); } else if (!strcmpi(key, "friction")) { prop.data.physics.friction = data->GetFloat(); } else if (!strcmpi(key, "dampening")) { prop.data.physics.dampening = data->GetFloat(); } else if (!strcmpi(key, "audioreflectivity")) { prop.data.audio.reflectivity = data->GetFloat(); } else if (!strcmpi(key, "audiohardnessfactor")) { prop.data.audio.hardnessFactor = data->GetFloat(); } else if (!strcmpi(key, "audioroughnessfactor")) { prop.data.audio.roughnessFactor = data->GetFloat(); } else if (!strcmpi(key, "scrapeRoughThreshold")) { prop.data.audio.roughThreshold = data->GetFloat(); } else if (!strcmpi(key, "impactHardThreshold")) { prop.data.audio.hardThreshold = data->GetFloat(); } else if (!strcmpi(key, "audioHardMinVelocity")) { prop.data.audio.hardVelocityThreshold = data->GetFloat(); } else if (!strcmpi(key, "maxspeedfactor")) { prop.data.game.maxSpeedFactor = data->GetFloat(); } else if (!strcmpi(key, "jumpfactor")) { prop.data.game.jumpFactor = data->GetFloat(); } else if (!strcmpi(key, "climbable")) { prop.data.game.climbable = data->GetInt(); } else if (!strcmpi(key, "gamematerial")) { if (data->GetDataType() == KeyValues::TYPE_STRING && strlen(data->GetString()) == 1) { prop.data.game.material = toupper(data->GetString()[0]); } else { prop.data.game.material = data->GetInt(); } } else if (!strcmpi(key, "stepleft")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.stepleft = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "stepright")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.stepright = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "impactsoft")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.impactSoft = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "impacthard")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.impactHard = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "scrapesmooth")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.scrapeSmooth = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "scraperough")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.scrapeRough = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "bulletimpact")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.bulletImpact = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "break")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.breakSound = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "strain")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.strainSound = m_soundList.AddToTail(sym); } else if (!strcmpi(key, "rolling")) { CUtlSymbol sym = m_strings->AddString(data->GetString()); prop.data.sounds.rolling = m_soundList.AddToTail(sym); } else { AssertMsg2(0, "Bad surfaceprop key %s (%s)\n", key, data->GetString()); } } if (GetSurfaceIndex(m_strings->String(prop.m_name)) >= 0) break; m_props.AddToTail(prop); } surfprops->deleteThis(); return 0; }
bool CommandMenu::LoadFromKeyValuesInternal(KeyValues * key, int depth) { char text[255]; KeyValues * subkey = NULL; if ( depth > 100 ) { Msg("CommandMenu::LoadFromKeyValueInternal: depth > 100.\n"); return false; } V_strncpy( text, key->GetString("custom"), sizeof(text) ); // get type if ( text[0] ) { AddMenuCustomItem( key ); // do whatever custom item wants to return true; } if ( !CheckRules( key->GetString("rule"), key->GetString("ruledata") ) ) { return true; } // rules OK add subkey V_strncpy( text, key->GetString("toggle"), sizeof(text) ); // get type if ( text[0] ) { AddMenuToggleItem( key ); return true; } V_strncpy( text, key->GetString("command"), sizeof(text) ); // get type if ( text[0] ) { AddMenuCommandItem( key ); return true; } // not a command, nor a toggle. Must be a submenu: StartNewSubMenu( key ); // create submenu // iterate through all subkeys subkey = key->GetFirstSubKey(); while ( subkey ) { if ( subkey->GetDataType() == KeyValues::TYPE_NONE ) { LoadFromKeyValuesInternal( subkey, depth+1 ); // recursive call } subkey = subkey->GetNextKey(); } FinishSubMenu(); // go one level back return true; }
//----------------------------------------------------------------------------- // Purpose: Gets the specified value from a panel //----------------------------------------------------------------------------- AnimationController::Value_t AnimationController::GetValue(ActiveAnimation_t& anim, Panel *panel, UtlSymId_t var) { Value_t val = { 0, 0, 0, 0 }; if (var == m_sPosition) { int x, y; panel->GetPos(x, y); val.a = (float)(x - GetRelativeOffset( anim.align, true ) ); val.b = (float)(y - GetRelativeOffset( anim.align, false ) ); } else if (var == m_sSize) { int w, t; panel->GetSize(w, t); val.a = (float)w; val.b = (float)t; } else if (var == m_sFgColor) { Color col = panel->GetFgColor(); val.a = col[0]; val.b = col[1]; val.c = col[2]; val.d = col[3]; } else if (var == m_sBgColor) { Color col = panel->GetBgColor(); val.a = col[0]; val.b = col[1]; val.c = col[2]; val.d = col[3]; } else if ( var == m_sXPos ) { int x, y; panel->GetPos(x, y); val.a = (float)( x - GetRelativeOffset( anim.align, true ) ); } else if ( var == m_sYPos ) { int x, y; panel->GetPos(x, y); val.a = (float)( y - GetRelativeOffset( anim.align, false ) ); } else if ( var == m_sWide ) { int w, h; panel->GetSize(w, h); val.a = (float)w; } else if ( var == m_sTall ) { int w, h; panel->GetSize(w, h); val.a = (float)h; } else { KeyValues *outputData = new KeyValues(g_ScriptSymbols.String(var)); if (panel->RequestInfo(outputData)) { // find the var and lookup it's type KeyValues *kv = outputData->FindKey(g_ScriptSymbols.String(var)); if (kv && kv->GetDataType() == KeyValues::TYPE_FLOAT) { val.a = kv->GetFloat(); val.b = 0.0f; val.c = 0.0f; val.d = 0.0f; } else if (kv && kv->GetDataType() == KeyValues::TYPE_COLOR) { Color col = kv->GetColor(); val.a = col[0]; val.b = col[1]; val.c = col[2]; val.d = col[3]; } } else { // Assert(!("Unhandlable var in AnimationController::GetValue())")); } outputData->deleteThis(); } return val; }