added already assigned key in the UI
parent
7ced12e13b
commit
cfa919b46c
|
@ -1,4 +1,5 @@
|
||||||
import {GamepadConfig} from "../inputs-controller";
|
import {GamepadConfig} from "../inputs-controller";
|
||||||
|
import {SettingGamepad} from "#app/system/settings-gamepad";
|
||||||
|
|
||||||
|
|
||||||
export function getKeyForButtonIndex(config: GamepadConfig, index: integer): String {
|
export function getKeyForButtonIndex(config: GamepadConfig, index: integer): String {
|
||||||
|
@ -13,3 +14,11 @@ export function getIconForCustomIndex(config: GamepadConfig, index: integer): St
|
||||||
const key = getKeyForButtonIndex(config, index);
|
const key = getKeyForButtonIndex(config, index);
|
||||||
return config.icons[key];
|
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;
|
||||||
|
}
|
|
@ -644,4 +644,8 @@ export class InputsController {
|
||||||
setBind(setting: SettingGamepad, button: Button) {
|
setBind(setting: SettingGamepad, button: Button) {
|
||||||
console.log('button,', button);
|
console.log('button,', button);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getActiveConfig() :GamepadConfig {
|
||||||
|
return this.configs[this.chosenGamepad] || pad_generic;
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -12,6 +12,7 @@ import {
|
||||||
settingGamepadOptions
|
settingGamepadOptions
|
||||||
} from "../system/settings-gamepad";
|
} from "../system/settings-gamepad";
|
||||||
import {truncateString} from "../utils";
|
import {truncateString} from "../utils";
|
||||||
|
import {getKeyForSettingName} from "#app/configs/gamepad-utils";
|
||||||
|
|
||||||
export default class SettingsGamepadUiHandler extends UiHandler {
|
export default class SettingsGamepadUiHandler extends UiHandler {
|
||||||
private settingsContainer: Phaser.GameObjects.Container;
|
private settingsContainer: Phaser.GameObjects.Container;
|
||||||
|
@ -32,6 +33,8 @@ export default class SettingsGamepadUiHandler extends UiHandler {
|
||||||
private reloadI18n: boolean;
|
private reloadI18n: boolean;
|
||||||
private gamepads: Array<String>;
|
private gamepads: Array<String>;
|
||||||
|
|
||||||
|
private inputsIcons;
|
||||||
|
|
||||||
constructor(scene: BattleScene, mode?: Mode) {
|
constructor(scene: BattleScene, mode?: Mode) {
|
||||||
super(scene, mode);
|
super(scene, mode);
|
||||||
|
|
||||||
|
@ -65,6 +68,7 @@ export default class SettingsGamepadUiHandler extends UiHandler {
|
||||||
|
|
||||||
this.settingLabels = [];
|
this.settingLabels = [];
|
||||||
this.optionValueLabels = [];
|
this.optionValueLabels = [];
|
||||||
|
this.inputsIcons = {};
|
||||||
|
|
||||||
Object.keys(SettingGamepad).forEach((setting, s) => {
|
Object.keys(SettingGamepad).forEach((setting, s) => {
|
||||||
let settingName = setting.replace(/\_/g, ' ');
|
let settingName = setting.replace(/\_/g, ' ');
|
||||||
|
@ -77,7 +81,22 @@ export default class SettingsGamepadUiHandler extends UiHandler {
|
||||||
const valueLabels = []
|
const valueLabels = []
|
||||||
for (const [o, option] of settingGamepadOptions[SettingGamepad[setting]].entries()) {
|
for (const [o, option] of settingGamepadOptions[SettingGamepad[setting]].entries()) {
|
||||||
if (noOptionsCursors.includes(SettingGamepad[setting])) {
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
const valueLabel = addTextObject(this.scene, 0, 0, option, settingGamepadDefaults[SettingGamepad[setting]] === o ? TextStyle.SETTINGS_SELECTED : TextStyle.WINDOW);
|
const valueLabel = addTextObject(this.scene, 0, 0, option, settingGamepadDefaults[SettingGamepad[setting]] === o ? TextStyle.SETTINGS_SELECTED : TextStyle.WINDOW);
|
||||||
|
|
Loading…
Reference in New Issue