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.

107 lines
2.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "CommentaryExplanationDialog.h"
  7. #include "BasePanel.h"
  8. #include "convar.h"
  9. #include "EngineInterface.h"
  10. #include "GameUI_Interface.h"
  11. #include "vgui/ISurface.h"
  12. #include "vgui/IInput.h"
  13. #include <stdio.h>
  14. using namespace vgui;
  15. // memdbgon must be the last include file in a .cpp file!!!
  16. #include "tier0/memdbgon.h"
  17. //-----------------------------------------------------------------------------
  18. // Purpose:
  19. //-----------------------------------------------------------------------------
  20. CCommentaryExplanationDialog::CCommentaryExplanationDialog(vgui::Panel *parent, char *pszFinishCommand) : BaseClass(parent, "CommentaryExplanationDialog")
  21. {
  22. SetDeleteSelfOnClose(true);
  23. SetSizeable( false );
  24. input()->SetAppModalSurface(GetVPanel());
  25. LoadControlSettings("Resource/CommentaryExplanationDialog.res");
  26. MoveToCenterOfScreen();
  27. GameUI().PreventEngineHideGameUI();
  28. // Save off the finish command
  29. Q_snprintf( m_pszFinishCommand, sizeof( m_pszFinishCommand ), "%s", pszFinishCommand );
  30. }
  31. //-----------------------------------------------------------------------------
  32. // Purpose:
  33. //-----------------------------------------------------------------------------
  34. CCommentaryExplanationDialog::~CCommentaryExplanationDialog()
  35. {
  36. }
  37. void CCommentaryExplanationDialog::OnKeyCodeTyped(KeyCode code)
  38. {
  39. if ( code == KEY_ESCAPE )
  40. {
  41. OnCommand( "cancel" );
  42. }
  43. else
  44. {
  45. BaseClass::OnKeyCodeTyped(code);
  46. }
  47. }
  48. //-----------------------------------------------------------------------------
  49. // Purpose:
  50. //-----------------------------------------------------------------------------
  51. void CCommentaryExplanationDialog::OnKeyCodePressed(KeyCode code)
  52. {
  53. if ( GetBaseButtonCode( code ) == KEY_XBUTTON_B || GetBaseButtonCode( code ) == STEAMCONTROLLER_B )
  54. {
  55. OnCommand( "cancel" );
  56. }
  57. else if ( GetBaseButtonCode( code ) == KEY_XBUTTON_A || GetBaseButtonCode( code ) == STEAMCONTROLLER_A )
  58. {
  59. OnCommand( "ok" );
  60. }
  61. else
  62. {
  63. BaseClass::OnKeyCodePressed(code);
  64. }
  65. }
  66. //-----------------------------------------------------------------------------
  67. // Purpose: handles button commands
  68. //-----------------------------------------------------------------------------
  69. void CCommentaryExplanationDialog::OnCommand( const char *command )
  70. {
  71. if ( !stricmp( command, "ok" ) )
  72. {
  73. Close();
  74. BasePanel()->FadeToBlackAndRunEngineCommand( m_pszFinishCommand );
  75. }
  76. else if ( !stricmp( command, "cancel" ) || !stricmp( command, "close" ) )
  77. {
  78. Close();
  79. }
  80. else
  81. {
  82. BaseClass::OnCommand( command );
  83. }
  84. }
  85. //-----------------------------------------------------------------------------
  86. // Purpose:
  87. //-----------------------------------------------------------------------------
  88. void CCommentaryExplanationDialog::OnClose( void )
  89. {
  90. BaseClass::OnClose();
  91. GameUI().AllowEngineHideGameUI();
  92. }