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.

109 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //===========================================================================//
  8. #include "dme_controls/AttributeSequencePickerPanel.h"
  9. #include "filesystem.h"
  10. #include "vgui_controls/Button.h"
  11. #include "vgui_controls/FileOpenDialog.h"
  12. #include "dme_controls/AttributeTextEntry.h"
  13. #include "matsys_controls/MDLPicker.h"
  14. #include "matsys_controls/sequencepicker.h"
  15. #include "tier1/KeyValues.h"
  16. // memdbgon must be the last include file in a .cpp file!!!
  17. #include "tier0/memdbgon.h"
  18. using namespace vgui;
  19. //-----------------------------------------------------------------------------
  20. // Constructor
  21. //-----------------------------------------------------------------------------
  22. CAttributeSequencePickerPanel::CAttributeSequencePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  23. BaseClass( parent, info )
  24. {
  25. }
  26. CAttributeSequencePickerPanel::~CAttributeSequencePickerPanel()
  27. {
  28. }
  29. //-----------------------------------------------------------------------------
  30. // Called when it's time to show the MDL picker
  31. //-----------------------------------------------------------------------------
  32. void CAttributeSequencePickerPanel::ShowPickerDialog()
  33. {
  34. CMDLPickerFrame *pMDLPickerDialog = new CMDLPickerFrame( this, "Select .MDL File" );
  35. pMDLPickerDialog->AddActionSignalTarget( this );
  36. pMDLPickerDialog->DoModal( );
  37. }
  38. //-----------------------------------------------------------------------------
  39. // Called when it's time to show the MDL picker
  40. //-----------------------------------------------------------------------------
  41. void CAttributeSequencePickerPanel::OnMDLSelected( KeyValues *pKeyValues )
  42. {
  43. const char *pMDLName = pKeyValues->GetString( "asset", NULL );
  44. char pRelativePath[MAX_PATH];
  45. Q_snprintf( pRelativePath, sizeof(pRelativePath), "models\\%s", pMDLName );
  46. ShowSequencePickerDialog( pRelativePath );
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Called when it's time to show the sequence picker
  50. //-----------------------------------------------------------------------------
  51. void CAttributeSequencePickerPanel::ShowSequencePickerDialog( const char *pMDLName )
  52. {
  53. if ( !pMDLName || !pMDLName[ 0 ] )
  54. return;
  55. // Open file
  56. CSequencePicker::PickType_t pickType = CSequencePicker::PICK_ALL;
  57. const char *pTextType = GetTextType();
  58. if ( pTextType )
  59. {
  60. if ( !Q_stricmp( pTextType, "activityName" ) )
  61. {
  62. pickType = CSequencePicker::PICK_ACTIVITIES;
  63. }
  64. else if ( !Q_stricmp( pTextType, "sequenceName" ) )
  65. {
  66. pickType = CSequencePicker::PICK_SEQUENCES;
  67. }
  68. }
  69. CSequencePickerFrame *pSequencePickerDialog = new CSequencePickerFrame( this, pickType );
  70. pSequencePickerDialog->AddActionSignalTarget( this );
  71. pSequencePickerDialog->DoModal( pMDLName );
  72. }
  73. //-----------------------------------------------------------------------------
  74. // Called when it's time to show the MDL picker
  75. //-----------------------------------------------------------------------------
  76. void CAttributeSequencePickerPanel::OnSequenceSelected( KeyValues *pKeyValues )
  77. {
  78. // We're either going to get an activity or sequence name
  79. const char *pActivityName = pKeyValues->GetString( "activity", NULL );
  80. const char *pSequenceName = pKeyValues->GetString( "sequence", pActivityName );
  81. if ( !pSequenceName || !pSequenceName[ 0 ] )
  82. return;
  83. // Apply to text panel
  84. m_pData->SetText( pSequenceName );
  85. SetDirty(true);
  86. if ( IsAutoApply() )
  87. {
  88. Apply();
  89. }
  90. }