Skip to content
This repository has been archived by the owner on Jan 10, 2025. It is now read-only.

Commit

Permalink
Make control blocking optional as workaround
Browse files Browse the repository at this point in the history
Will be optional until whenever.
  • Loading branch information
ikt32 committed Jun 22, 2017
1 parent d176d4c commit 1fa0f5d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 5 deletions.
8 changes: 8 additions & 0 deletions Gears/Input/ScriptControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(control)]), buttonState, time))
return true;
return false;
}

bool ScriptControls::ButtonHeld(ControllerControlType control) {
if (!controller.IsConnected())
return false;
Expand Down
1 change: 1 addition & 0 deletions Gears/Input/ScriptControls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions Gears/ScriptMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion Gears/ScriptSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -271,6 +271,8 @@ void ScriptSettings::parseSettingsGeneral(ScriptControls *scriptControl) {
// [CONTROLLER]
scriptControl->ControlXbox[static_cast<int>(ScriptControls::ControllerControlType::Toggle)] = settingsGeneral.GetValue("CONTROLLER", "Toggle", "DpadRight");
scriptControl->ControlXbox[static_cast<int>(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);
Expand Down
1 change: 1 addition & 0 deletions Gears/ScriptSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class ScriptSettings {
float SteerAngleBike = 180.0f;
float SteerAngleAlt = 180.0f;
float GameSteerMult = 1.0f;
bool BlockCarControls = false;

// Methods
/*
Expand Down
18 changes: 14 additions & 4 deletions Gears/script.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(ScriptControls::ControllerControlType::SIZEOF_ControllerControlType); i++) {
Expand All @@ -1587,17 +1587,27 @@ void handleVehicleButtons() {
if (i != (int)ScriptControls::ControllerControlType::ShiftUp && i != (int)ScriptControls::ControllerControlType::ShiftDown) continue;

if (controls.ButtonHeldOver(static_cast<ScriptControls::ControllerControlType>(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<ScriptControls::ControllerControlType>(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) ||
Expand Down

0 comments on commit 1fa0f5d

Please sign in to comment.