Skip to content

Commit

Permalink
[QOL] Add input delay for skipping egg summary (pagefaultgames#4644)
Browse files Browse the repository at this point in the history
  • Loading branch information
MokaStitcher authored Oct 14, 2024
1 parent 8981f0e commit 676322e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 12 deletions.
5 changes: 3 additions & 2 deletions src/phases/egg-lapse-phase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,16 @@ export class EggLapsePhase extends Phase {
if (eggsToHatchCount > 0) {
if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 1) {
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.setModeWithoutClear(Mode.CONFIRM, () => {
this.hatchEggsSkipped(eggsToHatch);
this.showSummary();
}, () => {
this.hatchEggsRegular(eggsToHatch);
this.end();
}
},
null, null, null, 1000, true
);
}, 100, true);
} else if (eggsToHatchCount >= this.minEggsToSkip && this.scene.eggSkipPreference === 2) {
Expand Down
3 changes: 0 additions & 3 deletions src/phases/egg-summary-phase.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import BattleScene from "#app/battle-scene";
import { Phase } from "#app/phase";
import { Mode } from "#app/ui/ui";
import EggHatchSceneHandler from "#app/ui/egg-hatch-scene-handler";
import { EggHatchData } from "#app/data/egg-hatch-data";

/**
Expand All @@ -11,7 +10,6 @@ import { EggHatchData } from "#app/data/egg-hatch-data";
*/
export class EggSummaryPhase extends Phase {
private eggHatchData: EggHatchData[];
private eggHatchHandler: EggHatchSceneHandler;

constructor(scene: BattleScene, eggHatchData: EggHatchData[]) {
super(scene);
Expand All @@ -26,7 +24,6 @@ export class EggSummaryPhase extends Phase {
if (i >= this.eggHatchData.length) {
this.scene.ui.setModeForceTransition(Mode.EGG_HATCH_SUMMARY, this.eggHatchData).then(() => {
this.scene.fadeOutBgm(undefined, false);
this.eggHatchHandler = this.scene.ui.getHandler() as EggHatchSceneHandler;
});

} else {
Expand Down
2 changes: 2 additions & 0 deletions src/ui/abstact-option-select-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {
if (this.config.delay) {
this.blockInput = true;
this.optionSelectText.setAlpha(0.5);
this.cursorObj?.setAlpha(0.8);
this.scene.time.delayedCall(Utils.fixedInt(this.config.delay), () => this.unblockInput());
}

Expand Down Expand Up @@ -256,6 +257,7 @@ export default abstract class AbstractOptionSelectUiHandler extends UiHandler {

this.blockInput = false;
this.optionSelectText.setAlpha(1);
this.cursorObj?.setAlpha(1);
}

getOptionsWithScroll(): OptionSelectItem[] {
Expand Down
5 changes: 3 additions & 2 deletions src/ui/confirm-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ]);
Expand All @@ -96,7 +97,7 @@ export default class ConfirmUiHandler extends AbstractOptionSelectUiHandler {
}

processInput(button: Button): boolean {
if (button === Button.CANCEL && this.blockInput) {
if (button === Button.CANCEL && this.blockInput && !this.config?.noCancel) {
this.unblockInput();
}

Expand Down
24 changes: 19 additions & 5 deletions src/ui/egg-summary-ui-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
private scrollGridHandler : ScrollableGridUiHandler;
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
*
Expand Down Expand Up @@ -168,6 +171,13 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
this.setCursor(0);

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;
}

Expand Down Expand Up @@ -203,13 +213,17 @@ export default class EggSummaryUiHandler extends MessageUiHandler {
const ui = this.getUi();

let success = false;
const error = false;
let error = false;
if (button === Button.CANCEL) {
const phase = this.scene.getCurrentPhase();
if (phase instanceof EggSummaryPhase) {
phase.end();
if (!this.blockExit) {
const phase = this.scene.getCurrentPhase();
if (phase instanceof EggSummaryPhase) {
phase.end();
}
success = true;
} else {
error = true;
}
success = true;
} else {
this.scrollGridHandler.processInput(button);
}
Expand Down

0 comments on commit 676322e

Please sign in to comment.