input detection for keyboards is working

pull/685/head
Greenlamp 2024-05-12 23:11:20 +02:00
parent c6d3f93b3f
commit 164838c669
4 changed files with 85 additions and 84 deletions

View File

@ -5,81 +5,79 @@ const cfg_keyboard_azerty = {
padID: 'keyboard',
padType: 'azerty',
gamepadMapping: {
NEED TO ADD KEYCODE FROM EVENT HERE
KEY_A: 0,
KEY_B: 0,
KEY_C: 0,
KEY_D: 0,
KEY_E: 0,
KEY_F: 0,
KEY_G: 0,
KEY_H: 0,
KEY_I: 0,
KEY_J: 0,
KEY_K: 0,
KEY_L: 0,
KEY_M: 0,
KEY_N: 0,
KEY_O: 0,
KEY_P: 0,
KEY_Q: 0,
KEY_R: 0,
KEY_S: 0,
KEY_T: 0,
KEY_U: 0,
KEY_V: 0,
KEY_W: 0,
KEY_X: 0,
KEY_Y: 0,
KEY_Z: 0,
KEY_0: 0,
KEY_1: 0,
KEY_2: 0,
KEY_3: 0,
KEY_4: 0,
KEY_5: 0,
KEY_6: 0,
KEY_7: 0,
KEY_8: 0,
KEY_9: 0,
KEY_CTRL: 0,
KEY_DEL: 0,
KEY_END: 0,
KEY_ENTER: 0,
KEY_ESC: 0,
KEY_F1: 0,
KEY_F2: 0,
KEY_F3: 0,
KEY_F4: 0,
KEY_F5: 0,
KEY_F6: 0,
KEY_F7: 0,
KEY_F8: 0,
KEY_F9: 0,
KEY_F10: 0,
KEY_F11: 0,
KEY_F12: 0,
KEY_HOME: 0,
KEY_INSERT: 0,
KEY_PAGE_DOWN: 0,
KEY_PAGE_UP: 0,
KEY_PLUS: 0,
KEY_MINUS: 0,
KEY_QUOTATION: 0,
KEY_SHIFT: 0,
KEY_LEFT_SHIFT: 0,
KEY_SPACE: 0,
KEY_TAB: 0,
KEY_TILDE: 0,
KEY_ARROW_UP: 0,
KEY_ARROW_DOWN: 0,
KEY_ARROW_LEFT: 0,
KEY_ARROW_RIGHT: 0,
KEY_LEFT_BRACKET: 0,
KEY_RIGHT_BRACKET: 0,
KEY_SEMICOLON: 0,
KEY_ASTERISK: 0,
T_Backspace_Alt_Key_Dark: 0
KEY_A: Phaser.Input.Keyboard.KeyCodes.A,
KEY_B: Phaser.Input.Keyboard.KeyCodes.B,
KEY_C: Phaser.Input.Keyboard.KeyCodes.C,
KEY_D: Phaser.Input.Keyboard.KeyCodes.D,
KEY_E: Phaser.Input.Keyboard.KeyCodes.E,
KEY_F: Phaser.Input.Keyboard.KeyCodes.F,
KEY_G: Phaser.Input.Keyboard.KeyCodes.G,
KEY_H: Phaser.Input.Keyboard.KeyCodes.H,
KEY_I: Phaser.Input.Keyboard.KeyCodes.I,
KEY_J: Phaser.Input.Keyboard.KeyCodes.J,
KEY_K: Phaser.Input.Keyboard.KeyCodes.K,
KEY_L: Phaser.Input.Keyboard.KeyCodes.L,
KEY_M: Phaser.Input.Keyboard.KeyCodes.M,
KEY_N: Phaser.Input.Keyboard.KeyCodes.N,
KEY_O: Phaser.Input.Keyboard.KeyCodes.O,
KEY_P: Phaser.Input.Keyboard.KeyCodes.P,
KEY_Q: Phaser.Input.Keyboard.KeyCodes.Q,
KEY_R: Phaser.Input.Keyboard.KeyCodes.R,
KEY_S: Phaser.Input.Keyboard.KeyCodes.S,
KEY_T: Phaser.Input.Keyboard.KeyCodes.T,
KEY_U: Phaser.Input.Keyboard.KeyCodes.U,
KEY_V: Phaser.Input.Keyboard.KeyCodes.V,
KEY_W: Phaser.Input.Keyboard.KeyCodes.W,
KEY_X: Phaser.Input.Keyboard.KeyCodes.X,
KEY_Y: Phaser.Input.Keyboard.KeyCodes.Y,
KEY_Z: Phaser.Input.Keyboard.KeyCodes.Z,
KEY_0: Phaser.Input.Keyboard.KeyCodes.ZERO,
KEY_1: Phaser.Input.Keyboard.KeyCodes.ONE,
KEY_2: Phaser.Input.Keyboard.KeyCodes.TWO,
KEY_3: Phaser.Input.Keyboard.KeyCodes.THREE,
KEY_4: Phaser.Input.Keyboard.KeyCodes.FOUR,
KEY_5: Phaser.Input.Keyboard.KeyCodes.FIVE,
KEY_6: Phaser.Input.Keyboard.KeyCodes.SIX,
KEY_7: Phaser.Input.Keyboard.KeyCodes.SEVEN,
KEY_8: Phaser.Input.Keyboard.KeyCodes.EIGHT,
KEY_9: Phaser.Input.Keyboard.KeyCodes.NINE,
KEY_CTRL: Phaser.Input.Keyboard.KeyCodes.CTRL,
KEY_DEL: Phaser.Input.Keyboard.KeyCodes.DELETE,
KEY_END: Phaser.Input.Keyboard.KeyCodes.END,
KEY_ENTER: Phaser.Input.Keyboard.KeyCodes.ENTER,
KEY_ESC: Phaser.Input.Keyboard.KeyCodes.ESC,
KEY_F1: Phaser.Input.Keyboard.KeyCodes.F1,
KEY_F2: Phaser.Input.Keyboard.KeyCodes.F2,
KEY_F3: Phaser.Input.Keyboard.KeyCodes.F3,
KEY_F4: Phaser.Input.Keyboard.KeyCodes.F4,
KEY_F5: Phaser.Input.Keyboard.KeyCodes.F5,
KEY_F6: Phaser.Input.Keyboard.KeyCodes.F6,
KEY_F7: Phaser.Input.Keyboard.KeyCodes.F7,
KEY_F8: Phaser.Input.Keyboard.KeyCodes.F8,
KEY_F9: Phaser.Input.Keyboard.KeyCodes.F9,
KEY_F10: Phaser.Input.Keyboard.KeyCodes.F10,
KEY_F11: Phaser.Input.Keyboard.KeyCodes.F11,
KEY_F12: Phaser.Input.Keyboard.KeyCodes.F12,
KEY_HOME: Phaser.Input.Keyboard.KeyCodes.HOME,
KEY_INSERT: Phaser.Input.Keyboard.KeyCodes.INSERT,
KEY_PAGE_DOWN: Phaser.Input.Keyboard.KeyCodes.PAGE_DOWN,
KEY_PAGE_UP: Phaser.Input.Keyboard.KeyCodes.PAGE_UP,
KEY_PLUS: Phaser.Input.Keyboard.KeyCodes.NUMPAD_ADD, // Assuming numpad plus
KEY_MINUS: Phaser.Input.Keyboard.KeyCodes.NUMPAD_SUBTRACT, // Assuming numpad minus
KEY_QUOTATION: Phaser.Input.Keyboard.KeyCodes.QUOTES,
KEY_SHIFT: Phaser.Input.Keyboard.KeyCodes.SHIFT,
KEY_SPACE: Phaser.Input.Keyboard.KeyCodes.SPACE,
KEY_TAB: Phaser.Input.Keyboard.KeyCodes.TAB,
KEY_TILDE: Phaser.Input.Keyboard.KeyCodes.BACKTICK,
KEY_ARROW_UP: Phaser.Input.Keyboard.KeyCodes.UP,
KEY_ARROW_DOWN: Phaser.Input.Keyboard.KeyCodes.DOWN,
KEY_ARROW_LEFT: Phaser.Input.Keyboard.KeyCodes.LEFT,
KEY_ARROW_RIGHT: Phaser.Input.Keyboard.KeyCodes.RIGHT,
KEY_LEFT_BRACKET: Phaser.Input.Keyboard.KeyCodes.OPEN_BRACKET,
KEY_RIGHT_BRACKET: Phaser.Input.Keyboard.KeyCodes.CLOSED_BRACKET,
KEY_SEMICOLON: Phaser.Input.Keyboard.KeyCodes.SEMICOLON,
KEY_BACKSPACE: Phaser.Input.Keyboard.KeyCodes.BACKSPACE,
KEY_ALT: Phaser.Input.Keyboard.KeyCodes.ALT
},
icons: {
KEY_A: "T_A_Key_Dark.png",
@ -143,13 +141,12 @@ const cfg_keyboard_azerty = {
KEY_ENTER: "T_Enter_Alt_Key_Dark.png",
KEY_ESC: "T_Esc_Key_Dark.png",
KEY_HOME: "T_Home_Key_Dark.png",
KEY_INSERT: "T_Insert_Key_Dark.png",
KEY_INSERT: "T_Ins_Key_Dark.png",
KEY_PLUS: "T_Plus_Tall_Key_Dark.png",
KEY_MINUS: "T_Minus_Key_Dark.png",
KEY_QUOTATION: "T_Quotation_Key_Dark.png",
KEY_SHIFT: "T_Shift_Key_Dark.png",
KEY_LEFT_SHIFT: "T_Shift_Super_Wide_Key_Dark.png",
KEY_SPACE: "T_Space_Key_Dark.png",
KEY_TAB: "T_Tab_Key_Dark.png",
@ -164,9 +161,9 @@ const cfg_keyboard_azerty = {
KEY_RIGHT_BRACKET: "T_Brackets_R_Key_Dark.png",
KEY_SEMICOLON: "T_Semicolon_Key_Dark.png",
KEY_ASTERISK: "T_Asterisk_Key_Dark.png",
KEY_BACKSPACE: "T_Backspace_Alt_Key_Dark.png"
KEY_BACKSPACE: "T_Backspace_Alt_Key_Dark.png",
KEY_ALT: "T_Alt_Key_Dark.png"
},
setting: {
KEY_ARROW_UP: SettingKeyboard.Button_Up,

View File

@ -14,6 +14,7 @@ import {
} from "./configs/gamepad-utils";
import SettingsKeyboardUiHandler from "#app/ui/settings/settings-keyboard-ui-handler";
import cfg_keyboard_azerty from "#app/configs/cfg_keyboard_azerty";
import {SettingKeyboard} from "#app/system/settings-keyboard";
export interface GamepadMapping {
[key: string]: number;
@ -725,7 +726,7 @@ export class InputsController {
}
getPressedKeyLabel(key): string {
return getCurrenlyAssignedIconFromKeyboardKey(this.configs[this.chosenKeyboard], key);
return getCurrenlyAssignedIconFromKeyboardKey(this.keyboardConfigs[this.chosenKeyboard], key);
}
/**
@ -738,8 +739,8 @@ export class InputsController {
return getCurrentlyAssignedIconToSettingName(this.configs[this.chosenGamepad], target);
}
getKeyboardCurrentlyAssignedIconToDisplay(target: SettingGamepad): string {
return getCurrentlyAssignedIconToSettingName(this.configs[this.chosenKeyboard], target);
getKeyboardCurrentlyAssignedIconToDisplay(target: SettingKeyboard): string {
return getCurrentlyAssignedIconToSettingName(this.keyboardConfigs[this.chosenKeyboard], target);
}
/**

View File

@ -113,6 +113,7 @@ export default class KeyboardBindingUiHandler extends UiHandler {
if (!this.listening || this.buttonPressed !== null) return;
this.buttonPressed = key;
const buttonIcon = this.scene.inputController.getPressedKeyLabel(key);
if (!buttonIcon) return;
const assignedButtonIcon = this.scene.inputController.getKeyboardCurrentlyAssignedIconToDisplay(this.target);
this.newButtonIcon.setFrame(buttonIcon);
this.targetButtonIcon.setFrame(assignedButtonIcon);

View File

@ -332,6 +332,7 @@ export default class SettingsGamepadUiHandler extends UiHandler {
const cursor = this.cursor + this.scrollCursor; // Calculate the absolute cursor position.
switch (button) {
case Button.UP: // Move up in the menu.
if (!this.optionValueLabels) return false;
if (cursor) { // If not at the top, move the cursor up.
if (this.cursor)
success = this.setCursor(this.cursor - 1);
@ -347,6 +348,7 @@ export default class SettingsGamepadUiHandler extends UiHandler {
}
break;
case Button.DOWN: // Move down in the menu.
if (!this.optionValueLabels) return false;
if (cursor < this.optionValueLabels.length - 1) {
if (this.cursor < rowsToDisplay - 1)
success = this.setCursor(this.cursor + 1);
@ -362,12 +364,12 @@ export default class SettingsGamepadUiHandler extends UiHandler {
}
break;
case Button.LEFT: // Move selection left within the current option set.
if (!this.optionCursors) return;
if (!this.optionCursors || !this.optionValueLabels) return;
if (this.optionCursors[cursor])
success = this.setOptionCursor(cursor, this.optionCursors[cursor] - 1, true);
break;
case Button.RIGHT: // Move selection right within the current option set.
if (!this.optionCursors) return;
if (!this.optionCursors || !this.optionValueLabels) return;
if (this.optionCursors[cursor] < this.optionValueLabels[cursor].length - 1)
success = this.setOptionCursor(cursor, this.optionCursors[cursor] + 1, true);
break;