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.

85 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/AttributeSoundPickerPanel.h"
  9. #include "dme_controls/soundpicker.h"
  10. #include "tier1/KeyValues.h"
  11. #include "dme_controls/AttributeTextEntry.h"
  12. #include "datamodel/dmelement.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. using namespace vgui;
  16. //-----------------------------------------------------------------------------
  17. // Constructor
  18. //-----------------------------------------------------------------------------
  19. CAttributeSoundPickerPanel::CAttributeSoundPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  20. BaseClass( parent, info )
  21. {
  22. }
  23. CAttributeSoundPickerPanel::~CAttributeSoundPickerPanel()
  24. {
  25. }
  26. //-----------------------------------------------------------------------------
  27. // Called when it's time to show the sound picker
  28. //-----------------------------------------------------------------------------
  29. void CAttributeSoundPickerPanel::ShowPickerDialog()
  30. {
  31. // Open file
  32. CSoundPicker::PickType_t pickType = CSoundPicker::PICK_ALL;
  33. const char *pTextType = GetTextType();
  34. if ( pTextType )
  35. {
  36. if ( !Q_stricmp( pTextType, "gamesoundName" ) )
  37. {
  38. pickType = CSoundPicker::PICK_GAMESOUNDS;
  39. }
  40. else if ( !Q_stricmp( pTextType, "wavName" ) )
  41. {
  42. pickType = CSoundPicker::PICK_WAVFILES;
  43. }
  44. }
  45. const char *pCurrentSound = GetAttributeValue<CUtlString>().Get();
  46. CSoundPickerFrame *pSoundPickerDialog = new CSoundPickerFrame( this, "Select sound", pickType );
  47. pSoundPickerDialog->AddActionSignalTarget( this );
  48. if ( pickType == CSoundPicker::PICK_ALL )
  49. {
  50. pickType = CSoundPicker::PICK_NONE;
  51. }
  52. pSoundPickerDialog->DoModal( pickType, pCurrentSound );
  53. }
  54. //-----------------------------------------------------------------------------
  55. // Called when the sound picker has picked a sound
  56. //-----------------------------------------------------------------------------
  57. void CAttributeSoundPickerPanel::OnSoundSelected( KeyValues *pKeyValues )
  58. {
  59. // We're either going to get an activity or sequence name
  60. const char *pGameSoundName = pKeyValues->GetString( "gamesound", NULL );
  61. const char *pSoundName = pKeyValues->GetString( "wav", pGameSoundName );
  62. if ( !pSoundName || !pSoundName[ 0 ] )
  63. return;
  64. // Apply to text panel
  65. m_pData->SetText( pSoundName );
  66. SetDirty(true);
  67. if ( IsAutoApply() )
  68. {
  69. Apply();
  70. }
  71. }