[QOL] Add input delay for skipping egg summary (#4644)

This commit is contained in:
MokaStitcher 2024-10-14 16:42:59 +02:00 committed by GitHub
parent 8981f0e7a8
commit 676322e800
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 12 deletions

View File

@ -33,7 +33,7 @@ export class EggLapsePhase extends Phase {
if (eggsToHatchCount > 0) { if (eggsToHatchCount > 0) {
if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 1) { if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 1) {
this.scene.ui.showText(i18next.t("battle:eggHatching"), 0, () => { this.scene.ui.showText(i18next.t("battle:eggHatching"), 0, () => {
// show prompt for skip // show prompt for skip, blocking inputs for 1 second
this.scene.ui.showText(i18next.t("battle:eggSkipPrompt"), 0); this.scene.ui.showText(i18next.t("battle:eggSkipPrompt"), 0);
this.scene.ui.setModeWithoutClear(Mode.CONFIRM, () => { this.scene.ui.setModeWithoutClear(Mode.CONFIRM, () => {
this.hatchEggsSkipped(eggsToHatch); this.hatchEggsSkipped(eggsToHatch);
@ -41,7 +41,8 @@ export class EggLapsePhase extends Phase {
}, () => { }, () => {
this.hatchEggsRegular(eggsToHatch); this.hatchEggsRegular(eggsToHatch);
this.end(); this.end();
} },
null, null, null, 1000, true
); );
}, 100, true); }, 100, true);
} else if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 2) { } else if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 2) {

View File

@ -1,7 +1,6 @@
import BattleScene from "#app/battle-scene"; import BattleScene from "#app/battle-scene";
import { Phase } from "#app/phase"; import { Phase } from "#app/phase";
import { Mode } from "#app/ui/ui"; import { Mode } from "#app/ui/ui";
import EggHatchSceneHandler from "#app/ui/egg-hatch-scene-handler";
import { EggHatchData } from "#app/data/egg-hatch-data"; import { EggHatchData } from "#app/data/egg-hatch-data";
/** /**
@ -11,7 +10,6 @@ import { EggHatchData } from "#app/data/egg-hatch-data";
*/ */
export class EggSummaryPhase extends Phase { export class EggSummaryPhase extends Phase {
private eggHatchData: EggHatchData[]; private eggHatchData: EggHatchData[];
private eggHatchHandler: EggHatchSceneHandler;
constructor(scene: BattleScene, eggHatchData: EggHatchData[]) { constructor(scene: BattleScene, eggHatchData: EggHatchData[]) {
super(scene); super(scene);
@ -26,7 +24,6 @@ export class EggSummaryPhase extends Phase {
if (i >= this.eggHatchData.length) { if (i >= this.eggHatchData.length) {
this.scene.ui.setModeForceTransition(Mode.EGG_HATCH_SUMMARY, this.eggHatchData).then(() => { this.scene.ui.setModeForceTransition(Mode.EGG_HATCH_SUMMARY, this.eggHatchData).then(() => {
this.scene.fadeOutBgm(undefined, false); this.scene.fadeOutBgm(undefined, false);
this.eggHatchHandler = this.scene.ui.getHandler() as EggHatchSceneHandler;
}); });
} else { } else {

View File

@ -165,6 +165,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {
if (this.config.delay) { if (this.config.delay) {
this.blockInput = true; this.blockInput = true;
this.optionSelectText.setAlpha(0.5); this.optionSelectText.setAlpha(0.5);
this.cursorObj?.setAlpha(0.8);
this.scene.time.delayedCall(Utils.fixedInt(this.config.delay), () => this.unblockInput()); this.scene.time.delayedCall(Utils.fixedInt(this.config.delay), () => this.unblockInput());
} }
@ -256,6 +257,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {
this.blockInput = false; this.blockInput = false;
this.optionSelectText.setAlpha(1); this.optionSelectText.setAlpha(1);
this.cursorObj?.setAlpha(1);
} }
getOptionsWithScroll(): OptionSelectItem[] { getOptionsWithScroll(): OptionSelectItem[] {

View File

@ -76,7 +76,8 @@ export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler {
} }
} }
], ],
delay: args.length >= 6 && args[5] !== null ? args[5] as integer : 0 delay: args.length >= 6 && args[5] !== null ? args[5] as number : 0,
noCancel: args.length >= 7 && args[6] !== null ? args[6] as boolean : false,
}; };
super.show([ config ]); super.show([ config ]);
@ -96,7 +97,7 @@ export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler {
} }
processInput(button: Button): boolean { processInput(button: Button): boolean {
if (button === Button.CANCEL && this.blockInput) { if (button === Button.CANCEL && this.blockInput && !this.config?.noCancel) {
this.unblockInput(); this.unblockInput();
} }

View File

@ -42,6 +42,9 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
private scrollGridHandler : ScrollableGridUiHandler; private scrollGridHandler : ScrollableGridUiHandler;
private cursorObj: Phaser.GameObjects.Image; private cursorObj: Phaser.GameObjects.Image;
/** used to add a delay before which it is not possible to exit the summary */
private blockExit: boolean;
/** /**
* Allows subscribers to listen for events * Allows subscribers to listen for events
* *
@ -168,6 +171,13 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
this.setCursor(0); this.setCursor(0);
this.scene.playSoundWithoutBgm("evolution_fanfare"); this.scene.playSoundWithoutBgm("evolution_fanfare");
// Prevent exiting the egg summary for 2 seconds if the egg hatching
// was skipped automatically and for 1 second otherwise
const exitBlockingDuration = (this.scene.eggSkipPreference === 2) ? 2000 : 1000;
this.blockExit = true;
this.scene.time.delayedCall(exitBlockingDuration, () => this.blockExit = false);
return true; return true;
} }
@ -203,13 +213,17 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
const ui = this.getUi(); const ui = this.getUi();
let success = false; let success = false;
const error = false; let error = false;
if (button === Button.CANCEL) { if (button === Button.CANCEL) {
const phase = this.scene.getCurrentPhase(); if (!this.blockExit) {
if (phase instanceof EggSummaryPhase) { const phase = this.scene.getCurrentPhase();
phase.end(); if (phase instanceof EggSummaryPhase) {
phase.end();
}
success = true;
} else {
error = true;
} }
success = true;
} else { } else {
this.scrollGridHandler.processInput(button); this.scrollGridHandler.processInput(button);
} }