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.

205 lines
6.8 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "OptionsSubMouse.h"
  9. //#include "CommandCheckButton.h"
  10. #include "KeyToggleCheckButton.h"
  11. #include "CvarNegateCheckButton.h"
  12. #include "CvarToggleCheckButton.h"
  13. #include "CvarSlider.h"
  14. #include "EngineInterface.h"
  15. #include <KeyValues.h>
  16. #include <vgui/IScheme.h>
  17. #include "tier1/convar.h"
  18. #include <stdio.h>
  19. #include <vgui_controls/TextEntry.h>
  20. // memdbgon must be the last include file in a .cpp file!!!
  21. #include <tier0/memdbgon.h>
  22. using namespace vgui;
  23. COptionsSubMouse::COptionsSubMouse(vgui::Panel *parent) : PropertyPage(parent, NULL)
  24. {
  25. m_pReverseMouseCheckBox = new CCvarNegateCheckButton(
  26. this,
  27. "ReverseMouse",
  28. "#GameUI_ReverseMouse",
  29. "m_pitch" );
  30. m_pMouseFilterCheckBox = new CCvarToggleCheckButton(
  31. this,
  32. "MouseFilter",
  33. "#GameUI_MouseFilter",
  34. "m_filter" );
  35. m_pJoystickCheckBox = new CCvarToggleCheckButton(
  36. this,
  37. "Joystick",
  38. "#GameUI_Joystick",
  39. "joystick" );
  40. m_pJoystickSouthpawCheckBox = new CCvarToggleCheckButton(
  41. this,
  42. "JoystickSouthpaw",
  43. "#GameUI_JoystickSouthpaw",
  44. "joy_movement_stick" );
  45. m_pReverseJoystickCheckBox = new CCvarToggleCheckButton(
  46. this,
  47. "ReverseJoystick",
  48. "#GameUI_ReverseJoystick",
  49. "joy_inverty" );
  50. m_pQuickInfoCheckBox = new CCvarToggleCheckButton(
  51. this,
  52. "HudQuickInfo",
  53. "#GameUI_HudQuickInfo",
  54. "hud_quickinfo" );
  55. m_pMouseSensitivitySlider = new CCvarSlider( this, "Slider", "#GameUI_MouseSensitivity",
  56. 1.0f, 20.0f, "sensitivity", true );
  57. m_pMouseSensitivityLabel = new TextEntry(this, "SensitivityLabel");
  58. m_pMouseSensitivityLabel->AddActionSignalTarget(this);
  59. m_pJoyYawSensitivitySlider = new CCvarSlider( this, "JoystickYawSlider", "#GameUI_JoystickYawSensitivity",
  60. -0.5f, -7.0f, "joy_yawsensitivity", true );
  61. m_pJoyYawSensitivityPreLabel = new Label(this, "JoystickYawSensitivityPreLabel", "#GameUI_JoystickLookSpeedYaw" );
  62. m_pJoyPitchSensitivitySlider = new CCvarSlider( this, "JoystickPitchSlider", "#GameUI_JoystickPitchSensitivity",
  63. 0.5f, 7.0f, "joy_pitchsensitivity", true );
  64. m_pJoyPitchSensitivityPreLabel = new Label(this, "JoystickPitchSensitivityPreLabel", "#GameUI_JoystickLookSpeedPitch" );
  65. LoadControlSettings("Resource\\OptionsSubMouse.res");
  66. //float sensitivity = engine->pfnGetCvarFloat( "sensitivity" );
  67. ConVarRef var( "sensitivity" );
  68. if ( var.IsValid() )
  69. {
  70. float sensitivity = var.GetFloat();
  71. char buf[64];
  72. Q_snprintf(buf, sizeof(buf), " %.1f", sensitivity);
  73. m_pMouseSensitivityLabel->SetText(buf);
  74. }
  75. UpdateJoystickPanels();
  76. }
  77. //-----------------------------------------------------------------------------
  78. // Purpose:
  79. //-----------------------------------------------------------------------------
  80. COptionsSubMouse::~COptionsSubMouse()
  81. {
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. //-----------------------------------------------------------------------------
  86. void COptionsSubMouse::OnResetData()
  87. {
  88. m_pReverseMouseCheckBox->Reset();
  89. m_pMouseFilterCheckBox->Reset();
  90. m_pJoystickCheckBox->Reset();
  91. m_pJoystickSouthpawCheckBox->Reset();
  92. m_pMouseSensitivitySlider->Reset();
  93. m_pQuickInfoCheckBox->Reset();
  94. m_pReverseJoystickCheckBox->Reset();
  95. m_pJoyYawSensitivitySlider->Reset();
  96. m_pJoyPitchSensitivitySlider->Reset();
  97. }
  98. //-----------------------------------------------------------------------------
  99. // Purpose:
  100. //-----------------------------------------------------------------------------
  101. void COptionsSubMouse::OnApplyChanges()
  102. {
  103. m_pReverseMouseCheckBox->ApplyChanges();
  104. m_pMouseFilterCheckBox->ApplyChanges();
  105. m_pJoystickCheckBox->ApplyChanges();
  106. m_pJoystickSouthpawCheckBox->ApplyChanges();
  107. m_pMouseSensitivitySlider->ApplyChanges();
  108. m_pQuickInfoCheckBox->ApplyChanges();
  109. m_pReverseJoystickCheckBox->ApplyChanges();
  110. m_pJoyYawSensitivitySlider->ApplyChanges();
  111. m_pJoyPitchSensitivitySlider->ApplyChanges();
  112. engine->ClientCmd_Unrestricted( "joyadvancedupdate" );
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose: sets background color & border
  116. //-----------------------------------------------------------------------------
  117. void COptionsSubMouse::ApplySchemeSettings(IScheme *pScheme)
  118. {
  119. BaseClass::ApplySchemeSettings(pScheme);
  120. }
  121. //-----------------------------------------------------------------------------
  122. // Purpose:
  123. //-----------------------------------------------------------------------------
  124. void COptionsSubMouse::OnControlModified(Panel *panel)
  125. {
  126. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  127. // the HasBeenModified() check is so that if the value is outside of the range of the
  128. // slider, it won't use the slider to determine the display value but leave the
  129. // real value that we determined in the constructor
  130. if (panel == m_pMouseSensitivitySlider && m_pMouseSensitivitySlider->HasBeenModified())
  131. {
  132. UpdateSensitivityLabel();
  133. }
  134. else if (panel == m_pJoystickCheckBox)
  135. {
  136. UpdateJoystickPanels();
  137. }
  138. }
  139. //-----------------------------------------------------------------------------
  140. // Purpose:
  141. //-----------------------------------------------------------------------------
  142. void COptionsSubMouse::OnTextChanged(Panel *panel)
  143. {
  144. if (panel == m_pMouseSensitivityLabel)
  145. {
  146. char buf[64];
  147. m_pMouseSensitivityLabel->GetText(buf, 64);
  148. float fValue = (float) atof(buf);
  149. if (fValue >= 1.0)
  150. {
  151. m_pMouseSensitivitySlider->SetSliderValue(fValue);
  152. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  153. }
  154. }
  155. }
  156. //-----------------------------------------------------------------------------
  157. // Purpose:
  158. //-----------------------------------------------------------------------------
  159. void COptionsSubMouse::UpdateSensitivityLabel()
  160. {
  161. char buf[64];
  162. Q_snprintf(buf, sizeof( buf ), " %.1f", m_pMouseSensitivitySlider->GetSliderValue());
  163. m_pMouseSensitivityLabel->SetText(buf);
  164. }
  165. //-----------------------------------------------------------------------------
  166. // Purpose:
  167. //-----------------------------------------------------------------------------
  168. void COptionsSubMouse::UpdateJoystickPanels()
  169. {
  170. bool bEnabled = m_pJoystickCheckBox->IsSelected();
  171. m_pReverseJoystickCheckBox->SetEnabled( bEnabled );
  172. m_pJoystickSouthpawCheckBox->SetEnabled( bEnabled );
  173. m_pJoyYawSensitivitySlider->SetEnabled( bEnabled );
  174. m_pJoyYawSensitivityPreLabel->SetEnabled( bEnabled );
  175. m_pJoyPitchSensitivitySlider->SetEnabled( bEnabled );
  176. m_pJoyPitchSensitivityPreLabel->SetEnabled( bEnabled );
  177. }