mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2025-07-05 07:52:17 +02:00
Breaking up processOptionMenuInput
This commit is contained in:
parent
1e342a5d58
commit
500f25abdb
@ -355,13 +355,153 @@ export default class PartyUiHandler extends MessageUiHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
processOptionMenuInput(button: Button) {
|
processSummaryOption(pokemon: Pokemon): boolean {
|
||||||
|
const ui = this.getUi();
|
||||||
|
ui.playSelect();
|
||||||
|
ui.setModeWithoutClear(UiMode.SUMMARY, pokemon).then(() => this.clearOptions());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
processPokedexOption(pokemon: Pokemon): boolean {
|
||||||
|
const ui = this.getUi();
|
||||||
|
ui.playSelect();
|
||||||
|
const attributes = {
|
||||||
|
shiny: pokemon.shiny,
|
||||||
|
variant: pokemon.variant,
|
||||||
|
form: pokemon.formIndex,
|
||||||
|
female: pokemon.gender === Gender.FEMALE,
|
||||||
|
};
|
||||||
|
ui.setOverlayMode(UiMode.POKEDEX_PAGE, pokemon.species, attributes).then(() => this.clearOptions());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
processUnpauseEvolutionOption(pokemon: Pokemon): boolean {
|
||||||
|
const ui = this.getUi();
|
||||||
|
this.clearOptions();
|
||||||
|
ui.playSelect();
|
||||||
|
pokemon.pauseEvolutions = !pokemon.pauseEvolutions;
|
||||||
|
this.showText(
|
||||||
|
i18next.t(pokemon.pauseEvolutions ? "partyUiHandler:pausedEvolutions" : "partyUiHandler:unpausedEvolutions", {
|
||||||
|
pokemonName: getPokemonNameWithAffix(pokemon, false),
|
||||||
|
}),
|
||||||
|
undefined,
|
||||||
|
() => this.showText("", 0),
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
processUnspliceOption(pokemon: PlayerPokemon): boolean {
|
||||||
|
const ui = this.getUi();
|
||||||
|
this.clearOptions();
|
||||||
|
ui.playSelect();
|
||||||
|
this.showText(
|
||||||
|
i18next.t("partyUiHandler:unspliceConfirmation", {
|
||||||
|
fusionName: pokemon.fusionSpecies?.name,
|
||||||
|
pokemonName: pokemon.getName(),
|
||||||
|
}),
|
||||||
|
null,
|
||||||
|
() => {
|
||||||
|
ui.setModeWithoutClear(
|
||||||
|
UiMode.CONFIRM,
|
||||||
|
() => {
|
||||||
|
const fusionName = pokemon.getName();
|
||||||
|
pokemon.unfuse().then(() => {
|
||||||
|
this.clearPartySlots();
|
||||||
|
this.populatePartySlots();
|
||||||
|
ui.setMode(UiMode.PARTY);
|
||||||
|
this.showText(
|
||||||
|
i18next.t("partyUiHandler:wasReverted", {
|
||||||
|
fusionName: fusionName,
|
||||||
|
pokemonName: pokemon.getName(false),
|
||||||
|
}),
|
||||||
|
undefined,
|
||||||
|
() => {
|
||||||
|
ui.setMode(UiMode.PARTY);
|
||||||
|
this.showText("", 0);
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
ui.setMode(UiMode.PARTY);
|
||||||
|
this.showText("", 0);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
processReleaseOption(pokemon: Pokemon): boolean {
|
||||||
|
const ui = this.getUi();
|
||||||
|
this.clearOptions();
|
||||||
|
ui.playSelect();
|
||||||
|
if (this.cursor >= globalScene.currentBattle.getBattlerCount() || !pokemon.isAllowedInBattle()) {
|
||||||
|
this.blockInput = true;
|
||||||
|
this.showText(
|
||||||
|
i18next.t("partyUiHandler:releaseConfirmation", {
|
||||||
|
pokemonName: getPokemonNameWithAffix(pokemon, false),
|
||||||
|
}),
|
||||||
|
null,
|
||||||
|
() => {
|
||||||
|
this.blockInput = false;
|
||||||
|
ui.setModeWithoutClear(
|
||||||
|
UiMode.CONFIRM,
|
||||||
|
() => {
|
||||||
|
ui.setMode(UiMode.PARTY);
|
||||||
|
this.doRelease(this.cursor);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
ui.setMode(UiMode.PARTY);
|
||||||
|
this.showText("", 0);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
this.showText(i18next.t("partyUiHandler:releaseInBattle"), null, () => this.showText("", 0), null, true);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
processRenameOption(pokemon: Pokemon): boolean {
|
||||||
|
const ui = this.getUi();
|
||||||
|
this.clearOptions();
|
||||||
|
ui.playSelect();
|
||||||
|
ui.setModeWithoutClear(
|
||||||
|
UiMode.RENAME_POKEMON,
|
||||||
|
{
|
||||||
|
buttonActions: [
|
||||||
|
(nickname: string) => {
|
||||||
|
ui.playSelect();
|
||||||
|
pokemon.nickname = nickname;
|
||||||
|
pokemon.updateInfo();
|
||||||
|
this.clearPartySlots();
|
||||||
|
this.populatePartySlots();
|
||||||
|
ui.setMode(UiMode.PARTY);
|
||||||
|
},
|
||||||
|
() => {
|
||||||
|
ui.setMode(UiMode.PARTY);
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
pokemon,
|
||||||
|
);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
processModifierTransferModeInput(button: Button) {
|
||||||
let success = false;
|
let success = false;
|
||||||
const ui = this.getUi();
|
const ui = this.getUi();
|
||||||
const option = this.options[this.optionsCursor];
|
const option = this.options[this.optionsCursor];
|
||||||
|
|
||||||
if (button === Button.ACTION) {
|
if (button === Button.ACTION) {
|
||||||
const pokemon = globalScene.getPlayerParty()[this.cursor];
|
const pokemon = globalScene.getPlayerParty()[this.cursor];
|
||||||
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER && !this.transferMode && option !== PartyOption.CANCEL) {
|
if (!this.transferMode && option !== PartyOption.CANCEL) {
|
||||||
this.startTransfer();
|
this.startTransfer();
|
||||||
|
|
||||||
let ableToTransfer: string;
|
let ableToTransfer: string;
|
||||||
@ -414,7 +554,63 @@ export default class PartyUiHandler extends MessageUiHandler {
|
|||||||
ui.playSelect();
|
ui.playSelect();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER && option !== PartyOption.CANCEL) {
|
}
|
||||||
|
|
||||||
|
if (button === Button.LEFT) {
|
||||||
|
/** Decrease quantity for the current item and update UI */
|
||||||
|
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
||||||
|
this.transferQuantities[option] =
|
||||||
|
this.transferQuantities[option] === 1
|
||||||
|
? this.transferQuantitiesMax[option]
|
||||||
|
: this.transferQuantities[option] - 1;
|
||||||
|
this.updateOptions();
|
||||||
|
success = this.setCursor(
|
||||||
|
this.optionsCursor,
|
||||||
|
); /** Place again the cursor at the same position. Necessary, otherwise the cursor disappears */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (button === Button.RIGHT) {
|
||||||
|
/** Increase quantity for the current item and update UI */
|
||||||
|
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
||||||
|
this.transferQuantities[option] =
|
||||||
|
this.transferQuantities[option] === this.transferQuantitiesMax[option]
|
||||||
|
? 1
|
||||||
|
: this.transferQuantities[option] + 1;
|
||||||
|
this.updateOptions();
|
||||||
|
success = this.setCursor(
|
||||||
|
this.optionsCursor,
|
||||||
|
); /** Place again the cursor at the same position. Necessary, otherwise the cursor disappears */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button === Button.UP || button === Button.DOWN) {
|
||||||
|
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
||||||
|
if (option !== PartyOption.ALL) {
|
||||||
|
this.transferQuantities[option] = this.transferQuantitiesMax[option];
|
||||||
|
}
|
||||||
|
this.updateOptions();
|
||||||
|
}
|
||||||
|
success = this.moveOptionCursor(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
moveOptionCursor(button: Button.UP | Button.DOWN): boolean {
|
||||||
|
if (button === Button.UP) {
|
||||||
|
return this.setCursor(this.optionsCursor ? this.optionsCursor - 1 : this.options.length - 1);
|
||||||
|
}
|
||||||
|
return this.setCursor(this.optionsCursor < this.options.length - 1 ? this.optionsCursor + 1 : 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
processRememberMoveModeInput(button: Button) {
|
||||||
|
let success = false;
|
||||||
|
const ui = this.getUi();
|
||||||
|
const option = this.options[this.optionsCursor];
|
||||||
|
|
||||||
|
if (button === Button.ACTION) {
|
||||||
|
const pokemon = globalScene.getPlayerParty()[this.cursor];
|
||||||
|
if (option !== PartyOption.CANCEL) {
|
||||||
// clear overlay on cancel
|
// clear overlay on cancel
|
||||||
this.moveInfoOverlay.clear();
|
this.moveInfoOverlay.clear();
|
||||||
const filterResult = (this.selectFilter as PokemonSelectFilter)(pokemon);
|
const filterResult = (this.selectFilter as PokemonSelectFilter)(pokemon);
|
||||||
@ -428,6 +624,46 @@ export default class PartyUiHandler extends MessageUiHandler {
|
|||||||
ui.playSelect();
|
ui.playSelect();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button === Button.UP || button === Button.DOWN) {
|
||||||
|
success = this.moveOptionCursor(button);
|
||||||
|
|
||||||
|
// show move description
|
||||||
|
const option = this.options[this.optionsCursor];
|
||||||
|
const pokemon = globalScene.getPlayerParty()[this.cursor];
|
||||||
|
const move = allMoves[pokemon.getLearnableLevelMoves()[option]];
|
||||||
|
if (move) {
|
||||||
|
this.moveInfoOverlay.show(move);
|
||||||
|
} else {
|
||||||
|
// or hide the overlay, in case it's the cancel button
|
||||||
|
this.moveInfoOverlay.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
processOptionMenuInput(button: Button) {
|
||||||
|
let success = false;
|
||||||
|
const ui = this.getUi();
|
||||||
|
const option = this.options[this.optionsCursor];
|
||||||
|
|
||||||
|
// TODO: Careful about using success for the return values here
|
||||||
|
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
||||||
|
success = this.processModifierTransferModeInput(button);
|
||||||
|
}
|
||||||
|
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) {
|
||||||
|
success = this.processRememberMoveModeInput(button);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the input has been already processed we are done, otherwise move on until the correct option is found
|
||||||
|
if (success) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (button === Button.ACTION) {
|
||||||
|
const pokemon = globalScene.getPlayerParty()[this.cursor];
|
||||||
if (
|
if (
|
||||||
![
|
![
|
||||||
PartyOption.SUMMARY,
|
PartyOption.SUMMARY,
|
||||||
@ -536,126 +772,19 @@ export default class PartyUiHandler extends MessageUiHandler {
|
|||||||
this.clearOptions();
|
this.clearOptions();
|
||||||
this.showText(filterResult as string, undefined, () => this.showText("", 0), undefined, true);
|
this.showText(filterResult as string, undefined, () => this.showText("", 0), undefined, true);
|
||||||
} else if (option === PartyOption.SUMMARY) {
|
} else if (option === PartyOption.SUMMARY) {
|
||||||
ui.playSelect();
|
return this.processSummaryOption(pokemon);
|
||||||
ui.setModeWithoutClear(UiMode.SUMMARY, pokemon).then(() => this.clearOptions());
|
|
||||||
return true;
|
|
||||||
} else if (option === PartyOption.POKEDEX) {
|
} else if (option === PartyOption.POKEDEX) {
|
||||||
ui.playSelect();
|
return this.processPokedexOption(pokemon);
|
||||||
const attributes = {
|
|
||||||
shiny: pokemon.shiny,
|
|
||||||
variant: pokemon.variant,
|
|
||||||
form: pokemon.formIndex,
|
|
||||||
female: pokemon.gender === Gender.FEMALE,
|
|
||||||
};
|
|
||||||
ui.setOverlayMode(UiMode.POKEDEX_PAGE, pokemon.species, attributes).then(() => this.clearOptions());
|
|
||||||
return true;
|
|
||||||
} else if (option === PartyOption.UNPAUSE_EVOLUTION) {
|
} else if (option === PartyOption.UNPAUSE_EVOLUTION) {
|
||||||
this.clearOptions();
|
return this.processUnpauseEvolutionOption(pokemon);
|
||||||
ui.playSelect();
|
|
||||||
pokemon.pauseEvolutions = !pokemon.pauseEvolutions;
|
|
||||||
this.showText(
|
|
||||||
i18next.t(pokemon.pauseEvolutions ? "partyUiHandler:pausedEvolutions" : "partyUiHandler:unpausedEvolutions", {
|
|
||||||
pokemonName: getPokemonNameWithAffix(pokemon, false),
|
|
||||||
}),
|
|
||||||
undefined,
|
|
||||||
() => this.showText("", 0),
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
} else if (option === PartyOption.UNSPLICE) {
|
} else if (option === PartyOption.UNSPLICE) {
|
||||||
this.clearOptions();
|
return this.processUnspliceOption(pokemon);
|
||||||
ui.playSelect();
|
|
||||||
this.showText(
|
|
||||||
i18next.t("partyUiHandler:unspliceConfirmation", {
|
|
||||||
fusionName: pokemon.fusionSpecies?.name,
|
|
||||||
pokemonName: pokemon.getName(),
|
|
||||||
}),
|
|
||||||
null,
|
|
||||||
() => {
|
|
||||||
ui.setModeWithoutClear(
|
|
||||||
UiMode.CONFIRM,
|
|
||||||
() => {
|
|
||||||
const fusionName = pokemon.getName();
|
|
||||||
pokemon.unfuse().then(() => {
|
|
||||||
this.clearPartySlots();
|
|
||||||
this.populatePartySlots();
|
|
||||||
ui.setMode(UiMode.PARTY);
|
|
||||||
this.showText(
|
|
||||||
i18next.t("partyUiHandler:wasReverted", {
|
|
||||||
fusionName: fusionName,
|
|
||||||
pokemonName: pokemon.getName(false),
|
|
||||||
}),
|
|
||||||
undefined,
|
|
||||||
() => {
|
|
||||||
ui.setMode(UiMode.PARTY);
|
|
||||||
this.showText("", 0);
|
|
||||||
},
|
|
||||||
null,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
ui.setMode(UiMode.PARTY);
|
|
||||||
this.showText("", 0);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else if (option === PartyOption.RELEASE) {
|
} else if (option === PartyOption.RELEASE) {
|
||||||
this.clearOptions();
|
return this.processReleaseOption(pokemon);
|
||||||
ui.playSelect();
|
|
||||||
if (this.cursor >= globalScene.currentBattle.getBattlerCount() || !pokemon.isAllowedInBattle()) {
|
|
||||||
this.blockInput = true;
|
|
||||||
this.showText(
|
|
||||||
i18next.t("partyUiHandler:releaseConfirmation", {
|
|
||||||
pokemonName: getPokemonNameWithAffix(pokemon, false),
|
|
||||||
}),
|
|
||||||
null,
|
|
||||||
() => {
|
|
||||||
this.blockInput = false;
|
|
||||||
ui.setModeWithoutClear(
|
|
||||||
UiMode.CONFIRM,
|
|
||||||
() => {
|
|
||||||
ui.setMode(UiMode.PARTY);
|
|
||||||
this.doRelease(this.cursor);
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
ui.setMode(UiMode.PARTY);
|
|
||||||
this.showText("", 0);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
this.showText(i18next.t("partyUiHandler:releaseInBattle"), null, () => this.showText("", 0), null, true);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
} else if (option === PartyOption.RENAME) {
|
} else if (option === PartyOption.RENAME) {
|
||||||
this.clearOptions();
|
return this.processRenameOption(pokemon);
|
||||||
ui.playSelect();
|
|
||||||
ui.setModeWithoutClear(
|
|
||||||
UiMode.RENAME_POKEMON,
|
|
||||||
{
|
|
||||||
buttonActions: [
|
|
||||||
(nickname: string) => {
|
|
||||||
ui.playSelect();
|
|
||||||
pokemon.nickname = nickname;
|
|
||||||
pokemon.updateInfo();
|
|
||||||
this.clearPartySlots();
|
|
||||||
this.populatePartySlots();
|
|
||||||
ui.setMode(UiMode.PARTY);
|
|
||||||
},
|
|
||||||
() => {
|
|
||||||
ui.setMode(UiMode.PARTY);
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
pokemon,
|
|
||||||
);
|
|
||||||
return true;
|
|
||||||
} else if (option === PartyOption.CANCEL) {
|
} else if (option === PartyOption.CANCEL) {
|
||||||
return this.processInput(Button.CANCEL);
|
return this.processOptionMenuInput(Button.CANCEL);
|
||||||
} else if (option === PartyOption.SELECT) {
|
} else if (option === PartyOption.SELECT) {
|
||||||
ui.playSelect();
|
ui.playSelect();
|
||||||
return true;
|
return true;
|
||||||
@ -664,72 +793,8 @@ export default class PartyUiHandler extends MessageUiHandler {
|
|||||||
this.clearOptions();
|
this.clearOptions();
|
||||||
ui.playSelect();
|
ui.playSelect();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else if (button === Button.UP || button === Button.DOWN) {
|
||||||
switch (button) {
|
success = this.moveOptionCursor(button);
|
||||||
case Button.LEFT:
|
|
||||||
/** Decrease quantity for the current item and update UI */
|
|
||||||
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
|
||||||
this.transferQuantities[option] =
|
|
||||||
this.transferQuantities[option] === 1
|
|
||||||
? this.transferQuantitiesMax[option]
|
|
||||||
: this.transferQuantities[option] - 1;
|
|
||||||
this.updateOptions();
|
|
||||||
success = this.setCursor(
|
|
||||||
this.optionsCursor,
|
|
||||||
); /** Place again the cursor at the same position. Necessary, otherwise the cursor disappears */
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Button.RIGHT:
|
|
||||||
/** Increase quantity for the current item and update UI */
|
|
||||||
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
|
||||||
this.transferQuantities[option] =
|
|
||||||
this.transferQuantities[option] === this.transferQuantitiesMax[option]
|
|
||||||
? 1
|
|
||||||
: this.transferQuantities[option] + 1;
|
|
||||||
this.updateOptions();
|
|
||||||
success = this.setCursor(
|
|
||||||
this.optionsCursor,
|
|
||||||
); /** Place again the cursor at the same position. Necessary, otherwise the cursor disappears */
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case Button.UP:
|
|
||||||
/** If currently selecting items to transfer, reset quantity selection */
|
|
||||||
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
|
||||||
if (option !== PartyOption.ALL) {
|
|
||||||
this.transferQuantities[option] = this.transferQuantitiesMax[option];
|
|
||||||
}
|
|
||||||
this.updateOptions();
|
|
||||||
}
|
|
||||||
success = this.setCursor(
|
|
||||||
this.optionsCursor ? this.optionsCursor - 1 : this.options.length - 1,
|
|
||||||
); /** Move cursor */
|
|
||||||
break;
|
|
||||||
case Button.DOWN:
|
|
||||||
/** If currently selecting items to transfer, reset quantity selection */
|
|
||||||
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
|
|
||||||
if (option !== PartyOption.ALL) {
|
|
||||||
this.transferQuantities[option] = this.transferQuantitiesMax[option];
|
|
||||||
}
|
|
||||||
this.updateOptions();
|
|
||||||
}
|
|
||||||
success = this.setCursor(
|
|
||||||
this.optionsCursor < this.options.length - 1 ? this.optionsCursor + 1 : 0,
|
|
||||||
); /** Move cursor */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// show move description
|
|
||||||
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) {
|
|
||||||
const option = this.options[this.optionsCursor];
|
|
||||||
const pokemon = globalScene.getPlayerParty()[this.cursor];
|
|
||||||
const move = allMoves[pokemon.getLearnableLevelMoves()[option]];
|
|
||||||
if (move) {
|
|
||||||
this.moveInfoOverlay.show(move);
|
|
||||||
} else {
|
|
||||||
// or hide the overlay, in case it's the cancel button
|
|
||||||
this.moveInfoOverlay.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
Loading…
Reference in New Issue
Block a user