Skip to content

Commit

Permalink
Add checkbox controlling if new mappings can be combo mappings.
Browse files Browse the repository at this point in the history
These can be problematic with certain controllers that send double
signals. Like PS4 controllers on Android, the analog triggers send dual
axis events, and additionally digital events.
  • Loading branch information
hrydgard committed Jul 7, 2023
1 parent f33660b commit b932707
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Common/Input/InputState.cpp
Expand Up @@ -20,7 +20,7 @@ const char *GetDeviceName(int deviceId) {
case DEVICE_ID_PAD_7: return "pad8";
case DEVICE_ID_PAD_8: return "pad9";
case DEVICE_ID_PAD_9: return "pad10";
case DEVICE_ID_XINPUT_0: return "x360"; // keeping these strings for backward compat
case DEVICE_ID_XINPUT_0: return "x360"; // keeping these strings for backward compat. Hm, what would break if we changed them to xbox?
case DEVICE_ID_XINPUT_1: return "x360_2";
case DEVICE_ID_XINPUT_2: return "x360_3";
case DEVICE_ID_XINPUT_3: return "x360_4";
Expand Down
2 changes: 2 additions & 0 deletions Core/Config.cpp
Expand Up @@ -758,6 +758,8 @@ static const ConfigSetting controlSettings[] = {

ConfigSetting("AnalogLimiterDeadzone", &g_Config.fAnalogLimiterDeadzone, 0.6f, CfgFlag::DEFAULT),

ConfigSetting("AllowMappingCombos", &g_Config.bAllowMappingCombos, false, CfgFlag::DEFAULT),

ConfigSetting("LeftStickHeadScale", &g_Config.fLeftStickHeadScale, 1.0f, CfgFlag::PER_GAME),
ConfigSetting("RightStickHeadScale", &g_Config.fRightStickHeadScale, 1.0f, CfgFlag::PER_GAME),
ConfigSetting("HideStickBackground", &g_Config.bHideStickBackground, false, CfgFlag::PER_GAME),
Expand Down
3 changes: 3 additions & 0 deletions Core/Config.h
Expand Up @@ -376,6 +376,9 @@ struct Config {
// Sets up how much the analog limiter button restricts digital->analog input.
float fAnalogLimiterDeadzone;

// Sets whether combo mapping is enabled.
bool bAllowMappingCombos;

bool bMouseControl;
bool bMapMouse; // Workaround for mapping screen:|
bool bMouseConfine; // Trap inside the window.
Expand Down
4 changes: 2 additions & 2 deletions Core/SaveState.cpp
Expand Up @@ -873,12 +873,12 @@ namespace SaveState
// Sometimes this exposes game bugs that were rarely seen on real devices,
// because few people played on a real PSP for 10 hours straight.
callbackMessage = sc->T("Loaded. Save in game, restart, and load for less bugs.");
return Status::WARNING;
return Status::SUCCESS;
}
if (IsOldVersion()) {
// Save states also preserve bugs from old PPSSPP versions, so warn.
callbackMessage = sc->T("Loaded. Save in game, restart, and load for less bugs.");
return Status::WARNING;
return Status::SUCCESS;
}
// If the loaded state (saveDataGeneration) is older, the game may prevent saving again.
// This can happen with newer too, but ignore to/from 0 as a common likely safe case.
Expand Down
9 changes: 8 additions & 1 deletion UI/ControlMappingScreen.cpp
Expand Up @@ -252,6 +252,7 @@ void ControlMappingScreen::CreateViews() {
}

leftColumn->Add(new Choice(km->T("Show PSP")))->OnClick.Handle(this, &ControlMappingScreen::OnVisualizeMapping);
leftColumn->Add(new CheckBox(&g_Config.bAllowMappingCombos, km->T("Allow combo mappings")));

leftColumn->Add(new Spacer(new LinearLayoutParams(1.0f)));
AddStandardBack(leftColumn);
Expand Down Expand Up @@ -333,6 +334,9 @@ void KeyMappingNewKeyDialog::CreatePopupContents(UI::ViewGroup *parent) {
parent->Add(new TextView(std::string(km->T("Map a new key for")) + " " + mc->T(pspButtonName), new LinearLayoutParams(Margins(10, 0))));
parent->Add(new TextView(std::string(mapping_.ToVisualString()), new LinearLayoutParams(Margins(10, 0))));

comboMappingsNotEnabled_ = parent->Add(new TextView(km->T("Combo mappings are not enabled"), new LinearLayoutParams(Margins(10, 0))));
comboMappingsNotEnabled_->SetVisibility(UI::V_GONE);

SetVRAppMode(VRAppMode::VR_CONTROLLER_MAPPING_MODE);
}

Expand All @@ -341,6 +345,7 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) {
return true;
if (time_now_d() < delayUntil_)
return true;

if (key.flags & KEY_DOWN) {
if (key.keyCode == NKCODE_EXT_MOUSEBUTTON_1) {
// Don't map
Expand All @@ -355,7 +360,9 @@ bool KeyMappingNewKeyDialog::key(const KeyInput &key) {
InputMapping newMapping(key.deviceId, key.keyCode);

if (!(key.flags & KEY_IS_REPEAT)) {
if (!mapping_.mappings.contains(newMapping)) {
if (!g_Config.bAllowMappingCombos && !mapping_.mappings.empty()) {
comboMappingsNotEnabled_->SetVisibility(UI::V_VISIBLE);
} else if (!mapping_.mappings.contains(newMapping)) {
mapping_.mappings.push_back(newMapping);
RecreateViews();
}
Expand Down
2 changes: 2 additions & 0 deletions UI/ControlMappingScreen.h
Expand Up @@ -81,6 +81,8 @@ class KeyMappingNewKeyDialog : public PopupScreen {

KeyMap::MultiInputMapping mapping_;

UI::View *comboMappingsNotEnabled_ = nullptr;

// We need to do our own detection for axis "keyup" here.
std::set<InputMapping> triggeredAxes_;

Expand Down
2 changes: 2 additions & 0 deletions assets/lang/en_US.ini
Expand Up @@ -644,10 +644,12 @@ Zip archive corrupt = ZIP archive corrupt
Zip file does not contain PSP software = ZIP file does not contain PSP software
[KeyMapping]
Allow combo mappings = Allow combo mappings
Autoconfigure = Auto configure
Autoconfigure for device = Autoconfigure for device
Bind All = Bind All
Clear All = Clear all
Combo mappings are not enabled = Combo mappings are not enabled
Default All = Restore defaults
Map a new key for = Map a new key for
Map Key = Map key
Expand Down

0 comments on commit b932707

Please sign in to comment.