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.

196 lines
7.9 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #include "OptionsSubHaptics.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. bool HasFalcon() {
  24. ConVarRef hap_hasDevice("hap_hasDevice");
  25. return (hap_hasDevice.IsValid() && hap_hasDevice.GetBool());
  26. }
  27. void COptionsSubHaptics::OnCommand(const char *command)
  28. {
  29. if ( !stricmp( command, "DoDefaults" ) )
  30. {
  31. engine->ClientCmd_Unrestricted("exec haptics_default.cfg");
  32. OnResetData();
  33. }
  34. }
  35. COptionsSubHaptics::COptionsSubHaptics(vgui::Panel *parent) : PropertyPage(parent, NULL)
  36. {
  37. m_pForceMasterPreLabel = new Label(this, "ForceMasterPreLabel", "#GameUI_Haptics_ForceMasterScale" );
  38. m_pForceMasterSlider = new CCvarSlider( this, "ForceMasterSlider", "#GameUI_Haptics_ForceMasterScale",
  39. 0.000001f, 3.0f, "hap_ForceMasterScale", true );
  40. m_pForceRecoilPreLabel = new Label(this, "ForceRecoilPreLabel", "#GameUI_Haptics_RecoilScale" );
  41. m_pForceRecoilSlider = new CCvarSlider( this, "ForceRecoilSlider", "#GameUI_Haptics_RecoilScale",
  42. 0.000001f, 3.0f, "hap_ForceRecoilScale", true );
  43. m_pForceDamagePreLabel = new Label(this, "ForceDamagePreLabel", "#GameUI_Haptics_DamageScale" );
  44. m_pForceDamageSlider = new CCvarSlider( this, "ForceDamageSlider", "#GameUI_Haptics_DamageScale",
  45. 0.000001f, 5.0f, "hap_ForceDamageScale" , true );
  46. m_pForceMovementPreLabel = new Label(this, "ForceMovementPreLabel", "#GameUI_Haptics_MovementScale" );
  47. m_pForceMovementSlider = new CCvarSlider( this, "ForceMovementSlider", "#GameUI_Haptics_MovementScale",
  48. 0.000001f, 3.0f, "hap_ForceMovementScale", true );
  49. //Player scaling
  50. m_pPlayerBoxPreLabel = new Label(this, "PlayerBoxPreLabel", "#GameUI_Haptics_PlayerBoxLabel" );
  51. m_pPlayerBoxScalePreLabel = new Label(this, "PlayerScalePreLabel", "#GameUI_Haptics_Scale" );
  52. m_pPlayerBoxScale = new CCvarSlider( this, "PlayerBoxScaleSlider", "#GameUI_Haptics_PlayerBoxScale",
  53. 0.1f, 0.9f, "hap_PlayerBoxScale", true );
  54. m_pPlayerBoxVisual = new ControlBoxVisual(this, "PlayerBoxVisual", m_pPlayerBoxScale, m_pPlayerBoxScale, m_pPlayerBoxScale, m_pPlayerBoxScale, m_pPlayerBoxScale, m_pPlayerBoxScale);
  55. m_pPlayerBoxStiffnessPreLabel = new Label(this, "PlayerStiffnessPreLabel", "#GameUI_Haptics_PlayerBoxStiffness" );
  56. m_pPlayerBoxStiffnessSlider = new CCvarSlider( this, "PlayerStiffnessSlider", "#GameUI_Haptics_PlayerBoxScale",
  57. 0.0f, 3.0f, "hap_PlayerBoxStiffness", true );
  58. m_pPlayerBoxTurnPreLabel = new Label(this, "PlayerTurnPreLabel", "#GameUI_Haptics_Turning" );
  59. m_pPlayerBoxTurnSlider = new CCvarSlider( this, "PlayerTurnSlider", "#GameUI_Haptics_Turning",
  60. 0.0f, 2.0f, "hap_PlayerTurnScale", true );
  61. m_pPlayerBoxAimPreLabel = new Label(this, "PlayerAimPreLabel", "#GameUI_Haptics_Aiming" );
  62. m_pPlayerBoxAimSlider = new CCvarSlider( this, "PlayerAimSlider", "#GameUI_Haptics_Aiming",
  63. 0.0f, 2.0f, "hap_PlayerAimScale", true );
  64. //Vehicle Scaling
  65. m_pVehicleBoxPreLabel = new Label(this, "VehicleBoxPreLabel", "#GameUI_Haptics_VehicleBoxLabel" );
  66. m_pVehicleBoxScalePreLabel = new Label(this, "VehicleScalePreLabel", "#GameUI_Haptics_Scale" );
  67. m_pVehicleBoxScale = new CCvarSlider( this, "VehicleBoxScaleSlider", "#GameUI_Haptics_VehicleBoxScale",
  68. 0.1f, 0.6f, "hap_VehicleBoxScale", true );
  69. m_pVehicleBoxVisual = new ControlBoxVisual(this, "VehicleBoxVisual", m_pVehicleBoxScale, m_pVehicleBoxScale, m_pVehicleBoxScale, m_pVehicleBoxScale, m_pVehicleBoxScale, m_pVehicleBoxScale);
  70. m_pVehicleBoxStiffnessPreLabel = new Label(this, "VehicleStiffnessPreLabel", "#GameUI_Haptics_VehicleBoxStiffness" );
  71. m_pVehicleBoxStiffnessSlider = new CCvarSlider( this, "VehicleStiffnessSlider", "#GameUI_Haptics_VehicleBoxScale",
  72. 0.0f, 3.0f, "hap_VehicleBoxStiffness", true );
  73. m_pVehicleBoxTurnPreLabel = new Label(this, "VehicleTurnPreLabel", "#GameUI_Haptics_Turning" );
  74. m_pVehicleBoxTurnSlider = new CCvarSlider( this, "VehicleTurnSlider", "#GameUI_Haptics_Turning",
  75. 0.0f, 2.0f, "hap_VehicleTurnScale", true );
  76. m_pVehicleBoxAimPreLabel = new Label(this, "VehicleAimPreLabel", "#GameUI_Haptics_Aiming" );
  77. m_pVehicleBoxAimSlider = new CCvarSlider( this, "VehicleAimSlider", "#GameUI_Haptics_Aiming",
  78. 0.0f, 2.0f, "hap_VehicleAimScale", true );
  79. vgui::Button *defaults = new vgui::Button( this, "Defaults", "Use Defaults" );
  80. defaults->SetCommand("DoDefaults");
  81. LoadControlSettings("Resource\\OptionsSubHaptics.res");
  82. UpdateVehicleEnabled();
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose:
  86. //-----------------------------------------------------------------------------
  87. COptionsSubHaptics::~COptionsSubHaptics()
  88. {
  89. }
  90. //-----------------------------------------------------------------------------
  91. // Purpose:
  92. //-----------------------------------------------------------------------------
  93. void COptionsSubHaptics::OnResetData()
  94. {
  95. m_pForceMasterSlider->Reset();
  96. m_pForceDamageSlider->Reset();
  97. m_pForceRecoilSlider->Reset();
  98. m_pForceMovementSlider->Reset();
  99. m_pPlayerBoxScale->Reset();
  100. m_pPlayerBoxStiffnessSlider->Reset();
  101. m_pPlayerBoxTurnSlider->Reset();
  102. m_pPlayerBoxAimSlider->Reset();
  103. m_pVehicleBoxScale->Reset();
  104. m_pVehicleBoxStiffnessSlider->Reset();
  105. m_pVehicleBoxTurnSlider->Reset();
  106. m_pVehicleBoxAimSlider->Reset();
  107. }
  108. //-----------------------------------------------------------------------------
  109. // Purpose:
  110. //-----------------------------------------------------------------------------
  111. void COptionsSubHaptics::OnApplyChanges()
  112. {
  113. m_pForceMasterSlider->ApplyChanges();
  114. m_pForceDamageSlider->ApplyChanges();
  115. m_pForceRecoilSlider->ApplyChanges();
  116. m_pForceMovementSlider->ApplyChanges();
  117. m_pPlayerBoxScale->ApplyChanges();
  118. m_pPlayerBoxStiffnessSlider->ApplyChanges();
  119. m_pPlayerBoxTurnSlider->ApplyChanges();
  120. m_pPlayerBoxAimSlider->ApplyChanges();
  121. m_pVehicleBoxScale->ApplyChanges();
  122. m_pVehicleBoxStiffnessSlider->ApplyChanges();
  123. m_pVehicleBoxTurnSlider->ApplyChanges();
  124. m_pVehicleBoxAimSlider->ApplyChanges();
  125. //Write out our config file
  126. engine->ClientCmd_Unrestricted("writehapticconfig");
  127. engine->ClientCmd_Unrestricted("reloadhaptics");
  128. }
  129. //-----------------------------------------------------------------------------
  130. // Purpose: sets background color & border
  131. //-----------------------------------------------------------------------------
  132. void COptionsSubHaptics::ApplySchemeSettings(IScheme *pScheme)
  133. {
  134. BaseClass::ApplySchemeSettings(pScheme);
  135. }
  136. //-----------------------------------------------------------------------------
  137. // Purpose:
  138. //-----------------------------------------------------------------------------
  139. void COptionsSubHaptics::OnControlModified(Panel *panel)
  140. {
  141. PostActionSignal(new KeyValues("ApplyButtonEnable"));
  142. }
  143. //-----------------------------------------------------------------------------
  144. // Purpose:
  145. //-----------------------------------------------------------------------------
  146. void COptionsSubHaptics::OnTextChanged(Panel *panel)
  147. {
  148. }
  149. void COptionsSubHaptics::UpdateVehicleEnabled()
  150. {
  151. ConVarRef checkVehicle("hap_ui_vehicles");
  152. checkVehicle.Init("hap_ui_vehicles",true);
  153. bool bEnabled = checkVehicle.GetBool();
  154. m_pVehicleBoxPreLabel->SetEnabled( bEnabled );
  155. m_pVehicleBoxScalePreLabel->SetEnabled( bEnabled );
  156. m_pVehicleBoxScale->SetEnabled( bEnabled );
  157. m_pVehicleBoxStiffnessPreLabel->SetEnabled( bEnabled );
  158. m_pVehicleBoxStiffnessSlider->SetEnabled( bEnabled );
  159. m_pVehicleBoxTurnPreLabel->SetEnabled( bEnabled );
  160. m_pVehicleBoxTurnSlider->SetEnabled( bEnabled );
  161. m_pVehicleBoxAimPreLabel ->SetEnabled( bEnabled );
  162. m_pVehicleBoxAimSlider ->SetEnabled( bEnabled );
  163. }