From b2939453d29487398343bc377b9e08d5bed742ec Mon Sep 17 00:00:00 2001 From: frutescens Date: Tue, 24 Sep 2024 17:11:57 -0700 Subject: [PATCH] Let's see --- src/ui/confirm-preview-ui-handler.ts | 97 --------------------------- src/ui/run-history-ui-handler.ts | 3 +- src/ui/run-info-ui-handler.ts | 93 +++++++++++++++++++------ src/ui/save-slot-select-ui-handler.ts | 7 ++ 4 files changed, 83 insertions(+), 117 deletions(-) delete mode 100644 src/ui/confirm-preview-ui-handler.ts diff --git a/src/ui/confirm-preview-ui-handler.ts b/src/ui/confirm-preview-ui-handler.ts deleted file mode 100644 index 12478b446c2..00000000000 --- a/src/ui/confirm-preview-ui-handler.ts +++ /dev/null @@ -1,97 +0,0 @@ -import BattleScene from "../battle-scene"; -import AbstractOptionSelectUiHandler, { OptionSelectConfig } from "./abstact-option-select-ui-handler"; -import { Mode } from "./ui"; -import i18next from "i18next"; -import {Button} from "#enums/buttons"; - -export enum PreviewMode { - CATCH_SUMMARY, - SAVE_PREVIEW -} - -export default class ConfirmPreviewUiHandler extends AbstractOptionSelectUiHandler { - - public static readonly windowWidth: integer = 48; - - private switchCheck: boolean; - private switchCheckCursor: integer; - - constructor(scene: BattleScene) { - super(scene, Mode.CONFIRM); - } - - getWindowWidth(): integer { - return ConfirmPreviewUiHandler.windowWidth; - } - - determineLabels(mode: PreviewMode): string[] { - const yes = i18next.t("menu:yes"); - const no = i18next.t("menu:no"); - switch (previewMode) { - case PreviewMode.CATCH_SUMMARY: - return [i18next.t("partyUiHandler:SUMMARY"), yes, no]; - case PreviewMode.SAVE_PREVIEW: - return [yes, i18next.t(""), no]; - default: - return ["", "", ""]; - } - } - - show(args: any[]): boolean { - const labels = this.determineLabels(args[3]); - const config: OptionSelectConfig = { - options: [ - { - label: labels[0], - handler: () => { - args[0](); - return true; - }, - }, { - label: labels[1], - handler: () => { - args[1](); - return true; - } - }, { - label: labels[2], - handler: () => { - args[2](); - return true; - } - } - ], - delay: args.length >= 8 && args[7] !== null ? args[7] as integer : 0 - }; - - super.show([ config ]); - - this.switchCheck = args.length >= 5 && args[4] !== null && args[4] as boolean; - - const xOffset = (args.length >= 6 && args[5] !== null ? args[5] as number : 0); - const yOffset = (args.length >= 7 && args[6] !== null ? args[6] as number : 0); - - this.optionSelectContainer.setPosition((this.scene.game.canvas.width / 6) - 1 + xOffset, -48 + yOffset); - - this.setCursor(this.switchCheck ? this.switchCheckCursor : 0); - return true; - } - - processInput(button: Button): boolean { - if (button === Button.CANCEL && this.blockInput) { - this.unblockInput(); - } - - return super.processInput(button); - } - - setCursor(cursor: integer): boolean { - const ret = super.setCursor(cursor); - - if (ret && this.switchCheck) { - this.switchCheckCursor = this.cursor; - } - - return ret; - } -} diff --git a/src/ui/run-history-ui-handler.ts b/src/ui/run-history-ui-handler.ts index d983fb0b0b8..d6438b3b076 100644 --- a/src/ui/run-history-ui-handler.ts +++ b/src/ui/run-history-ui-handler.ts @@ -12,6 +12,7 @@ import { BattleType } from "../battle"; import { RunEntry } from "../system/game-data"; import { PlayerGender } from "#enums/player-gender"; import { TrainerVariant } from "../field/trainer"; +import { RunDisplayMode } from "#app/ui/run-info-ui-handler"; export type RunSelectCallback = (cursor: number) => void; @@ -104,7 +105,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler { if (button === Button.ACTION) { const cursor = this.cursor + this.scrollCursor; if (this.runs[cursor]) { - this.scene.ui.setOverlayMode(Mode.RUN_INFO, this.runs[cursor].entryData, true); + this.scene.ui.setOverlayMode(Mode.RUN_INFO, this.runs[cursor].entryData, RunDisplayMode.RUN_HISTORY, true); } else { return false; } diff --git a/src/ui/run-info-ui-handler.ts b/src/ui/run-info-ui-handler.ts index b4e4ad1130d..158c124724b 100644 --- a/src/ui/run-info-ui-handler.ts +++ b/src/ui/run-info-ui-handler.ts @@ -22,6 +22,7 @@ import * as Modifier from "../modifier/modifier"; import { Species } from "#enums/species"; import { PlayerGender } from "#enums/player-gender"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; +import { getBiomeName } from "#app/data/biomes"; /** * RunInfoUiMode indicates possible overlays of RunInfoUiHandler. @@ -34,6 +35,11 @@ enum RunInfoUiMode { ENDING_ART } +export enum RunDisplayMode { + RUN_HISTORY, + SAVE_PREVIEW +} + /** * Some variables are protected because this UI class will most likely be extended in the future to display more information. * These variables will most likely be shared across 'classes' aka pages. @@ -41,6 +47,7 @@ enum RunInfoUiMode { * For now, I leave as is. */ export default class RunInfoUiHandler extends UiHandler { + protected runDisplayMode: RunDisplayMode; protected runInfo: SessionSaveData; protected isVictory: boolean; protected pageMode: RunInfoUiMode; @@ -87,9 +94,15 @@ export default class RunInfoUiHandler extends UiHandler { this.runContainer.add(gameStatsBg); const run = args[0]; + this.runDisplayMode = args[1]; + if (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) { + this.runInfo = this.scene.gameData.parseSessionData(JSON.stringify(run.entry)); + this.isVictory = run.isVictory ?? false; + } else if (this.runDisplayMode === RunDisplayMode.SAVE_PREVIEW) { + this.runInfo = args[0]; + } // Assigning information necessary for the UI's creation - this.runInfo = this.scene.gameData.parseSessionData(JSON.stringify(run.entry)); - this.isVictory = run.isVictory; + this.pageMode = RunInfoUiMode.MAIN; // Creates Header and adds to this.runContainer @@ -102,7 +115,11 @@ export default class RunInfoUiHandler extends UiHandler { const runResultWindow = addWindow(this.scene, 0, 0, this.statsBgWidth-11, 65); runResultWindow.setOrigin(0, 0); this.runResultContainer.add(runResultWindow); - this.parseRunResult(); + if (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) { + this.parseRunResult(); + } else if (this.runDisplayMode === RunDisplayMode.SAVE_PREVIEW) { + this.parseRunStatus(); + } // Creates Run Info Container this.runInfoContainer = this.scene.add.container(0, 89); @@ -226,6 +243,31 @@ export default class RunInfoUiHandler extends UiHandler { this.runContainer.add(this.runResultContainer); } + private parseRunStatus() { + console.log(this.runInfo); + const runStatusText = addTextObject(this.scene, 6, 5, `${i18next.t("saveSlotSelectUiHandler:wave")} ${this.runInfo.waveIndex} - ${getBiomeName(this.runInfo.arena.biome)}`, TextStyle.WINDOW, {fontSize : "65px", lineSpacing: 0.1}); + this.runResultContainer.add(runStatusText); + + const enemyContainer = this.scene.add.container(0, 0); + // Wild - Single and Doubles + if (this.runInfo.battleType === BattleType.WILD || (this.runInfo.battleType === BattleType.MYSTERY_ENCOUNTER && !this.runInfo.trainer)) { + switch (this.runInfo.enemyParty.length) { + case 1: + // Wild - Singles + this.parseWildSingleDefeat(enemyContainer); + break; + case 2: + //Wild - Doubles + this.parseWildDoubleDefeat(enemyContainer); + break; + } + } else if (this.runInfo.battleType === BattleType.TRAINER || (this.runInfo.battleType === BattleType.MYSTERY_ENCOUNTER && this.runInfo.trainer)) { + this.loadTrainerSprites(enemyContainer); + } + this.runResultContainer.add(enemyContainer); + this.runContainer.add(this.runResultContainer); + } + /** * This function is called to edit an enemyContainer to represent a loss from a defeat by a wild single Pokemon battle. * @param enemyContainer - container holding enemy visual and level information @@ -277,15 +319,7 @@ export default class RunInfoUiHandler extends UiHandler { enemyContainer.setPosition(8, 14); } - /** - * This edits a container to represent a loss from a defeat by a trainer battle. - * @param enemyContainer - container holding enemy visuals and level information - * The trainers are placed to the left of their party. - * Depending on the trainer icon, there may be overlap between the edges of the box or their party. (Capes...) - * - * Party Pokemon have their icons, terastalization status, and level shown. - */ - private parseTrainerDefeat(enemyContainer: Phaser.GameObjects.Container) { + private loadTrainerSprites(enemyContainer: Phaser.GameObjects.Container) { // Creating the trainer sprite and adding it to enemyContainer const tObj = this.runInfo.trainer.toTrainer(this.scene); @@ -299,19 +333,40 @@ export default class RunInfoUiHandler extends UiHandler { const tObjPartnerSpriteKey = tObj.config.getSpriteKey(true, true); const tObjPartnerSprite = this.scene.add.sprite(5, -3, tObjPartnerSpriteKey); // Double Trainers have smaller sprites than Single Trainers - tObjPartnerSprite.setScale(0.20); - tObjSprite.setScale(0.20); - doubleContainer.add(tObjSprite); - doubleContainer.add(tObjPartnerSprite); - doubleContainer.setPosition(12, 38); + if (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) { + tObjPartnerSprite.setScale(0.20); + tObjSprite.setScale(0.20); + doubleContainer.add(tObjSprite); + doubleContainer.add(tObjPartnerSprite); + doubleContainer.setPosition(12, 38); + } else { + tObjSprite.setScale(0.75); + tObjPartnerSprite.setScale(0.75); + doubleContainer.add([tObjSprite, tObjPartnerSprite]); + doubleContainer.setPosition(8, 14); + } enemyContainer.add(doubleContainer); } else { - tObjSprite.setScale(0.35, 0.35); - tObjSprite.setPosition(12, 28); + const scale = (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) ? 0.35 : 1; + const position = (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) ? [12, 28] : [28, 12]; + tObjSprite.setScale(scale, scale); + tObjSprite.setPosition(position[0], position[1]); enemyContainer.add(tObjSprite); } }); + } + /** + * This edits a container to represent a loss from a defeat by a trainer battle. + * @param enemyContainer - container holding enemy visuals and level information + * The trainers are placed to the left of their party. + * Depending on the trainer icon, there may be overlap between the edges of the box or their party. (Capes...) + * + * Party Pokemon have their icons, terastalization status, and level shown. + */ + private parseTrainerDefeat(enemyContainer: Phaser.GameObjects.Container) { + // Load trainer sprites + this.loadTrainerSprites(enemyContainer); // Determining which Terastallize Modifier belongs to which Pokemon // Creates a dictionary {PokemonId: TeraShardType} const teraPokemon = {}; diff --git a/src/ui/save-slot-select-ui-handler.ts b/src/ui/save-slot-select-ui-handler.ts index 89b20322a68..22e3891d160 100644 --- a/src/ui/save-slot-select-ui-handler.ts +++ b/src/ui/save-slot-select-ui-handler.ts @@ -10,6 +10,7 @@ import MessageUiHandler from "./message-ui-handler"; import { TextStyle, addTextObject } from "./text"; import { Mode } from "./ui"; import { addWindow } from "./ui-theme"; +import { RunDisplayMode } from "#app/ui/run-info-ui-handler"; const sessionSlotCount = 5; @@ -162,6 +163,10 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler { success = this.setScrollCursor(this.scrollCursor + 1); } break; + case Button.RIGHT: + if (this.sessionSlots[this.cursor].hasData) { + this.scene.ui.setOverlayMode(Mode.RUN_INFO, this.sessionSlots[this.cursor].saveData, RunDisplayMode.SAVE_PREVIEW); + } } } @@ -253,6 +258,7 @@ class SessionSlot extends Phaser.GameObjects.Container { public slotId: integer; public hasData: boolean; private loadingLabel: Phaser.GameObjects.Text; + public saveData: SessionSaveData; constructor(scene: BattleScene, slotId: integer) { super(scene, 0, slotId * 56); @@ -337,6 +343,7 @@ class SessionSlot extends Phaser.GameObjects.Container { return; } this.hasData = true; + this.saveData = sessionData; await this.setupWithData(sessionData); resolve(true); });