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.

260 lines
8.3 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_pMouseRawCheckBox = new CCvarToggleCheckButton(
  36. this,
  37. "MouseRaw",
  38. "#GameUI_MouseRaw",
  39. "m_rawinput" );
  40. m_pMouseAccelerationCheckBox = new CheckButton(
  41. this,
  42. "MouseAccelerationCheckbox",
  43. "#GameUI_MouseCustomAccel" );
  44. m_pJoystickCheckBox = new CCvarToggleCheckButton(
  45. this,
  46. "Joystick",
  47. "#GameUI_Joystick",
  48. "joystick" );
  49. m_pJoystickSouthpawCheckBox = new CCvarToggleCheckButton(
  50. this,
  51. "JoystickSouthpaw",
  52. "#GameUI_JoystickSouthpaw",
  53. "joy_movement_stick" );
  54. m_pReverseJoystickCheckBox = new CCvarToggleCheckButton(
  55. this,
  56. "ReverseJoystick",
  57. "#GameUI_ReverseJoystick",
  58. "joy_inverty" );
  59. m_pQuickInfoCheckBox = new CCvarToggleCheckButton(
  60. this,
  61. "HudQuickInfo",
  62. "#GameUI_HudQuickInfo",
  63. "hud_quickinfo" );
  64. m_pMouseSensitivitySlider = new CCvarSlider( this, "Slider", "#GameUI_MouseSensitivity",
  65. 0.1f, 6.0f, "sensitivity", true );
  66. m_pMouseSensitivityLabel = new TextEntry(this, "SensitivityLabel");
  67. m_pMouseSensitivityLabel->AddActionSignalTarget(this);
  68. m_pMouseAccelExponentSlider = new CCvarSlider( this, "MouseAccelerationSlider", "#GameUI_MouseAcceleration",
  69. 1.0f, 1.4f, "m_customaccel_exponent", true );
  70. m_pMouseAccelExponentLabel = new TextEntry(this, "MouseAccelerationLabel");
  71. m_pMouseAccelExponentLabel->AddActionSignalTarget(this);
  72. m_pJoyYawSensitivitySlider = new CCvarSlider( this, "JoystickYawSlider", "#GameUI_JoystickYawSensitivity",
  73. -0.5f, -7.0f, "joy_yawsensitivity", true );
  74. m_pJoyYawSensitivityPreLabel = new Label(this, "JoystickYawSensitivityPreLabel", "#GameUI_JoystickLookSpeedYaw" );
  75. m_pJoyPitchSensitivitySlider = new CCvarSlider( this, "JoystickPitchSlider", "#GameUI_JoystickPitchSensitivity",
  76. 0.5f, 7.0f, "joy_pitchsensitivity", true );
  77. m_pJoyPitchSensitivityPreLabel = new Label(this, "JoystickPitchSensitivityPreLabel", "#GameUI_JoystickLookSpeedPitch" );
  78. LoadControlSettings("Resource\\OptionsSubMouse.res");
  79. UpdateSensitivityLabel();
  80. UpdateAccelerationLabel();
  81. UpdateJoystickPanels();
  82. }
  83. //-----------------------------------------------------------------------------
  84. // Purpose:
  85. //-----------------------------------------------------------------------------
  86. COptionsSubMouse::~COptionsSubMouse()
  87. {
  88. }
  89. //-----------------------------------------------------------------------------
  90. // Purpose:
  91. //-----------------------------------------------------------------------------
  92. void COptionsSubMouse::OnResetData()
  93. {
  94. m_pReverseMouseCheckBox->Reset();
  95. m_pMouseFilterCheckBox->Reset();
  96. m_pMouseRawCheckBox->Reset();
  97. m_pJoystickCheckBox->Reset();
  98. m_pJoystickSouthpawCheckBox->Reset();
  99. m_pMouseSensitivitySlider->Reset();
  100. m_pMouseAccelExponentSlider->Reset();
  101. m_pQuickInfoCheckBox->Reset();
  102. m_pReverseJoystickCheckBox->Reset();
  103. m_pJoyYawSensitivitySlider->Reset();
  104. m_pJoyPitchSensitivitySlider->Reset();
  105. ConVarRef m_customacel("m_customaccel");
  106. if ( m_customacel.IsValid() )
  107. m_pMouseAccelerationCheckBox->SetSelected( m_customacel.GetBool() );
  108. }
  109. //-----------------------------------------------------------------------------
  110. // Purpose:
  111. //-----------------------------------------------------------------------------
  112. void COptionsSubMouse::OnApplyChanges()
  113. {
  114. m_pReverseMouseCheckBox->ApplyChanges();
  115. m_pMouseFilterCheckBox->ApplyChanges();
  116. m_pMouseRawCheckBox->ApplyChanges();
  117. m_pJoystickCheckBox->ApplyChanges();
  118. m_pJoystickSouthpawCheckBox->ApplyChanges();
  119. m_pMouseSensitivitySlider->ApplyChanges();
  120. m_pMouseAccelExponentSlider->ApplyChanges();
  121. m_pQuickInfoCheckBox->ApplyChanges();
  122. m_pReverseJoystickCheckBox->ApplyChanges();
  123. m_pJoyYawSensitivitySlider->ApplyChanges();
  124. m_pJoyPitchSensitivitySlider->ApplyChanges();
  125. engine->ClientCmd_Unrestricted( "joyadvancedupdate" );
  126. engine->ClientCmd_Unrestricted( "exec userconfig.cfg\nhost_writeconfig\n" );
  127. ConVarRef m_customacel("m_customaccel");
  128. if ( m_customacel.IsValid() )
  129. m_customacel.SetValue(m_pMouseAccelerationCheckBox->IsSelected() ? 3 : 0);
  130. }
  131. //-----------------------------------------------------------------------------
  132. // Purpose: sets background color & border
  133. //-----------------------------------------------------------------------------
  134. void COptionsSubMouse::ApplySchemeSettings(IScheme *pScheme)
  135. {
  136. BaseClass::ApplySchemeSettings(pScheme);
  137. }
  138. //-----------------------------------------------------------------------------
  139. // Purpose:
  140. //-----------------------------------------------------------------------------
  141. void COptionsSubMouse::OnControlModified(Panel *panel)
  142. {
  143. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  144. // the HasBeenModified() check is so that if the value is outside of the range of the
  145. // slider, it won't use the slider to determine the display value but leave the
  146. // real value that we determined in the constructor
  147. if (panel == m_pMouseSensitivitySlider && m_pMouseSensitivitySlider->HasBeenModified())
  148. {
  149. UpdateSensitivityLabel();
  150. }
  151. else if (panel == m_pMouseAccelExponentSlider && m_pMouseAccelExponentSlider->HasBeenModified())
  152. {
  153. UpdateAccelerationLabel();
  154. }
  155. else if (panel == m_pJoystickCheckBox)
  156. {
  157. UpdateJoystickPanels();
  158. }
  159. else if (panel == m_pMouseAccelerationCheckBox)
  160. {
  161. m_pMouseAccelExponentSlider->SetEnabled(m_pMouseAccelerationCheckBox->IsSelected());
  162. m_pMouseAccelExponentLabel->SetEnabled(m_pMouseAccelerationCheckBox->IsSelected());
  163. }
  164. }
  165. //-----------------------------------------------------------------------------
  166. // Purpose:
  167. //-----------------------------------------------------------------------------
  168. void COptionsSubMouse::OnTextChanged(Panel *panel)
  169. {
  170. if ( panel == m_pMouseSensitivityLabel )
  171. {
  172. char buf[64];
  173. m_pMouseSensitivityLabel->GetText(buf, 64);
  174. float fValue = (float) atof(buf);
  175. if (fValue >= 1.0)
  176. {
  177. m_pMouseSensitivitySlider->SetSliderValue(fValue);
  178. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  179. }
  180. return;
  181. }
  182. if ( panel == m_pMouseAccelExponentLabel )
  183. {
  184. char buf[64];
  185. m_pMouseAccelExponentLabel->GetText(buf, 64);
  186. float fValue = (float) atof(buf);
  187. if (fValue >= 1.0)
  188. {
  189. m_pMouseAccelExponentSlider->SetSliderValue(fValue);
  190. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  191. }
  192. }
  193. }
  194. //-----------------------------------------------------------------------------
  195. // Purpose:
  196. //-----------------------------------------------------------------------------
  197. void COptionsSubMouse::UpdateSensitivityLabel()
  198. {
  199. char buf[64];
  200. Q_snprintf(buf, sizeof( buf ), " %.2f", m_pMouseSensitivitySlider->GetSliderValue());
  201. m_pMouseSensitivityLabel->SetText(buf);
  202. }
  203. void COptionsSubMouse::UpdateAccelerationLabel()
  204. {
  205. char buf[64];
  206. Q_snprintf(buf, sizeof( buf ), " %.2f", m_pMouseAccelExponentSlider->GetSliderValue());
  207. m_pMouseAccelExponentLabel->SetText(buf);
  208. }
  209. //-----------------------------------------------------------------------------
  210. // Purpose:
  211. //-----------------------------------------------------------------------------
  212. void COptionsSubMouse::UpdateJoystickPanels()
  213. {
  214. bool bEnabled = m_pJoystickCheckBox->IsSelected();
  215. m_pReverseJoystickCheckBox->SetEnabled( bEnabled );
  216. m_pJoystickSouthpawCheckBox->SetEnabled( bEnabled );
  217. m_pJoyYawSensitivitySlider->SetEnabled( bEnabled );
  218. m_pJoyYawSensitivityPreLabel->SetEnabled( bEnabled );
  219. m_pJoyPitchSensitivitySlider->SetEnabled( bEnabled );
  220. m_pJoyPitchSensitivityPreLabel->SetEnabled( bEnabled );
  221. }