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.

143 lines
4.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "dme_controls/DmeSourceSkinPanel.h"
  7. #include "dme_controls/DmePanel.h"
  8. #include "movieobjects/dmemdlmakefile.h"
  9. #include "vgui_controls/TextEntry.h"
  10. #include "vgui_controls/CheckButton.h"
  11. #include "tier1/KeyValues.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. using namespace vgui;
  15. //-----------------------------------------------------------------------------
  16. //
  17. // Hook into the dme panel editor system
  18. //
  19. //-----------------------------------------------------------------------------
  20. IMPLEMENT_DMEPANEL_FACTORY( CDmeSourceSkinPanel, DmeSourceSkin, "DmeSourceSkinDefault", "MDL Skin Editor", true );
  21. //-----------------------------------------------------------------------------
  22. // Purpose: Constructor, destructor
  23. //-----------------------------------------------------------------------------
  24. CDmeSourceSkinPanel::CDmeSourceSkinPanel( vgui::Panel *pParent, const char *pPanelName ) :
  25. BaseClass( pParent, pPanelName )
  26. {
  27. m_pSkinName = new vgui::TextEntry( this, "SkinName" );
  28. m_pSkinName->AddActionSignalTarget( this );
  29. m_pScale = new vgui::TextEntry( this, "Scale" );
  30. m_pScale->AddActionSignalTarget( this );
  31. m_pFlipTriangles = new vgui::CheckButton( this, "FlipTriangles", "" );
  32. m_pFlipTriangles->AddActionSignalTarget( this );
  33. // Load layout settings; has to happen before pinning occurs in code
  34. LoadControlSettings( "resource/DmeSourceSkinPanel.res" );
  35. }
  36. CDmeSourceSkinPanel::~CDmeSourceSkinPanel()
  37. {
  38. }
  39. //-----------------------------------------------------------------------------
  40. // Marks the file as dirty (or not)
  41. //-----------------------------------------------------------------------------
  42. void CDmeSourceSkinPanel::SetDirty()
  43. {
  44. PostActionSignal( new KeyValues( "DmeElementChanged" ) );
  45. }
  46. //-----------------------------------------------------------------------------
  47. // Resets the state
  48. //-----------------------------------------------------------------------------
  49. void CDmeSourceSkinPanel::SetDmeElement( CDmeSourceSkin *pSourceSkin )
  50. {
  51. m_hSourceSkin = pSourceSkin;
  52. bool bEnabled = (pSourceSkin != NULL);
  53. m_pSkinName->SetEnabled( bEnabled );
  54. m_pScale->SetEnabled( bEnabled );
  55. m_pFlipTriangles->SetEnabled( bEnabled );
  56. if ( !bEnabled )
  57. {
  58. m_pSkinName->SetText( "" );
  59. m_pScale->SetText( "" );
  60. m_pFlipTriangles->SetSelected( false );
  61. return;
  62. }
  63. char pBuf[32];
  64. Q_snprintf( pBuf, sizeof(pBuf), "%.3f", pSourceSkin->m_flScale.Get() );
  65. m_pSkinName->SetText( pSourceSkin->m_SkinName );
  66. m_pScale->SetText( pBuf );
  67. m_pFlipTriangles->SetSelected( pSourceSkin->m_bFlipTriangles );
  68. }
  69. //-----------------------------------------------------------------------------
  70. // Command handler
  71. //-----------------------------------------------------------------------------
  72. void CDmeSourceSkinPanel::OnCheckButtonChecked( int nChecked )
  73. {
  74. if ( !m_hSourceSkin.Get() )
  75. return;
  76. bool bFlipTriangles = ( nChecked != 0 );
  77. if ( bFlipTriangles != m_hSourceSkin->m_bFlipTriangles )
  78. {
  79. m_hSourceSkin->m_bFlipTriangles = bFlipTriangles;
  80. SetDirty();
  81. }
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Called when something is typed in a text entry field
  85. //-----------------------------------------------------------------------------
  86. void CDmeSourceSkinPanel::OnTextChanged( KeyValues *kv )
  87. {
  88. if ( !m_hSourceSkin.Get() )
  89. return;
  90. Panel *pPanel = (Panel *)kv->GetPtr( "panel", NULL );
  91. if ( pPanel == m_pSkinName )
  92. {
  93. char pTextBuf[256];
  94. m_pSkinName->GetText( pTextBuf, sizeof( pTextBuf) );
  95. if ( Q_stricmp( pTextBuf, m_hSourceSkin->m_SkinName ) )
  96. {
  97. m_hSourceSkin->m_SkinName = pTextBuf;
  98. SetDirty();
  99. }
  100. return;
  101. }
  102. if ( pPanel == m_pScale )
  103. {
  104. char pTextBuf[256];
  105. m_pScale->GetText( pTextBuf, sizeof( pTextBuf) );
  106. float flScale = atoi( pTextBuf );
  107. if ( flScale != m_hSourceSkin->m_flScale )
  108. {
  109. m_hSourceSkin->m_flScale = flScale;
  110. SetDirty();
  111. }
  112. return;
  113. }
  114. }