From 70f7ab89f326e69c6a4ce43b024f28469747f513 Mon Sep 17 00:00:00 2001 From: Wlowscha <54003515+Wlowscha@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:11:12 +0100 Subject: [PATCH] Introducing globalScene everywhere --- src/ui/base-stats-overlay.ts | 25 +-- src/ui/filter-bar.ts | 6 +- src/ui/filter-text.ts | 36 ++-- src/ui/pokedex-info-overlay.ts | 29 +-- src/ui/pokedex-page-ui-handler.ts | 271 +++++++++++++------------- src/ui/pokedex-scan-ui-handler.ts | 11 +- src/ui/pokedex-ui-handler.ts | 305 ++++++++++++++---------------- 7 files changed, 330 insertions(+), 353 deletions(-) diff --git a/src/ui/base-stats-overlay.ts b/src/ui/base-stats-overlay.ts index 9bae1da7999..30520bdf3ec 100644 --- a/src/ui/base-stats-overlay.ts +++ b/src/ui/base-stats-overlay.ts @@ -1,8 +1,9 @@ -import BattleScene, { InfoToggle } from "../battle-scene"; +import type { InfoToggle } from "../battle-scene"; import { TextStyle, addTextObject } from "./text"; import { addWindow } from "./ui-theme"; import * as Utils from "../utils"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; export interface BaseStatsOverlaySettings { scale?:number; // scale the box? A scale of 0.5 is recommended @@ -33,35 +34,35 @@ export default class BaseStatsOverlay extends Phaser.GameObjects.Container imple public scale: number; public width: number; - constructor(scene: BattleScene, options?: BaseStatsOverlaySettings) { - super(scene, options?.x, options?.y); + constructor(options?: BaseStatsOverlaySettings) { + super(globalScene, options?.x, options?.y); this.scale = options?.scale || 1; // set up the scale this.setScale(this.scale); this.options = options || {}; // prepare the description box - this.width = (options?.width || BaseStatsOverlay.getWidth(this.scale, scene)) / this.scale; // divide by scale as we always want this to be half a window wide - this.statsBg = addWindow(scene, 0, 0, this.width, HEIGHT); + this.width = (options?.width || BaseStatsOverlay.getWidth(this.scale)) / this.scale; // divide by scale as we always want this to be half a window wide + this.statsBg = addWindow(0, 0, this.width, HEIGHT); this.statsBg.setOrigin(0, 0); this.add(this.statsBg); for (let i = 0; i < 6; i++) { - const shadow = this.scene.add.rectangle(this.width - BORDER + 1, BORDER + 3 + i * 15, 100, 5, 0x006860); + const shadow = globalScene.add.rectangle(this.width - BORDER + 1, BORDER + 3 + i * 15, 100, 5, 0x006860); shadow.setOrigin(1, 0); this.statsShadows.push(shadow); this.add(shadow); - const rectangle = this.scene.add.rectangle(this.width - BORDER, BORDER + 2 + i * 15, 100, 5, 0x66aa99); + const rectangle = globalScene.add.rectangle(this.width - BORDER, BORDER + 2 + i * 15, 100, 5, 0x66aa99); rectangle.setOrigin(1, 0); this.statsRectangles.push(rectangle); this.add(rectangle); - const label = addTextObject(scene, BORDER, BORDER - 2 + i * 15, "A", TextStyle.BATTLE_INFO); + const label = addTextObject(BORDER, BORDER - 2 + i * 15, "A", TextStyle.BATTLE_INFO); this.statsLabels.push(label); this.add(label); } - this.statsTotalLabel = addTextObject(scene, BORDER, BORDER + 6 * 15, "A", TextStyle.MONEY_WINDOW); + this.statsTotalLabel = addTextObject(BORDER, BORDER + 6 * 15, "A", TextStyle.MONEY_WINDOW); this.add(this.statsTotalLabel); // hide this component for now @@ -96,7 +97,7 @@ export default class BaseStatsOverlay extends Phaser.GameObjects.Container imple if (visible) { this.setVisible(true); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.statsLabels, duration: Utils.fixedInt(125), ease: "Sine.easeInOut", @@ -112,8 +113,8 @@ export default class BaseStatsOverlay extends Phaser.GameObjects.Container imple } // width of this element - static getWidth(scale:number, scene: BattleScene):number { - return scene.game.canvas.width / GLOBAL_SCALE / 2; + static getWidth(scale:number):number { + return globalScene.game.canvas.width / GLOBAL_SCALE / 2; } // height of this element diff --git a/src/ui/filter-bar.ts b/src/ui/filter-bar.ts index fa807b41551..1eba81247d4 100644 --- a/src/ui/filter-bar.ts +++ b/src/ui/filter-bar.ts @@ -48,8 +48,6 @@ export class FilterBar extends Phaser.GameObjects.Container { this.cursorObj.setVisible(false); this.cursorObj.setOrigin(0, 0); this.add(this.cursorObj); - - this.uiTheme = globalScene.uiTheme; } /** @@ -94,9 +92,9 @@ export class FilterBar extends Phaser.GameObjects.Container { updateFilterLabels(): void { for (let i = 0; i < this.numFilters; i++) { if (this.dropDowns[i].hasDefaultValues()) { - this.labels[i].setColor(getTextColor(TextStyle.TOOLTIP_CONTENT, false, this.uiTheme)); + this.labels[i].setColor(getTextColor(TextStyle.TOOLTIP_CONTENT, false, globalScene.uiTheme)); } else { - this.labels[i].setColor(getTextColor(TextStyle.STATS_LABEL, false, this.uiTheme)); + this.labels[i].setColor(getTextColor(TextStyle.STATS_LABEL, false, globalScene.uiTheme)); } } } diff --git a/src/ui/filter-text.ts b/src/ui/filter-text.ts index 5aeea3a955d..22f8b6e8ac5 100644 --- a/src/ui/filter-text.ts +++ b/src/ui/filter-text.ts @@ -1,11 +1,12 @@ -import BattleScene from "#app/battle-scene"; -import { StarterContainer } from "./starter-container"; +import type { StarterContainer } from "./starter-container"; import { addTextObject, getTextColor, TextStyle } from "./text"; -import { UiTheme } from "#enums/ui-theme"; +import type { UiTheme } from "#enums/ui-theme"; import { addWindow, WindowVariant } from "./ui-theme"; import i18next from "i18next"; -import AwaitableUiHandler from "./awaitable-ui-handler"; -import UI, { Mode } from "./ui"; +import type AwaitableUiHandler from "./awaitable-ui-handler"; +import type UI from "./ui"; +import { Mode } from "./ui"; +import { globalScene } from "#app/global-scene"; export enum FilterTextRow{ NAME, @@ -38,36 +39,33 @@ export class FilterText extends Phaser.GameObjects.Container { public defaultText: string = "---"; - constructor(scene: BattleScene, x: number, y: number, width: number, height: number, onChange: () => void,) { - super(scene, x, y); + constructor(x: number, y: number, width: number, height: number, onChange: () => void,) { + super(globalScene, x, y); this.onChange = onChange; this.width = width; this.height = height; - this.window = addWindow(scene, 0, 0, width, height, false, false, undefined, undefined, WindowVariant.THIN); + this.window = addWindow(0, 0, width, height, false, false, undefined, undefined, WindowVariant.THIN); this.add(this.window); - this.cursorObj = this.scene.add.image(1, 1, "cursor"); + this.cursorObj = globalScene.add.image(1, 1, "cursor"); this.cursorObj.setScale(0.5); this.cursorObj.setVisible(false); this.cursorObj.setOrigin(0, 0); this.add(this.cursorObj); - this.uiTheme = scene.uiTheme; - - - this.menuMessageBoxContainer = this.scene.add.container(0, 130); + this.menuMessageBoxContainer = globalScene.add.container(0, 130); this.menuMessageBoxContainer.setName("menu-message-box"); this.menuMessageBoxContainer.setVisible(false); // Full-width window used for testing dialog messages in debug mode - this.dialogueMessageBox = addWindow(scene, -this.textPadding, 0, this.scene.game.canvas.width / 6 + this.textPadding * 2, 49, false, false, 0, 0, WindowVariant.THIN); + this.dialogueMessageBox = addWindow(-this.textPadding, 0, globalScene.game.canvas.width / 6 + this.textPadding * 2, 49, false, false, 0, 0, WindowVariant.THIN); this.dialogueMessageBox.setOrigin(0, 0); this.menuMessageBoxContainer.add(this.dialogueMessageBox); - const menuMessageText = addTextObject(this.scene, this.textPadding, this.textPadding, "", TextStyle.WINDOW, { maxLines: 2 }); + const menuMessageText = addTextObject(this.textPadding, this.textPadding, "", TextStyle.WINDOW, { maxLines: 2 }); menuMessageText.setName("menu-message"); menuMessageText.setOrigin(0, 0); this.menuMessageBoxContainer.add(menuMessageText); @@ -99,11 +97,11 @@ export class FilterText extends Phaser.GameObjects.Container { this.rows.push(row); - const filterTypesLabel = addTextObject(this.scene, paddingX + cursorOffset, 3, title, TextStyle.TOOLTIP_CONTENT); + const filterTypesLabel = addTextObject(paddingX + cursorOffset, 3, title, TextStyle.TOOLTIP_CONTENT); this.labels.push(filterTypesLabel); this.add(filterTypesLabel); - const filterTypesSelection = addTextObject(this.scene, paddingX + cursorOffset + extraSpaceX, 3, this.defaultText, TextStyle.TOOLTIP_CONTENT); + const filterTypesSelection = addTextObject(paddingX + cursorOffset + extraSpaceX, 3, this.defaultText, TextStyle.TOOLTIP_CONTENT); this.selections.push(filterTypesSelection); this.add(filterTypesSelection); @@ -170,9 +168,9 @@ export class FilterText extends Phaser.GameObjects.Container { updateFilterLabels(): void { for (let i = 0; i < this.numFilters; i++) { if (this.selections[i].text === this.defaultText) { - this.labels[i].setColor(getTextColor(TextStyle.TOOLTIP_CONTENT, false, this.uiTheme)); + this.labels[i].setColor(getTextColor(TextStyle.TOOLTIP_CONTENT, false, globalScene.uiTheme)); } else { - this.labels[i].setColor(getTextColor(TextStyle.STATS_LABEL, false, this.uiTheme)); + this.labels[i].setColor(getTextColor(TextStyle.STATS_LABEL, false, globalScene.uiTheme)); } } } diff --git a/src/ui/pokedex-info-overlay.ts b/src/ui/pokedex-info-overlay.ts index f47eaaadef6..fe0b47b57e0 100644 --- a/src/ui/pokedex-info-overlay.ts +++ b/src/ui/pokedex-info-overlay.ts @@ -1,8 +1,9 @@ -import BattleScene, { InfoToggle } from "../battle-scene"; +import type { InfoToggle } from "../battle-scene"; import { TextStyle, addTextObject } from "./text"; import { addWindow } from "./ui-theme"; import * as Utils from "../utils"; import i18next from "i18next"; +import { globalScene } from "#app/global-scene"; export interface PokedexInfoOverlaySettings { delayVisibility?: boolean; // if true, showing the overlay will only set it to active and populate the fields and the handler using this field has to manually call setVisible later. @@ -38,20 +39,20 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp public scale: number; public width: number; - constructor(scene: BattleScene, options?: PokedexInfoOverlaySettings) { - super(scene, options?.x, options?.y); + constructor(options?: PokedexInfoOverlaySettings) { + super(globalScene, options?.x, options?.y); this.scale = options?.scale || 1; // set up the scale this.setScale(this.scale); this.options = options || {}; // prepare the description box - this.width = (options?.width || PokedexInfoOverlay.getWidth(this.scale, scene)) / this.scale; // divide by scale as we always want this to be half a window wide - this.descBg = addWindow(scene, 0, 0, this.width, DESC_HEIGHT); + this.width = (options?.width || PokedexInfoOverlay.getWidth(this.scale)) / this.scale; // divide by scale as we always want this to be half a window wide + this.descBg = addWindow(0, 0, this.width, DESC_HEIGHT); this.descBg.setOrigin(0, 0); this.add(this.descBg); // set up the description; wordWrap uses true pixels, unaffected by any scaling, while other values are affected - this.desc = addTextObject(scene, BORDER, BORDER - 2, "", TextStyle.BATTLE_INFO, { wordWrap: { width: (this.width - (BORDER - 2) * 2) * GLOBAL_SCALE }}); + this.desc = addTextObject(BORDER, BORDER - 2, "", TextStyle.BATTLE_INFO, { wordWrap: { width: (this.width - (BORDER - 2) * 2) * GLOBAL_SCALE }}); this.desc.setLineSpacing(i18next.resolvedLanguage === "ja" ? 25 : 5); // limit the text rendering, required for scrolling later on @@ -59,13 +60,13 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp this.maskPointOriginY = options?.y || 0; if (this.maskPointOriginX < 0) { - this.maskPointOriginX += this.scene.game.canvas.width / GLOBAL_SCALE; + this.maskPointOriginX += globalScene.game.canvas.width / GLOBAL_SCALE; } if (this.maskPointOriginY < 0) { - this.maskPointOriginY += this.scene.game.canvas.height / GLOBAL_SCALE; + this.maskPointOriginY += globalScene.game.canvas.height / GLOBAL_SCALE; } - this.textMaskRect = this.scene.make.graphics(); + this.textMaskRect = globalScene.make.graphics(); this.textMaskRect.fillStyle(0xFF0000); this.textMaskRect.fillRect( this.maskPointOriginX + BORDER * this.scale, this.maskPointOriginY + (BORDER - 2) * this.scale, @@ -86,7 +87,7 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp // show this component with infos for the specific move show(text: string):boolean { - if (!(this.scene as BattleScene).enableMoveInfo) { + if (!globalScene.enableMoveInfo) { return false; // move infos have been disabled // TODO:: is `false` correct? i used to be `undeefined` } @@ -120,7 +121,7 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp if (lineCount > 3) { // generate scrolling effects - this.descScroll = this.scene.tweens.add({ + this.descScroll = globalScene.tweens.add({ targets: this.desc, delay: Utils.fixedInt(2000), loop: -1, @@ -146,7 +147,7 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp if (visible) { this.setVisible(true); } - this.scene.tweens.add({ + globalScene.tweens.add({ targets: this.desc, duration: Utils.fixedInt(125), ease: "Sine.easeInOut", @@ -162,8 +163,8 @@ export default class PokedexInfoOverlay extends Phaser.GameObjects.Container imp } // width of this element - static getWidth(scale:number, scene: BattleScene):number { - return scene.game.canvas.width / GLOBAL_SCALE / 2; + static getWidth(scale:number):number { + return globalScene.game.canvas.width / GLOBAL_SCALE / 2; } // height of this element diff --git a/src/ui/pokedex-page-ui-handler.ts b/src/ui/pokedex-page-ui-handler.ts index 7148de6fb3c..9a201330130 100644 --- a/src/ui/pokedex-page-ui-handler.ts +++ b/src/ui/pokedex-page-ui-handler.ts @@ -1,8 +1,11 @@ -import { EvolutionItem, pokemonEvolutions, pokemonPrevolutions, pokemonStarters, SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions"; -import { Variant, getVariantTint, getVariantIcon } from "#app/data/variant"; +import type { SpeciesFormEvolution } from "#app/data/balance/pokemon-evolutions"; +import { EvolutionItem, pokemonEvolutions, pokemonPrevolutions, pokemonStarters } from "#app/data/balance/pokemon-evolutions"; +import type { Variant } from "#app/data/variant"; +import { getVariantTint, getVariantIcon } from "#app/data/variant"; import { argbFromRgba } from "@material/material-color-utilities"; import i18next from "i18next"; -import BattleScene, { AnySound, starterColors } from "#app/battle-scene"; +import type { AnySound } from "#app/battle-scene"; +import { starterColors } from "#app/battle-scene"; import { allAbilities } from "#app/data/ability"; import { speciesEggMoves } from "#app/data/balance/egg-moves"; import { GrowthRate, getGrowthRateColor } from "#app/data/exp"; @@ -10,14 +13,18 @@ import { Gender, getGenderColor, getGenderSymbol } from "#app/data/gender"; import { allMoves } from "#app/data/move"; import { getNatureName } from "#app/data/nature"; import { pokemonFormChanges } from "#app/data/pokemon-forms"; -import { LevelMoves, pokemonFormLevelMoves, pokemonSpeciesLevelMoves } from "#app/data/balance/pokemon-level-moves"; -import PokemonSpecies, { allSpecies, getPokemonSpeciesForm, PokemonForm } from "#app/data/pokemon-species"; +import type { LevelMoves } from "#app/data/balance/pokemon-level-moves"; +import { pokemonFormLevelMoves, pokemonSpeciesLevelMoves } from "#app/data/balance/pokemon-level-moves"; +import type { PokemonForm } from "#app/data/pokemon-species"; +import type PokemonSpecies from "#app/data/pokemon-species"; +import { allSpecies, getPokemonSpeciesForm } from "#app/data/pokemon-species"; import { getStarterValueFriendshipCap, speciesStarterCosts } from "#app/data/balance/starters"; import { starterPassiveAbilities } from "#app/data/balance/passives"; import { Type } from "#enums/type"; import { GameModes } from "#app/game-mode"; -import { AbilityAttr, DexAttr, DexEntry, StarterAttributes } from "#app/system/game-data"; -import { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; +import type { DexEntry, StarterAttributes } from "#app/system/game-data"; +import { AbilityAttr, DexAttr } from "#app/system/game-data"; +import type { OptionSelectItem } from "#app/ui/abstact-option-select-ui-handler"; import MessageUiHandler from "#app/ui/message-ui-handler"; import { StatsContainer } from "#app/ui/stats-container"; import { TextStyle, addTextObject, getTextStyleOptions } from "#app/ui/text"; @@ -32,7 +39,7 @@ import MoveInfoOverlay from "#app/ui/move-info-overlay"; import PokedexInfoOverlay from "#app/ui/pokedex-info-overlay"; import { getEggTierForSpecies } from "#app/data/egg"; import { Device } from "#enums/devices"; -import { Moves } from "#enums/moves"; +import type { Moves } from "#enums/moves"; import { Species } from "#enums/species"; import { Button } from "#enums/buttons"; import { EggSourceType } from "#enums/egg-source-types"; @@ -43,11 +50,13 @@ import type { Nature } from "#enums/nature"; import BgmBar from "./bgm-bar"; import * as Utils from "../utils"; import { speciesTmMoves } from "#app/data/balance/tms"; -import { BiomePoolTier, BiomeTierTod, catchableSpecies } from "#app/data/balance/biomes"; +import type { BiomeTierTod } from "#app/data/balance/biomes"; +import { BiomePoolTier, catchableSpecies } from "#app/data/balance/biomes"; import { Biome } from "#app/enums/biome"; import { TimeOfDay } from "#app/enums/time-of-day"; -import { Abilities } from "#app/enums/abilities"; +import type { Abilities } from "#app/enums/abilities"; import BaseStatsOverlay from "./base-stats-overlay"; +import { globalScene } from "#app/global-scene"; interface LanguageSetting { @@ -238,8 +247,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { protected scale: number = 0.1666666667; private menuDescriptions: string[]; - constructor(scene: BattleScene) { - super(scene, Mode.POKEDEX_PAGE); + constructor() { + super(Mode.POKEDEX_PAGE); } setup() { @@ -248,49 +257,49 @@ export default class PokedexPageUiHandler extends MessageUiHandler { const langSettingKey = Object.keys(languageSettings).find(lang => currentLanguage.includes(lang)) ?? "en"; const textSettings = languageSettings[langSettingKey]; - this.starterSelectContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.starterSelectContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); this.starterSelectContainer.setVisible(false); ui.add(this.starterSelectContainer); - const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860); + const bgColor = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0x006860); bgColor.setOrigin(0, 0); this.starterSelectContainer.add(bgColor); - const starterSelectBg = this.scene.add.image(0, 0, "pokedex_summary_bg"); + const starterSelectBg = globalScene.add.image(0, 0, "pokedex_summary_bg"); starterSelectBg.setOrigin(0, 0); this.starterSelectContainer.add(starterSelectBg); - this.shinyOverlay = this.scene.add.image(6, 6, "summary_overlay_shiny"); + this.shinyOverlay = globalScene.add.image(6, 6, "summary_overlay_shiny"); this.shinyOverlay.setOrigin(0, 0); this.shinyOverlay.setVisible(false); this.starterSelectContainer.add(this.shinyOverlay); - this.pokemonNumberText = addTextObject(this.scene, 17, 1, "0000", TextStyle.SUMMARY); + this.pokemonNumberText = addTextObject(17, 1, "0000", TextStyle.SUMMARY); this.pokemonNumberText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNumberText); - this.pokemonNameText = addTextObject(this.scene, 6, 112, "", TextStyle.SUMMARY); + this.pokemonNameText = addTextObject(6, 112, "", TextStyle.SUMMARY); this.pokemonNameText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNameText); - this.pokemonGrowthRateLabelText = addTextObject(this.scene, 8, 106, i18next.t("pokedexUiHandler:growthRate"), TextStyle.SUMMARY_ALT, { fontSize: "36px" }); + this.pokemonGrowthRateLabelText = addTextObject(8, 106, i18next.t("pokedexUiHandler:growthRate"), TextStyle.SUMMARY_ALT, { fontSize: "36px" }); this.pokemonGrowthRateLabelText.setOrigin(0, 0); this.pokemonGrowthRateLabelText.setVisible(false); this.starterSelectContainer.add(this.pokemonGrowthRateLabelText); - this.pokemonGrowthRateText = addTextObject(this.scene, 34, 106, "", TextStyle.SUMMARY_PINK, { fontSize: "36px" }); + this.pokemonGrowthRateText = addTextObject(34, 106, "", TextStyle.SUMMARY_PINK, { fontSize: "36px" }); this.pokemonGrowthRateText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonGrowthRateText); - this.pokemonGenderText = addTextObject(this.scene, 96, 112, "", TextStyle.SUMMARY_ALT); + this.pokemonGenderText = addTextObject(96, 112, "", TextStyle.SUMMARY_ALT); this.pokemonGenderText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonGenderText); - this.pokemonUncaughtText = addTextObject(this.scene, 6, 127, i18next.t("pokedexUiHandler:uncaught"), TextStyle.WINDOW, { fontSize: "56px" }); + this.pokemonUncaughtText = addTextObject(6, 127, i18next.t("pokedexUiHandler:uncaught"), TextStyle.WINDOW, { fontSize: "56px" }); this.pokemonUncaughtText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonUncaughtText); - const starterBoxContainer = this.scene.add.container(speciesContainerX + 6, 9); //115 + const starterBoxContainer = globalScene.add.container(speciesContainerX + 6, 9); //115 for (const species of allSpecies) { if (!speciesStarterCosts.hasOwnProperty(species.speciesId) || !species.isObtainable()) { @@ -300,161 +309,161 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.speciesLoaded.set(species.speciesId, false); this.allSpecies.push(species); - const starterContainer = new StarterContainer(this.scene, species).setVisible(false); + const starterContainer = new StarterContainer(species).setVisible(false); this.starterContainers.push(starterContainer); starterBoxContainer.add(starterContainer); } this.starterSelectContainer.add(starterBoxContainer); - this.pokemonSprite = this.scene.add.sprite(53, 63, "pkmn__sub"); - this.pokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + this.pokemonSprite = globalScene.add.sprite(53, 63, "pkmn__sub"); + this.pokemonSprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); this.starterSelectContainer.add(this.pokemonSprite); - this.type1Icon = this.scene.add.sprite(8, 98, getLocalizedSpriteKey("types")); + this.type1Icon = globalScene.add.sprite(8, 98, getLocalizedSpriteKey("types")); this.type1Icon.setScale(0.5); this.type1Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type1Icon); - this.type2Icon = this.scene.add.sprite(26, 98, getLocalizedSpriteKey("types")); + this.type2Icon = globalScene.add.sprite(26, 98, getLocalizedSpriteKey("types")); this.type2Icon.setScale(0.5); this.type2Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type2Icon); - this.pokemonLuckLabelText = addTextObject(this.scene, 8, 89, i18next.t("common:luckIndicator"), TextStyle.WINDOW_ALT, { fontSize: "56px" }); + this.pokemonLuckLabelText = addTextObject(8, 89, i18next.t("common:luckIndicator"), TextStyle.WINDOW_ALT, { fontSize: "56px" }); this.pokemonLuckLabelText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonLuckLabelText); - this.pokemonLuckText = addTextObject(this.scene, 8 + this.pokemonLuckLabelText.displayWidth + 2, 89, "0", TextStyle.WINDOW, { fontSize: "56px" }); + this.pokemonLuckText = addTextObject(8 + this.pokemonLuckLabelText.displayWidth + 2, 89, "0", TextStyle.WINDOW, { fontSize: "56px" }); this.pokemonLuckText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonLuckText); // Candy icon and count - this.pokemonCandyContainer = this.scene.add.container(4.5, 18); + this.pokemonCandyContainer = globalScene.add.container(4.5, 18); - this.pokemonCandyIcon = this.scene.add.sprite(0, 0, "candy"); + this.pokemonCandyIcon = globalScene.add.sprite(0, 0, "candy"); this.pokemonCandyIcon.setScale(0.5); this.pokemonCandyIcon.setOrigin(0, 0); this.pokemonCandyContainer.add(this.pokemonCandyIcon); - this.pokemonCandyOverlayIcon = this.scene.add.sprite(0, 0, "candy_overlay"); + this.pokemonCandyOverlayIcon = globalScene.add.sprite(0, 0, "candy_overlay"); this.pokemonCandyOverlayIcon.setScale(0.5); this.pokemonCandyOverlayIcon.setOrigin(0, 0); this.pokemonCandyContainer.add(this.pokemonCandyOverlayIcon); - this.pokemonCandyDarknessOverlay = this.scene.add.sprite(0, 0, "candy"); + this.pokemonCandyDarknessOverlay = globalScene.add.sprite(0, 0, "candy"); this.pokemonCandyDarknessOverlay.setScale(0.5); this.pokemonCandyDarknessOverlay.setOrigin(0, 0); this.pokemonCandyDarknessOverlay.setTint(0x000000); this.pokemonCandyDarknessOverlay.setAlpha(0.50); this.pokemonCandyContainer.add(this.pokemonCandyDarknessOverlay); - this.pokemonCandyCountText = addTextObject(this.scene, 9.5, 0, "x0", TextStyle.WINDOW_ALT, { fontSize: "56px" }); + this.pokemonCandyCountText = addTextObject(9.5, 0, "x0", TextStyle.WINDOW_ALT, { fontSize: "56px" }); this.pokemonCandyCountText.setOrigin(0, 0); this.pokemonCandyContainer.add(this.pokemonCandyCountText); this.pokemonCandyContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, 30, 20), Phaser.Geom.Rectangle.Contains); this.starterSelectContainer.add(this.pokemonCandyContainer); - this.pokemonFormText = addTextObject(this.scene, 6, 42, "Form", TextStyle.WINDOW_ALT, { fontSize: "42px" }); + this.pokemonFormText = addTextObject(6, 42, "Form", TextStyle.WINDOW_ALT, { fontSize: "42px" }); this.pokemonFormText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonFormText); - this.pokemonCaughtHatchedContainer = this.scene.add.container(2, 25); + this.pokemonCaughtHatchedContainer = globalScene.add.container(2, 25); this.pokemonCaughtHatchedContainer.setScale(0.5); this.starterSelectContainer.add(this.pokemonCaughtHatchedContainer); - const pokemonCaughtIcon = this.scene.add.sprite(1, 0, "items", "pb"); + const pokemonCaughtIcon = globalScene.add.sprite(1, 0, "items", "pb"); pokemonCaughtIcon.setOrigin(0, 0); pokemonCaughtIcon.setScale(0.75); this.pokemonCaughtHatchedContainer.add(pokemonCaughtIcon); - this.pokemonCaughtCountText = addTextObject(this.scene, 24, 4, "0", TextStyle.SUMMARY_ALT); + this.pokemonCaughtCountText = addTextObject(24, 4, "0", TextStyle.SUMMARY_ALT); this.pokemonCaughtCountText.setOrigin(0, 0); this.pokemonCaughtHatchedContainer.add(this.pokemonCaughtCountText); - this.pokemonHatchedIcon = this.scene.add.sprite(1, 14, "egg_icons"); + this.pokemonHatchedIcon = globalScene.add.sprite(1, 14, "egg_icons"); this.pokemonHatchedIcon.setOrigin(0.15, 0.2); this.pokemonHatchedIcon.setScale(0.8); this.pokemonCaughtHatchedContainer.add(this.pokemonHatchedIcon); - this.pokemonShinyIcon = this.scene.add.sprite(14, 76, "shiny_icons"); + this.pokemonShinyIcon = globalScene.add.sprite(14, 76, "shiny_icons"); this.pokemonShinyIcon.setOrigin(0.15, 0.2); this.pokemonShinyIcon.setScale(1); this.pokemonCaughtHatchedContainer.add(this.pokemonShinyIcon); - this.pokemonHatchedCountText = addTextObject(this.scene, 24, 19, "0", TextStyle.SUMMARY_ALT); + this.pokemonHatchedCountText = addTextObject(24, 19, "0", TextStyle.SUMMARY_ALT); this.pokemonHatchedCountText.setOrigin(0, 0); this.pokemonCaughtHatchedContainer.add(this.pokemonHatchedCountText); // The font size should be set per language const instructionTextSize = textSettings.instructionTextSize; - this.instructionsContainer = this.scene.add.container(4, 128); + this.instructionsContainer = globalScene.add.container(4, 128); this.instructionsContainer.setVisible(true); this.starterSelectContainer.add(this.instructionsContainer); - this.candyUpgradeIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "C.png"); + this.candyUpgradeIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "C.png"); this.candyUpgradeIconElement.setName("sprite-candyUpgrade-icon-element"); this.candyUpgradeIconElement.setScale(0.675); this.candyUpgradeIconElement.setOrigin(0.0, 0.0); - this.candyUpgradeLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:candyUpgrade"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.candyUpgradeLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:candyUpgrade"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.candyUpgradeLabel.setName("text-candyUpgrade-label"); // instruction rows that will be pushed into the container dynamically based on need // creating new sprites since they will be added to the scene later - this.shinyIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "R.png"); + this.shinyIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "R.png"); this.shinyIconElement.setName("sprite-shiny-icon-element"); this.shinyIconElement.setScale(0.675); this.shinyIconElement.setOrigin(0.0, 0.0); - this.shinyLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleShiny"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.shinyLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleShiny"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.shinyLabel.setName("text-shiny-label"); - this.formIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "F.png"); + this.formIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "F.png"); this.formIconElement.setName("sprite-form-icon-element"); this.formIconElement.setScale(0.675); this.formIconElement.setOrigin(0.0, 0.0); - this.formLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleForm"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.formLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleForm"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.formLabel.setName("text-form-label"); - this.genderIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "G.png"); + this.genderIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "G.png"); this.genderIconElement.setName("sprite-gender-icon-element"); this.genderIconElement.setScale(0.675); this.genderIconElement.setOrigin(0.0, 0.0); - this.genderLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleGender"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.genderLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleGender"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.genderLabel.setName("text-gender-label"); - this.variantIconElement = new Phaser.GameObjects.Sprite(this.scene, this.instructionRowX, this.instructionRowY, "keyboard", "V.png"); + this.variantIconElement = new Phaser.GameObjects.Sprite(globalScene, this.instructionRowX, this.instructionRowY, "keyboard", "V.png"); this.variantIconElement.setName("sprite-variant-icon-element"); this.variantIconElement.setScale(0.675); this.variantIconElement.setOrigin(0.0, 0.0); - this.variantLabel = addTextObject(this.scene, this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleVariant"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.variantLabel = addTextObject(this.instructionRowX + this.instructionRowTextOffset, this.instructionRowY, i18next.t("pokedexUiHandler:cycleVariant"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.variantLabel.setName("text-variant-label"); this.hideInstructions(); - this.filterInstructionsContainer = this.scene.add.container(50, 5); + this.filterInstructionsContainer = globalScene.add.container(50, 5); this.filterInstructionsContainer.setVisible(true); this.starterSelectContainer.add(this.filterInstructionsContainer); - this.starterSelectMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6); + this.starterSelectMessageBoxContainer = globalScene.add.container(0, globalScene.game.canvas.height / 6); this.starterSelectMessageBoxContainer.setVisible(false); this.starterSelectContainer.add(this.starterSelectMessageBoxContainer); - this.starterSelectMessageBox = addWindow(this.scene, 1, -1, 318, 28); + this.starterSelectMessageBox = addWindow(1, -1, 318, 28); this.starterSelectMessageBox.setOrigin(0, 1); this.starterSelectMessageBoxContainer.add(this.starterSelectMessageBox); - this.message = addTextObject(this.scene, 8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); + this.message = addTextObject(8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); this.message.setOrigin(0, 0); this.starterSelectMessageBoxContainer.add(this.message); // arrow icon for the message box this.initPromptSprite(this.starterSelectMessageBoxContainer); - this.statsContainer = new StatsContainer(this.scene, 6, 16); + this.statsContainer = new StatsContainer(6, 16); - this.scene.add.existing(this.statsContainer); + globalScene.add.existing(this.statsContainer); this.statsContainer.setVisible(false); @@ -462,11 +471,11 @@ export default class PokedexPageUiHandler extends MessageUiHandler { // Adding menu container - this.menuContainer = this.scene.add.container(-130, 0); + this.menuContainer = globalScene.add.container(-130, 0); this.menuContainer.setName("menu"); - this.menuContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); + this.menuContainer.setInteractive(new Phaser.Geom.Rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6), Phaser.Geom.Rectangle.Contains); - this.bgmBar = new BgmBar(this.scene); + this.bgmBar = new BgmBar(); this.bgmBar.setup(); ui.bgmBar = this.bgmBar; this.menuContainer.add(this.bgmBar); @@ -474,7 +483,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.menuOptions = Utils.getEnumKeys(MenuOptions).map(m => parseInt(MenuOptions[m]) as MenuOptions); - this.optionSelectText = addTextObject(this.scene, 0, 0, this.menuOptions.map(o => `${i18next.t(`pokedexUiHandler:${MenuOptions[o]}`)}`).join("\n"), TextStyle.WINDOW, { maxLines: this.menuOptions.length }); + this.optionSelectText = addTextObject(0, 0, this.menuOptions.map(o => `${i18next.t(`pokedexUiHandler:${MenuOptions[o]}`)}`).join("\n"), TextStyle.WINDOW, { maxLines: this.menuOptions.length }); this.optionSelectText.setLineSpacing(12); this.menuDescriptions = [ @@ -489,12 +498,12 @@ export default class PokedexPageUiHandler extends MessageUiHandler { i18next.t("pokedexUiHandler:showEvolutions") ]; - this.scale = getTextStyleOptions(TextStyle.WINDOW, (this.scene as BattleScene).uiTheme).scale; - this.menuBg = addWindow(this.scene, - (this.scene.game.canvas.width / 6) - (this.optionSelectText.displayWidth + 25), + this.scale = getTextStyleOptions(TextStyle.WINDOW, globalScene.uiTheme).scale; + this.menuBg = addWindow( + (globalScene.game.canvas.width / 6) - (this.optionSelectText.displayWidth + 25), 0, this.optionSelectText.displayWidth + 19 + 24 * this.scale, - (this.scene.game.canvas.height / 6) - 2 + (globalScene.game.canvas.height / 6) - 2 ); this.menuBg.setOrigin(0, 0); @@ -510,24 +519,24 @@ export default class PokedexPageUiHandler extends MessageUiHandler { // adding base stats - this.baseStatsOverlay = new BaseStatsOverlay(this.scene, { x: 317, y: 0, width:133 }); + this.baseStatsOverlay = new BaseStatsOverlay({ x: 317, y: 0, width:133 }); this.menuContainer.add(this.baseStatsOverlay); this.menuContainer.bringToTop(this.baseStatsOverlay); // add the info overlay last to be the top most ui element and prevent the IVs from overlaying this const overlayScale = 1; - this.moveInfoOverlay = new MoveInfoOverlay(this.scene, { + this.moveInfoOverlay = new MoveInfoOverlay({ scale: overlayScale, top: true, x: 1, - y: this.scene.game.canvas.height / 6 - MoveInfoOverlay.getHeight(overlayScale) - 29, + y: globalScene.game.canvas.height / 6 - MoveInfoOverlay.getHeight(overlayScale) - 29, }); this.starterSelectContainer.add(this.moveInfoOverlay); - this.infoOverlay = new PokedexInfoOverlay(this.scene, { + this.infoOverlay = new PokedexInfoOverlay({ scale: overlayScale, x: 1, - y: this.scene.game.canvas.height / 6 - PokedexInfoOverlay.getHeight(overlayScale) - 29, + y: globalScene.game.canvas.height / 6 - PokedexInfoOverlay.getHeight(overlayScale) - 29, }); this.starterSelectContainer.add(this.infoOverlay); @@ -570,7 +579,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { const key = this.lastSpecies.getCryKey(this.lastFormIndex); const rate = 0.85; - this.scene.playSound(key, { rate: rate }) as AnySound; + globalScene.playSound(key, { rate: rate }) as AnySound; return true; @@ -612,13 +621,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } this.eggMoves = speciesEggMoves[this.getStarterSpeciesId(species.speciesId)] ?? []; - this.hasEggMoves = Array.from({ length: 4 }, (_, em) => (this.scene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)].eggMoves & (1 << em)) !== 0); + this.hasEggMoves = Array.from({ length: 4 }, (_, em) => (globalScene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)].eggMoves & (1 << em)) !== 0); this.tmMoves = (speciesTmMoves[species.speciesId] ?? []).sort((a, b) => allMoves[a].name > allMoves[b].name ? 1 : -1); this.passive = starterPassiveAbilities[this.getStarterSpeciesId(species.speciesId)]; - const starterData = this.scene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)]; + const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)]; const abilityAttr = starterData.abilityAttr; this.hasPassive = starterData.passiveAttr > 0; @@ -728,8 +737,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { */ initStarterPrefs(): StarterAttributes { const starterAttributes = this.starterAttributes; - const dexEntry = this.scene.gameData.dexData[this.lastSpecies.speciesId]; - const starterData = this.scene.gameData.starterData[this.getStarterSpeciesId(this.lastSpecies.speciesId)]; + const dexEntry = globalScene.gameData.dexData[this.lastSpecies.speciesId]; + const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(this.lastSpecies.speciesId)]; // no preferences or Pokemon wasn't caught, return empty attribute if (!starterAttributes || !dexEntry.caughtAttr) { @@ -788,13 +797,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } const selectedForm = starterAttributes.form; - if (selectedForm !== undefined && (this.lastSpecies.forms[selectedForm]?.isStarterSelectable && !(caughtAttr & this.scene.gameData.getFormAttr(selectedForm)))) { + if (selectedForm !== undefined && (this.lastSpecies.forms[selectedForm]?.isStarterSelectable && !(caughtAttr & globalScene.gameData.getFormAttr(selectedForm)))) { // requested form wasn't unlocked and is selectable as a starter delete starterAttributes.form; } if (starterAttributes.nature !== undefined) { - const unlockedNatures = this.scene.gameData.getNaturesForAttr(dexEntry.natureAttr); + const unlockedNatures = globalScene.gameData.getNaturesForAttr(dexEntry.natureAttr); if (unlockedNatures.indexOf(starterAttributes.nature as unknown as Nature) < 0) { // requested nature wasn't unlocked, purging setting delete starterAttributes.nature; @@ -816,7 +825,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.starterSelectMessageBoxContainer.setY(0); this.message.setY(4); } else { - this.starterSelectMessageBoxContainer.setY(this.scene.game.canvas.height / 6); + this.starterSelectMessageBoxContainer.setY(globalScene.game.canvas.height / 6); this.starterSelectMessageBox.setOrigin(0, 1); this.message.setY(singleLine ? -22 : -37); } @@ -829,18 +838,18 @@ export default class PokedexPageUiHandler extends MessageUiHandler { * @returns true if upgrade notifications are enabled and set to display an 'Icon' */ isUpgradeIconEnabled(): boolean { - return this.scene.candyUpgradeNotification !== 0 && this.scene.candyUpgradeDisplay === 0; + return globalScene.candyUpgradeNotification !== 0 && globalScene.candyUpgradeDisplay === 0; } /** * Determines if 'Animation' based upgrade notifications should be shown * @returns true if upgrade notifications are enabled and set to display an 'Animation' */ isUpgradeAnimationEnabled(): boolean { - return this.scene.candyUpgradeNotification !== 0 && this.scene.candyUpgradeDisplay === 1; + return globalScene.candyUpgradeNotification !== 0 && globalScene.candyUpgradeDisplay === 1; } getStarterSpeciesId(speciesId): number { - if (this.scene.gameData.starterData.hasOwnProperty(speciesId)) { + if (globalScene.gameData.starterData.hasOwnProperty(speciesId)) { return speciesId; } else { return pokemonStarters[speciesId]; @@ -848,7 +857,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } getStarterSpecies(species): PokemonSpecies { - if (this.scene.gameData.starterData.hasOwnProperty(species.speciesId)) { + if (globalScene.gameData.starterData.hasOwnProperty(species.speciesId)) { return species; } else { return allSpecies.find(sp => sp.speciesId === pokemonStarters[species.speciesId]) ?? species; @@ -917,7 +926,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } } else { - const starterData = this.scene.gameData.starterData[this.getStarterSpeciesId(this.lastSpecies.speciesId)]; + const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(this.lastSpecies.speciesId)]; // prepare persistent starter data to store changes const starterAttributes = this.starterAttributes; @@ -1357,7 +1366,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { }); this.evolutions.map(evo => { const evoSpecies = allSpecies.find(species => species.speciesId === evo.speciesId); - const evoSpeciesStarterDexEntry = evoSpecies ? this.scene.gameData.dexData[evoSpecies.speciesId] : null; + const evoSpeciesStarterDexEntry = evoSpecies ? globalScene.gameData.dexData[evoSpecies.speciesId] : null; const isCaughtEvo = evoSpeciesStarterDexEntry?.caughtAttr ? true : false; options.push({ label: evo.evoFormKey ? @@ -1467,11 +1476,11 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.blockInput = true; ui.setMode(Mode.POKEDEX_PAGE, "refresh").then(() => { ui.showText(i18next.t("pokedexUiHandler:showNature"), null, () => { - const natures = this.scene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr); + const natures = globalScene.gameData.getNaturesForAttr(this.speciesStarterDexEntry?.natureAttr); ui.setModeWithoutClear(Mode.OPTION_SELECT, { options: natures.map((n: Nature, i: number) => { const option: OptionSelectItem = { - label: getNatureName(n, true, true, true, this.scene.uiTheme), + label: getNatureName(n, true, true, true, globalScene.uiTheme), handler: () => { return false; } @@ -1497,7 +1506,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } } else { - const props = this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)); + const props = globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, this.getCurrentDexProps(this.lastSpecies.speciesId)); switch (button) { case Button.CYCLE_SHINY: if (this.canCycleShiny) { @@ -1508,7 +1517,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { const newVariant = starterAttributes.variant ? starterAttributes.variant as Variant : 0; this.setSpeciesDetails(this.lastSpecies, { shiny: true, variant: newVariant }); - this.scene.playSound("se/sparkle"); + globalScene.playSound("se/sparkle"); // Set the variant label to the shiny tint const tint = getVariantTint(newVariant); this.pokemonShinyIcon.setFrame(getVariantIcon(newVariant)); @@ -1555,7 +1564,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { let newFormIndex = this.lastFormIndex; do { newFormIndex = (newFormIndex + 1) % formCount; - if (this.speciesStarterDexEntry!.caughtAttr! & this.scene.gameData.getFormAttr(newFormIndex)) { // TODO: are those bangs correct? + if (this.speciesStarterDexEntry!.caughtAttr! & globalScene.gameData.getFormAttr(newFormIndex)) { // TODO: are those bangs correct? break; } } while (newFormIndex !== props.formIndex); @@ -1596,14 +1605,14 @@ export default class PokedexPageUiHandler extends MessageUiHandler { starterData.candyCount -= passiveCost; } this.pokemonCandyCountText.setText(`x${starterData.candyCount}`); - this.scene.gameData.saveSystem().then(success => { + globalScene.gameData.saveSystem().then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } }); ui.setMode(Mode.POKEDEX_PAGE, "refresh"); this.setSpeciesDetails(this.lastSpecies); - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); return true; } @@ -1627,13 +1636,13 @@ export default class PokedexPageUiHandler extends MessageUiHandler { starterData.candyCount -= reductionCost; } this.pokemonCandyCountText.setText(`x${starterData.candyCount}`); - this.scene.gameData.saveSystem().then(success => { + globalScene.gameData.saveSystem().then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } }); ui.setMode(Mode.POKEDEX_PAGE, "refresh"); - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); return true; } @@ -1650,7 +1659,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { label: `x${sameSpeciesEggCost} ${i18next.t("pokedexUiHandler:sameSpeciesEgg")}`, handler: () => { if (Overrides.FREE_CANDY_UPGRADE_OVERRIDE || candyCount >= sameSpeciesEggCost) { - if (this.scene.gameData.eggs.length >= 99 && !Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { + if (globalScene.gameData.eggs.length >= 99 && !Overrides.UNLIMITED_EGG_COUNT_OVERRIDE) { // Egg list full, show error message at the top of the screen and abort this.showText(i18next.t("egg:tooManyEggs"), undefined, () => this.showText("", 0, () => this.tutorialActive = false), 2000, false, undefined, true); return false; @@ -1660,16 +1669,16 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } this.pokemonCandyCountText.setText(`x${starterData.candyCount}`); - const egg = new Egg({ scene: this.scene, species: this.lastSpecies.speciesId, sourceType: EggSourceType.SAME_SPECIES_EGG }); - egg.addEggToGameData(this.scene); + const egg = new Egg({ scene: globalScene, species: this.lastSpecies.speciesId, sourceType: EggSourceType.SAME_SPECIES_EGG }); + egg.addEggToGameData(); - this.scene.gameData.saveSystem().then(success => { + globalScene.gameData.saveSystem().then(success => { if (!success) { - return this.scene.reset(true); + return globalScene.reset(true); } }); ui.setMode(Mode.POKEDEX_PAGE, "refresh"); - this.scene.playSound("se/buy"); + globalScene.playSound("se/buy"); return true; } @@ -1750,7 +1759,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { break; } } else { - iconPath = this.scene.inputController?.getIconForLatestInputRecorded(iconSetting); + iconPath = globalScene.inputController?.getIconForLatestInputRecorded(iconSetting); } iconElement.setTexture(gamepadType, iconPath); iconElement.setPosition(this.instructionRowX, this.instructionRowY); @@ -1774,10 +1783,10 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.instructionsContainer.removeAll(); this.filterInstructionsContainer.removeAll(); let gamepadType; - if (this.scene.inputMethod === "gamepad") { - gamepadType = this.scene.inputController.getConfig(this.scene.inputController.selectedDevice[Device.GAMEPAD]).padType; + if (globalScene.inputMethod === "gamepad") { + gamepadType = globalScene.inputController.getConfig(globalScene.inputController.selectedDevice[Device.GAMEPAD]).padType; } else { - gamepadType = this.scene.inputMethod; + gamepadType = globalScene.inputMethod; } if (!gamepadType) { @@ -1805,7 +1814,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { getValueLimit(): number { const valueLimit = new NumberHolder(0); - switch (this.scene.gameMode.modeId) { + switch (globalScene.gameMode.modeId) { case GameModes.ENDLESS: case GameModes.SPLICED_ENDLESS: valueLimit.value = 15; @@ -1814,7 +1823,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { valueLimit.value = 10; } - Challenge.applyChallenges(this.scene.gameMode, Challenge.ChallengeType.STARTER_POINTS, valueLimit); + Challenge.applyChallenges(globalScene.gameMode, Challenge.ChallengeType.STARTER_POINTS, valueLimit); return valueLimit.value; } @@ -1824,7 +1833,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { const ret = super.setCursor(cursor); if (!this.cursorObj) { - this.cursorObj = this.scene.add.image(0, 0, "cursor"); + this.cursorObj = globalScene.add.image(0, 0, "cursor"); this.cursorObj.setOrigin(0, 0); this.menuContainer.add(this.cursorObj); } @@ -1843,7 +1852,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } getFriendship(speciesId: number) { - let currentFriendship = this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)].friendship; + let currentFriendship = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].friendship; if (!currentFriendship || currentFriendship === undefined) { currentFriendship = 0; } @@ -1854,10 +1863,10 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } setSpecies(species: PokemonSpecies | null) { - this.speciesStarterDexEntry = species ? this.scene.gameData.dexData[species.speciesId] : null; + this.speciesStarterDexEntry = species ? globalScene.gameData.dexData[species.speciesId] : null; - if (!species && this.scene.ui.getTooltip().visible) { - this.scene.ui.hideTooltip(); + if (!species && globalScene.ui.getTooltip().visible) { + globalScene.ui.hideTooltip(); } const starterAttributes : StarterAttributes | null = species ? { ...this.starterAttributes } : null; @@ -1887,7 +1896,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { if (this.speciesStarterDexEntry?.caughtAttr) { const colorScheme = starterColors[species.speciesId]; - const luck = this.scene.gameData.getDexAttrLuck(this.speciesStarterDexEntry.caughtAttr); + const luck = globalScene.gameData.getDexAttrLuck(this.speciesStarterDexEntry.caughtAttr); this.pokemonLuckText.setVisible(!!luck); this.pokemonLuckText.setText(luck.toString()); this.pokemonLuckText.setTint(getVariantTint(Math.min(luck - 1, 2) as Variant)); @@ -1914,7 +1923,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.pokemonHatchedCountText.setText(`${this.speciesStarterDexEntry.hatchedCount}`); const defaultDexAttr = this.getCurrentDexProps(species.speciesId); - const defaultProps = this.scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const defaultProps = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); const variant = defaultProps.variant; const tint = getVariantTint(variant); this.pokemonShinyIcon.setFrame(getVariantIcon(variant)); @@ -1938,7 +1947,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.pokemonShinyIcon.setY(117); this.pokemonCandyIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[0]))); this.pokemonCandyOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(colorScheme[1]))); - this.pokemonCandyCountText.setText(`x${this.scene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)].candyCount}`); + this.pokemonCandyCountText.setText(`x${globalScene.gameData.starterData[this.getStarterSpeciesId(species.speciesId)].candyCount}`); this.pokemonCandyContainer.setVisible(true); this.pokemonFormText.setY(42); this.pokemonHatchedIcon.setVisible(true); @@ -1949,18 +1958,18 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.pokemonCandyDarknessOverlay.setCrop(0, 0, 16, candyCropY); this.pokemonCandyContainer.on("pointerover", () => { - this.scene.ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true); + globalScene.ui.showTooltip("", `${currentFriendship}/${friendshipCap}`, true); this.activeTooltip = "CANDY"; }); this.pokemonCandyContainer.on("pointerout", () => { - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); this.activeTooltip = undefined; }); } // load default nature from stater save data, if set - const props: StarterAttributes = this.scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const props: StarterAttributes = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); if (starterAttributes?.variant && !isNaN(starterAttributes.variant)) { if (props.shiny) { props.variant = starterAttributes.variant as Variant; @@ -1993,8 +2002,8 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.pokemonCandyContainer.setVisible(false); this.pokemonFormText.setVisible(false); - const defaultDexAttr = this.scene.gameData.getSpeciesDefaultDexAttr(species, true, true); - const props = this.scene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); + const defaultDexAttr = globalScene.gameData.getSpeciesDefaultDexAttr(species, true, true); + const props = globalScene.gameData.getSpeciesDexAttrProps(species, defaultDexAttr); this.setSpeciesDetails(species, { shiny: props.shiny, @@ -2043,9 +2052,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler { if (this.activeTooltip === "CANDY") { if (this.lastSpecies && this.pokemonCandyContainer.visible) { const { currentFriendship, friendshipCap } = this.getFriendship(this.lastSpecies.speciesId); - this.scene.ui.editTooltip("", `${currentFriendship}/${friendshipCap}`); + globalScene.ui.editTooltip("", `${currentFriendship}/${friendshipCap}`); } else { - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); } } @@ -2081,9 +2090,9 @@ export default class PokedexPageUiHandler extends MessageUiHandler { } if (species) { - const dexEntry = this.scene.gameData.dexData[species.speciesId]; + const dexEntry = globalScene.gameData.dexData[species.speciesId]; - const caughtAttr = this.scene.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0); + const caughtAttr = globalScene.gameData.dexData[species.speciesId]?.caughtAttr || BigInt(0); if (!dexEntry.caughtAttr) { const props = this.starterAttributes; @@ -2111,7 +2120,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.assetLoadCancelled = assetLoadCancelled; if (shouldUpdateSprite) { - species.loadAssets(this.scene, female!, formIndex, shiny, variant as Variant, true).then(() => { // TODO: is this bang correct? + species.loadAssets(female!, formIndex, shiny, variant as Variant, true).then(() => { // TODO: is this bang correct? if (assetLoadCancelled.value) { return; } @@ -2148,7 +2157,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.canCycleGender = isMaleCaught && isFemaleCaught; this.canCycleForm = species.forms.filter(f => f.isStarterSelectable || !pokemonFormChanges[species.speciesId]?.find(fc => fc.formKey)) - .map((_, f) => dexEntry.caughtAttr & this.scene.gameData.getFormAttr(f)).filter(f => f).length > 1; + .map((_, f) => dexEntry.caughtAttr & globalScene.gameData.getFormAttr(f)).filter(f => f).length > 1; if (dexEntry.caughtAttr && species.malePercent !== null) { @@ -2206,7 +2215,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { */ getCurrentDexProps(speciesId: number): bigint { let props = 0n; - const caughtAttr = this.scene.gameData.dexData[speciesId].caughtAttr; + const caughtAttr = globalScene.gameData.dexData[speciesId].caughtAttr; /* this checks the gender of the pokemon; this works by checking a) that the starter preferences for the species exist, and if so, is it female. If so, it'll add DexAttr.FEMALE to our temp props * It then checks b) if the caughtAttr for the pokemon is female and NOT male - this means that the ONLY gender we've gotten is female, and we need to add DexAttr.FEMALE to our temp props @@ -2244,7 +2253,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { props += BigInt(Math.pow(2, this.starterAttributes?.form)) * DexAttr.DEFAULT_FORM; } else { // Get the first unlocked form - props += this.scene.gameData.getFormAttr(this.scene.gameData.getFormIndex(caughtAttr)); + props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr)); } return props; @@ -2301,7 +2310,7 @@ export default class PokedexPageUiHandler extends MessageUiHandler { this.cursor = -1; this.hideInstructions(); this.activeTooltip = undefined; - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); this.starterSelectContainer.setVisible(false); this.blockInput = false; diff --git a/src/ui/pokedex-scan-ui-handler.ts b/src/ui/pokedex-scan-ui-handler.ts index 524ab76bd83..37727d85a73 100644 --- a/src/ui/pokedex-scan-ui-handler.ts +++ b/src/ui/pokedex-scan-ui-handler.ts @@ -1,7 +1,8 @@ -import { FormModalUiHandler, InputFieldConfig } from "./form-modal-ui-handler"; -import { ModalConfig } from "./modal-ui-handler"; -import { PlayerPokemon } from "#app/field/pokemon"; -import { OptionSelectItem } from "./abstact-option-select-ui-handler"; +import type { InputFieldConfig } from "./form-modal-ui-handler"; +import { FormModalUiHandler } from "./form-modal-ui-handler"; +import type { ModalConfig } from "./modal-ui-handler"; +import type { PlayerPokemon } from "#app/field/pokemon"; +import type { OptionSelectItem } from "./abstact-option-select-ui-handler"; import { isNullOrUndefined } from "#app/utils"; import { Mode } from "./ui"; import { FilterTextRow } from "./filter-text"; @@ -21,7 +22,7 @@ export default class PokedexScanUiHandler extends FormModalUiHandler { row: number; constructor(scene, mode) { - super(scene, mode); + super(mode); } setup() { diff --git a/src/ui/pokedex-ui-handler.ts b/src/ui/pokedex-ui-handler.ts index 8c891fd80e1..4f3cf8afd9e 100644 --- a/src/ui/pokedex-ui-handler.ts +++ b/src/ui/pokedex-ui-handler.ts @@ -1,25 +1,26 @@ -import { BattleSceneEventType, CandyUpgradeNotificationChangedEvent } from "#app/events/battle-scene"; -import { Variant, getVariantTint, getVariantIcon } from "#app/data/variant"; +import type { Variant } from "#app/data/variant"; +import { getVariantTint, getVariantIcon } from "#app/data/variant"; import { argbFromRgba } from "@material/material-color-utilities"; import i18next from "i18next"; -import BattleScene, { starterColors } from "#app/battle-scene"; +import { starterColors } from "#app/battle-scene"; import { speciesEggMoves } from "#app/data/balance/egg-moves"; import { pokemonFormLevelMoves, pokemonSpeciesLevelMoves } from "#app/data/balance/pokemon-level-moves"; -import PokemonSpecies, { allSpecies, getPokemonSpeciesForm, getPokerusStarters, PokemonForm } from "#app/data/pokemon-species"; +import type { PokemonForm } from "#app/data/pokemon-species"; +import type PokemonSpecies from "#app/data/pokemon-species"; +import { allSpecies, getPokemonSpeciesForm, getPokerusStarters } from "#app/data/pokemon-species"; import { getStarterValueFriendshipCap, speciesStarterCosts, POKERUS_STARTER_COUNT } from "#app/data/balance/starters"; import { catchableSpecies } from "#app/data/balance/biomes"; import { Type } from "#enums/type"; -import { AbilityAttr, DexAttr, DexAttrProps, DexEntry, StarterMoveset, StarterAttributes, StarterPreferences, StarterPrefs } from "#app/system/game-data"; -import { Tutorial, handleTutorial } from "#app/tutorial"; +import type { DexAttrProps, DexEntry, StarterMoveset, StarterAttributes, StarterPreferences } from "#app/system/game-data"; +import { AbilityAttr, DexAttr, StarterPrefs } from "#app/system/game-data"; import MessageUiHandler from "#app/ui/message-ui-handler"; import PokemonIconAnimHandler, { PokemonIconAnimMode } from "#app/ui/pokemon-icon-anim-handler"; import { TextStyle, addTextObject } from "#app/ui/text"; import { Mode } from "#app/ui/ui"; -//import { addWindow } from "#app/ui/ui-theme"; import { SettingKeyboard } from "#app/system/settings/settings-keyboard"; import { Passive as PassiveAttr } from "#enums/passive"; -import { Moves } from "#enums/moves"; -import { Species } from "#enums/species"; +import type { Moves } from "#enums/moves"; +import type { Species } from "#enums/species"; import { Button } from "#enums/buttons"; import { DropDown, DropDownLabel, DropDownOption, DropDownState, DropDownType, SortCriteria } from "#app/ui/dropdown"; import { StarterContainer } from "#app/ui/starter-container"; @@ -30,7 +31,7 @@ import { getPassiveCandyCount, getValueReductionCandyCounts, getSameSpeciesEggCa import { BooleanHolder, fixedInt, getLocalizedSpriteKey, padInt, randIntRange, rgbHexToRgba } from "#app/utils"; import type { Nature } from "#enums/nature"; import { addWindow } from "./ui-theme"; -import { OptionSelectConfig } from "./abstact-option-select-ui-handler"; +import type { OptionSelectConfig } from "./abstact-option-select-ui-handler"; import { FilterText, FilterTextRow } from "./filter-text"; import { allAbilities } from "#app/data/ability"; import { starterPassiveAbilities } from "#app/data/balance/passives"; @@ -38,6 +39,7 @@ import { allMoves } from "#app/data/move"; import { speciesTmMoves } from "#app/data/balance/tms"; import { pokemonStarters } from "#app/data/balance/pokemon-evolutions"; import { Biome } from "#enums/biome"; +import { globalScene } from "#app/global-scene"; // We don't need this interface here @@ -223,8 +225,8 @@ export default class PokedexUiHandler extends MessageUiHandler { private toggleDecorationsIconElement: Phaser.GameObjects.Sprite; private toggleDecorationsLabel: Phaser.GameObjects.Text; - constructor(scene: BattleScene) { - super(scene, Mode.POKEDEX); + constructor() { + super(Mode.POKEDEX); } setup() { @@ -233,27 +235,25 @@ export default class PokedexUiHandler extends MessageUiHandler { const langSettingKey = Object.keys(languageSettings).find(lang => currentLanguage.includes(lang)) ?? "en"; const textSettings = languageSettings[langSettingKey]; - this.starterSelectContainer = this.scene.add.container(0, -this.scene.game.canvas.height / 6); + this.starterSelectContainer = globalScene.add.container(0, -globalScene.game.canvas.height / 6); this.starterSelectContainer.setVisible(false); ui.add(this.starterSelectContainer); - const bgColor = this.scene.add.rectangle(0, 0, this.scene.game.canvas.width / 6, this.scene.game.canvas.height / 6, 0x006860); + const bgColor = globalScene.add.rectangle(0, 0, globalScene.game.canvas.width / 6, globalScene.game.canvas.height / 6, 0x006860); bgColor.setOrigin(0, 0); this.starterSelectContainer.add(bgColor); - const starterContainerWindow = addWindow(this.scene, speciesContainerX, filterBarHeight + 1, 175, 161); - const starterContainerBg = this.scene.add.image(speciesContainerX + 1, filterBarHeight + 2, "starter_container_bg"); + const starterContainerWindow = addWindow(speciesContainerX, filterBarHeight + 1, 175, 161); + const starterContainerBg = globalScene.add.image(speciesContainerX + 1, filterBarHeight + 2, "starter_container_bg"); starterContainerBg.setOrigin(0, 0); this.starterSelectContainer.add(starterContainerBg); this.starterSelectContainer.add(starterContainerWindow); // Create and initialise filter text fields + this.filterTextContainer = globalScene.add.container(0, 0); + this.filterText = new FilterText(1, filterBarHeight + 2, 140, 100, this.updateStarters); - this.filterTextContainer = this.scene.add.container(0, 0); - this.filterText = new FilterText(this.scene, 1, filterBarHeight + 2, 140, 100, this.updateStarters); - - // const nameTextField: TextField = new TextField(this.scene, 0, 0, genOptions, this.updateStarters, DropDownType.HYBRID); this.filterText.addFilter(FilterTextRow.NAME, i18next.t("filterText:nameField")); this.filterText.addFilter(FilterTextRow.MOVE_1, i18next.t("filterText:move1Field")); this.filterText.addFilter(FilterTextRow.MOVE_2, i18next.t("filterText:move2Field")); @@ -265,22 +265,22 @@ export default class PokedexUiHandler extends MessageUiHandler { // Create and initialise filter bar - this.filterBarContainer = this.scene.add.container(0, 0); - this.filterBar = new FilterBar(this.scene, speciesContainerX, 1, 175, filterBarHeight, 2, 0, 6); + this.filterBarContainer = globalScene.add.container(0, 0); + this.filterBar = new FilterBar(speciesContainerX, 1, 175, filterBarHeight, 2, 0, 6); // gen filter const genOptions: DropDownOption[] = [ - new DropDownOption(this.scene, 1, new DropDownLabel(i18next.t("pokedexUiHandler:gen1"))), - new DropDownOption(this.scene, 2, new DropDownLabel(i18next.t("pokedexUiHandler:gen2"))), - new DropDownOption(this.scene, 3, new DropDownLabel(i18next.t("pokedexUiHandler:gen3"))), - new DropDownOption(this.scene, 4, new DropDownLabel(i18next.t("pokedexUiHandler:gen4"))), - new DropDownOption(this.scene, 5, new DropDownLabel(i18next.t("pokedexUiHandler:gen5"))), - new DropDownOption(this.scene, 6, new DropDownLabel(i18next.t("pokedexUiHandler:gen6"))), - new DropDownOption(this.scene, 7, new DropDownLabel(i18next.t("pokedexUiHandler:gen7"))), - new DropDownOption(this.scene, 8, new DropDownLabel(i18next.t("pokedexUiHandler:gen8"))), - new DropDownOption(this.scene, 9, new DropDownLabel(i18next.t("pokedexUiHandler:gen9"))), + new DropDownOption(1, new DropDownLabel(i18next.t("pokedexUiHandler:gen1"))), + new DropDownOption(2, new DropDownLabel(i18next.t("pokedexUiHandler:gen2"))), + new DropDownOption(3, new DropDownLabel(i18next.t("pokedexUiHandler:gen3"))), + new DropDownOption(4, new DropDownLabel(i18next.t("pokedexUiHandler:gen4"))), + new DropDownOption(5, new DropDownLabel(i18next.t("pokedexUiHandler:gen5"))), + new DropDownOption(6, new DropDownLabel(i18next.t("pokedexUiHandler:gen6"))), + new DropDownOption(7, new DropDownLabel(i18next.t("pokedexUiHandler:gen7"))), + new DropDownOption(8, new DropDownLabel(i18next.t("pokedexUiHandler:gen8"))), + new DropDownOption(9, new DropDownLabel(i18next.t("pokedexUiHandler:gen9"))), ]; - const genDropDown: DropDown = new DropDown(this.scene, 0, 0, genOptions, this.updateStarters, DropDownType.HYBRID); + const genDropDown: DropDown = new DropDown(0, 0, genOptions, this.updateStarters, DropDownType.HYBRID); this.filterBar.addFilter(DropDownColumn.GEN, i18next.t("filterBar:genFilter"), genDropDown); // type filter @@ -290,49 +290,49 @@ export default class PokedexUiHandler extends MessageUiHandler { if (index === 0 || index === 19) { return; } - const typeSprite = this.scene.add.sprite(0, 0, getLocalizedSpriteKey("types")); + const typeSprite = globalScene.add.sprite(0, 0, getLocalizedSpriteKey("types")); typeSprite.setScale(0.5); typeSprite.setFrame(type.toLowerCase()); - typeOptions.push(new DropDownOption(this.scene, index, new DropDownLabel("", typeSprite))); + typeOptions.push(new DropDownOption( index, new DropDownLabel("", typeSprite))); }); - this.filterBar.addFilter(DropDownColumn.TYPES, i18next.t("filterBar:typeFilter"), new DropDown(this.scene, 0, 0, typeOptions, this.updateStarters, DropDownType.HYBRID, 0.5)); + this.filterBar.addFilter(DropDownColumn.TYPES, i18next.t("filterBar:typeFilter"), new DropDown(0, 0, typeOptions, this.updateStarters, DropDownType.HYBRID, 0.5)); // biome filter, making an entry in the dropdown for each biome const biomeOptions = Object.values(Biome) .filter((value) => typeof value === "number") // Filter numeric values from the enum .map((biomeValue, index) => - new DropDownOption(this.scene, index, new DropDownLabel(i18next.t(`biome:${Biome[biomeValue].toUpperCase()}`))) + new DropDownOption( index, new DropDownLabel(i18next.t(`biome:${Biome[biomeValue].toUpperCase()}`))) ); - biomeOptions.push(new DropDownOption(this.scene, biomeOptions.length, new DropDownLabel(i18next.t("filterBar:uncatchable")))); - const biomeDropDown: DropDown = new DropDown(this.scene, 0, 0, biomeOptions, this.updateStarters, DropDownType.HYBRID); + biomeOptions.push(new DropDownOption( biomeOptions.length, new DropDownLabel(i18next.t("filterBar:uncatchable")))); + const biomeDropDown: DropDown = new DropDown(0, 0, biomeOptions, this.updateStarters, DropDownType.HYBRID); this.filterBar.addFilter(DropDownColumn.BIOME, i18next.t("filterBar:biomeFilter"), biomeDropDown); // caught filter - const shiny1Sprite = this.scene.add.sprite(0, 0, "shiny_icons"); + const shiny1Sprite = globalScene.add.sprite(0, 0, "shiny_icons"); shiny1Sprite.setOrigin(0.15, 0.2); shiny1Sprite.setScale(0.6); shiny1Sprite.setFrame(getVariantIcon(0)); shiny1Sprite.setTint(getVariantTint(0)); - const shiny2Sprite = this.scene.add.sprite(0, 0, "shiny_icons"); + const shiny2Sprite = globalScene.add.sprite(0, 0, "shiny_icons"); shiny2Sprite.setOrigin(0.15, 0.2); shiny2Sprite.setScale(0.6); shiny2Sprite.setFrame(getVariantIcon(1)); shiny2Sprite.setTint(getVariantTint(1)); - const shiny3Sprite = this.scene.add.sprite(0, 0, "shiny_icons"); + const shiny3Sprite = globalScene.add.sprite(0, 0, "shiny_icons"); shiny3Sprite.setOrigin(0.15, 0.2); shiny3Sprite.setScale(0.6); shiny3Sprite.setFrame(getVariantIcon(2)); shiny3Sprite.setTint(getVariantTint(2)); const caughtOptions = [ - new DropDownOption(this.scene, "SHINY3", new DropDownLabel("", shiny3Sprite)), - new DropDownOption(this.scene, "SHINY2", new DropDownLabel("", shiny2Sprite)), - new DropDownOption(this.scene, "SHINY", new DropDownLabel("", shiny1Sprite)), - new DropDownOption(this.scene, "NORMAL", new DropDownLabel(i18next.t("filterBar:normal"))), - new DropDownOption(this.scene, "UNCAUGHT", new DropDownLabel(i18next.t("filterBar:uncaught"))) + new DropDownOption("SHINY3", new DropDownLabel("", shiny3Sprite)), + new DropDownOption("SHINY2", new DropDownLabel("", shiny2Sprite)), + new DropDownOption("SHINY", new DropDownLabel("", shiny1Sprite)), + new DropDownOption("NORMAL", new DropDownLabel(i18next.t("filterBar:normal"))), + new DropDownOption("UNCAUGHT", new DropDownLabel(i18next.t("filterBar:uncaught"))) ]; - this.filterBar.addFilter(DropDownColumn.CAUGHT, i18next.t("filterBar:caughtFilter"), new DropDown(this.scene, 0, 0, caughtOptions, this.updateStarters, DropDownType.HYBRID)); + this.filterBar.addFilter(DropDownColumn.CAUGHT, i18next.t("filterBar:caughtFilter"), new DropDown(0, 0, caughtOptions, this.updateStarters, DropDownType.HYBRID)); // unlocks filter const passiveLabels = [ @@ -350,11 +350,11 @@ export default class PokedexUiHandler extends MessageUiHandler { ]; const unlocksOptions = [ - new DropDownOption(this.scene, "PASSIVE", passiveLabels), - new DropDownOption(this.scene, "COST_REDUCTION", costReductionLabels), + new DropDownOption("PASSIVE", passiveLabels), + new DropDownOption("COST_REDUCTION", costReductionLabels), ]; - this.filterBar.addFilter(DropDownColumn.UNLOCKS, i18next.t("filterBar:unlocksFilter"), new DropDown(this.scene, 0, 0, unlocksOptions, this.updateStarters, DropDownType.RADIAL)); + this.filterBar.addFilter(DropDownColumn.UNLOCKS, i18next.t("filterBar:unlocksFilter"), new DropDown(0, 0, unlocksOptions, this.updateStarters, DropDownType.RADIAL)); // misc filter const starters = [ @@ -386,24 +386,24 @@ export default class PokedexUiHandler extends MessageUiHandler { new DropDownLabel(i18next.t("filterBar:hasPokerus"), undefined, DropDownState.ON), ]; const miscOptions = [ - new DropDownOption(this.scene, "STARTER", starters), - new DropDownOption(this.scene, "FAVORITE", favoriteLabels), - new DropDownOption(this.scene, "WIN", winLabels), - new DropDownOption(this.scene, "HIDDEN_ABILITY", hiddenAbilityLabels), - new DropDownOption(this.scene, "EGG", eggLabels), - new DropDownOption(this.scene, "POKERUS", pokerusLabels), + new DropDownOption("STARTER", starters), + new DropDownOption("FAVORITE", favoriteLabels), + new DropDownOption("WIN", winLabels), + new DropDownOption("HIDDEN_ABILITY", hiddenAbilityLabels), + new DropDownOption("EGG", eggLabels), + new DropDownOption("POKERUS", pokerusLabels), ]; - this.filterBar.addFilter(DropDownColumn.MISC, i18next.t("filterBar:miscFilter"), new DropDown(this.scene, 0, 0, miscOptions, this.updateStarters, DropDownType.RADIAL)); + this.filterBar.addFilter(DropDownColumn.MISC, i18next.t("filterBar:miscFilter"), new DropDown(0, 0, miscOptions, this.updateStarters, DropDownType.RADIAL)); // sort filter const sortOptions = [ - new DropDownOption(this.scene, SortCriteria.NUMBER, new DropDownLabel(i18next.t("filterBar:sortByNumber"), undefined, DropDownState.ON)), - new DropDownOption(this.scene, SortCriteria.COST, new DropDownLabel(i18next.t("filterBar:sortByCost"))), - new DropDownOption(this.scene, SortCriteria.CANDY, new DropDownLabel(i18next.t("filterBar:sortByCandies"))), - new DropDownOption(this.scene, SortCriteria.IV, new DropDownLabel(i18next.t("filterBar:sortByIVs"))), - new DropDownOption(this.scene, SortCriteria.NAME, new DropDownLabel(i18next.t("filterBar:sortByName"))) + new DropDownOption(SortCriteria.NUMBER, new DropDownLabel(i18next.t("filterBar:sortByNumber"), undefined, DropDownState.ON)), + new DropDownOption(SortCriteria.COST, new DropDownLabel(i18next.t("filterBar:sortByCost"))), + new DropDownOption(SortCriteria.CANDY, new DropDownLabel(i18next.t("filterBar:sortByCandies"))), + new DropDownOption(SortCriteria.IV, new DropDownLabel(i18next.t("filterBar:sortByIVs"))), + new DropDownOption(SortCriteria.NAME, new DropDownLabel(i18next.t("filterBar:sortByName"))) ]; - this.filterBar.addFilter(DropDownColumn.SORT, i18next.t("filterBar:sortFilter"), new DropDown(this.scene, 0, 0, sortOptions, this.updateStarters, DropDownType.SINGLE)); + this.filterBar.addFilter(DropDownColumn.SORT, i18next.t("filterBar:sortFilter"), new DropDown(0, 0, sortOptions, this.updateStarters, DropDownType.SINGLE)); this.filterBarContainer.add(this.filterBar); this.starterSelectContainer.add(this.filterBarContainer); @@ -411,36 +411,36 @@ export default class PokedexUiHandler extends MessageUiHandler { // Offset the generation filter dropdown to avoid covering the filtered pokemon this.filterBar.offsetHybridFilters(); - if (!this.scene.uiTheme) { + if (!globalScene.uiTheme) { starterContainerWindow.setVisible(false); } this.iconAnimHandler = new PokemonIconAnimHandler(); - this.iconAnimHandler.setup(this.scene); + this.iconAnimHandler.setup(); - this.pokemonNumberText = addTextObject(this.scene, 6, 140, "", TextStyle.SUMMARY); + this.pokemonNumberText = addTextObject(6, 140, "", TextStyle.SUMMARY); this.pokemonNumberText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNumberText); - this.pokemonNameText = addTextObject(this.scene, 6, 127, "", TextStyle.SUMMARY); + this.pokemonNameText = addTextObject(6, 127, "", TextStyle.SUMMARY); this.pokemonNameText.setOrigin(0, 0); this.starterSelectContainer.add(this.pokemonNameText); - const starterBoxContainer = this.scene.add.container(speciesContainerX + 6, 9); //115 + const starterBoxContainer = globalScene.add.container(speciesContainerX + 6, 9); //115 - this.starterSelectScrollBar = new ScrollBar(this.scene, 161, 12, 5, starterContainerWindow.height - 6, 9); + this.starterSelectScrollBar = new ScrollBar(161, 12, 5, starterContainerWindow.height - 6, 9); starterBoxContainer.add(this.starterSelectScrollBar); this.pokerusCursorObjs = new Array(POKERUS_STARTER_COUNT).fill(null).map(() => { - const cursorObj = this.scene.add.image(0, 0, "select_cursor_pokerus"); + const cursorObj = globalScene.add.image(0, 0, "select_cursor_pokerus"); cursorObj.setVisible(false); cursorObj.setOrigin(0, 0); starterBoxContainer.add(cursorObj); return cursorObj; }); - this.cursorObj = this.scene.add.image(0, 0, "select_cursor"); + this.cursorObj = globalScene.add.image(0, 0, "select_cursor"); this.cursorObj.setOrigin(0, 0); starterBoxContainer.add(this.cursorObj); @@ -449,7 +449,7 @@ export default class PokedexUiHandler extends MessageUiHandler { this.speciesLoaded.set(species.speciesId, false); this.allSpecies.push(species); - const starterContainer = new StarterContainer(this.scene, species).setVisible(false); + const starterContainer = new StarterContainer(species).setVisible(false); this.iconAnimHandler.addOrUpdate(starterContainer.icon, PokemonIconAnimMode.NONE); this.starterContainers.push(starterContainer); starterBoxContainer.add(starterContainer); @@ -457,55 +457,55 @@ export default class PokedexUiHandler extends MessageUiHandler { this.starterSelectContainer.add(starterBoxContainer); - this.pokemonSprite = this.scene.add.sprite(96, 143, "pkmn__sub"); - this.pokemonSprite.setPipeline(this.scene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); + this.pokemonSprite = globalScene.add.sprite(96, 143, "pkmn__sub"); + this.pokemonSprite.setPipeline(globalScene.spritePipeline, { tone: [ 0.0, 0.0, 0.0, 0.0 ], ignoreTimeTint: true }); this.starterSelectContainer.add(this.pokemonSprite); - this.type1Icon = this.scene.add.sprite(10, 158, getLocalizedSpriteKey("types")); + this.type1Icon = globalScene.add.sprite(10, 158, getLocalizedSpriteKey("types")); this.type1Icon.setScale(0.5); this.type1Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type1Icon); - this.type2Icon = this.scene.add.sprite(10, 166, getLocalizedSpriteKey("types")); + this.type2Icon = globalScene.add.sprite(10, 166, getLocalizedSpriteKey("types")); this.type2Icon.setScale(0.5); this.type2Icon.setOrigin(0, 0); this.starterSelectContainer.add(this.type2Icon); - this.starterSelectMessageBoxContainer = this.scene.add.container(0, this.scene.game.canvas.height / 6); + this.starterSelectMessageBoxContainer = globalScene.add.container(0, globalScene.game.canvas.height / 6); this.starterSelectMessageBoxContainer.setVisible(false); this.starterSelectContainer.add(this.starterSelectMessageBoxContainer); - this.starterSelectMessageBox = addWindow(this.scene, 1, -1, 318, 28); + this.starterSelectMessageBox = addWindow(1, -1, 318, 28); this.starterSelectMessageBox.setOrigin(0, 1); this.starterSelectMessageBoxContainer.add(this.starterSelectMessageBox); // Instruction for "C" button to toggle showDecorations const instructionTextSize = textSettings.instructionTextSize; - this.goFilterIconElement1 = new Phaser.GameObjects.Sprite(this.scene, 10, 2, "keyboard", "C.png"); + this.goFilterIconElement1 = new Phaser.GameObjects.Sprite(globalScene, 10, 2, "keyboard", "C.png"); this.goFilterIconElement1.setName("sprite-goFilter1-icon-element"); this.goFilterIconElement1.setScale(0.675); this.goFilterIconElement1.setOrigin(0.0, 0.0); - this.goFilterIconElement2 = new Phaser.GameObjects.Sprite(this.scene, 20, 2, "keyboard", "V.png"); + this.goFilterIconElement2 = new Phaser.GameObjects.Sprite(globalScene, 20, 2, "keyboard", "V.png"); this.goFilterIconElement2.setName("sprite-goFilter2-icon-element"); this.goFilterIconElement2.setScale(0.675); this.goFilterIconElement2.setOrigin(0.0, 0.0); - this.goFilterLabel = addTextObject(this.scene, 30, 2, i18next.t("pokedexUiHandler:goFilters"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.goFilterLabel = addTextObject(30, 2, i18next.t("pokedexUiHandler:goFilters"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.goFilterLabel.setName("text-goFilter-label"); this.starterSelectContainer.add(this.goFilterIconElement1); this.starterSelectContainer.add(this.goFilterIconElement2); this.starterSelectContainer.add(this.goFilterLabel); - this.toggleDecorationsIconElement = new Phaser.GameObjects.Sprite(this.scene, 10, 10, "keyboard", "R.png"); + this.toggleDecorationsIconElement = new Phaser.GameObjects.Sprite(globalScene, 10, 10, "keyboard", "R.png"); this.toggleDecorationsIconElement.setName("sprite-toggleDecorations-icon-element"); this.toggleDecorationsIconElement.setScale(0.675); this.toggleDecorationsIconElement.setOrigin(0.0, 0.0); - this.toggleDecorationsLabel = addTextObject(this.scene, 20, 10, i18next.t("pokedexUiHandler:toggleDecorations"), TextStyle.PARTY, { fontSize: instructionTextSize }); + this.toggleDecorationsLabel = addTextObject(20, 10, i18next.t("pokedexUiHandler:toggleDecorations"), TextStyle.PARTY, { fontSize: instructionTextSize }); this.toggleDecorationsLabel.setName("text-toggleDecorations-label"); this.starterSelectContainer.add(this.toggleDecorationsIconElement); this.starterSelectContainer.add(this.toggleDecorationsLabel); - this.message = addTextObject(this.scene, 8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); + this.message = addTextObject(8, 8, "", TextStyle.WINDOW, { maxLines: 2 }); this.message.setOrigin(0, 0); this.starterSelectMessageBoxContainer.add(this.message); @@ -516,8 +516,6 @@ export default class PokedexUiHandler extends MessageUiHandler { this.starterSelectContainer.bringToTop(this.filterBarContainer); this.initTutorialOverlay(this.starterSelectContainer); this.starterSelectContainer.bringToTop(this.starterSelectMessageBoxContainer); - - this.scene.eventTarget.addEventListener(BattleSceneEventType.CANDY_UPGRADE_NOTIFICATION_CHANGED, (e) => this.onCandyUpgradeDisplayChanged(e)); } show(args: any[]): boolean { @@ -526,7 +524,7 @@ export default class PokedexUiHandler extends MessageUiHandler { this.starterPreferences = StarterPrefs.load(); } - this.pokerusSpecies = getPokerusStarters(this.scene); + this.pokerusSpecies = getPokerusStarters(); // When calling with "refresh", we do not reset the cursor and filters if (args.length >= 1 && args[0] === "refresh") { @@ -542,7 +540,7 @@ export default class PokedexUiHandler extends MessageUiHandler { // Making caught pokemon visible icons, etc this.allSpecies.forEach((species, s) => { const icon = this.starterContainers[s].icon; - const dexEntry = this.scene.gameData.dexData[species.speciesId]; + const dexEntry = globalScene.gameData.dexData[species.speciesId]; this.starterPreferences[species.speciesId] = this.initStarterPrefs(species); @@ -564,8 +562,6 @@ export default class PokedexUiHandler extends MessageUiHandler { this.filterTextCursor = 0; this.setCursor(0); - handleTutorial(this.scene, Tutorial.Pokedex); - this.filterTextContainer.setVisible(true); return true; @@ -581,8 +577,8 @@ export default class PokedexUiHandler extends MessageUiHandler { */ initStarterPrefs(species: PokemonSpecies): StarterAttributes { const starterAttributes = this.starterPreferences[species.speciesId]; - const dexEntry = this.scene.gameData.dexData[species.speciesId]; - const starterData = this.scene.gameData.starterData[species.speciesId]; + const dexEntry = globalScene.gameData.dexData[species.speciesId]; + const starterData = globalScene.gameData.starterData[species.speciesId]; // no preferences or Pokemon wasn't caught, return empty attribute if (!starterAttributes || !dexEntry.caughtAttr) { @@ -641,13 +637,13 @@ export default class PokedexUiHandler extends MessageUiHandler { } const selectedForm = starterAttributes.form; - if (selectedForm !== undefined && (!species.forms[selectedForm]?.isStarterSelectable || !(caughtAttr & this.scene.gameData.getFormAttr(selectedForm)))) { + if (selectedForm !== undefined && (!species.forms[selectedForm]?.isStarterSelectable || !(caughtAttr & globalScene.gameData.getFormAttr(selectedForm)))) { // requested form wasn't unlocked/isn't a starter form, purging setting delete starterAttributes.form; } if (starterAttributes.nature !== undefined) { - const unlockedNatures = this.scene.gameData.getNaturesForAttr(dexEntry.natureAttr); + const unlockedNatures = globalScene.gameData.getNaturesForAttr(dexEntry.natureAttr); if (unlockedNatures.indexOf(starterAttributes.nature as unknown as Nature) < 0) { // requested nature wasn't unlocked, purging setting delete starterAttributes.nature; @@ -677,7 +673,7 @@ export default class PokedexUiHandler extends MessageUiHandler { this.starterSelectMessageBoxContainer.setY(0); this.message.setY(4); } else { - this.starterSelectMessageBoxContainer.setY(this.scene.game.canvas.height / 6); + this.starterSelectMessageBoxContainer.setY(globalScene.game.canvas.height / 6); this.starterSelectMessageBox.setOrigin(0, 1); this.message.setY(singleLine ? -22 : -37); } @@ -690,14 +686,14 @@ export default class PokedexUiHandler extends MessageUiHandler { * @returns true if upgrade notifications are enabled and set to display an 'Icon' */ isUpgradeIconEnabled(): boolean { - return this.scene.candyUpgradeNotification !== 0 && this.scene.candyUpgradeDisplay === 0; + return globalScene.candyUpgradeNotification !== 0 && globalScene.candyUpgradeDisplay === 0; } /** * Determines if 'Animation' based upgrade notifications should be shown * @returns true if upgrade notifications are enabled and set to display an 'Animation' */ isUpgradeAnimationEnabled(): boolean { - return this.scene.candyUpgradeNotification !== 0 && this.scene.candyUpgradeDisplay === 1; + return globalScene.candyUpgradeNotification !== 0 && globalScene.candyUpgradeDisplay === 1; } getStarterSpeciesId(speciesId): number { @@ -715,7 +711,7 @@ export default class PokedexUiHandler extends MessageUiHandler { */ isPassiveAvailable(speciesId: number): boolean { // Get this species ID's starter data - const starterData = this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; + const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; return starterData.candyCount >= getPassiveCandyCount(speciesStarterCosts[this.getStarterSpeciesId(speciesId)]) && !(starterData.passiveAttr & PassiveAttr.UNLOCKED); @@ -728,7 +724,7 @@ export default class PokedexUiHandler extends MessageUiHandler { */ isValueReductionAvailable(speciesId: number): boolean { // Get this species ID's starter data - const starterData = this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; + const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; return starterData.candyCount >= getValueReductionCandyCounts(speciesStarterCosts[this.getStarterSpeciesId(speciesId)])[starterData.valueReduction] && starterData.valueReduction < valueReductionMax; @@ -741,7 +737,7 @@ export default class PokedexUiHandler extends MessageUiHandler { */ isSameSpeciesEggAvailable(speciesId: number): boolean { // Get this species ID's starter data - const starterData = this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; + const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)]; return starterData.candyCount >= getSameSpeciesEggCandyCounts(speciesStarterCosts[this.getStarterSpeciesId(speciesId)]); } @@ -753,9 +749,9 @@ export default class PokedexUiHandler extends MessageUiHandler { * @param startPaused Should this animation be paused after it is added? */ setUpgradeAnimation(icon: Phaser.GameObjects.Sprite, species: PokemonSpecies, startPaused: boolean = false): void { - this.scene.tweens.killTweensOf(icon); + globalScene.tweens.killTweensOf(icon); // Skip animations if they are disabled - if (this.scene.candyUpgradeDisplay === 0 || species.speciesId !== species.getRootSpeciesId(false)) { + if (globalScene.candyUpgradeDisplay === 0 || species.speciesId !== species.getRootSpeciesId(false)) { return; } @@ -789,14 +785,14 @@ export default class PokedexUiHandler extends MessageUiHandler { const isSameSpeciesEggAvailable = this.isSameSpeciesEggAvailable(species.speciesId); // 'Passives Only' mode - if (this.scene.candyUpgradeNotification === 1) { + if (globalScene.candyUpgradeNotification === 1) { if (isPassiveAvailable) { - this.scene.tweens.chain(tweenChain).paused = startPaused; + globalScene.tweens.chain(tweenChain).paused = startPaused; } // 'On' mode - } else if (this.scene.candyUpgradeNotification === 2) { + } else if (globalScene.candyUpgradeNotification === 2) { if (isPassiveAvailable || isValueReductionAvailable || isSameSpeciesEggAvailable) { - this.scene.tweens.chain(tweenChain).paused = startPaused; + globalScene.tweens.chain(tweenChain).paused = startPaused; } } } @@ -808,7 +804,7 @@ export default class PokedexUiHandler extends MessageUiHandler { const species = starter.species; const slotVisible = !!species?.speciesId; - if (!species || this.scene.candyUpgradeNotification === 0 || species.speciesId !== species.getRootSpeciesId(false)) { + if (!species || globalScene.candyUpgradeNotification === 0 || species.speciesId !== species.getRootSpeciesId(false)) { starter.candyUpgradeIcon.setVisible(false); starter.candyUpgradeOverlayIcon.setVisible(false); return; @@ -819,12 +815,12 @@ export default class PokedexUiHandler extends MessageUiHandler { const isSameSpeciesEggAvailable = this.isSameSpeciesEggAvailable(species.speciesId); // 'Passive Only' mode - if (this.scene.candyUpgradeNotification === 1) { + if (globalScene.candyUpgradeNotification === 1) { starter.candyUpgradeIcon.setVisible(slotVisible && isPassiveAvailable); starter.candyUpgradeOverlayIcon.setVisible(slotVisible && starter.candyUpgradeIcon.visible); // 'On' mode - } else if (this.scene.candyUpgradeNotification === 2) { + } else if (globalScene.candyUpgradeNotification === 2) { starter.candyUpgradeIcon.setVisible( slotVisible && ( isPassiveAvailable || isValueReductionAvailable || isSameSpeciesEggAvailable )); starter.candyUpgradeOverlayIcon.setVisible(slotVisible && starter.candyUpgradeIcon.visible); @@ -844,33 +840,6 @@ export default class PokedexUiHandler extends MessageUiHandler { } } - /** - * Processes an {@linkcode CandyUpgradeNotificationChangedEvent} sent when the corresponding setting changes - * @param event {@linkcode Event} sent by the callback - */ - onCandyUpgradeDisplayChanged(event: Event): void { - const candyUpgradeDisplayEvent = event as CandyUpgradeNotificationChangedEvent; - if (!candyUpgradeDisplayEvent) { - return; - } - - // Loop through all visible candy icons when set to 'Icon' mode - if (this.scene.candyUpgradeDisplay === 0) { - this.filteredStarterContainers.forEach((starter) => { - this.setUpgradeIcon(starter); - }); - - return; - } - - // Loop through all animations when set to 'Animation' mode - this.filteredStarterContainers.forEach((starter, s) => { - const icon = this.filteredStarterContainers[s].icon; - - this.setUpgradeAnimation(icon, starter.species); - }); - } - processInput(button: Button): boolean { if (this.blockInput) { return false; @@ -1136,7 +1105,7 @@ export default class PokedexUiHandler extends MessageUiHandler { break; } } else { - iconPath = this.scene.inputController?.getIconForLatestInputRecorded(iconSetting); + iconPath = globalScene.inputController?.getIconForLatestInputRecorded(iconSetting); } iconElement.setTexture(gamepadType, iconPath); iconElement.setVisible(true); @@ -1151,7 +1120,7 @@ export default class PokedexUiHandler extends MessageUiHandler { gamepadType = "keyboard"; iconPath = "C.png"; } else { - iconPath = this.scene.inputController?.getIconForLatestInputRecorded(iconSetting); + iconPath = globalScene.inputController?.getIconForLatestInputRecorded(iconSetting); } iconElement.setTexture(gamepadType, iconPath); iconElement.setVisible(true); @@ -1197,7 +1166,7 @@ export default class PokedexUiHandler extends MessageUiHandler { const starterSprite = currentFilteredContainer.icon as Phaser.GameObjects.Sprite; const currentDexAttr = this.getCurrentDexProps(currentFilteredContainer.species.speciesId); - const props = this.getSanitizedProps(this.scene.gameData.getSpeciesDexAttrProps(currentFilteredContainer.species, currentDexAttr)); + const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(currentFilteredContainer.species, currentDexAttr)); starterSprite.setTexture(currentFilteredContainer.species.getIconAtlasKey(props.formIndex, props.shiny, props.variant), currentFilteredContainer.species.getIconId(props.female!, props.formIndex, props.shiny, props.variant)); currentFilteredContainer.checkIconId(props.female, props.formIndex, props.shiny, props.variant); @@ -1207,12 +1176,12 @@ export default class PokedexUiHandler extends MessageUiHandler { this.validStarterContainers.forEach(container => { container.setVisible(false); - container.cost = this.scene.gameData.getSpeciesStarterValue(this.getStarterSpeciesId(container.species.speciesId)); + container.cost = globalScene.gameData.getSpeciesStarterValue(this.getStarterSpeciesId(container.species.speciesId)); // First, ensure you have the caught attributes for the species else default to bigint 0 // TODO: This might be removed depending on how accessible we want the pokedex function to be - const caughtAttr = this.scene.gameData.dexData[container.species.speciesId]?.caughtAttr || BigInt(0); - const starterData = this.scene.gameData.starterData[this.getStarterSpeciesId(container.species.speciesId)]; + const caughtAttr = globalScene.gameData.dexData[container.species.speciesId]?.caughtAttr || BigInt(0); + const starterData = globalScene.gameData.starterData[this.getStarterSpeciesId(container.species.speciesId)]; const isStarterProgressable = speciesEggMoves.hasOwnProperty(this.getStarterSpeciesId(container.species.speciesId)); // Name filter @@ -1425,12 +1394,12 @@ export default class PokedexUiHandler extends MessageUiHandler { case SortCriteria.COST: return (a.cost - b.cost) * -sort.dir; case SortCriteria.CANDY: - const candyCountA = this.scene.gameData.starterData[a.species.speciesId].candyCount; - const candyCountB = this.scene.gameData.starterData[b.species.speciesId].candyCount; + const candyCountA = globalScene.gameData.starterData[a.species.speciesId].candyCount; + const candyCountB = globalScene.gameData.starterData[b.species.speciesId].candyCount; return (candyCountA - candyCountB) * -sort.dir; case SortCriteria.IV: - const avgIVsA = this.scene.gameData.dexData[a.species.speciesId].ivs.reduce((a, b) => a + b, 0) / this.scene.gameData.dexData[a.species.speciesId].ivs.length; - const avgIVsB = this.scene.gameData.dexData[b.species.speciesId].ivs.reduce((a, b) => a + b, 0) / this.scene.gameData.dexData[b.species.speciesId].ivs.length; + const avgIVsA = globalScene.gameData.dexData[a.species.speciesId].ivs.reduce((a, b) => a + b, 0) / globalScene.gameData.dexData[a.species.speciesId].ivs.length; + const avgIVsB = globalScene.gameData.dexData[b.species.speciesId].ivs.reduce((a, b) => a + b, 0) / globalScene.gameData.dexData[b.species.speciesId].ivs.length; return (avgIVsA - avgIVsB) * -sort.dir; case SortCriteria.NAME: return a.species.name.localeCompare(b.species.name) * -sort.dir; @@ -1476,8 +1445,8 @@ export default class PokedexUiHandler extends MessageUiHandler { this.updateStarterValueLabel(container); container.label.setVisible(true); - const speciesVariants = speciesId && this.scene.gameData.dexData[speciesId].caughtAttr & DexAttr.SHINY - ? [ DexAttr.DEFAULT_VARIANT, DexAttr.VARIANT_2, DexAttr.VARIANT_3 ].filter(v => !!(this.scene.gameData.dexData[speciesId].caughtAttr & v)) + const speciesVariants = speciesId && globalScene.gameData.dexData[speciesId].caughtAttr & DexAttr.SHINY + ? [ DexAttr.DEFAULT_VARIANT, DexAttr.VARIANT_2, DexAttr.VARIANT_3 ].filter(v => !!(globalScene.gameData.dexData[speciesId].caughtAttr & v)) : []; for (let v = 0; v < 3; v++) { const hasVariant = speciesVariants.length > v; @@ -1487,13 +1456,13 @@ export default class PokedexUiHandler extends MessageUiHandler { } } - container.starterPassiveBgs.setVisible(!!this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)].passiveAttr); - container.hiddenAbilityIcon.setVisible(!!this.scene.gameData.dexData[speciesId].caughtAttr && !!(this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)].abilityAttr & 4)); - container.classicWinIcon.setVisible(this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)].classicWinCount > 0); + container.starterPassiveBgs.setVisible(!!globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].passiveAttr); + container.hiddenAbilityIcon.setVisible(!!globalScene.gameData.dexData[speciesId].caughtAttr && !!(globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].abilityAttr & 4)); + container.classicWinIcon.setVisible(globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].classicWinCount > 0); container.favoriteIcon.setVisible(this.starterPreferences[speciesId]?.favorite ?? false); // 'Candy Icon' mode - if (this.scene.candyUpgradeDisplay === 0) { + if (globalScene.candyUpgradeDisplay === 0) { if (!starterColors[this.getStarterSpeciesId(speciesId)]) { // Default to white if no colors are found @@ -1504,7 +1473,7 @@ export default class PokedexUiHandler extends MessageUiHandler { container.candyUpgradeIcon.setTint(argbFromRgba(rgbHexToRgba(starterColors[this.getStarterSpeciesId(speciesId)][0]))); container.candyUpgradeOverlayIcon.setTint(argbFromRgba(rgbHexToRgba(starterColors[this.getStarterSpeciesId(speciesId)][1]))); - } else if (this.scene.candyUpgradeDisplay === 1) { + } else if (globalScene.candyUpgradeDisplay === 1) { container.candyUpgradeIcon.setVisible(false); container.candyUpgradeOverlayIcon.setVisible(false); } @@ -1586,7 +1555,7 @@ export default class PokedexUiHandler extends MessageUiHandler { } getFriendship(speciesId: number) { - let currentFriendship = this.scene.gameData.starterData[this.getStarterSpeciesId(speciesId)].friendship; + let currentFriendship = globalScene.gameData.starterData[this.getStarterSpeciesId(speciesId)].friendship; if (!currentFriendship || currentFriendship === undefined) { currentFriendship = 0; } @@ -1598,15 +1567,15 @@ export default class PokedexUiHandler extends MessageUiHandler { setSpecies(species: PokemonSpecies | null) { - this.speciesStarterDexEntry = species ? this.scene.gameData.dexData[species.speciesId] : null; + this.speciesStarterDexEntry = species ? globalScene.gameData.dexData[species.speciesId] : null; - if (!species && this.scene.ui.getTooltip().visible) { - this.scene.ui.hideTooltip(); + if (!species && globalScene.ui.getTooltip().visible) { + globalScene.ui.hideTooltip(); } if (this.lastSpecies) { const dexAttr = this.getCurrentDexProps(this.lastSpecies.speciesId); - const props = this.getSanitizedProps(this.scene.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr)); + const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(this.lastSpecies, dexAttr)); const speciesIndex = this.allSpecies.indexOf(this.lastSpecies); const lastSpeciesIcon = this.starterContainers[speciesIndex].icon; this.checkIconId(lastSpeciesIcon, this.lastSpecies, props.female, props.formIndex, props.shiny, props.variant); @@ -1614,7 +1583,7 @@ export default class PokedexUiHandler extends MessageUiHandler { // Resume the animation for the previously selected species const icon = this.starterContainers[speciesIndex].icon; - this.scene.tweens.getTweensOf(icon).forEach(tween => tween.resume()); + globalScene.tweens.getTweensOf(icon).forEach(tween => tween.resume()); } this.lastSpecies = species!; // TODO: is this bang correct? @@ -1632,7 +1601,7 @@ export default class PokedexUiHandler extends MessageUiHandler { const icon = this.starterContainers[speciesIndex].icon; if (this.isUpgradeAnimationEnabled()) { - this.scene.tweens.getTweensOf(icon).forEach(tween => tween.pause()); + globalScene.tweens.getTweensOf(icon).forEach(tween => tween.pause()); // Reset the position of the icon icon.x = -2; icon.y = 2; @@ -1698,10 +1667,10 @@ export default class PokedexUiHandler extends MessageUiHandler { this.speciesStarterMoves = []; if (species) { - const dexEntry = this.scene.gameData.dexData[species.speciesId]; + const dexEntry = globalScene.gameData.dexData[species.speciesId]; if (!dexEntry.caughtAttr) { - const props = this.getSanitizedProps(this.scene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId))); + const props = this.getSanitizedProps(globalScene.gameData.getSpeciesDexAttrProps(species, this.getCurrentDexProps(species.speciesId))); if (shiny === undefined || shiny !== props.shiny) { shiny = props.shiny; @@ -1722,7 +1691,7 @@ export default class PokedexUiHandler extends MessageUiHandler { if (shouldUpdateSprite) { - species.loadAssets(this.scene, female!, formIndex, shiny, variant, true).then(() => { // TODO: is this bang correct? + species.loadAssets(female!, formIndex, shiny, variant, true).then(() => { // TODO: is this bang correct? if (assetLoadCancelled.value) { return; } @@ -1773,7 +1742,7 @@ export default class PokedexUiHandler extends MessageUiHandler { updateStarterValueLabel(starter: StarterContainer): void { const speciesId = starter.species.speciesId; const baseStarterValue = speciesStarterCosts[speciesId]; - const starterValue = this.scene.gameData.getSpeciesStarterValue(this.getStarterSpeciesId(speciesId)); + const starterValue = globalScene.gameData.getSpeciesStarterValue(this.getStarterSpeciesId(speciesId)); starter.cost = starterValue; let valueStr = starterValue.toString(); if (valueStr.startsWith("0.")) { @@ -1811,7 +1780,7 @@ export default class PokedexUiHandler extends MessageUiHandler { ui.showText(i18next.t("pokedexUiHandler:confirmExit"), null, () => { ui.setModeWithoutClear(Mode.CONFIRM, () => { ui.setMode(Mode.POKEDEX, "refresh"); - this.scene.clearPhaseQueue(); + globalScene.clearPhaseQueue(); this.clearText(); this.clear(); ui.revertMode(); @@ -1831,7 +1800,7 @@ export default class PokedexUiHandler extends MessageUiHandler { */ getCurrentDexProps(speciesId: number): bigint { let props = 0n; - const caughtAttr = this.scene.gameData.dexData[speciesId].caughtAttr; + const caughtAttr = globalScene.gameData.dexData[speciesId].caughtAttr; /* this checks the gender of the pokemon; this works by checking a) that the starter preferences for the species exist, and if so, is it female. If so, it'll add DexAttr.FEMALE to our temp props * It then checks b) if the caughtAttr for the pokemon is female and NOT male - this means that the ONLY gender we've gotten is female, and we need to add DexAttr.FEMALE to our temp props @@ -1869,7 +1838,7 @@ export default class PokedexUiHandler extends MessageUiHandler { props += BigInt(Math.pow(2, this.starterPreferences[speciesId]?.form)) * DexAttr.DEFAULT_FORM; } else { // Get the first unlocked form - props += this.scene.gameData.getFormAttr(this.scene.gameData.getFormIndex(caughtAttr)); + props += globalScene.gameData.getFormAttr(globalScene.gameData.getFormIndex(caughtAttr)); } return props; @@ -1885,7 +1854,7 @@ export default class PokedexUiHandler extends MessageUiHandler { // StarterPrefs.save(this.starterPreferences); this.cursor = -1; - this.scene.ui.hideTooltip(); + globalScene.ui.hideTooltip(); this.starterSelectContainer.setVisible(false); this.blockInput = false;