Counter Strike : Global Offensive Source Code
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.

182 lines
5.2 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "dme_controls/AttributeElementPickerPanel.h"
  9. #include "dme_controls/AttributeTextEntry.h"
  10. #include "dme_controls/AttributeWidgetFactory.h"
  11. #include "datamodel/dmelement.h"
  12. #include "tier1/KeyValues.h"
  13. #include "vgui_controls/Button.h"
  14. #include "vgui_controls/ComboBox.h"
  15. #include "dme_controls/dmepicker.h"
  16. #include "movieobjects/dmeeditortypedictionary.h"
  17. #include "dme_controls/inotifyui.h"
  18. #include "dme_controls/dmecontrols.h"
  19. #include "dme_controls/dmecontrols_utils.h"
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include "tier0/memdbgon.h"
  22. using namespace vgui;
  23. // ----------------------------------------------------------------------------
  24. CAttributeElementPickerPanel::CAttributeElementPickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  25. BaseClass( parent, info )
  26. {
  27. m_hEdit = new vgui::Button( this, "Open", "...", this, "open" );
  28. m_pData = new CAttributeTextEntry( this, "AttributeValue" );
  29. m_pData->SetEnabled( !HasFlag( READONLY ) );
  30. m_pData->AddActionSignalTarget(this);
  31. m_pType->SetText( "element" );
  32. m_bShowMemoryUsage = info.m_bShowMemoryUsage;
  33. m_bShowUniqueID = info.m_bShowMemoryUsage;
  34. }
  35. void CAttributeElementPickerPanel::PostConstructor()
  36. {
  37. Refresh();
  38. }
  39. // ----------------------------------------------------------------------------
  40. vgui::Panel *CAttributeElementPickerPanel::GetDataPanel()
  41. {
  42. return static_cast< vgui::Panel * >( m_pData );
  43. }
  44. void CAttributeElementPickerPanel::Apply()
  45. {
  46. // FIXME: Implement when needed
  47. Assert( 0 );
  48. }
  49. void CAttributeElementPickerPanel::Refresh()
  50. {
  51. char elemText[ 512 ];
  52. elemText[0] = 0;
  53. CDmElement *element = NULL;
  54. if ( !GetEditorInfo() || !GetEditorInfo()->GetValue<bool>( "hideText" ) )
  55. {
  56. if ( HasAttribute( ) )
  57. {
  58. element = GetAttributeValueElement( );
  59. }
  60. else
  61. {
  62. element = GetPanelElement();
  63. }
  64. }
  65. if ( element )
  66. {
  67. char idstr[ 37 ] = "";
  68. if( m_bShowUniqueID )
  69. {
  70. UniqueIdToString( element->GetId(), idstr, sizeof( idstr ) );
  71. }
  72. if ( m_bShowMemoryUsage )
  73. {
  74. Q_snprintf( elemText, sizeof( elemText ), "%s %s (%.3fMB total / %.3fKB self)", element->GetTypeString(),
  75. idstr, element->EstimateMemoryUsage( TD_DEEP ) / float( 1 << 20 ), element->EstimateMemoryUsage( TD_NONE ) / float( 1 << 10 ) );
  76. }
  77. else
  78. {
  79. Q_snprintf( elemText, sizeof( elemText ), "%s %s", element->GetTypeString(), idstr );
  80. }
  81. }
  82. m_pData->SetText( elemText );
  83. m_pData->SetEditable( false );
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Called when it's time to show the Dme picker
  87. //-----------------------------------------------------------------------------
  88. void CAttributeElementPickerPanel::ShowPickerDialog()
  89. {
  90. CDmeEditorChoicesInfo *pInfo = CastElement<CDmeEditorChoicesInfo>( GetEditorInfo() );
  91. if ( !pInfo )
  92. return;
  93. // FIXME: Sucky. Should we make GetElementChoiceList return a DmeHandleVec_t?
  94. ElementChoiceList_t choices;
  95. CUtlVector< DmePickerInfo_t > vec;
  96. if ( ElementPropertiesChoices()->GetElementChoiceList( pInfo->GetChoiceType(), GetPanelElement(), GetAttributeName(), IsArrayEntry(), choices ) )
  97. {
  98. int c = choices.Count();
  99. vec.EnsureCapacity( c );
  100. for ( int i = 0; i < c; ++i )
  101. {
  102. int j = vec.AddToTail( );
  103. vec[j].m_hElement = choices[i].m_pValue->GetHandle();
  104. vec[j].m_pChoiceString = choices[i].m_pChoiceString;
  105. }
  106. }
  107. CDmePickerFrame *pDmePickerDialog = new CDmePickerFrame( this, "Select DME Element" );
  108. pDmePickerDialog->AddActionSignalTarget( this );
  109. pDmePickerDialog->DoModal( vec );
  110. }
  111. //-----------------------------------------------------------------------------
  112. // Called by the dme picker dialog if a dme was selected
  113. //-----------------------------------------------------------------------------
  114. void CAttributeElementPickerPanel::OnDmeSelected( KeyValues *pKeyValues )
  115. {
  116. // We're either going to get an activity or sequence name
  117. CDmElement *pElement = GetElementKeyValue< CDmElement >( pKeyValues, "dme" );
  118. SetAttributeValueElement( pElement );
  119. Refresh( );
  120. }
  121. //-----------------------------------------------------------------------------
  122. // Handle commands
  123. //-----------------------------------------------------------------------------
  124. void CAttributeElementPickerPanel::OnCommand( char const *cmd )
  125. {
  126. if ( !Q_stricmp( cmd, "open" ) )
  127. {
  128. ShowPickerDialog();
  129. }
  130. else
  131. {
  132. BaseClass::OnCommand( cmd );
  133. }
  134. }
  135. //-----------------------------------------------------------------------------
  136. // Layout the panel
  137. //-----------------------------------------------------------------------------
  138. void CAttributeElementPickerPanel::PerformLayout()
  139. {
  140. BaseClass::PerformLayout();
  141. int viewWidth, viewHeight;
  142. GetSize( viewWidth, viewHeight );
  143. IImage *arrowImage = vgui::scheme()->GetImage( "tools/ifm/icon_properties_linkarrow" , false);
  144. if( arrowImage )
  145. {
  146. m_hEdit->SetImage( arrowImage , 0 );
  147. m_hEdit->SetPaintBorderEnabled( false );
  148. m_hEdit->SetContentAlignment( vgui::Label::a_center );
  149. m_hEdit->SetBounds( (FirstColumnWidth - ColumnBorderWidth - 16) * 0.5 , ( viewHeight - 16 )* 0.5 , 16, 16 );
  150. }
  151. else
  152. {
  153. m_hEdit->SetBounds( 0, 0, 100, 20 );
  154. }
  155. }