added already assigned key in the UI

pull/685/head
Greenlamp 2024-05-11 14:51:01 +02:00
parent 7ced12e13b
commit cfa919b46c
3 changed files with 33 additions and 1 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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<String>;
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);