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.

260 lines
8.2 KiB

  1. //========= Copyright 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. ConVarRef m_customacel("m_customaccel");
  127. if ( m_customacel.IsValid() )
  128. m_customacel.SetValue(m_pMouseAccelerationCheckBox->IsSelected() ? 3 : 0);
  129. }
  130. //-----------------------------------------------------------------------------
  131. // Purpose: sets background color & border
  132. //-----------------------------------------------------------------------------
  133. void COptionsSubMouse::ApplySchemeSettings(IScheme *pScheme)
  134. {
  135. BaseClass::ApplySchemeSettings(pScheme);
  136. }
  137. //-----------------------------------------------------------------------------
  138. // Purpose:
  139. //-----------------------------------------------------------------------------
  140. void COptionsSubMouse::OnControlModified(Panel *panel)
  141. {
  142. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  143. // the HasBeenModified() check is so that if the value is outside of the range of the
  144. // slider, it won't use the slider to determine the display value but leave the
  145. // real value that we determined in the constructor
  146. if (panel == m_pMouseSensitivitySlider && m_pMouseSensitivitySlider->HasBeenModified())
  147. {
  148. UpdateSensitivityLabel();
  149. }
  150. else if (panel == m_pMouseAccelExponentSlider && m_pMouseAccelExponentSlider->HasBeenModified())
  151. {
  152. UpdateAccelerationLabel();
  153. }
  154. else if (panel == m_pJoystickCheckBox)
  155. {
  156. UpdateJoystickPanels();
  157. }
  158. else if (panel == m_pMouseAccelerationCheckBox)
  159. {
  160. m_pMouseAccelExponentSlider->SetEnabled(m_pMouseAccelerationCheckBox->IsSelected());
  161. m_pMouseAccelExponentLabel->SetEnabled(m_pMouseAccelerationCheckBox->IsSelected());
  162. }
  163. }
  164. //-----------------------------------------------------------------------------
  165. // Purpose:
  166. //-----------------------------------------------------------------------------
  167. void COptionsSubMouse::OnTextChanged(Panel *panel)
  168. {
  169. if ( panel == m_pMouseSensitivityLabel )
  170. {
  171. char buf[64];
  172. m_pMouseSensitivityLabel->GetText(buf, 64);
  173. float fValue;
  174. int numParsed = sscanf(buf, "%f", &fValue);
  175. if ( ( numParsed == 1 ) && ( fValue >= 0.0f ) )
  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. }