From 2f5f161e4f529c482dfac452f6d24bb95d386f6a Mon Sep 17 00:00:00 2001 From: frutescens Date: Mon, 11 Nov 2024 13:50:01 -0800 Subject: [PATCH 1/4] Added more intelligent cursor memory for target selection in Doubles --- src/ui/target-select-ui-handler.ts | 36 +++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/ui/target-select-ui-handler.ts b/src/ui/target-select-ui-handler.ts index ecc15e5985e..a4eb6c6ddd4 100644 --- a/src/ui/target-select-ui-handler.ts +++ b/src/ui/target-select-ui-handler.ts @@ -13,9 +13,11 @@ import { SubstituteTag } from "#app/data/battler-tags"; export type TargetSelectCallback = (targets: BattlerIndex[]) => void; export default class TargetSelectUiHandler extends UiHandler { - private fieldIndex: integer; + private fieldIndex: number; private move: Moves; private targetSelectCallback: TargetSelectCallback; + private cursor1: number; + private cursor2: number; private isMultipleTargets: boolean = false; private targets: BattlerIndex[]; @@ -42,8 +44,9 @@ export default class TargetSelectUiHandler extends UiHandler { this.fieldIndex = args[0] as integer; this.move = args[1] as Moves; this.targetSelectCallback = args[2] as TargetSelectCallback; + const user = this.scene.getPlayerField()[this.fieldIndex]; - const moveTargets = getMoveTargets(this.scene.getPlayerField()[this.fieldIndex], this.move); + const moveTargets = getMoveTargets(user, this.move); this.targets = moveTargets.targets; this.isMultipleTargets = moveTargets.multiple ?? false; @@ -53,11 +56,25 @@ export default class TargetSelectUiHandler extends UiHandler { this.enemyModifiers = this.scene.getModifierBar(true); - this.setCursor(this.targets.includes(this.cursor) ? this.cursor : this.targets[0]); - + if (this.fieldIndex === BattlerIndex.PLAYER) { + this.resetCursor(this.cursor1, user); + } else if (this.fieldIndex === BattlerIndex.PLAYER_2) { + this.resetCursor(this.cursor2, user); + } return true; } + resetCursor(cursorN: number, user: Pokemon): void { + if (!Utils.isNullOrUndefined(cursorN)) { + if ([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ].includes(cursorN) || user.battleSummonData.waveTurnCount === 1) { + this.cursor = cursorN = -1; + } else if (user.battleSummonData.waveTurnCount > 1) { + this.cursor = cursorN; + } + } + this.setCursor(this.targets.includes(cursorN) ? cursorN : this.targets[0]); + } + processInput(button: Button): boolean { const ui = this.getUi(); @@ -67,6 +84,15 @@ export default class TargetSelectUiHandler extends UiHandler { const targetIndexes: BattlerIndex[] = this.isMultipleTargets ? this.targets : [ this.cursor ]; this.targetSelectCallback(button === Button.ACTION ? targetIndexes : []); success = true; + if (this.fieldIndex === BattlerIndex.PLAYER) { + if (Utils.isNullOrUndefined(this.cursor1) || this.cursor1 !== this.cursor) { + this.cursor1 = this.cursor; + } + } else if (this.fieldIndex === BattlerIndex.PLAYER_2) { + if (Utils.isNullOrUndefined(this.cursor1) || this.cursor2 !== this.cursor) { + this.cursor2 = this.cursor; + } + } } else if (this.isMultipleTargets) { success = false; } else { @@ -152,7 +178,6 @@ export default class TargetSelectUiHandler extends UiHandler { yoyo: true })); }); - return ret; } @@ -184,7 +209,6 @@ export default class TargetSelectUiHandler extends UiHandler { } clear() { - this.cursor = -1; super.clear(); this.eraseCursor(); } From 9670380c5c371235fb677e6714ab60bfbd5866d5 Mon Sep 17 00:00:00 2001 From: frutescens Date: Mon, 11 Nov 2024 14:05:42 -0800 Subject: [PATCH 2/4] Added documentation --- src/ui/target-select-ui-handler.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ui/target-select-ui-handler.ts b/src/ui/target-select-ui-handler.ts index a4eb6c6ddd4..38cb4a076aa 100644 --- a/src/ui/target-select-ui-handler.ts +++ b/src/ui/target-select-ui-handler.ts @@ -16,8 +16,8 @@ export default class TargetSelectUiHandler extends UiHandler { private fieldIndex: number; private move: Moves; private targetSelectCallback: TargetSelectCallback; - private cursor1: number; - private cursor2: number; + private cursor0: number; // associated with BattlerIndex.PLAYER + private cursor1: number; // associated with BattlerIndex.PLAYER_2 private isMultipleTargets: boolean = false; private targets: BattlerIndex[]; @@ -57,13 +57,18 @@ export default class TargetSelectUiHandler extends UiHandler { this.enemyModifiers = this.scene.getModifierBar(true); if (this.fieldIndex === BattlerIndex.PLAYER) { - this.resetCursor(this.cursor1, user); + this.resetCursor(this.cursor0, user); } else if (this.fieldIndex === BattlerIndex.PLAYER_2) { - this.resetCursor(this.cursor2, user); + this.resetCursor(this.cursor1, user); } return true; } + /** + * Determines what value to assign the main cursor on previous history or the user's status + * @param cursorN the cursor associated with the user's field index + * @param user the Pokemon using the move + */ resetCursor(cursorN: number, user: Pokemon): void { if (!Utils.isNullOrUndefined(cursorN)) { if ([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ].includes(cursorN) || user.battleSummonData.waveTurnCount === 1) { @@ -85,12 +90,12 @@ export default class TargetSelectUiHandler extends UiHandler { this.targetSelectCallback(button === Button.ACTION ? targetIndexes : []); success = true; if (this.fieldIndex === BattlerIndex.PLAYER) { - if (Utils.isNullOrUndefined(this.cursor1) || this.cursor1 !== this.cursor) { - this.cursor1 = this.cursor; + if (Utils.isNullOrUndefined(this.cursor0) || this.cursor0 !== this.cursor) { + this.cursor0 = this.cursor; } } else if (this.fieldIndex === BattlerIndex.PLAYER_2) { - if (Utils.isNullOrUndefined(this.cursor1) || this.cursor2 !== this.cursor) { - this.cursor2 = this.cursor; + if (Utils.isNullOrUndefined(this.cursor0) || this.cursor1 !== this.cursor) { + this.cursor1 = this.cursor; } } } else if (this.isMultipleTargets) { From c35e63595beec4e3d6c94316662247acdbf162d5 Mon Sep 17 00:00:00 2001 From: frutescens Date: Mon, 11 Nov 2024 16:36:24 -0800 Subject: [PATCH 3/4] Fixed variable name. --- src/ui/target-select-ui-handler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ui/target-select-ui-handler.ts b/src/ui/target-select-ui-handler.ts index 38cb4a076aa..be3c763dcf7 100644 --- a/src/ui/target-select-ui-handler.ts +++ b/src/ui/target-select-ui-handler.ts @@ -94,7 +94,7 @@ export default class TargetSelectUiHandler extends UiHandler { this.cursor0 = this.cursor; } } else if (this.fieldIndex === BattlerIndex.PLAYER_2) { - if (Utils.isNullOrUndefined(this.cursor0) || this.cursor1 !== this.cursor) { + if (Utils.isNullOrUndefined(this.cursor1) || this.cursor1 !== this.cursor) { this.cursor1 = this.cursor; } } From eaf943e14c5d6f7b09c0c547a9395b8731d246d3 Mon Sep 17 00:00:00 2001 From: Mumble <171087428+frutescens@users.noreply.github.com> Date: Thu, 14 Nov 2024 13:57:20 -0800 Subject: [PATCH 4/4] Apply suggestions from code review Co-authored-by: Moka <54149968+MokaStitcher@users.noreply.github.com> --- src/ui/target-select-ui-handler.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/ui/target-select-ui-handler.ts b/src/ui/target-select-ui-handler.ts index be3c763dcf7..249ae7b8b01 100644 --- a/src/ui/target-select-ui-handler.ts +++ b/src/ui/target-select-ui-handler.ts @@ -65,16 +65,15 @@ export default class TargetSelectUiHandler extends UiHandler { } /** - * Determines what value to assign the main cursor on previous history or the user's status + * Determines what value to assign the main cursor based on the previous turn's target or the user's status * @param cursorN the cursor associated with the user's field index * @param user the Pokemon using the move */ resetCursor(cursorN: number, user: Pokemon): void { if (!Utils.isNullOrUndefined(cursorN)) { if ([ BattlerIndex.PLAYER, BattlerIndex.PLAYER_2 ].includes(cursorN) || user.battleSummonData.waveTurnCount === 1) { - this.cursor = cursorN = -1; - } else if (user.battleSummonData.waveTurnCount > 1) { - this.cursor = cursorN; + // Reset cursor on the first turn of a fight or if an ally was targeted last turn + cursorN = -1; } } this.setCursor(this.targets.includes(cursorN) ? cursorN : this.targets[0]);