diff options
| author | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
|---|---|---|
| committer | FluorescentCIAAfricanAmerican <[email protected]> | 2020-04-22 12:56:21 -0400 |
| commit | 3bf9df6b2785fa6d951086978a3e66f49427166a (patch) | |
| tree | 2c0f1f0c63c4832882bc93814ebd2c2b1c6224e5 /vgui2/dme_controls/attributesurfacepropertypickerpanel.cpp | |
| download | archived-source-engine-2018-hl2-src-master.tar.xz archived-source-engine-2018-hl2-src-master.zip | |
Diffstat (limited to 'vgui2/dme_controls/attributesurfacepropertypickerpanel.cpp')
| -rw-r--r-- | vgui2/dme_controls/attributesurfacepropertypickerpanel.cpp | 103 |
1 files changed, 103 insertions, 0 deletions
diff --git a/vgui2/dme_controls/attributesurfacepropertypickerpanel.cpp b/vgui2/dme_controls/attributesurfacepropertypickerpanel.cpp new file mode 100644 index 0000000..0de7868 --- /dev/null +++ b/vgui2/dme_controls/attributesurfacepropertypickerpanel.cpp @@ -0,0 +1,103 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +// +//=============================================================================// + +#include "dme_controls/AttributeSurfacePropertyPickerPanel.h" +#include "dme_controls/AttributeTextEntry.h" +#include "tier1/KeyValues.h" +#include "filesystem.h" + + +using namespace vgui; + + +const char *SURFACEPROP_MANIFEST_FILE = "scripts/surfaceproperties_manifest.txt"; + + +//----------------------------------------------------------------------------- +// Constructor +//----------------------------------------------------------------------------- +CAttributeSurfacePropertyPickerPanel::CAttributeSurfacePropertyPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) : + BaseClass( parent, info ) +{ +} + +CAttributeSurfacePropertyPickerPanel::~CAttributeSurfacePropertyPickerPanel() +{ +} + + +//----------------------------------------------------------------------------- +// Reads the surface properties +//----------------------------------------------------------------------------- +void CAttributeSurfacePropertyPickerPanel::AddSurfacePropertiesToList( PickerList_t &list ) +{ + KeyValues *manifest = new KeyValues( SURFACEPROP_MANIFEST_FILE ); + if ( manifest->LoadFromFile( g_pFullFileSystem, SURFACEPROP_MANIFEST_FILE, "GAME" ) ) + { + for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() ) + { + if ( Q_stricmp( sub->GetName(), "file" ) ) + continue; + + KeyValues *file = new KeyValues( SURFACEPROP_MANIFEST_FILE ); + if ( file->LoadFromFile( g_pFullFileSystem, sub->GetString(), "GAME" ) ) + { + for ( KeyValues *pTrav = file; pTrav; pTrav = pTrav->GetNextKey() ) + { + int i = list.AddToTail(); + list[i].m_pChoiceString = pTrav->GetName(); + list[i].m_pChoiceValue = pTrav->GetName(); + } + } + else + { + Warning( "Unable to load surface properties file '%s'\n", sub->GetString() ); + } + file->deleteThis(); + } + } + else + { + Warning( "Unable to load manifest file '%s'\n", SURFACEPROP_MANIFEST_FILE ); + } + + manifest->deleteThis(); +} + + +//----------------------------------------------------------------------------- +// Called when it's time to show the picker +//----------------------------------------------------------------------------- +void CAttributeSurfacePropertyPickerPanel::ShowPickerDialog() +{ + CPickerFrame *pSurfacePropPickerDialog = new CPickerFrame( this, "Select Surface Property", "Surface Property", "surfacePropertyName" ); + PickerList_t surfacePropList; + AddSurfacePropertiesToList( surfacePropList ); + pSurfacePropPickerDialog->AddActionSignalTarget( this ); + pSurfacePropPickerDialog->DoModal( surfacePropList ); +} + + +//----------------------------------------------------------------------------- +// Called by the picker dialog if a asset was selected +//----------------------------------------------------------------------------- +void CAttributeSurfacePropertyPickerPanel::OnPicked( KeyValues *pKeyValues ) +{ + // Get the asset name back + const char *pSurfacePropertyName = pKeyValues->GetString( "choice", NULL ); + if ( !pSurfacePropertyName || !pSurfacePropertyName[ 0 ] ) + return; + + // Apply to text panel + m_pData->SetText( pSurfacePropertyName ); + SetDirty(true); + if ( IsAutoApply() ) + { + Apply(); + } +} |