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.

140 lines
3.7 KiB

  1. //======= Copyright (c) 1996-2009, Valve Corporation, All rights reserved. ======
  2. //
  3. // CAttributeSheetSequencePickerPanel - Panel for editing int attributes that select a sprite sheet sequence
  4. //
  5. //===============================================================================
  6. #include "dme_controls/attributesheetsequencepickerpanel.h"
  7. #include "FileSystem.h"
  8. #include "vgui_controls/MenuButton.h"
  9. #include "vgui_controls/FileOpenDialog.h"
  10. #include "dme_controls/AttributeTextEntry.h"
  11. #include "matsys_controls/sheetsequencepanel.h"
  12. #include "movieobjects/dmeparticlesystemdefinition.h"
  13. #include "tier1/keyvalues.h"
  14. #include "dme_controls/AttributeWidgetFactory.h"
  15. #include "movieobjects/dmeeditortypedictionary.h"
  16. // NOTE: This has to be the last file included!
  17. #include "tier0/memdbgon.h"
  18. using namespace vgui;
  19. //-----------------------------------------------------------------------------
  20. //
  21. // CNotifyMenuButton - MenuButton with a notify before the menu is shown
  22. //
  23. //-----------------------------------------------------------------------------
  24. class CNotifyMenuButton: public vgui::MenuButton
  25. {
  26. DECLARE_CLASS_SIMPLE( CNotifyMenuButton, vgui::MenuButton );
  27. public:
  28. CNotifyMenuButton(CAttributeSheetSequencePickerPanel *parent, const char *panelName, const char *text);
  29. virtual void OnShowMenu(Menu *menu);
  30. private:
  31. CAttributeSheetSequencePickerPanel* m_pParent;
  32. };
  33. CNotifyMenuButton::CNotifyMenuButton(CAttributeSheetSequencePickerPanel *parent, const char *panelName, const char *text):
  34. BaseClass(parent,panelName,text)
  35. {
  36. m_pParent = parent;
  37. }
  38. void CNotifyMenuButton::OnShowMenu(Menu *menu)
  39. {
  40. if ( m_pParent )
  41. {
  42. m_pParent->UpdateSheetPanel();
  43. }
  44. BaseClass::OnShowMenu(menu);
  45. }
  46. //-----------------------------------------------------------------------------
  47. //
  48. // CAttributeSheetSequencePickerPanel
  49. //
  50. //-----------------------------------------------------------------------------
  51. CAttributeSheetSequencePickerPanel::CAttributeSheetSequencePickerPanel( vgui::Panel *parent, const AttributeWidgetInfo_t &info ) :
  52. BaseClass( parent, info )
  53. {
  54. if ( info.m_pEditorInfo )
  55. {
  56. m_bIsSecondView = !V_stricmp( info.m_pEditorInfo->GetWidgetName(), "sheetsequencepicker_second" );
  57. }
  58. else
  59. {
  60. m_bIsSecondView = false;
  61. }
  62. m_pSheetPanel = new CSheetSequencePanel(this, "sheetsequencepanel");
  63. m_pSheetPanel->AddActionSignalTarget( this );
  64. m_pSequenceSelection = new CNotifyMenuButton( this, "SequenceSelection", "seq" );
  65. m_pSequenceSelection->SetMenu( m_pSheetPanel );
  66. m_pSheetPanel->AddActionSignalTarget( this );
  67. UpdateSheetPanel();
  68. }
  69. void CAttributeSheetSequencePickerPanel::UpdateSheetPanel()
  70. {
  71. CDmElement* pElement = GetPanelElement();
  72. CDmAttribute* pMaterialAttr = pElement->GetAttribute("material");
  73. if ( m_bIsSecondView )
  74. {
  75. m_pSheetPanel->SetSecondSequenceView( true );
  76. m_pSequenceSelection->SetText( "sq2" );
  77. }
  78. if ( pMaterialAttr == NULL )
  79. {
  80. pElement = FindReferringElement< CDmeParticleSystemDefinition >( pElement, "initializers" );
  81. if ( pElement )
  82. {
  83. pMaterialAttr = pElement->GetAttribute("material");
  84. }
  85. }
  86. if ( pMaterialAttr )
  87. {
  88. m_pSheetPanel->SetFromMaterialName( pMaterialAttr->GetValueString() );
  89. }
  90. }
  91. CAttributeSheetSequencePickerPanel::~CAttributeSheetSequencePickerPanel()
  92. {
  93. }
  94. void CAttributeSheetSequencePickerPanel::OnSheetSequenceSelected( int nSequenceNumber )
  95. {
  96. CUndoScopeGuard guard( 0, NOTIFY_SETDIRTYFLAG, GetNotify(), "Select Sheet Sequence" );
  97. SetAttributeValue(nSequenceNumber);
  98. }
  99. // MOC_TODO: factor this somewhere else - shared with other attribute controls
  100. void CAttributeSheetSequencePickerPanel::PerformLayout()
  101. {
  102. BaseClass::PerformLayout();
  103. int x, y, w, h;
  104. m_pType->GetBounds( x, y, w, h );
  105. int inset = 25;
  106. m_pType->SetWide( w - inset );
  107. x += w;
  108. x -= inset;
  109. h -= 2;
  110. m_pSequenceSelection->SetBounds( x, y, inset, h );
  111. }