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.

295 lines
8.0 KiB

  1. //====== Copyright � 1996-2006, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "dme_controls/BaseAnimationSetEditor.h"
  7. #include "tier1/KeyValues.h"
  8. #include "vgui_controls/Splitter.h"
  9. #include "vgui_controls/Menu.h"
  10. #include "studio.h"
  11. #include "dme_controls/BaseAnimSetAttributeSliderPanel.h"
  12. #include "dme_controls/BaseAnimSetPresetFaderPanel.h"
  13. #include "dme_controls/BaseAnimSetControlGroupPanel.h"
  14. #include "dme_controls/dmecontrols_utils.h"
  15. #include "movieobjects/dmechannel.h"
  16. #include "movieobjects/dmeanimationset.h"
  17. #include "movieobjects/dmegamemodel.h"
  18. // memdbgon must be the last include file in a .cpp file!!!
  19. #include "tier0/memdbgon.h"
  20. using namespace vgui;
  21. #define ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT 38
  22. #define ANIMATION_SET_BUTTON_INSET 0
  23. CBaseAnimationSetEditor::CBaseAnimationSetEditor( vgui::Panel *parent, const char *className, CBaseAnimationSetControl *pAnimationSetController ) :
  24. BaseClass( parent, className ),
  25. m_Layout( LAYOUT_SPLIT ),
  26. m_pController( pAnimationSetController )
  27. {
  28. // SETUP_PANEL( this );
  29. //#pragma warning( disable: 4355 )
  30. m_pController->SetAnimationSetEditorPanel( this );
  31. //#pragma warning( default: 4355 )
  32. PostMessage( GetVPanel(), new KeyValues( "OnChangeLayout", "value", m_Layout ) );
  33. }
  34. CBaseAnimationSetEditor::~CBaseAnimationSetEditor()
  35. {
  36. }
  37. CBaseAnimationSetControl *CBaseAnimationSetEditor::GetController()
  38. {
  39. return m_pController;
  40. }
  41. void CBaseAnimationSetEditor::CreateToolsSubPanels()
  42. {
  43. m_hControlGroup = new CBaseAnimSetControlGroupPanel( (Panel *)NULL, "AnimSetControlGroup", this, false );
  44. m_hPresetFader = new CBaseAnimSetPresetFaderPanel( (Panel *)NULL, "AnimSetPresetFader", this );
  45. m_hAttributeSlider = new CBaseAnimSetAttributeSliderPanel( (Panel *)NULL, "AnimSetAttributeSliderPanel", this );
  46. }
  47. void CBaseAnimationSetEditor::ChangeLayout( EAnimSetLayout_t newLayout )
  48. {
  49. m_Layout = newLayout;
  50. // Make sure these don't get blown away...
  51. m_hControlGroup->SetParent( (Panel *)NULL );
  52. m_hPresetFader->SetParent( (Panel *)NULL );
  53. m_hAttributeSlider->SetParent( (Panel *)NULL );
  54. delete m_Splitter.Get();
  55. m_Splitter = NULL;
  56. CUtlVector< Panel * > list;
  57. list.AddToTail( m_hControlGroup.Get() );
  58. list.AddToTail( m_hPresetFader.Get() );
  59. list.AddToTail( m_hAttributeSlider.Get() );
  60. Splitter *sub = NULL;
  61. switch ( m_Layout )
  62. {
  63. default:
  64. case LAYOUT_SPLIT:
  65. {
  66. m_Splitter = new Splitter( this, "AnimSetEditorMainSplitter", SPLITTER_MODE_VERTICAL, 1 );
  67. m_Splitter->SetAutoResize
  68. (
  69. Panel::PIN_TOPLEFT,
  70. Panel::AUTORESIZE_DOWNANDRIGHT,
  71. 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT,
  72. 0, 0
  73. );
  74. m_Splitter->SetBounds( 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT, GetWide(), GetTall() - ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT );
  75. m_Splitter->SetSplitterColor( Color(32, 32, 32, 255) );
  76. // m_Splitter->EnableBorders( false );
  77. m_hControlGroup->SetParent( m_Splitter->GetChild( 0 ) );
  78. m_hControlGroup->SetAutoResize
  79. (
  80. Panel::PIN_TOPLEFT,
  81. Panel::AUTORESIZE_DOWNANDRIGHT,
  82. 0, 0,
  83. 0, 0
  84. );
  85. sub = new Splitter( m_Splitter->GetChild( 1 ), "AnimSetEditorSubSplitter", SPLITTER_MODE_HORIZONTAL, 1 );
  86. sub->SetAutoResize
  87. (
  88. Panel::PIN_TOPLEFT,
  89. Panel::AUTORESIZE_DOWNANDRIGHT,
  90. 0, 0,
  91. 0, 0
  92. );
  93. m_hPresetFader->SetParent( sub->GetChild( 0 ) );
  94. m_hPresetFader->SetAutoResize
  95. (
  96. Panel::PIN_TOPLEFT,
  97. Panel::AUTORESIZE_DOWNANDRIGHT,
  98. 0, 0,
  99. 0, 0
  100. );
  101. m_hAttributeSlider->SetParent( sub->GetChild( 1 ) );
  102. m_hAttributeSlider->SetAutoResize
  103. (
  104. Panel::PIN_TOPLEFT,
  105. Panel::AUTORESIZE_DOWNANDRIGHT,
  106. 0, 0,
  107. 0, 0
  108. );
  109. }
  110. break;
  111. case LAYOUT_VERTICAL:
  112. {
  113. m_Splitter = new Splitter( this, "AnimSetEditorMainSplitter", SPLITTER_MODE_VERTICAL, 2 );
  114. m_Splitter->SetSplitterColor( Color(32, 32, 32, 255) );
  115. m_Splitter->SetAutoResize
  116. (
  117. Panel::PIN_TOPLEFT,
  118. Panel::AUTORESIZE_DOWNANDRIGHT,
  119. 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT,
  120. 0, 0
  121. );
  122. m_Splitter->SetBounds( 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT, GetWide(), GetTall() - ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT );
  123. for ( int i = 0; i < list.Count(); ++i )
  124. {
  125. list[ i ]->SetParent( m_Splitter->GetChild( i ) );
  126. list[ i ]->SetSize( m_Splitter->GetChild( i )->GetWide(), m_Splitter->GetChild( i )->GetTall() );
  127. list[ i ]->SetAutoResize
  128. (
  129. Panel::PIN_TOPLEFT,
  130. Panel::AUTORESIZE_DOWNANDRIGHT,
  131. 0, 0,
  132. 0, 0
  133. );
  134. }
  135. m_Splitter->EvenlyRespaceSplitters();
  136. }
  137. break;
  138. case LAYOUT_HORIZONTAL:
  139. {
  140. m_Splitter = new Splitter( this, "AnimSetEditorMainSplitter", SPLITTER_MODE_HORIZONTAL, 2 );
  141. m_Splitter->SetSplitterColor( Color(32, 32, 32, 255) );
  142. m_Splitter->SetAutoResize
  143. (
  144. Panel::PIN_TOPLEFT,
  145. Panel::AUTORESIZE_DOWNANDRIGHT,
  146. 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT,
  147. 0, 0
  148. );
  149. m_Splitter->SetBounds( 0, ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT, GetWide(), GetTall() - ANIMATION_SET_EDITOR_BUTTONTRAY_HEIGHT );
  150. for ( int i = 0; i < list.Count(); ++i )
  151. {
  152. list[ i ]->SetParent( m_Splitter->GetChild( i ) );
  153. list[ i ]->SetSize( m_Splitter->GetChild( i )->GetWide(), m_Splitter->GetChild( i )->GetTall() );
  154. list[ i ]->SetAutoResize
  155. (
  156. Panel::PIN_TOPLEFT,
  157. Panel::AUTORESIZE_DOWNANDRIGHT,
  158. 0, 0,
  159. 0, 0
  160. );
  161. }
  162. m_Splitter->EvenlyRespaceSplitters();
  163. }
  164. break;
  165. }
  166. if ( sub )
  167. {
  168. sub->OnSizeChanged( sub->GetWide(), sub->GetTall() );
  169. sub->EvenlyRespaceSplitters();
  170. }
  171. }
  172. void CBaseAnimationSetEditor::OnChangeLayout( int value )
  173. {
  174. ChangeLayout( ( EAnimSetLayout_t )value );
  175. }
  176. void CBaseAnimationSetEditor::OnOpenContextMenu( KeyValues *params )
  177. {
  178. if ( m_hContextMenu.Get() )
  179. {
  180. delete m_hContextMenu.Get();
  181. m_hContextMenu = NULL;
  182. }
  183. m_hContextMenu = new Menu( this, "ActionMenu" );
  184. m_hContextMenu->AddMenuItem( "#BxAnimSetSplitLayout", new KeyValues( "OnChangeLayout", "value", (int)LAYOUT_SPLIT ), this );
  185. m_hContextMenu->AddMenuItem( "#BxAnimSetVerticalLayout", new KeyValues( "OnChangeLayout", "value", (int)LAYOUT_VERTICAL ), this );
  186. m_hContextMenu->AddMenuItem( "#BxAnimSetHorizontalLayout", new KeyValues( "OnChangeLayout", "value", (int)LAYOUT_HORIZONTAL ), this );
  187. Panel *rpanel = reinterpret_cast< Panel * >( params->GetPtr( "contextlabel" ) );
  188. if ( rpanel )
  189. {
  190. // force the menu to compute required width/height
  191. m_hContextMenu->PerformLayout();
  192. m_hContextMenu->PositionRelativeToPanel( rpanel, Menu::DOWN, 0, true );
  193. }
  194. else
  195. {
  196. Menu::PlaceContextMenu( this, m_hContextMenu.Get() );
  197. }
  198. }
  199. void CBaseAnimationSetEditor::OpenTreeViewContextMenu( KeyValues *pItemData )
  200. {
  201. }
  202. void CBaseAnimationSetEditor::ApplySchemeSettings( vgui::IScheme *pScheme )
  203. {
  204. BaseClass::ApplySchemeSettings( pScheme );
  205. // Have to manually apply settings here if they aren't attached in hierarchy
  206. if ( m_hControlGroup->GetParent() != this )
  207. {
  208. m_hControlGroup->ApplySchemeSettings( pScheme );
  209. }
  210. if ( m_hPresetFader->GetParent() != this )
  211. {
  212. m_hPresetFader->ApplySchemeSettings( pScheme );
  213. }
  214. if ( m_hAttributeSlider->GetParent() != this )
  215. {
  216. m_hAttributeSlider->ApplySchemeSettings( pScheme );
  217. }
  218. }
  219. CBaseAnimSetControlGroupPanel *CBaseAnimationSetEditor::GetControlGroup()
  220. {
  221. return m_hControlGroup.Get();
  222. }
  223. CBaseAnimSetPresetFaderPanel *CBaseAnimationSetEditor::GetPresetFader()
  224. {
  225. return m_hPresetFader.Get();
  226. }
  227. CBaseAnimSetAttributeSliderPanel *CBaseAnimationSetEditor::GetAttributeSlider()
  228. {
  229. return m_hAttributeSlider.Get();
  230. }
  231. void CBaseAnimationSetEditor::OnControlsAddedOrRemoved()
  232. {
  233. m_pController->OnControlsAddedOrRemoved();
  234. if ( m_hControlGroup )
  235. {
  236. m_hControlGroup->OnControlsAddedOrRemoved();
  237. }
  238. if ( m_hAttributeSlider )
  239. {
  240. m_hAttributeSlider->OnControlsAddedOrRemoved();
  241. }
  242. }
  243. void CBaseAnimationSetEditor::ChangeAnimationSetClip( CDmeFilmClip *pFilmClip )
  244. {
  245. m_pController->ChangeAnimationSetClip( pFilmClip );
  246. if ( m_hControlGroup )
  247. {
  248. m_hControlGroup->ChangeAnimationSetClip( pFilmClip );
  249. }
  250. if ( m_hAttributeSlider )
  251. {
  252. m_hAttributeSlider->ChangeAnimationSetClip( pFilmClip );
  253. }
  254. }