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.

155 lines
4.4 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "BasePanel.h"
  8. #include "OptionsDialog.h"
  9. #include "vgui_controls/Button.h"
  10. #include "vgui_controls/CheckButton.h"
  11. #include "vgui_controls/PropertySheet.h"
  12. #include "vgui_controls/Label.h"
  13. #include "vgui_controls/QueryBox.h"
  14. #include "vgui/ILocalize.h"
  15. #include "vgui/ISurface.h"
  16. #include "vgui/ISystem.h"
  17. #include "vgui/IVGui.h"
  18. #include "KeyValues.h"
  19. #include "OptionsSubKeyboard.h"
  20. #include "OptionsSubMouse.h"
  21. #include "OptionsSubAudio.h"
  22. #include "OptionsSubVideo.h"
  23. #include "OptionsSubVoice.h"
  24. #include "OptionsSubMultiplayer.h"
  25. #include "OptionsSubDifficulty.h"
  26. #include "OptionsSubPortal.h"
  27. #ifdef WIN32
  28. // NVNT haptic configuration dialog
  29. #include "OptionsSubHaptics.h"
  30. #endif
  31. #include "ModInfo.h"
  32. using namespace vgui;
  33. // memdbgon must be the last include file in a .cpp file!!!
  34. #include <tier0/memdbgon.h>
  35. //-----------------------------------------------------------------------------
  36. // Purpose: Basic help dialog
  37. //-----------------------------------------------------------------------------
  38. COptionsDialog::COptionsDialog(vgui::Panel *parent) : PropertyDialog(parent, "OptionsDialog")
  39. {
  40. SetDeleteSelfOnClose(true);
  41. SetBounds(0, 0, 512, 406);
  42. SetSizeable( false );
  43. SetTitle("#GameUI_Options", true);
  44. // debug timing code, this function takes too long
  45. // double s4 = system()->GetCurrentTime();
  46. #if defined( WIN32 ) && !defined( _X360 )
  47. // NVNT START see if the user has a haptic device via convar. if so create haptics dialog.
  48. ConVarRef checkHap("hap_HasDevice");
  49. checkHap.Init("hap_HasDevice",true);
  50. if(checkHap.GetBool())
  51. {
  52. AddPage(new COptionsSubHaptics(this), "#GameUI_Haptics_TabTitle");
  53. }
  54. // NVNT END
  55. #endif
  56. if (ModInfo().IsSinglePlayerOnly() && !ModInfo().NoDifficulty())
  57. {
  58. AddPage(new COptionsSubDifficulty(this), "#GameUI_Difficulty");
  59. }
  60. if (ModInfo().HasPortals())
  61. {
  62. AddPage(new COptionsSubPortal(this), "#GameUI_Portal");
  63. }
  64. AddPage(new COptionsSubKeyboard(this), "#GameUI_Keyboard");
  65. AddPage(new COptionsSubMouse(this), "#GameUI_Mouse");
  66. m_pOptionsSubAudio = new COptionsSubAudio(this);
  67. AddPage(m_pOptionsSubAudio, "#GameUI_Audio");
  68. m_pOptionsSubVideo = new COptionsSubVideo(this);
  69. AddPage(m_pOptionsSubVideo, "#GameUI_Video");
  70. if ( !ModInfo().IsSinglePlayerOnly() )
  71. {
  72. AddPage(new COptionsSubVoice(this), "#GameUI_Voice");
  73. }
  74. // add the multiplay page last, if we're combo single/multi or just multi
  75. if ( (ModInfo().IsMultiplayerOnly() && !ModInfo().IsSinglePlayerOnly()) ||
  76. (!ModInfo().IsMultiplayerOnly() && !ModInfo().IsSinglePlayerOnly()) )
  77. {
  78. m_pOptionsSubMultiplayer = new COptionsSubMultiplayer(this);
  79. AddPage(m_pOptionsSubMultiplayer, "#GameUI_Multiplayer");
  80. }
  81. // double s5 = system()->GetCurrentTime();
  82. // Msg("COptionsDialog::COptionsDialog(): %.3fms\n", (float)(s5 - s4) * 1000.0f);
  83. SetApplyButtonVisible(true);
  84. GetPropertySheet()->SetTabWidth(84);
  85. }
  86. //-----------------------------------------------------------------------------
  87. // Purpose: Destructor
  88. //-----------------------------------------------------------------------------
  89. COptionsDialog::~COptionsDialog()
  90. {
  91. }
  92. //-----------------------------------------------------------------------------
  93. // Purpose: Brings the dialog to the fore
  94. //-----------------------------------------------------------------------------
  95. void COptionsDialog::Activate()
  96. {
  97. BaseClass::Activate();
  98. EnableApplyButton(false);
  99. }
  100. void COptionsDialog::OnKeyCodePressed( KeyCode code )
  101. {
  102. switch ( GetBaseButtonCode( code ) )
  103. {
  104. case KEY_XBUTTON_B:
  105. OnCommand( "Cancel" );
  106. return;
  107. }
  108. BaseClass::OnKeyCodePressed( code );
  109. }
  110. //-----------------------------------------------------------------------------
  111. // Purpose: Opens the dialog
  112. //-----------------------------------------------------------------------------
  113. void COptionsDialog::Run()
  114. {
  115. SetTitle("#GameUI_Options", true);
  116. Activate();
  117. }
  118. //-----------------------------------------------------------------------------
  119. // Purpose: Called when the GameUI is hidden
  120. //-----------------------------------------------------------------------------
  121. void COptionsDialog::OnGameUIHidden()
  122. {
  123. // tell our children about it
  124. for ( int i = 0 ; i < GetChildCount() ; i++ )
  125. {
  126. Panel *pChild = GetChild( i );
  127. if ( pChild )
  128. {
  129. PostMessage( pChild, new KeyValues( "GameUIHidden" ) );
  130. }
  131. }
  132. }