Splitting up processing of transfer and move recall mode; ensuring that the cancel option works properly

This commit is contained in:
Wlowscha 2025-05-15 22:57:30 +02:00
parent f876dcf76d
commit 85b92bffed
No known key found for this signature in database
GPG Key ID: 3C8F1AD330565D04

View File

@ -532,60 +532,66 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
// TODO: This will be largely changed with the modifier rework // TODO: This will be largely changed with the modifier rework
processModifierTransferModeInput(button: Button) { processModifierTransferModeInput(pokemon: PlayerPokemon) {
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 (option === PartyOption.TRANSFER) {
const pokemon = globalScene.getPlayerParty()[this.cursor]; return this.processTransferOption();
// TODO: Revise this condition }
if (!this.transferMode && option !== PartyOption.CANCEL) {
this.startTransfer();
let ableToTransferText: string; // TODO: Revise this condition
for (let p = 0; p < globalScene.getPlayerParty().length; p++) { if (!this.transferMode) {
// this for look goes through each of the party pokemon this.startTransfer();
const newPokemon = globalScene.getPlayerParty()[p];
// this next bit checks to see if the the selected item from the original transfer pokemon exists on the new pokemon [p]; this returns undefined if the new pokemon doesn't have the item at all, otherwise it returns the pokemonHeldItemModifier for that item let ableToTransferText: string;
const matchingModifier = globalScene.findModifier( for (let p = 0; p < globalScene.getPlayerParty().length; p++) {
m => // this for look goes through each of the party pokemon
m instanceof PokemonHeldItemModifier && const newPokemon = globalScene.getPlayerParty()[p];
m.pokemonId === newPokemon.id && // this next bit checks to see if the the selected item from the original transfer pokemon exists on the new pokemon [p]; this returns undefined if the new pokemon doesn't have the item at all, otherwise it returns the pokemonHeldItemModifier for that item
m.matchType(this.getTransferrableItemsFromPokemon(pokemon)[this.transferOptionCursor]), const matchingModifier = globalScene.findModifier(
) as PokemonHeldItemModifier; m =>
const partySlot = this.partySlots.filter(m => m.getPokemon() === newPokemon)[0]; // this gets pokemon [p] for us m instanceof PokemonHeldItemModifier &&
if (p !== this.transferCursor) { m.pokemonId === newPokemon.id &&
// this skips adding the able/not able labels on the pokemon doing the transfer m.matchType(this.getTransferrableItemsFromPokemon(pokemon)[this.transferOptionCursor]),
if (matchingModifier) { ) as PokemonHeldItemModifier;
// if matchingModifier exists then the item exists on the new pokemon const partySlot = this.partySlots.filter(m => m.getPokemon() === newPokemon)[0]; // this gets pokemon [p] for us
if (matchingModifier.getMaxStackCount() === matchingModifier.stackCount) { if (p !== this.transferCursor) {
// checks to see if the stack of items is at max stack; if so, set the description label to "Not able" // this skips adding the able/not able labels on the pokemon doing the transfer
ableToTransferText = i18next.t("partyUiHandler:notAble"); if (matchingModifier) {
} else { // if matchingModifier exists then the item exists on the new pokemon
// if the pokemon isn't at max stack, make the label "Able" if (matchingModifier.getMaxStackCount() === matchingModifier.stackCount) {
ableToTransferText = i18next.t("partyUiHandler:able"); // checks to see if the stack of items is at max stack; if so, set the description label to "Not able"
} ableToTransferText = i18next.t("partyUiHandler:notAble");
} else { } else {
// if matchingModifier doesn't exist, that means the pokemon doesn't have any of the item, and we need to show "Able" // if the pokemon isn't at max stack, make the label "Able"
ableToTransferText = i18next.t("partyUiHandler:able"); ableToTransferText = i18next.t("partyUiHandler:able");
} }
} else { } else {
// this else relates to the transfer pokemon. We set the text to be blank so there's no "Able"/"Not able" text // if matchingModifier doesn't exist, that means the pokemon doesn't have any of the item, and we need to show "Able"
ableToTransferText = ""; ableToTransferText = i18next.t("partyUiHandler:able");
} }
partySlot.slotHpBar.setVisible(false); } else {
partySlot.slotHpOverlay.setVisible(false); // this else relates to the transfer pokemon. We set the text to be blank so there's no "Able"/"Not able" text
partySlot.slotHpText.setVisible(false); ableToTransferText = "";
partySlot.slotDescriptionLabel.setText(ableToTransferText);
partySlot.slotDescriptionLabel.setVisible(true);
} }
this.clearOptions(); partySlot.slotHpBar.setVisible(false);
ui.playSelect(); partySlot.slotHpOverlay.setVisible(false);
return true; partySlot.slotHpText.setVisible(false);
partySlot.slotDescriptionLabel.setText(ableToTransferText);
partySlot.slotDescriptionLabel.setVisible(true);
} }
this.clearOptions();
ui.playSelect();
return true;
} }
return false;
}
// TODO: Might need a check here actually for when this.transferMode is active...
processModifierTransferModeLeftRightInput(button: Button) {
let success = false;
const option = this.options[this.optionsCursor];
if (button === Button.LEFT) { if (button === Button.LEFT) {
/** Decrease quantity for the current item and update UI */ /** Decrease quantity for the current item and update UI */
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) { if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
@ -613,16 +619,21 @@ export default class PartyUiHandler extends MessageUiHandler {
); /** Place again the cursor at the same position. Necessary, otherwise the cursor disappears */ ); /** Place again the cursor at the same position. Necessary, otherwise the cursor disappears */
} }
} }
return success;
}
if (button === Button.UP || button === Button.DOWN) { // TODO: Might need a check here actually for when this.transferMode is active...
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) { processModifierTransferModeUpDownInput(button: Button.UP | Button.DOWN) {
if (option !== PartyOption.ALL) { let success = false;
this.transferQuantities[option] = this.transferQuantitiesMax[option]; const option = this.options[this.optionsCursor];
}
this.updateOptions(); if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
if (option !== PartyOption.ALL) {
this.transferQuantities[option] = this.transferQuantitiesMax[option];
} }
success = this.moveOptionCursor(button); this.updateOptions();
} }
success = this.moveOptionCursor(button);
return success; return success;
} }
@ -634,42 +645,38 @@ export default class PartyUiHandler extends MessageUiHandler {
return this.setCursor(this.optionsCursor < this.options.length - 1 ? this.optionsCursor + 1 : 0); return this.setCursor(this.optionsCursor < this.options.length - 1 ? this.optionsCursor + 1 : 0);
} }
processRememberMoveModeInput(button: Button) { processRememberMoveModeInput(pokemon: PlayerPokemon) {
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) { // clear overlay on cancel
const pokemon = globalScene.getPlayerParty()[this.cursor]; this.moveInfoOverlay.clear();
if (option !== PartyOption.CANCEL) { const filterResult = (this.selectFilter as PokemonSelectFilter)(pokemon);
// clear overlay on cancel if (filterResult === null) {
this.moveInfoOverlay.clear(); this.selectCallback?.(this.cursor, option);
const filterResult = (this.selectFilter as PokemonSelectFilter)(pokemon); this.clearOptions();
if (filterResult === null) { } else {
this.selectCallback?.(this.cursor, option); this.clearOptions();
this.clearOptions(); this.showText(filterResult as string, undefined, () => this.showText("", 0), undefined, true);
} else {
this.clearOptions();
this.showText(filterResult as string, undefined, () => this.showText("", 0), undefined, true);
}
ui.playSelect();
return true;
}
} }
ui.playSelect();
return true;
}
if (button === Button.UP || button === Button.DOWN) { processRememberMoveModeUpDownInput(button: Button.UP | Button.DOWN) {
success = this.moveOptionCursor(button); let success = false;
// show move description success = this.moveOptionCursor(button);
const option = this.options[this.optionsCursor];
const pokemon = globalScene.getPlayerParty()[this.cursor]; // show move description
const move = allMoves[pokemon.getLearnableLevelMoves()[option]]; const option = this.options[this.optionsCursor];
if (move) { const pokemon = globalScene.getPlayerParty()[this.cursor];
this.moveInfoOverlay.show(move); const move = allMoves[pokemon.getLearnableLevelMoves()[option]];
} else { if (move) {
// or hide the overlay, in case it's the cancel button this.moveInfoOverlay.show(move);
this.moveInfoOverlay.clear(); } else {
} // or hide the overlay, in case it's the cancel button
this.moveInfoOverlay.clear();
} }
return success; return success;
@ -703,39 +710,35 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
processOptionMenuInput(button: Button) { processOptionMenuInput(button: Button) {
let success = false;
const ui = this.getUi(); const ui = this.getUi();
const option = this.options[this.optionsCursor]; const option = this.options[this.optionsCursor];
// Button.CANCEL has no special behavior for any option // Button.CANCEL has no special behavior for any option
if (button === Button.CANCEL || option === PartyOption.CANCEL) { if (button === Button.CANCEL) {
this.clearOptions(); this.clearOptions();
ui.playSelect(); ui.playSelect();
return true; return true;
} }
console.log(PartyUiMode[this.partyUiMode]);
console.log(PartyOption[option]);
console.log(this.selectCallback);
// TODO: Careful about using success for the return values here. Find a better way
// PartyOption.ALL, and options specific to the mode (held items)
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
success = this.processModifierTransferModeInput(button);
}
// options specific to the mode (moves)
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) { if (button === Button.ACTION) {
if (option === PartyOption.CANCEL) {
return this.processOptionMenuInput(Button.CANCEL);
}
// If the input has been already processed we are done, otherwise move on until the correct option is found
const pokemon = globalScene.getPlayerParty()[this.cursor]; const pokemon = globalScene.getPlayerParty()[this.cursor];
// TODO: Careful about using success for the return values here. Find a better way
// PartyOption.ALL, and options specific to the mode (held items)
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
return this.processModifierTransferModeInput(pokemon);
}
// options specific to the mode (moves)
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) {
return this.processRememberMoveModeInput(pokemon);
}
// These are the options that do not involve a callback // These are the options that do not involve a callback
if (option === PartyOption.SUMMARY) { if (option === PartyOption.SUMMARY) {
return this.processSummaryOption(pokemon); return this.processSummaryOption(pokemon);
@ -786,10 +789,6 @@ export default class PartyUiHandler extends MessageUiHandler {
// PartyUiMode.POST_BATTLE_SWITCH (SEND_OUT) // PartyUiMode.POST_BATTLE_SWITCH (SEND_OUT)
// These are the options that need a callback // These are the options that need a callback
if (option === PartyOption.TRANSFER) {
return this.processTransferOption();
}
if (option === PartyOption.RELEASE) { if (option === PartyOption.RELEASE) {
return this.processReleaseOption(pokemon); return this.processReleaseOption(pokemon);
} }
@ -857,10 +856,24 @@ export default class PartyUiHandler extends MessageUiHandler {
} }
if (button === Button.UP || button === Button.DOWN) { if (button === Button.UP || button === Button.DOWN) {
success = this.moveOptionCursor(button); if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
return this.processModifierTransferModeUpDownInput(button);
}
if (this.partyUiMode === PartyUiMode.REMEMBER_MOVE_MODIFIER) {
return this.processRememberMoveModeUpDownInput(button);
}
return this.moveOptionCursor(button);
} }
return success; if (button === Button.LEFT || button === Button.RIGHT) {
if (this.partyUiMode === PartyUiMode.MODIFIER_TRANSFER) {
return this.processModifierTransferModeLeftRightInput(button);
}
}
return false;
} }
processInput(button: Button): boolean { processInput(button: Button): boolean {