From f0a1298208c33781a96e4e45a017baee6b82305f Mon Sep 17 00:00:00 2001 From: LunaMoo Date: Wed, 27 Jun 2018 18:47:09 +0200 Subject: [PATCH] Make Axis to button threshold changeable. --- Common/KeyMap.h | 2 -- Core/Config.cpp | 1 + Core/Config.h | 1 + UI/ControlMappingScreen.cpp | 10 +++++----- UI/EmuScreen.cpp | 4 ++-- UI/GameSettingsScreen.cpp | 6 ++++++ 6 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Common/KeyMap.h b/Common/KeyMap.h index 9f408ed7f6..5aafa6d707 100644 --- a/Common/KeyMap.h +++ b/Common/KeyMap.h @@ -67,8 +67,6 @@ enum DefaultMaps { DEFAULT_MAPPING_XPERIA_PLAY, }; -const float AXIS_BIND_THRESHOLD = 0.75f; - typedef std::map> KeyMapping; // KeyMap diff --git a/Core/Config.cpp b/Core/Config.cpp index e7c22fe0ad..6e28be6475 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -739,6 +739,7 @@ static ConfigSetting controlSettings[] = { // Also reused as generic analog sensitivity ConfigSetting("XInputAnalogSensitivity", &g_Config.fXInputAnalogSensitivity, 1.0f, true, true), ConfigSetting("AnalogLimiterDeadzone", &g_Config.fAnalogLimiterDeadzone, 0.6f, true, true), + ConfigSetting("AxisBindThreshold", &g_Config.fAxisBindThreshold, 0.75f, true, true), ConfigSetting("UseMouse", &g_Config.bMouseControl, false, true, true), ConfigSetting("MapMouse", &g_Config.bMapMouse, false, true, true), diff --git a/Core/Config.h b/Core/Config.h index d39957e7fb..9dace891e7 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -329,6 +329,7 @@ public: float fXInputAnalogSensitivity; float fAnalogLimiterDeadzone; + float fAxisBindThreshold; bool bMouseControl; bool bMapMouse; // Workaround for mapping screen:| diff --git a/UI/ControlMappingScreen.cpp b/UI/ControlMappingScreen.cpp index 3412cc34b5..5365f11638 100644 --- a/UI/ControlMappingScreen.cpp +++ b/UI/ControlMappingScreen.cpp @@ -381,7 +381,7 @@ bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) { if (IgnoreAxisForMapping(axis.axisId)) return false; - if (axis.value > AXIS_BIND_THRESHOLD) { + if (axis.value > g_Config.fAxisBindThreshold) { mapped_ = true; KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, 1)); TriggerFinish(DR_OK); @@ -389,7 +389,7 @@ bool KeyMappingNewKeyDialog::axis(const AxisInput &axis) { callback_(kdf); } - if (axis.value < -AXIS_BIND_THRESHOLD) { + if (axis.value < -g_Config.fAxisBindThreshold) { mapped_ = true; KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, -1)); TriggerFinish(DR_OK); @@ -405,7 +405,7 @@ bool KeyMappingNewMouseKeyDialog::axis(const AxisInput &axis) { if (IgnoreAxisForMapping(axis.axisId)) return false; - if (axis.value > AXIS_BIND_THRESHOLD) { + if (axis.value > g_Config.fAxisBindThreshold) { mapped_ = true; KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, 1)); TriggerFinish(DR_OK); @@ -413,7 +413,7 @@ bool KeyMappingNewMouseKeyDialog::axis(const AxisInput &axis) { callback_(kdf); } - if (axis.value < -AXIS_BIND_THRESHOLD) { + if (axis.value < -g_Config.fAxisBindThreshold) { mapped_ = true; KeyDef kdf(axis.deviceId, KeyMap::TranslateKeyCodeFromAxis(axis.axisId, -1)); TriggerFinish(DR_OK); @@ -525,7 +525,7 @@ bool AnalogTestScreen::axis(const AxisInput &axis) { if (IgnoreAxisForMapping(axis.axisId)) return false; - if (axis.value > AXIS_BIND_THRESHOLD || axis.value < -AXIS_BIND_THRESHOLD) { + if (axis.value > g_Config.fAxisBindThreshold || axis.value < -g_Config.fAxisBindThreshold) { snprintf(buf, sizeof(buf), "Axis: %d (value %1.3f) Device ID: %d", axis.axisId, axis.value, axis.deviceId); // Null-check just in case they weren't created yet. diff --git a/UI/EmuScreen.cpp b/UI/EmuScreen.cpp index b4e761e980..b1495210f7 100644 --- a/UI/EmuScreen.cpp +++ b/UI/EmuScreen.cpp @@ -845,9 +845,9 @@ void EmuScreen::processAxis(const AxisInput &axis, int direction) { KeyMap::AxisToPspButton(axis.deviceId, axis.axisId, -direction, &resultsOpposite); int axisState = 0; - if ((direction == 1 && axis.value >= AXIS_BIND_THRESHOLD)) { + if ((direction == 1 && axis.value >= g_Config.fAxisBindThreshold)) { axisState = 1; - } else if (direction == -1 && axis.value <= -AXIS_BIND_THRESHOLD) { + } else if (direction == -1 && axis.value <= -g_Config.fAxisBindThreshold) { axisState = -1; } else { axisState = 0; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index 8ccec4b5e7..d129347846 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -534,6 +534,12 @@ void GameSettingsScreen::CreateViews() { #if defined(USING_WIN_UI) controlsSettings->Add(new CheckBox(&g_Config.bGamepadOnlyFocused, co->T("Ignore gamepads when not focused"))); #endif + auto axisToButton = new PopupSliderChoiceFloat(&g_Config.fAxisBindThreshold, 0.01f, 0.96f, co->T("Axis to button threshold"), 0.05f, screenManager()); + controlsSettings->Add(axisToButton); + axisToButton->OnChange.Add([=](EventParams &e) { + settingInfo_->Show(co->T("AxisToButton Tip", "Affects how far you have to push the stick(or move mouse on supported platforms) to trigger button mapped to it."), e.v); + return UI::EVENT_CONTINUE; + }); #if defined(MOBILE_DEVICE) controlsSettings->Add(new CheckBox(&g_Config.bHapticFeedback, co->T("HapticFeedback", "Haptic Feedback (vibration)")));