Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
3.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/AttributeSurfacePropertyPickerPanel.h"
  9. #include "dme_controls/AttributeTextEntry.h"
  10. #include "tier1/KeyValues.h"
  11. #include "filesystem.h"
  12. using namespace vgui;
  13. const char *SURFACEPROP_MANIFEST_FILE = "scripts/surfaceproperties_manifest.txt";
  14. //-----------------------------------------------------------------------------
  15. // Constructor
  16. //-----------------------------------------------------------------------------
  17. CAttributeSurfacePropertyPickerPanel::CAttributeSurfacePropertyPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  18. BaseClass( parent, info )
  19. {
  20. }
  21. CAttributeSurfacePropertyPickerPanel::~CAttributeSurfacePropertyPickerPanel()
  22. {
  23. }
  24. //-----------------------------------------------------------------------------
  25. // Reads the surface properties
  26. //-----------------------------------------------------------------------------
  27. void CAttributeSurfacePropertyPickerPanel::AddSurfacePropertiesToList( PickerList_t &list )
  28. {
  29. KeyValues *manifest = new KeyValues( SURFACEPROP_MANIFEST_FILE );
  30. if ( manifest->LoadFromFile( g_pFullFileSystem, SURFACEPROP_MANIFEST_FILE, "GAME" ) )
  31. {
  32. for ( KeyValues *sub = manifest->GetFirstSubKey(); sub != NULL; sub = sub->GetNextKey() )
  33. {
  34. if ( Q_stricmp( sub->GetName(), "file" ) )
  35. continue;
  36. KeyValues *file = new KeyValues( SURFACEPROP_MANIFEST_FILE );
  37. if ( file->LoadFromFile( g_pFullFileSystem, sub->GetString(), "GAME" ) )
  38. {
  39. for ( KeyValues *pTrav = file; pTrav; pTrav = pTrav->GetNextKey() )
  40. {
  41. int i = list.AddToTail();
  42. list[i].m_pChoiceString = pTrav->GetName();
  43. list[i].m_pChoiceValue = pTrav->GetName();
  44. }
  45. }
  46. else
  47. {
  48. Warning( "Unable to load surface properties file '%s'\n", sub->GetString() );
  49. }
  50. file->deleteThis();
  51. }
  52. }
  53. else
  54. {
  55. Warning( "Unable to load manifest file '%s'\n", SURFACEPROP_MANIFEST_FILE );
  56. }
  57. manifest->deleteThis();
  58. }
  59. //-----------------------------------------------------------------------------
  60. // Called when it's time to show the picker
  61. //-----------------------------------------------------------------------------
  62. void CAttributeSurfacePropertyPickerPanel::ShowPickerDialog()
  63. {
  64. CPickerFrame *pSurfacePropPickerDialog = new CPickerFrame( this, "Select Surface Property", "Surface Property", "surfacePropertyName" );
  65. PickerList_t surfacePropList;
  66. AddSurfacePropertiesToList( surfacePropList );
  67. pSurfacePropPickerDialog->AddActionSignalTarget( this );
  68. pSurfacePropPickerDialog->DoModal( surfacePropList );
  69. }
  70. //-----------------------------------------------------------------------------
  71. // Called by the picker dialog if a asset was selected
  72. //-----------------------------------------------------------------------------
  73. void CAttributeSurfacePropertyPickerPanel::OnPicked( KeyValues *pKeyValues )
  74. {
  75. // Get the asset name back
  76. const char *pSurfacePropertyName = pKeyValues->GetString( "choice", NULL );
  77. if ( !pSurfacePropertyName || !pSurfacePropertyName[ 0 ] )
  78. return;
  79. // Apply to text panel
  80. m_pData->SetText( pSurfacePropertyName );
  81. SetDirty(true);
  82. if ( IsAutoApply() )
  83. {
  84. Apply();
  85. }
  86. }