From b116828b075aa726e291102b0470e79a299a63ff Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Tue, 16 Apr 2024 15:58:02 -0400 Subject: [PATCH] Convert biome select UI handler to option select --- src/battle-scene.ts | 1 - src/data/move.ts | 2 +- src/phases.ts | 25 +++++- src/ui/biome-select-ui-handler.ts | 134 ------------------------------ src/ui/ui.ts | 3 - 5 files changed, 22 insertions(+), 143 deletions(-) delete mode 100644 src/ui/biome-select-ui-handler.ts diff --git a/src/battle-scene.ts b/src/battle-scene.ts index c94522d3af5..c75e44bf694 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -1246,7 +1246,6 @@ export default class BattleScene extends SceneBase { case Mode.SAVE_SLOT: case Mode.PARTY: case Mode.SUMMARY: - case Mode.BIOME_SELECT: case Mode.STARTER_SELECT: case Mode.CONFIRM: case Mode.OPTION_SELECT: diff --git a/src/data/move.ts b/src/data/move.ts index 42c7f5ed322..938a911f057 100644 --- a/src/data/move.ts +++ b/src/data/move.ts @@ -94,7 +94,7 @@ export default class Move { constructor(id: Moves, type: Type, category: MoveCategory, defaultMoveTarget: MoveTarget, power: integer, accuracy: integer, pp: integer, chance: integer, priority: integer, generation: integer) { this.id = id; - const i18nKey = Moves[id].split('_').filter(f => f).map((f, i) => i ? `${f[0]}${f.slice(1).toLowerCase()}` : f.toLowerCase()).join('') as string; + const i18nKey = Moves[id].split('_').filter(f => f).map((f, i) => i ? `${f[0]}${f.slice(1).toLowerCase()}` : f.toLowerCase()).join('') as unknown as string; this.name = id ? i18next.t(`move:${i18nKey}.name`) as string : ''; this.type = type; diff --git a/src/phases.ts b/src/phases.ts index 6a1716a8fc6..6ec1cfdf853 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -16,7 +16,7 @@ import EvolutionSceneHandler from "./ui/evolution-scene-handler"; import { EvolutionPhase } from "./evolution-phase"; import { Phase } from "./phase"; import { BattleStat, getBattleStatLevelChangeDescription, getBattleStatName } from "./data/battle-stat"; -import { biomeLinks } from "./data/biomes"; +import { biomeLinks, getBiomeName } from "./data/biomes"; import { Biome } from "./data/enums/biome"; import { ModifierTier } from "./modifier/modifier-tier"; import { FusePokemonModifierType, ModifierPoolType, ModifierType, ModifierTypeFunc, ModifierTypeOption, PokemonModifierType, PokemonMoveModifierType, RememberMoveModifierType, TmModifierType, getDailyRunStarterModifiers, getEnemyBuffModifierForWave, getModifierType, getPlayerModifierTypeOptions, getPlayerShopModifierTypeOptionsForWave, modifierTypes, regenerateModifierPoolThresholds } from "./modifier/modifier-type"; @@ -1034,9 +1034,26 @@ export class SelectBiomePhase extends BattlePhase { .map(b => !Array.isArray(b) ? b : b[0]); }, this.scene.currentBattle.waveIndex); if (biomes.length > 1 && this.scene.findModifier(m => m instanceof MapModifier)) { - this.scene.ui.setMode(Mode.BIOME_SELECT, currentBiome, (biomeIndex: integer) => { - this.scene.ui.setMode(Mode.MESSAGE); - setNextBiome(biomes[biomeIndex]); + let biomeChoices: Biome[]; + this.scene.executeWithSeedOffset(() => { + biomeChoices = (!Array.isArray(biomeLinks[currentBiome]) + ? [ biomeLinks[currentBiome] as Biome ] + : biomeLinks[currentBiome] as (Biome | [Biome, integer])[]) + .filter((b, i) => !Array.isArray(b) || !Utils.randSeedInt(b[1])) + .map(b => Array.isArray(b) ? b[0] : b); + }, this.scene.currentBattle.waveIndex); + const biomeSelectItems = biomeChoices.map(b => { + return { + label: getBiomeName(b), + handler: () => { + this.scene.ui.setMode(Mode.MESSAGE); + setNextBiome(b); + } + }; + }); + this.scene.ui.setMode(Mode.OPTION_SELECT, { + options: biomeSelectItems, + delay: 1000 }); } else setNextBiome(biomes[Utils.randSeedInt(biomes.length)]); diff --git a/src/ui/biome-select-ui-handler.ts b/src/ui/biome-select-ui-handler.ts deleted file mode 100644 index 083a13d020e..00000000000 --- a/src/ui/biome-select-ui-handler.ts +++ /dev/null @@ -1,134 +0,0 @@ -import BattleScene, { Button } from "../battle-scene"; -import { biomeLinks, getBiomeName } from "../data/biomes"; -import { Biome } from "../data/enums/biome"; -import { addTextObject, TextStyle } from "./text"; -import { Mode } from "./ui"; -import UiHandler from "./ui-handler"; -import * as Utils from "../utils"; -import { addWindow } from "./ui-theme"; - -export default class BiomeSelectUiHandler extends UiHandler { - private biomeSelectContainer: Phaser.GameObjects.Container; - private biomeSelectBg: Phaser.GameObjects.NineSlice; - private biomesText: Phaser.GameObjects.Text; - private biomeChoices: Biome[]; - - private cursorObj: Phaser.GameObjects.Image; - - private blockInput: boolean; - - private biomeSelectHandler: Function; - - constructor(scene: BattleScene) { - super(scene, Mode.BIOME_SELECT); - } - - setup() { - const ui = this.getUi(); - - this.biomeSelectContainer = this.scene.add.container((this.scene.game.canvas.width / 6) - 97, -49); - this.biomeSelectContainer.setVisible(false); - ui.add(this.biomeSelectContainer); - - this.biomeSelectBg = addWindow(this.scene, 0, 0, 96, 32); - this.biomeSelectBg.setOrigin(0, 1); - this.biomeSelectContainer.add(this.biomeSelectBg); - - this.biomesText = addTextObject(this.scene, 0, 0, '', TextStyle.WINDOW, { maxLines: 3 }); - this.biomesText.setLineSpacing(12); - this.biomeSelectContainer.add(this.biomesText); - } - - show(args: any[]): boolean { - if (args.length >= 2 && typeof(args[0]) === 'number' && args[1] instanceof Function) { - super.show(args); - - this.scene.executeWithSeedOffset(() => { - this.biomeChoices = (!Array.isArray(biomeLinks[args[0]]) - ? [ biomeLinks[args[0]] as Biome ] - : biomeLinks[args[0]] as (Biome | [Biome, integer])[]) - .filter((b, i) => !Array.isArray(b) || !Utils.randSeedInt(b[1])) - .map(b => Array.isArray(b) ? b[0] : b); - }, this.scene.currentBattle.waveIndex); - - if (this.biomeChoices.length <= 1) - return; - - this.biomeSelectBg.height = (this.biomeChoices.length + 1) * 16; - this.biomesText.setText(this.biomeChoices.map(b => getBiomeName(b)).join('\n')); - this.biomesText.setPositionRelative(this.biomeSelectBg, 16, 9); - this.biomeSelectHandler = args[1] as Function; - - this.biomeSelectContainer.setVisible(true); - this.setCursor(0); - - this.blockInput = true; - this.biomesText.setAlpha(0.5); - this.scene.time.delayedCall(Utils.fixedInt(1000), () => { - this.blockInput = false; - this.biomesText.setAlpha(1); - }); - } - - return true; - } - - processInput(button: Button): boolean { - const ui = this.getUi(); - - let success = false; - - if (button === Button.ACTION || button === Button.CANCEL) { - if (this.blockInput) - return false; - - success = true; - const originalBiomeSelectHandler = this.biomeSelectHandler; - this.biomeSelectHandler = null; - originalBiomeSelectHandler(this.cursor); - this.clear(); - } else { - switch (button) { - case Button.UP: - if (this.cursor) - success = this.setCursor(this.cursor - 1); - break; - case Button.DOWN: - if (this.cursor < this.biomeChoices.length - 1) - success = this.setCursor(this.cursor + 1); - break; - } - } - - if (success) - ui.playSelect(); - - return success; - } - - setCursor(cursor: integer): boolean { - const ret = super.setCursor(cursor); - - if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, 'cursor'); - this.biomeSelectContainer.add(this.cursorObj); - } - - this.cursorObj.setPositionRelative(this.biomeSelectBg, 12, 17 + 16 * this.cursor); - - return ret; - } - - clear() { - super.clear(); - this.biomeSelectContainer.setVisible(false); - this.biomeSelectHandler = null; - this.eraseCursor(); - } - - eraseCursor() { - if (this.cursorObj) - this.cursorObj.destroy(); - this.cursorObj = null; - } -} \ No newline at end of file diff --git a/src/ui/ui.ts b/src/ui/ui.ts index 82eead45eb4..f1fe29d9035 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -11,7 +11,6 @@ import BallUiHandler from './ball-ui-handler'; import SummaryUiHandler from './summary-ui-handler'; import StarterSelectUiHandler from './starter-select-ui-handler'; import EvolutionSceneHandler from './evolution-scene-handler'; -import BiomeSelectUiHandler from './biome-select-ui-handler'; import TargetSelectUiHandler from './target-select-ui-handler'; import SettingsUiHandler from './settings-ui-handler'; import { TextStyle, addTextObject } from './text'; @@ -47,7 +46,6 @@ export enum Mode { SAVE_SLOT, PARTY, SUMMARY, - BIOME_SELECT, STARTER_SELECT, EVOLUTION_SCENE, EGG_HATCH_SCENE, @@ -127,7 +125,6 @@ export default class UI extends Phaser.GameObjects.Container { new SaveSlotSelectUiHandler(scene), new PartyUiHandler(scene), new SummaryUiHandler(scene), - new BiomeSelectUiHandler(scene), new StarterSelectUiHandler(scene), new EvolutionSceneHandler(scene), new EggHatchSceneHandler(scene),