From ae85f1b416983ea6e55b2eaced7f755109a4a0ff Mon Sep 17 00:00:00 2001 From: Greenlamp Date: Sun, 12 May 2024 00:20:47 +0200 Subject: [PATCH] fix a floating cursor not destroyed --- src/ui/settings-gamepad-ui-handler.ts | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/ui/settings-gamepad-ui-handler.ts b/src/ui/settings-gamepad-ui-handler.ts index 8f0f105e5..278d5732b 100644 --- a/src/ui/settings-gamepad-ui-handler.ts +++ b/src/ui/settings-gamepad-ui-handler.ts @@ -166,6 +166,9 @@ export default class SettingsGamepadUiHandler extends UiHandler { Object.keys(this.layout).forEach((key) => this.layout[key].optionsContainer.setVisible(false)); const activeConfig = this.scene.inputController.getActiveConfig(); const configType = activeConfig.padType; + this.cursorObj?.destroy(); + this.cursorObj = null; + this.scrollCursor = null; const layout = this.layout[configType]; this.keys = layout.keys; this.optionsContainer = layout.optionsContainer; @@ -188,8 +191,8 @@ export default class SettingsGamepadUiHandler extends UiHandler { if (!this.inputsIcons[key]) debugger; this.inputsIcons[key].setFrame(icon); } - this.setCursor(0, true); - this.setScrollCursor(0, true); + this.setCursor(0); + this.setScrollCursor(0); } show(args: any[]): boolean { @@ -197,7 +200,6 @@ export default class SettingsGamepadUiHandler extends UiHandler { this.updateBindings(); this.settingsContainer.setVisible(true); - this.setCursor(0); this.setScrollCursor(0); this.getUi().moveTo(this.settingsContainer, this.getUi().length - 1); @@ -258,14 +260,9 @@ export default class SettingsGamepadUiHandler extends UiHandler { return success; } - setCursor(cursor: integer, override?: boolean): boolean { + setCursor(cursor: integer): boolean { const ret = super.setCursor(cursor); - if (override) { - Object.keys(this.layout).forEach(k => this.layout[k].optionsContainer.remove(this.cursorObj)); - this.cursorObj = null; - } - if (!this.cursorObj) { this.cursorObj = this.scene.add.nineslice(0, 0, 'summary_moves_cursor', null, (this.scene.game.canvas.width / 6) - 10, 16, 1, 1, 1, 1); this.cursorObj.setOrigin(0, 0); @@ -313,8 +310,8 @@ export default class SettingsGamepadUiHandler extends UiHandler { return true; } - setScrollCursor(scrollCursor: integer, override?: boolean): boolean { - if (scrollCursor === this.scrollCursor && !override) + setScrollCursor(scrollCursor: integer): boolean { + if (scrollCursor === this.scrollCursor) return false; this.scrollCursor = scrollCursor;