[UI][Misc] Force users to have an active challenge (#3953)
* I hope this is good enough * renamed variable to better name * Remove random newline * When player is ready cool box * Fixed cancel behavior * standardized action/cancel behavior * Added comments --------- Co-authored-by: frutescens <info@laptop> Co-authored-by: NightKev <34855794+DayKev@users.noreply.github.com>
This commit is contained in:
parent
84ef7f0683
commit
0cbdaab28e
|
@ -1,6 +1,7 @@
|
|||
{
|
||||
"title": "Challenge Modifiers",
|
||||
"illegalEvolution": "{{pokemon}} changed into an ineligble pokémon\nfor this challenge!",
|
||||
"noneSelected": "None Selected",
|
||||
"singleGeneration": {
|
||||
"name": "Mono Gen",
|
||||
"desc": "You can only use Pokémon from Generation {{gen}}.",
|
||||
|
|
|
@ -5,13 +5,13 @@ import UiHandler from "./ui-handler";
|
|||
import { addWindow } from "./ui-theme";
|
||||
import {Button} from "#enums/buttons";
|
||||
import i18next from "i18next";
|
||||
import { Challenge } from "#app/data/challenge.js";
|
||||
import { Challenge } from "#app/data/challenge";
|
||||
import * as Utils from "../utils";
|
||||
import { Challenges } from "#app/enums/challenges.js";
|
||||
import { Challenges } from "#app/enums/challenges";
|
||||
import BBCodeText from "phaser3-rex-plugins/plugins/bbcodetext";
|
||||
import { Color, ShadowColor } from "#app/enums/color.js";
|
||||
import { SelectStarterPhase } from "#app/phases/select-starter-phase.js";
|
||||
import { TitlePhase } from "#app/phases/title-phase.js";
|
||||
import { Color, ShadowColor } from "#app/enums/color";
|
||||
import { SelectStarterPhase } from "#app/phases/select-starter-phase";
|
||||
import { TitlePhase } from "#app/phases/title-phase";
|
||||
|
||||
/**
|
||||
* Handles all the UI for choosing optional challenges.
|
||||
|
@ -33,7 +33,10 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
|
||||
private cursorObj: Phaser.GameObjects.NineSlice | null;
|
||||
|
||||
private startBg: Phaser.GameObjects.NineSlice;
|
||||
private startCursor: Phaser.GameObjects.NineSlice;
|
||||
private startText: Phaser.GameObjects.Text;
|
||||
private hasSelectedChallenge: boolean;
|
||||
|
||||
private optionsWidth: number;
|
||||
|
||||
|
@ -104,20 +107,20 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
this.descriptionText.setShadow(4, 5, ShadowColor.ORANGE);
|
||||
this.descriptionText.setOrigin(0, 0);
|
||||
|
||||
const startBg = addWindow(this.scene, 0, 0, descriptionBg.width, 24);
|
||||
startBg.setName("window-start-bg");
|
||||
startBg.setOrigin(0, 0);
|
||||
startBg.setPositionRelative(descriptionBg, 0, descriptionBg.height);
|
||||
this.startBg = addWindow(this.scene, 0, 0, descriptionBg.width, 24);
|
||||
this.startBg.setName("window-start-bg");
|
||||
this.startBg.setOrigin(0, 0);
|
||||
this.startBg.setPositionRelative(descriptionBg, 0, descriptionBg.height);
|
||||
|
||||
const startText = addTextObject(this.scene, 0, 0, i18next.t("common:start"), TextStyle.SETTINGS_LABEL);
|
||||
startText.setName("text-start");
|
||||
startText.setOrigin(0, 0);
|
||||
startText.setPositionRelative(startBg, (startBg.width - startText.displayWidth) / 2, 4);
|
||||
this.startText = addTextObject(this.scene, 0, 0, i18next.t("challenges:noneSelected"), TextStyle.SETTINGS_LABEL);
|
||||
this.startText.setName("text-start");
|
||||
this.startText.setOrigin(0, 0);
|
||||
this.startText.setPositionRelative(this.startBg, (this.startBg.width - this.startText.displayWidth) / 2, 4);
|
||||
|
||||
this.startCursor = this.scene.add.nineslice(0, 0, "summary_moves_cursor", undefined, descriptionBg.width - 8, 16, 1, 1, 1, 1);
|
||||
this.startCursor.setName("9s-start-cursor");
|
||||
this.startCursor.setOrigin(0, 0);
|
||||
this.startCursor.setPositionRelative(startBg, 4, 3);
|
||||
this.startCursor.setPositionRelative(this.startBg, 4, 3);
|
||||
this.startCursor.setVisible(false);
|
||||
|
||||
this.valuesContainer = this.scene.add.container(0, 0);
|
||||
|
@ -157,8 +160,8 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
this.challengesContainer.add(this.optionsBg);
|
||||
this.challengesContainer.add(descriptionBg);
|
||||
this.challengesContainer.add(this.descriptionText);
|
||||
this.challengesContainer.add(startBg);
|
||||
this.challengesContainer.add(startText);
|
||||
this.challengesContainer.add(this.startBg);
|
||||
this.challengesContainer.add(this.startText);
|
||||
this.challengesContainer.add(this.startCursor);
|
||||
this.challengesContainer.add(this.valuesContainer);
|
||||
|
||||
|
@ -216,6 +219,21 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
this.monoTypeValue.setVisible(false);
|
||||
}
|
||||
|
||||
// This checks if a challenge has been selected by the user and updates the text/its opacity accordingly.
|
||||
this.hasSelectedChallenge = this.scene.gameMode.challenges.some(c => c.value !== 0);
|
||||
if (this.hasSelectedChallenge) {
|
||||
|
||||
this.startText.setText(i18next.t("common:start"));
|
||||
this.startText.setAlpha(1);
|
||||
this.startText.setPositionRelative(this.startBg, (this.startBg.width - this.startText.displayWidth) / 2, 4);
|
||||
} else {
|
||||
|
||||
this.startText.setText(i18next.t("challenges:noneSelected"));
|
||||
this.startText.setAlpha(0.5);
|
||||
this.startText.setPositionRelative(this.startBg, (this.startBg.width - this.startText.displayWidth) / 2, 4);
|
||||
}
|
||||
this.challengesContainer.update();
|
||||
|
||||
// const totalDifficulty = this.scene.gameMode.challenges.reduce((v, c) => v + c.getDifficulty(), 0);
|
||||
// const totalMinDifficulty = this.scene.gameMode.challenges.reduce((v, c) => v + c.getMinDifficulty(), 0);
|
||||
// this.difficultyText.text = `${totalDifficulty}` + (totalMinDifficulty ? `/${totalMinDifficulty}` : "");
|
||||
|
@ -227,6 +245,8 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
|
||||
this.startCursor.setVisible(false);
|
||||
this.challengesContainer.setVisible(true);
|
||||
// Should always be false at the start
|
||||
this.hasSelectedChallenge = this.scene.gameMode.challenges.some(c => c.value !== 0);
|
||||
this.setCursor(0);
|
||||
|
||||
this.initLabels();
|
||||
|
@ -257,6 +277,7 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
|
||||
if (button === Button.CANCEL) {
|
||||
if (this.startCursor.visible) {
|
||||
// If the user presses cancel when the start cursor has been activated, the game deactivates the start cursor and allows typical challenge selection behavior
|
||||
this.startCursor.setVisible(false);
|
||||
this.cursorObj?.setVisible(true);
|
||||
} else {
|
||||
|
@ -266,22 +287,20 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
}
|
||||
success = true;
|
||||
} else if (button === Button.SUBMIT || button === Button.ACTION) {
|
||||
if (this.hasSelectedChallenge) {
|
||||
if (this.startCursor.visible) {
|
||||
const totalDifficulty = this.scene.gameMode.challenges.reduce((v, c) => v + c.getDifficulty(), 0);
|
||||
const totalMinDifficulty = this.scene.gameMode.challenges.reduce((v, c) => v + c.getMinDifficulty(), 0);
|
||||
if (totalDifficulty >= totalMinDifficulty) {
|
||||
this.scene.unshiftPhase(new SelectStarterPhase(this.scene));
|
||||
this.scene.getCurrentPhase()?.end();
|
||||
} else {
|
||||
this.startCursor.setVisible(true);
|
||||
this.cursorObj?.setVisible(false);
|
||||
}
|
||||
success = true;
|
||||
} else {
|
||||
success = false;
|
||||
}
|
||||
} else {
|
||||
this.startCursor.setVisible(true);
|
||||
this.cursorObj?.setVisible(false);
|
||||
success = true;
|
||||
}
|
||||
} else {
|
||||
if (this.cursorObj?.visible && !this.startCursor.visible) {
|
||||
switch (button) {
|
||||
case Button.UP:
|
||||
if (this.cursor === 0) {
|
||||
|
@ -345,12 +364,12 @@ export default class GameChallengesUiHandler extends UiHandler {
|
|||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Plays a select sound effect if an action was successfully processed.
|
||||
if (success) {
|
||||
ui.playSelect();
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue