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.

301 lines
8.0 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #include "cbase.h"
  7. #include "vgui/IInput.h"
  8. #include <vgui/IVGui.h>
  9. #include "commentary_modelviewer.h"
  10. #include "iclientmode.h"
  11. #include "baseviewport.h"
  12. // NOTE: This has to be the last file included!
  13. #include "tier0/memdbgon.h"
  14. /*
  15. // FIXME!!!!!!
  16. // FIXME!!!!!!
  17. // FIXME!!!!!!
  18. DECLARE_BUILD_FACTORY( CCommentaryModelPanel );
  19. //-----------------------------------------------------------------------------
  20. // Purpose:
  21. //-----------------------------------------------------------------------------
  22. CCommentaryModelPanel::CCommentaryModelPanel( vgui::Panel *parent, const char *name ) : CModelPanel( parent, name )
  23. {
  24. }
  25. */
  26. //-----------------------------------------------------------------------------
  27. // Purpose:
  28. //-----------------------------------------------------------------------------
  29. CCommentaryModelViewer::CCommentaryModelViewer(IViewPort *pViewPort) : Frame(NULL, PANEL_COMMENTARY_MODELVIEWER )
  30. {
  31. m_pViewPort = pViewPort;
  32. // FIXME!!!!!!
  33. //m_pModelPanel = NULL;
  34. }
  35. //-----------------------------------------------------------------------------
  36. // Purpose:
  37. //-----------------------------------------------------------------------------
  38. CCommentaryModelViewer::~CCommentaryModelViewer()
  39. {
  40. }
  41. //-----------------------------------------------------------------------------
  42. // Purpose:
  43. //-----------------------------------------------------------------------------
  44. void CCommentaryModelViewer::ApplySchemeSettings( vgui::IScheme *pScheme )
  45. {
  46. BaseClass::ApplySchemeSettings( pScheme );
  47. LoadControlSettings( "Resource/UI/CommentaryModelViewer.res" );
  48. // FIXME!!!!!!
  49. //m_pModelPanel = dynamic_cast<CCommentaryModelPanel*>( FindChildByName( "modelpanel" ) );
  50. }
  51. //-----------------------------------------------------------------------------
  52. // Purpose:
  53. //-----------------------------------------------------------------------------
  54. void CCommentaryModelViewer::PerformLayout( void )
  55. {
  56. int w,h;
  57. GetParent()->GetSize( w, h );
  58. SetBounds(0,0,w,h);
  59. // FIXME!!!!!!
  60. /*if ( m_pModelPanel )
  61. {
  62. m_pModelPanel->SetBounds(0,0,w,h);
  63. }*/
  64. BaseClass::PerformLayout();
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose:
  68. //-----------------------------------------------------------------------------
  69. void CCommentaryModelViewer::SetModel( const char *pszName, const char *pszAttached )
  70. {
  71. // FIXME!!!!!!
  72. /*
  73. if ( !m_pModelPanel )
  74. return;
  75. m_pModelPanel->SwapModel( pszName, pszAttached );
  76. m_flYawSpeed = 0;
  77. m_flZoomSpeed = 0;
  78. m_bTranslating = false;
  79. m_vecResetPos = m_pModelPanel->m_pModelInfo->m_vecOriginOffset;
  80. m_vecResetAngles = m_pModelPanel->m_pModelInfo->m_vecAbsAngles;
  81. */
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. //-----------------------------------------------------------------------------
  86. void CCommentaryModelViewer::ShowPanel(bool bShow)
  87. {
  88. if ( BaseClass::IsVisible() == bShow )
  89. return;
  90. if ( bShow )
  91. {
  92. Activate();
  93. SetMouseInputEnabled( true );
  94. }
  95. else
  96. {
  97. SetVisible( false );
  98. SetMouseInputEnabled( false );
  99. }
  100. m_pViewPort->ShowBackGround( bShow );
  101. }
  102. //-----------------------------------------------------------------------------
  103. // Purpose:
  104. //-----------------------------------------------------------------------------
  105. void CCommentaryModelViewer::OnCommand( const char *command )
  106. {
  107. if ( Q_stricmp( command, "vguicancel" ) )
  108. {
  109. engine->ClientCmd( const_cast<char *>( command ) );
  110. }
  111. Close();
  112. m_pViewPort->ShowBackGround( false );
  113. BaseClass::OnCommand( command );
  114. }
  115. //-----------------------------------------------------------------------------
  116. // Purpose:
  117. //-----------------------------------------------------------------------------
  118. void CCommentaryModelViewer::OnKeyCodePressed( vgui::KeyCode code )
  119. {
  120. if ( code == KEY_ENTER )
  121. {
  122. Close();
  123. m_pViewPort->ShowBackGround( false );
  124. }
  125. else if ( code == KEY_SPACE )
  126. {
  127. m_bTranslating = !m_bTranslating;
  128. }
  129. else if ( code == KEY_R )
  130. {
  131. // FIXME!!!!!!
  132. /*
  133. m_pModelPanel->m_pModelInfo->m_vecOriginOffset = m_vecResetPos;
  134. m_pModelPanel->m_pModelInfo->m_vecAbsAngles = m_vecResetAngles;
  135. m_flYawSpeed = 0;
  136. m_flZoomSpeed = 0;
  137. m_pModelPanel->ZoomToFrameDistance();
  138. */
  139. }
  140. else
  141. {
  142. BaseClass::OnKeyCodePressed( code );
  143. }
  144. }
  145. //-----------------------------------------------------------------------------
  146. // Purpose:
  147. //-----------------------------------------------------------------------------
  148. void CCommentaryModelViewer::OnThink( void )
  149. {
  150. HandleMovementInput();
  151. BaseClass::OnThink();
  152. }
  153. //-----------------------------------------------------------------------------
  154. // Purpose:
  155. //-----------------------------------------------------------------------------
  156. void CCommentaryModelViewer::HandleMovementInput( void )
  157. {
  158. bool bLeftDown = input()->IsKeyDown(KEY_LEFT);
  159. bool bRightDown = input()->IsKeyDown(KEY_RIGHT);
  160. bool bForwardDown = input()->IsKeyDown(KEY_UP);
  161. bool bBackDown = input()->IsKeyDown(KEY_DOWN);
  162. float flAccel = 0.05;
  163. // Rotation around Z
  164. if ( bLeftDown )
  165. {
  166. if ( m_flYawSpeed > 0 )
  167. {
  168. m_flYawSpeed = 0;
  169. }
  170. m_flYawSpeed = MAX(m_flYawSpeed-flAccel, -3.0);
  171. }
  172. else if ( bRightDown )
  173. {
  174. if ( m_flYawSpeed < 0 )
  175. {
  176. m_flYawSpeed = 0;
  177. }
  178. m_flYawSpeed = MIN(m_flYawSpeed+flAccel, 3.0);
  179. }
  180. if ( m_flYawSpeed != 0 )
  181. {
  182. // FIXME!!!!!!
  183. /*
  184. if ( m_bTranslating )
  185. {
  186. m_pModelPanel->m_pModelInfo->m_vecOriginOffset.y = clamp( m_pModelPanel->m_pModelInfo->m_vecOriginOffset.y + m_flYawSpeed, -100, 100 );
  187. }
  188. else
  189. {
  190. m_pModelPanel->m_pModelInfo->m_vecAbsAngles.y = anglemod( m_pModelPanel->m_pModelInfo->m_vecAbsAngles.y + m_flYawSpeed );
  191. }
  192. */
  193. if ( !bLeftDown && !bRightDown )
  194. {
  195. m_flYawSpeed = ( m_flYawSpeed > 0 ) ? MAX(0,m_flYawSpeed-0.1) : MIN(0,m_flYawSpeed+0.1);
  196. }
  197. }
  198. // Zooming
  199. if ( bForwardDown )
  200. {
  201. if ( m_flZoomSpeed > 0 )
  202. {
  203. m_flZoomSpeed = 0;
  204. }
  205. m_flZoomSpeed = MAX(m_flZoomSpeed-flAccel, -3.0);
  206. }
  207. else if ( bBackDown )
  208. {
  209. if ( m_flZoomSpeed < 0 )
  210. {
  211. m_flZoomSpeed = 0;
  212. }
  213. m_flZoomSpeed = MIN(m_flZoomSpeed+flAccel, 3.0);
  214. }
  215. if ( m_flZoomSpeed != 0 )
  216. {
  217. // FIXME!!!!!!
  218. /*
  219. if ( m_bTranslating )
  220. {
  221. m_pModelPanel->m_pModelInfo->m_vecOriginOffset.z = clamp( m_pModelPanel->m_pModelInfo->m_vecOriginOffset.z + m_flZoomSpeed, -100, 300 );
  222. }
  223. else
  224. {
  225. float flZoomMin = m_pModelPanel->m_flFrameDistance * 0.75;
  226. float flZoomMax = m_pModelPanel->m_flFrameDistance * 1.5;
  227. m_pModelPanel->m_pModelInfo->m_vecOriginOffset.x = clamp( m_pModelPanel->m_pModelInfo->m_vecOriginOffset.x + m_flZoomSpeed, flZoomMin, flZoomMax );
  228. }
  229. */
  230. if ( !bForwardDown && !bBackDown )
  231. {
  232. m_flZoomSpeed = ( m_flZoomSpeed > 0 ) ? MAX(0,m_flZoomSpeed-0.1) : MIN(0,m_flZoomSpeed+0.1);
  233. }
  234. }
  235. }
  236. //-----------------------------------------------------------------------------
  237. // Purpose:
  238. //-----------------------------------------------------------------------------
  239. void CommentaryShowModelViewer( const CCommand &args )
  240. {
  241. if ( args.ArgC() < 2 )
  242. {
  243. ConMsg( "Usage: commentary_showmodelviewer <model name> <optional attached model name>\n" );
  244. return;
  245. }
  246. CBaseViewport *pViewport = dynamic_cast<CBaseViewport *>( GetClientMode()->GetViewport() );
  247. if ( pViewport )
  248. {
  249. IViewPortPanel *pCommentaryPanel = pViewport->FindPanelByName( PANEL_COMMENTARY_MODELVIEWER );
  250. if ( !pCommentaryPanel )
  251. {
  252. pCommentaryPanel = pViewport->CreatePanelByName( PANEL_COMMENTARY_MODELVIEWER );
  253. pViewport->AddNewPanel( pCommentaryPanel, "PANEL_COMMENTARY_MODELVIEWER" );
  254. }
  255. if ( pCommentaryPanel )
  256. {
  257. //((CCommentaryModelViewer*)pCommentaryPanel)->InvalidateLayout( false, true );
  258. ((CCommentaryModelViewer*)pCommentaryPanel)->SetModel( args[1], args[2] );
  259. pViewport->ShowPanel( pCommentaryPanel, true );
  260. }
  261. }
  262. }
  263. ConCommand commentary_showmodelviewer( "commentary_showmodelviewer", CommentaryShowModelViewer, "Display the commentary model viewer. Usage: commentary_showmodelviewer <model name> <optional attached model name>", FCVAR_NONE );