diff --git a/src/configs/gamepad-utils.ts b/src/configs/gamepad-utils.ts index 946db4d4e..a01813db2 100644 --- a/src/configs/gamepad-utils.ts +++ b/src/configs/gamepad-utils.ts @@ -29,10 +29,18 @@ export function getKeyForRebindedAction(config: GamepadConfig, action: Button): return null; } +export function getKeyForAction(config: GamepadConfig, action: Button): String { + for (const key of Object.keys(config.custom)) { + if (config.custom[key] === action) return key; + } + return null; +} + export function getKeyForRebindedSettingName(config: GamepadConfig, settingName: SettingGamepad): String { const oldKey = getKeyForSettingName(config, settingName) const action = config.custom[oldKey]; - return getKeyForRebindedAction(config, action); + const key = getKeyForRebindedAction(config, action); + return key; } export function getIconForRebindedKey(config: GamepadConfig, _key): String { @@ -48,3 +56,10 @@ export function getKeyForSettingName(config: GamepadConfig, settingName: Setting } return null; } + +export function getIconForSettingName(config: GamepadConfig, settingName: SettingGamepad) { + const key = getKeyForSettingName(config, settingName); + const action = config.default[key]; + const rebindedKey = getKeyForAction(config, action); + return config.icons[rebindedKey]; +} diff --git a/src/configs/pad_generic.ts b/src/configs/pad_generic.ts index f64d6c342..de07ef478 100644 --- a/src/configs/pad_generic.ts +++ b/src/configs/pad_generic.ts @@ -58,8 +58,8 @@ const pad_generic = { RS: SettingGamepad.Button_Slow_Down, }, default: { - RC_S: Button.ACTION, - RC_E: Button.CANCEL, + RC_S: Button.ACTION, //5 + RC_E: Button.CANCEL, // 6 RC_W: Button.CYCLE_NATURE, RC_N: Button.CYCLE_VARIANT, START: Button.MENU, diff --git a/src/configs/pad_xbox360.ts b/src/configs/pad_xbox360.ts index 189c2a349..08bbd71a5 100644 --- a/src/configs/pad_xbox360.ts +++ b/src/configs/pad_xbox360.ts @@ -59,7 +59,7 @@ const pad_xbox360 = { }, default: { RC_S: Button.ACTION, //5 - RC_E: Button.CANCEL, + RC_E: Button.CANCEL, // 6 RC_W: Button.CYCLE_NATURE, RC_N: Button.CYCLE_VARIANT, //14 START: Button.MENU, //7 diff --git a/src/inputs-controller.ts b/src/inputs-controller.ts index f56f3e77f..102824518 100644 --- a/src/inputs-controller.ts +++ b/src/inputs-controller.ts @@ -307,8 +307,9 @@ export class InputsController { // for each gamepad, we set its mapping in this.configs const gamepadID = gamepad.toLowerCase(); const config = this.getConfig(gamepadID); - config.custom = this.configs[gamepad]?.custom || config.default; + config.custom = this.configs[gamepad]?.custom || {...config.default}; this.configs[gamepad] = config; + this.scene.gameData?.saveCustomMapping(this.chosenGamepad, this.configs[gamepad]?.custom); } if (this.chosenGamepad === thisGamepad.id) this.initChosenGamepad(this.chosenGamepad) } diff --git a/src/ui/settings-gamepad-ui-handler.ts b/src/ui/settings-gamepad-ui-handler.ts index 2dad71523..e099190d3 100644 --- a/src/ui/settings-gamepad-ui-handler.ts +++ b/src/ui/settings-gamepad-ui-handler.ts @@ -12,7 +12,10 @@ import { settingGamepadOptions } from "../system/settings-gamepad"; import {truncateString} from "../utils"; -import {getIconForRebindedKey, getKeyForSettingName} from "#app/configs/gamepad-utils"; +import { + getIconForSettingName, + getKeyForSettingName +} from "#app/configs/gamepad-utils"; export default class SettingsGamepadUiHandler extends UiHandler { private settingsContainer: Phaser.GameObjects.Container; @@ -141,7 +144,7 @@ export default class SettingsGamepadUiHandler extends UiHandler { const activeConfig = this.scene.inputController.getActiveConfig(); for (const elm of noOptionsCursors) { const key = getKeyForSettingName(activeConfig, elm); - const icon = getIconForRebindedKey(activeConfig, key); + const icon = getIconForSettingName(activeConfig, elm); this.inputsIcons[key].setFrame(icon); } }