Let's see

This commit is contained in:
frutescens 2024-09-24 17:11:57 -07:00
parent 60931d3f25
commit b2939453d2
4 changed files with 83 additions and 117 deletions

View File

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

View File

@ -12,6 +12,7 @@ import { BattleType } from "../battle";
import { RunEntry } from "../system/game-data"; import { RunEntry } from "../system/game-data";
import { PlayerGender } from "#enums/player-gender"; import { PlayerGender } from "#enums/player-gender";
import { TrainerVariant } from "../field/trainer"; import { TrainerVariant } from "../field/trainer";
import { RunDisplayMode } from "#app/ui/run-info-ui-handler";
export type RunSelectCallback = (cursor: number) => void; export type RunSelectCallback = (cursor: number) => void;
@ -104,7 +105,7 @@ export default class RunHistoryUiHandler extends MessageUiHandler {
if (button === Button.ACTION) { if (button === Button.ACTION) {
const cursor = this.cursor + this.scrollCursor; const cursor = this.cursor + this.scrollCursor;
if (this.runs[cursor]) { 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 { } else {
return false; return false;
} }

View File

@ -22,6 +22,7 @@ import * as Modifier from "../modifier/modifier";
import { Species } from "#enums/species"; import { Species } from "#enums/species";
import { PlayerGender } from "#enums/player-gender"; import { PlayerGender } from "#enums/player-gender";
import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard";
import { getBiomeName } from "#app/data/biomes";
/** /**
* RunInfoUiMode indicates possible overlays of RunInfoUiHandler. * RunInfoUiMode indicates possible overlays of RunInfoUiHandler.
@ -34,6 +35,11 @@ enum RunInfoUiMode {
ENDING_ART 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. * 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. * These variables will most likely be shared across 'classes' aka pages.
@ -41,6 +47,7 @@ enum RunInfoUiMode {
* For now, I leave as is. * For now, I leave as is.
*/ */
export default class RunInfoUiHandler extends UiHandler { export default class RunInfoUiHandler extends UiHandler {
protected runDisplayMode: RunDisplayMode;
protected runInfo: SessionSaveData; protected runInfo: SessionSaveData;
protected isVictory: boolean; protected isVictory: boolean;
protected pageMode: RunInfoUiMode; protected pageMode: RunInfoUiMode;
@ -87,9 +94,15 @@ export default class RunInfoUiHandler extends UiHandler {
this.runContainer.add(gameStatsBg); this.runContainer.add(gameStatsBg);
const run = args[0]; 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 // 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; this.pageMode = RunInfoUiMode.MAIN;
// Creates Header and adds to this.runContainer // 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); const runResultWindow = addWindow(this.scene, 0, 0, this.statsBgWidth-11, 65);
runResultWindow.setOrigin(0, 0); runResultWindow.setOrigin(0, 0);
this.runResultContainer.add(runResultWindow); 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 // Creates Run Info Container
this.runInfoContainer = this.scene.add.container(0, 89); this.runInfoContainer = this.scene.add.container(0, 89);
@ -226,6 +243,31 @@ export default class RunInfoUiHandler extends UiHandler {
this.runContainer.add(this.runResultContainer); 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. * 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 * @param enemyContainer - container holding enemy visual and level information
@ -277,15 +319,7 @@ export default class RunInfoUiHandler extends UiHandler {
enemyContainer.setPosition(8, 14); enemyContainer.setPosition(8, 14);
} }
/** private loadTrainerSprites(enemyContainer: Phaser.GameObjects.Container) {
* 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) {
// Creating the trainer sprite and adding it to enemyContainer // Creating the trainer sprite and adding it to enemyContainer
const tObj = this.runInfo.trainer.toTrainer(this.scene); 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 tObjPartnerSpriteKey = tObj.config.getSpriteKey(true, true);
const tObjPartnerSprite = this.scene.add.sprite(5, -3, tObjPartnerSpriteKey); const tObjPartnerSprite = this.scene.add.sprite(5, -3, tObjPartnerSpriteKey);
// Double Trainers have smaller sprites than Single Trainers // Double Trainers have smaller sprites than Single Trainers
tObjPartnerSprite.setScale(0.20); if (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) {
tObjSprite.setScale(0.20); tObjPartnerSprite.setScale(0.20);
doubleContainer.add(tObjSprite); tObjSprite.setScale(0.20);
doubleContainer.add(tObjPartnerSprite); doubleContainer.add(tObjSprite);
doubleContainer.setPosition(12, 38); 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); enemyContainer.add(doubleContainer);
} else { } else {
tObjSprite.setScale(0.35, 0.35); const scale = (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) ? 0.35 : 1;
tObjSprite.setPosition(12, 28); const position = (this.runDisplayMode === RunDisplayMode.RUN_HISTORY) ? [12, 28] : [28, 12];
tObjSprite.setScale(scale, scale);
tObjSprite.setPosition(position[0], position[1]);
enemyContainer.add(tObjSprite); 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 // Determining which Terastallize Modifier belongs to which Pokemon
// Creates a dictionary {PokemonId: TeraShardType} // Creates a dictionary {PokemonId: TeraShardType}
const teraPokemon = {}; const teraPokemon = {};

View File

@ -10,6 +10,7 @@ import MessageUiHandler from "./message-ui-handler";
import { TextStyle, addTextObject } from "./text"; import { TextStyle, addTextObject } from "./text";
import { Mode } from "./ui"; import { Mode } from "./ui";
import { addWindow } from "./ui-theme"; import { addWindow } from "./ui-theme";
import { RunDisplayMode } from "#app/ui/run-info-ui-handler";
const sessionSlotCount = 5; const sessionSlotCount = 5;
@ -162,6 +163,10 @@ export default class SaveSlotSelectUiHandler extends MessageUiHandler {
success = this.setScrollCursor(this.scrollCursor + 1); success = this.setScrollCursor(this.scrollCursor + 1);
} }
break; 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 slotId: integer;
public hasData: boolean; public hasData: boolean;
private loadingLabel: Phaser.GameObjects.Text; private loadingLabel: Phaser.GameObjects.Text;
public saveData: SessionSaveData;
constructor(scene: BattleScene, slotId: integer) { constructor(scene: BattleScene, slotId: integer) {
super(scene, 0, slotId * 56); super(scene, 0, slotId * 56);
@ -337,6 +343,7 @@ class SessionSlot extends Phaser.GameObjects.Container {
return; return;
} }
this.hasData = true; this.hasData = true;
this.saveData = sessionData;
await this.setupWithData(sessionData); await this.setupWithData(sessionData);
resolve(true); resolve(true);
}); });