added a message instead of nothing in the keyboard menu if playing on mobile

pull/685/head
Greenlamp 2024-05-15 00:32:38 +02:00
parent b75bea7402
commit ac9a011da4
2 changed files with 38 additions and 4 deletions

View File

@ -389,10 +389,14 @@ export class InputsController {
} }
} }
keyboardKeyDown(event): void { checkIfKeyboardIsInit(): void {
const keyDown = event.keyCode;
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID) if (!this.keyboardConfigs[this.chosenKeyboard]?.padID)
this.setupKeyboard(); this.setupKeyboard();
}
keyboardKeyDown(event): void {
const keyDown = event.keyCode;
this.checkIfKeyboardIsInit();
if (this.keys.includes(keyDown)) return; if (this.keys.includes(keyDown)) return;
this.keys.push(keyDown); this.keys.push(keyDown);
const key = getKeyFromMapping(this.keyboardConfigs[this.chosenKeyboard], keyDown); const key = getKeyFromMapping(this.keyboardConfigs[this.chosenKeyboard], keyDown);
@ -410,8 +414,7 @@ export class InputsController {
keyboardKeyUp(event): void { keyboardKeyUp(event): void {
const keyDown = event.keyCode; const keyDown = event.keyCode;
this.keys = this.keys.filter(k => k !== keyDown); this.keys = this.keys.filter(k => k !== keyDown);
if (!this.keyboardConfigs[this.chosenKeyboard]?.padID) this.checkIfKeyboardIsInit()
this.setupKeyboard();
const key = getKeyFromMapping(this.keyboardConfigs[this.chosenKeyboard], keyDown); const key = getKeyFromMapping(this.keyboardConfigs[this.chosenKeyboard], keyDown);
const buttonUp = this.keyboardConfigs[this.chosenKeyboard].custom[key]; const buttonUp = this.keyboardConfigs[this.chosenKeyboard].custom[key];
if (buttonUp !== undefined) { if (buttonUp !== undefined) {

View File

@ -6,6 +6,7 @@ import {reverseValueToKeySetting, truncateString} from "#app/utils";
import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler"; import AbstractSettingsUiUiHandler from "#app/ui/settings/abstract-settings-ui-handler";
import {InterfaceConfig} from "#app/inputs-controller"; import {InterfaceConfig} from "#app/inputs-controller";
import {deleteBind} from "#app/configs/gamepad-utils"; import {deleteBind} from "#app/configs/gamepad-utils";
import {addTextObject, TextStyle} from "#app/ui/text";
export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandler { export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandler {
@ -24,6 +25,22 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
deleteEvent.on('up', this.onDeleteDown, this); deleteEvent.on('up', this.onDeleteDown, this);
} }
setup() {
super.setup();
// If no gamepads are detected, set up a default UI prompt in the settings container.
this.layout['noKeyboard'] = new Map();
const optionsContainer = this.scene.add.container(0, 0);
optionsContainer.setVisible(false); // Initially hide the container as no gamepads are connected.
const label = addTextObject(this.scene, 8, 28, 'Please press a key on your keyboard', TextStyle.SETTINGS_LABEL);
label.setOrigin(0, 0);
optionsContainer.add(label);
this.settingsContainer.add(optionsContainer);
// Map the 'noKeyboard' layout options for easy access.
this.layout['noKeyboard'].optionsContainer = optionsContainer;
this.layout['noKeyboard'].label = label;
}
onDeleteDown(): void { onDeleteDown(): void {
const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position. const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position.
const selection = this.settingLabels[cursor].text; const selection = this.settingLabels[cursor].text;
@ -45,6 +62,20 @@ export default class SettingsKeyboardUiHandler extends AbstractSettingsUiUiHandl
return settings; return settings;
} }
setLayout(activeConfig: InterfaceConfig): boolean {
// Check if there is no active configuration (e.g., no gamepad connected).
if (!activeConfig) {
// Retrieve the layout for when no gamepads are connected.
const layout = this.layout['noKeyboard'];
// Make the options container visible to show message.
layout.optionsContainer.setVisible(true);
// Return false indicating the layout application was not successful due to lack of gamepad.
return false;
}
return super.setLayout(activeConfig);
}
navigateMenuLeft(): boolean { navigateMenuLeft(): boolean {
this.scene.ui.setMode(Mode.SETTINGS_GAMEPAD) this.scene.ui.setMode(Mode.SETTINGS_GAMEPAD)
return true; return true;