diff --git a/src/ui/party-ui-handler.ts b/src/ui/party-ui-handler.ts index 21e5f9077f4..6a9b565989d 100644 --- a/src/ui/party-ui-handler.ts +++ b/src/ui/party-ui-handler.ts @@ -574,9 +574,7 @@ export default class PartyUiHandler extends MessageUiHandler { form: pokemon.formIndex, female: pokemon.gender === Gender.FEMALE, }; - ui.setOverlayMode(Mode.POKEDEX_PAGE, pokemon.species, pokemon.formIndex, attributes).then(() => - this.clearOptions(), - ); + ui.setOverlayMode(Mode.POKEDEX_PAGE, pokemon.species, attributes).then(() => this.clearOptions()); return true; } else if (option === PartyOption.UNPAUSE_EVOLUTION) { this.clearOptions(); diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index fc6e96d427f..86460a24fdc 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -239,6 +239,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler { private starterAttributes: StarterAttributes; private savedStarterAttributes: StarterAttributes; + private previousSpecies: PokemonSpecies[]; + private previousStarterAttributes: StarterAttributes[]; + protected blockInput = false; protected blockInputOverlay = false; @@ -653,6 +656,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler { // Filter bar sits above everything, except the message box this.starterSelectContainer.bringToTop(this.starterSelectMessageBoxContainer); + + this.previousSpecies = []; + this.previousStarterAttributes = []; } show(args: any[]): boolean { @@ -665,14 +671,14 @@ export default class PokedexPageUiHandler extends MessageUiHandler { return false; } this.species = args[0]; - this.formIndex = args[1] ?? 0; - this.savedStarterAttributes = args[2] ?? { + this.savedStarterAttributes = args[1] ?? { shiny: false, female: true, variant: 0, form: 0, }; - this.filteredIndices = args[3] ?? null; + this.formIndex = this.savedStarterAttributes.form ?? 0; + this.filteredIndices = args[2] ?? null; this.starterSetup(); this.moveInfoOverlay.clear(); // clear this when removing a menu; the cancel button doesn't seem to trigger this automatically on controllers @@ -1088,8 +1094,19 @@ export default class PokedexPageUiHandler extends MessageUiHandler { if (this.statsMode) { this.toggleStatsMode(false); success = true; + } else if (this.previousSpecies.length > 0) { + this.blockInput = true; + ui.setModeWithoutClear(Mode.OPTION_SELECT).then(() => { + const species = this.previousSpecies.pop(); + const starterAttributes = this.previousStarterAttributes.pop(); + this.moveInfoOverlay.clear(); + this.clearText(); + ui.setModeForceTransition(Mode.POKEDEX_PAGE, species, starterAttributes); + success = true; + }); + this.blockInput = false; } else { - this.getUi().revertMode(); + ui.revertMode(); success = true; } } else { @@ -1504,6 +1521,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { ? (preSpecies ?? this.species).getFormNameToDisplay(preFormIndex, true) : (preSpecies ?? this.species).getExpandedSpeciesName(), handler: () => { + this.previousSpecies.push(this.species); + this.previousStarterAttributes.push({ ...this.savedStarterAttributes }); const newSpecies = allSpecies.find( species => species.speciesId === pokemonPrevolutions[pre.speciesId], ); @@ -1519,7 +1538,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.savedStarterAttributes.form = newFormIndex; this.moveInfoOverlay.clear(); this.clearText(); - ui.setMode(Mode.POKEDEX_PAGE, newSpecies, newFormIndex, this.savedStarterAttributes); + ui.setMode(Mode.POKEDEX_PAGE, newSpecies, this.savedStarterAttributes); return true; }, onHover: () => this.showText(conditionText), @@ -1555,11 +1574,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { : (evoSpecies ?? this.species).getExpandedSpeciesName(), style: isCaughtEvo && isFormCaughtEvo ? TextStyle.WINDOW : TextStyle.SHADOW_TEXT, handler: () => { + this.previousSpecies.push(this.species); + this.previousStarterAttributes.push({ ...this.savedStarterAttributes }); this.starterAttributes.form = newFormIndex; this.savedStarterAttributes.form = newFormIndex; this.moveInfoOverlay.clear(); this.clearText(); - ui.setMode(Mode.POKEDEX_PAGE, evoSpecies, newFormIndex, this.savedStarterAttributes); + ui.setMode(Mode.POKEDEX_PAGE, evoSpecies, this.savedStarterAttributes); return true; }, onHover: () => this.showText(conditionText), @@ -1595,6 +1616,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { label: label, style: isFormCaught ? TextStyle.WINDOW : TextStyle.SHADOW_TEXT, handler: () => { + this.previousSpecies.push(this.species); + this.previousStarterAttributes.push({ ...this.savedStarterAttributes }); const newSpecies = this.species; const newFormIndex = this.species.forms.find(f => f.formKey === bf.formKey)?.formIndex; this.starterAttributes.form = newFormIndex; @@ -1604,7 +1627,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler { ui.setMode( Mode.POKEDEX_PAGE, newSpecies, - newFormIndex, this.savedStarterAttributes, this.filteredIndices, ); @@ -1955,6 +1977,11 @@ export default class PokedexPageUiHandler extends MessageUiHandler { case Button.LEFT: this.blockInput = true; ui.setModeWithoutClear(Mode.OPTION_SELECT).then(() => { + // Always go back to first selection after scrolling around + if (this.previousSpecies.length === 0) { + this.previousSpecies.push(this.species); + this.previousStarterAttributes.push({ ...this.savedStarterAttributes }); + } let newSpecies: PokemonSpecies; if (this.filteredIndices) { const index = this.filteredIndices.findIndex(id => id === this.species.speciesId); @@ -1976,7 +2003,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler { ui.setModeForceTransition( Mode.POKEDEX_PAGE, newSpecies, - newFormIndex, this.savedStarterAttributes, this.filteredIndices, ); @@ -1985,6 +2011,11 @@ export default class PokedexPageUiHandler extends MessageUiHandler { break; case Button.RIGHT: ui.setModeWithoutClear(Mode.OPTION_SELECT).then(() => { + // Always go back to first selection after scrolling around + if (this.previousSpecies.length === 0) { + this.previousSpecies.push(this.species); + this.previousStarterAttributes.push({ ...this.savedStarterAttributes }); + } let newSpecies: PokemonSpecies; if (this.filteredIndices) { const index = this.filteredIndices.findIndex(id => id === this.species.speciesId); @@ -2006,7 +2037,6 @@ export default class PokedexPageUiHandler extends MessageUiHandler { ui.setModeForceTransition( Mode.POKEDEX_PAGE, newSpecies, - newFormIndex, this.savedStarterAttributes, this.filteredIndices, ); diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index f3625f64476..1f79d7006b0 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -1125,7 +1125,7 @@ export default class PokedexUiHandler extends MessageUiHandler { } else if (this.showingTray) { if (button === Button.ACTION) { const formIndex = this.trayForms[this.trayCursor].formIndex; - ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, formIndex, { form: formIndex }, this.filteredIndices); + ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, { form: formIndex }, this.filteredIndices); success = true; } else { const numberOfForms = this.trayContainers.length; @@ -1174,7 +1174,7 @@ export default class PokedexUiHandler extends MessageUiHandler { } } else { if (button === Button.ACTION) { - ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, 0, null, this.filteredIndices); + ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, null, this.filteredIndices); success = true; } else { switch (button) { diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index ab8ea0adf7c..8265ad827bc 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -2324,7 +2324,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { form: starterAttributes.form, female: starterAttributes.female, }; - ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, starterAttributes.form, attributes); + ui.setOverlayMode(Mode.POKEDEX_PAGE, this.lastSpecies, attributes); }); return true; },