mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-16 13:22:18 +02:00
added a timeout to the binding windows + fix update layout on new gamepad
This commit is contained in:
parent
19349ef0bb
commit
d08b028498
@ -331,6 +331,8 @@ export class InputsController {
|
|||||||
this.scene.gameData?.saveMappingConfigs(gamepadID, this.configs[gamepadID]);
|
this.scene.gameData?.saveMappingConfigs(gamepadID, this.configs[gamepadID]);
|
||||||
}
|
}
|
||||||
this.lastSource = 'gamepad';
|
this.lastSource = 'gamepad';
|
||||||
|
const handler = this.scene.ui?.handlers[Mode.SETTINGS_GAMEPAD] as SettingsGamepadUiHandler;
|
||||||
|
handler && handler.updateChosenGamepadDisplay()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,7 +129,7 @@ export function setSettingGamepad(scene: BattleScene, setting: SettingGamepad, v
|
|||||||
};
|
};
|
||||||
scene.ui.setOverlayMode(Mode.OPTION_SELECT, {
|
scene.ui.setOverlayMode(Mode.OPTION_SELECT, {
|
||||||
options: [...gp.map((g) => ({
|
options: [...gp.map((g) => ({
|
||||||
label: truncateString(g, 22), // Truncate the gamepad name for display
|
label: truncateString(g, 30), // Truncate the gamepad name for display
|
||||||
handler: () => changeGamepadHandler(g)
|
handler: () => changeGamepadHandler(g)
|
||||||
})), {
|
})), {
|
||||||
label: 'Cancel',
|
label: 'Cancel',
|
||||||
|
@ -21,6 +21,7 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
|
|
||||||
// Text elements for displaying instructions and actions.
|
// Text elements for displaying instructions and actions.
|
||||||
protected unlockText: Phaser.GameObjects.Text;
|
protected unlockText: Phaser.GameObjects.Text;
|
||||||
|
protected timerText: Phaser.GameObjects.Text;
|
||||||
protected swapText: Phaser.GameObjects.Text;
|
protected swapText: Phaser.GameObjects.Text;
|
||||||
protected actionLabel: Phaser.GameObjects.Text;
|
protected actionLabel: Phaser.GameObjects.Text;
|
||||||
protected cancelLabel: Phaser.GameObjects.Text;
|
protected cancelLabel: Phaser.GameObjects.Text;
|
||||||
@ -37,6 +38,8 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
protected swapAction: () => boolean;
|
protected swapAction: () => boolean;
|
||||||
|
|
||||||
protected confirmText: string;
|
protected confirmText: string;
|
||||||
|
protected timeLeftAutoClose: number = 5;
|
||||||
|
protected countdownTimer;
|
||||||
|
|
||||||
// The specific setting being modified.
|
// The specific setting being modified.
|
||||||
protected target;
|
protected target;
|
||||||
@ -81,6 +84,11 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
this.unlockText.setPositionRelative(this.titleBg, 36, 4);
|
this.unlockText.setPositionRelative(this.titleBg, 36, 4);
|
||||||
this.optionSelectContainer.add(this.unlockText);
|
this.optionSelectContainer.add(this.unlockText);
|
||||||
|
|
||||||
|
this.timerText = addTextObject(this.scene, 0, 0, '(5)', TextStyle.WINDOW);
|
||||||
|
this.timerText.setOrigin(0, 0);
|
||||||
|
this.timerText.setPositionRelative(this.unlockText, (this.unlockText.width/6) + 5, 0);
|
||||||
|
this.optionSelectContainer.add(this.timerText);
|
||||||
|
|
||||||
this.optionSelectBg = addWindow(this.scene, (this.scene.game.canvas.width / 6) - this.getWindowWidth(), -(this.scene.game.canvas.height / 6) + this.getWindowHeight() + 28, this.getWindowWidth(), this.getWindowHeight());
|
this.optionSelectBg = addWindow(this.scene, (this.scene.game.canvas.width / 6) - this.getWindowWidth(), -(this.scene.game.canvas.height / 6) + this.getWindowHeight() + 28, this.getWindowWidth(), this.getWindowHeight());
|
||||||
this.optionSelectBg.setOrigin(0.5);
|
this.optionSelectBg.setOrigin(0.5);
|
||||||
this.optionSelectContainer.add(this.optionSelectBg);
|
this.optionSelectContainer.add(this.optionSelectBg);
|
||||||
@ -91,6 +99,18 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
this.actionsContainer.add(this.cancelLabel);
|
this.actionsContainer.add(this.cancelLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
manageAutoCloseTimer(){
|
||||||
|
clearTimeout(this.countdownTimer);
|
||||||
|
this.countdownTimer = setTimeout(() => {
|
||||||
|
this.timeLeftAutoClose -= 1;
|
||||||
|
this.timerText.setText(`(${this.timeLeftAutoClose})`);
|
||||||
|
if (this.timeLeftAutoClose >= 0)
|
||||||
|
this.manageAutoCloseTimer();
|
||||||
|
else
|
||||||
|
this.cancelFn();
|
||||||
|
}, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the UI with the provided arguments.
|
* Show the UI with the provided arguments.
|
||||||
*
|
*
|
||||||
@ -100,6 +120,7 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
show(args: any[]): boolean {
|
show(args: any[]): boolean {
|
||||||
super.show(args);
|
super.show(args);
|
||||||
this.buttonPressed = null;
|
this.buttonPressed = null;
|
||||||
|
this.timeLeftAutoClose = 5;
|
||||||
this.cancelFn = args[0].cancelHandler;
|
this.cancelFn = args[0].cancelHandler;
|
||||||
this.target = args[0].target;
|
this.target = args[0].target;
|
||||||
|
|
||||||
@ -108,7 +129,10 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
this.getUi().bringToTop(this.actionsContainer);
|
this.getUi().bringToTop(this.actionsContainer);
|
||||||
|
|
||||||
this.optionSelectContainer.setVisible(true);
|
this.optionSelectContainer.setVisible(true);
|
||||||
setTimeout(() => this.listening = true, 100);
|
setTimeout(() => {
|
||||||
|
this.listening = true;
|
||||||
|
this.manageAutoCloseTimer();
|
||||||
|
}, 100);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,6 +218,9 @@ export default abstract class AbstractBindingUiHandler extends UiHandler {
|
|||||||
*/
|
*/
|
||||||
clear() {
|
clear() {
|
||||||
super.clear();
|
super.clear();
|
||||||
|
clearTimeout(this.countdownTimer);
|
||||||
|
this.timerText.setText('(5)');
|
||||||
|
this.timeLeftAutoClose = 5;
|
||||||
this.listening = false;
|
this.listening = false;
|
||||||
this.target = null;
|
this.target = null;
|
||||||
this.cancelFn = null;
|
this.cancelFn = null;
|
||||||
|
@ -373,8 +373,7 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
// Make the settings container visible to the user.
|
// Make the settings container visible to the user.
|
||||||
this.settingsContainer.setVisible(true);
|
this.settingsContainer.setVisible(true);
|
||||||
// Reset the scroll cursor to the top of the settings container.
|
// Reset the scroll cursor to the top of the settings container.
|
||||||
this.setCursor(0);
|
this.resetScroll();
|
||||||
this.setScrollCursor(0);
|
|
||||||
|
|
||||||
// Move the settings container to the end of the UI stack to ensure it is displayed on top.
|
// Move the settings container to the end of the UI stack to ensure it is displayed on top.
|
||||||
this.getUi().moveTo(this.settingsContainer, this.getUi().length - 1);
|
this.getUi().moveTo(this.settingsContainer, this.getUi().length - 1);
|
||||||
@ -510,6 +509,15 @@ export default abstract class AbstractSettingsUiUiHandler extends UiHandler {
|
|||||||
return success; // Return whether the input resulted in a successful action.
|
return success; // Return whether the input resulted in a successful action.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resetScroll() {
|
||||||
|
this.cursorObj?.destroy();
|
||||||
|
this.cursorObj = null;
|
||||||
|
this.cursor = null;
|
||||||
|
this.setCursor(0);
|
||||||
|
this.setScrollCursor(0);
|
||||||
|
this.updateSettingsScroll();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the cursor to the specified position.
|
* Set the cursor to the specified position.
|
||||||
*
|
*
|
||||||
|
@ -133,6 +133,7 @@ export default class SettingsGamepadUiHandler extends AbstractSettingsUiUiHandle
|
|||||||
updateChosenGamepadDisplay(): void {
|
updateChosenGamepadDisplay(): void {
|
||||||
// Update any bindings that might have changed since the last update.
|
// Update any bindings that might have changed since the last update.
|
||||||
this.updateBindings();
|
this.updateBindings();
|
||||||
|
this.resetScroll();
|
||||||
|
|
||||||
// Iterate over the keys in the settingDevice enumeration.
|
// Iterate over the keys in the settingDevice enumeration.
|
||||||
for (const [index, key] of Object.keys(this.settingDevice).entries()) {
|
for (const [index, key] of Object.keys(this.settingDevice).entries()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user