diff --git a/Gears/Input/ScriptControls.cpp b/Gears/Input/ScriptControls.cpp index 3b8f9800..57e8118f 100644 --- a/Gears/Input/ScriptControls.cpp +++ b/Gears/Input/ScriptControls.cpp @@ -257,6 +257,14 @@ bool ScriptControls::ButtonReleased(ControllerControlType control) { return false; } +bool ScriptControls::ButtonReleasedAfter(ControllerControlType control, int time) { + if (!controller.IsConnected()) + return false; + if (controller.WasButtonHeldForMs(controller.StringToButton(ControlXbox[static_cast(control)]), buttonState, time)) + return true; + return false; +} + bool ScriptControls::ButtonHeld(ControllerControlType control) { if (!controller.IsConnected()) return false; diff --git a/Gears/Input/ScriptControls.hpp b/Gears/Input/ScriptControls.hpp index 19aeff95..5d76d0da 100644 --- a/Gears/Input/ScriptControls.hpp +++ b/Gears/Input/ScriptControls.hpp @@ -121,6 +121,7 @@ class ScriptControls { public: bool ButtonJustPressed(ControllerControlType control); bool ButtonReleased(ControllerControlType control); + bool ButtonReleasedAfter(ControllerControlType control, int time); bool ButtonHeld(ControllerControlType control); bool ButtonHeldOver(ControllerControlType control, int millis); XboxController::TapState ButtonTapped(ControllerControlType control); diff --git a/Gears/ScriptMenu.cpp b/Gears/ScriptMenu.cpp index 7684302d..71656ad6 100644 --- a/Gears/ScriptMenu.cpp +++ b/Gears/ScriptMenu.cpp @@ -272,6 +272,8 @@ void update_menu() { menu.MenuOption("Keyboard", "keyboardmenu",{"Change keyboard control assignments."}); menu.BoolOption("Non-Xinput controller", controls.UseLegacyController, { "If you needed to set up your controller in","the pause menu, you should enable this." }); + menu.BoolOption("Block car controls", settings.BlockCarControls, { "Blocks car action controls like ducking, switching guns, handbrake, aim." + "Holding activates the original button again. Experimental! Only works for XInput." } ); } /* Yes hello I am root - 2 */ diff --git a/Gears/ScriptSettings.cpp b/Gears/ScriptSettings.cpp index 86567450..ef96a447 100644 --- a/Gears/ScriptSettings.cpp +++ b/Gears/ScriptSettings.cpp @@ -122,7 +122,7 @@ void ScriptSettings::SaveController(ScriptControls *scriptControl) const { settingsGeneral.SetBoolValue("CONTROLLER", "ToggleEngine", ToggleEngine); settingsGeneral.SetLongValue("CONTROLLER", "ToggleTime", scriptControl->CToggleTime); settingsGeneral.SetDoubleValue("CONTROLLER", "TriggerValue", scriptControl->GetXboxTrigger()); - + settingsGeneral.SetBoolValue("CONTROLLER", "BlockCarControls", BlockCarControls); #ifdef GAME_BUILD settingsGeneral.SetBoolValue("CONTROLLER_LEGACY", "Enable", scriptControl->UseLegacyController); #endif @@ -271,6 +271,8 @@ void ScriptSettings::parseSettingsGeneral(ScriptControls *scriptControl) { // [CONTROLLER] scriptControl->ControlXbox[static_cast(ScriptControls::ControllerControlType::Toggle)] = settingsGeneral.GetValue("CONTROLLER", "Toggle", "DpadRight"); scriptControl->ControlXbox[static_cast(ScriptControls::ControllerControlType::ToggleH)] = settingsGeneral.GetValue("CONTROLLER", "ToggleShift", "B"); + BlockCarControls = settingsGeneral.GetBoolValue("CONTROLLER", "BlockCarControls", false); + scriptControl->CToggleTime = settingsGeneral.GetLongValue("CONTROLLER", "ToggleTime", 500); double tval = settingsGeneral.GetDoubleValue("CONTROLLER", "TriggerValue", 0.75); diff --git a/Gears/ScriptSettings.hpp b/Gears/ScriptSettings.hpp index d4d2dea6..703b7101 100644 --- a/Gears/ScriptSettings.hpp +++ b/Gears/ScriptSettings.hpp @@ -126,6 +126,7 @@ class ScriptSettings { float SteerAngleBike = 180.0f; float SteerAngleAlt = 180.0f; float GameSteerMult = 1.0f; + bool BlockCarControls = false; // Methods /* diff --git a/Gears/script.cpp b/Gears/script.cpp index a1bc42a5..5f33d4a7 100644 --- a/Gears/script.cpp +++ b/Gears/script.cpp @@ -1578,7 +1578,7 @@ void functionAutoReverse() { void handleVehicleButtons() { // Limited button blocking - if (settings.EnableManual && controls.PrevInput == ScriptControls::Controller && + if (settings.BlockCarControls && settings.EnableManual && controls.PrevInput == ScriptControls::Controller && !(settings.ShiftMode == Automatic && vehData.CurrGear > 1)) { for (int i = 0; i < static_cast(ScriptControls::ControllerControlType::SIZEOF_ControllerControlType); i++) { @@ -1587,17 +1587,27 @@ void handleVehicleButtons() { if (i != (int)ScriptControls::ControllerControlType::ShiftUp && i != (int)ScriptControls::ControllerControlType::ShiftDown) continue; if (controls.ButtonHeldOver(static_cast(i), 200)) { - // todo: Neither of these two should be needed but I can't get tap-controls to activate. (switch wpn) - CONTROLS::ENABLE_CONTROL_ACTION(0, controls.ControlXboxBlocks[i], true); - CONTROLS::_SET_CONTROL_NORMAL(0, controls.ControlXboxBlocks[i], 1.0f); + // todo: Neither of these two should be needed but I can't get tap-controls to activate. (switch weapon) + //CONTROLS::DISABLE_CONTROL_ACTION(0, controls.ControlXboxBlocks[i], false); + //CONTROLS::ENABLE_CONTROL_ACTION(0, controls.ControlXboxBlocks[i], true); + //CONTROLS::_SET_CONTROL_NORMAL(0, controls.ControlXboxBlocks[i], 1.0f); } else { CONTROLS::DISABLE_CONTROL_ACTION(0, controls.ControlXboxBlocks[i], true); } + + if (controls.ButtonReleasedAfter(static_cast(i), 200)) { + CONTROLS::DISABLE_CONTROL_ACTION(0, controls.ControlXboxBlocks[i], false); + CONTROLS::ENABLE_CONTROL_ACTION(0, controls.ControlXboxBlocks[i], true); + CONTROLS::_SET_CONTROL_NORMAL(0, controls.ControlXboxBlocks[i], 1.0f); + showSubtitle("Fuck."); + } } } + + if (!VEHICLE::GET_IS_VEHICLE_ENGINE_RUNNING(vehicle) && (controls.PrevInput == ScriptControls::Controller && controls.ButtonJustPressed(ScriptControls::ControllerControlType::Engine) || controls.PrevInput == ScriptControls::Controller && controls.ButtonJustPressed(ScriptControls::LegacyControlType::Engine) ||