From cfa919b46c19d737727bc9edc07e32968ea8cf94 Mon Sep 17 00:00:00 2001 From: Greenlamp Date: Sat, 11 May 2024 14:51:01 +0200 Subject: [PATCH] added already assigned key in the UI --- src/configs/gamepad-utils.ts | 9 +++++++++ src/inputs-controller.ts | 4 ++++ src/ui/settings-gamepad-ui-handler.ts | 21 ++++++++++++++++++++- 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/configs/gamepad-utils.ts b/src/configs/gamepad-utils.ts index 6bf99f28a..d8be247ef 100644 --- a/src/configs/gamepad-utils.ts +++ b/src/configs/gamepad-utils.ts @@ -1,4 +1,5 @@ import {GamepadConfig} from "../inputs-controller"; +import {SettingGamepad} from "#app/system/settings-gamepad"; export function getKeyForButtonIndex(config: GamepadConfig, index: integer): String { @@ -12,4 +13,12 @@ export function getKeyForButtonIndex(config: GamepadConfig, index: integer): Str export function getIconForCustomIndex(config: GamepadConfig, index: integer): String { const key = getKeyForButtonIndex(config, index); return config.icons[key]; +} + +export function getKeyForSettingName(config: GamepadConfig, settingName: SettingGamepad) { + for (const key of Object.keys(config.setting)) { + const name = config.setting[key]; + if (name === settingName) return key; + } + return null; } \ No newline at end of file diff --git a/src/inputs-controller.ts b/src/inputs-controller.ts index df7320984..2568f49ee 100644 --- a/src/inputs-controller.ts +++ b/src/inputs-controller.ts @@ -644,4 +644,8 @@ export class InputsController { setBind(setting: SettingGamepad, button: Button) { console.log('button,', button); } + + getActiveConfig() :GamepadConfig { + return this.configs[this.chosenGamepad] || pad_generic; + } } \ No newline at end of file diff --git a/src/ui/settings-gamepad-ui-handler.ts b/src/ui/settings-gamepad-ui-handler.ts index be1db4dc5..d14196db2 100644 --- a/src/ui/settings-gamepad-ui-handler.ts +++ b/src/ui/settings-gamepad-ui-handler.ts @@ -12,6 +12,7 @@ import { settingGamepadOptions } from "../system/settings-gamepad"; import {truncateString} from "../utils"; +import {getKeyForSettingName} from "#app/configs/gamepad-utils"; export default class SettingsGamepadUiHandler extends UiHandler { private settingsContainer: Phaser.GameObjects.Container; @@ -32,6 +33,8 @@ export default class SettingsGamepadUiHandler extends UiHandler { private reloadI18n: boolean; private gamepads: Array; + private inputsIcons; + constructor(scene: BattleScene, mode?: Mode) { super(scene, mode); @@ -65,6 +68,7 @@ export default class SettingsGamepadUiHandler extends UiHandler { this.settingLabels = []; this.optionValueLabels = []; + this.inputsIcons = {}; Object.keys(SettingGamepad).forEach((setting, s) => { let settingName = setting.replace(/\_/g, ' '); @@ -77,7 +81,22 @@ export default class SettingsGamepadUiHandler extends UiHandler { const valueLabels = [] for (const [o, option] of settingGamepadOptions[SettingGamepad[setting]].entries()) { if (noOptionsCursors.includes(SettingGamepad[setting])) { - // need to find a way to fetch icons and display, maybe a placeholder. + if (o) { + const valueLabel = addTextObject(this.scene, 0, 0, option, settingGamepadDefaults[SettingGamepad[setting]] === o ? TextStyle.SETTINGS_SELECTED : TextStyle.WINDOW); + valueLabel.setOrigin(0, 0); + this.optionsContainer.add(valueLabel); + valueLabels.push(valueLabel); + continue; + } + const key = getKeyForSettingName(this.scene.inputController.getActiveConfig(), SettingGamepad[setting]); + const frame = this.scene.inputController.getActiveConfig().icons[key]; + const icon = this.scene.add.sprite(0, 0, 'xbox'); + icon.setScale(0.1); + icon.setOrigin(0, 0); + icon.setFrame(frame); + this.inputsIcons[key] = icon; + this.optionsContainer.add(icon); + valueLabels.push(icon); continue; } const valueLabel = addTextObject(this.scene, 0, 0, option, settingGamepadDefaults[SettingGamepad[setting]] === o ? TextStyle.SETTINGS_SELECTED : TextStyle.WINDOW);