From 24bf116b37f7b0e72227374b21598f88822b06f8 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Wed, 14 Feb 2024 10:44:55 -0500 Subject: [PATCH] Expand tutorials --- src/battle-phases.ts | 5 +-- src/tutorial.ts | 55 ++++++++++++++++++++++++---- src/ui/awaitable-ui-handler.ts | 16 +++++++- src/ui/egg-gacha-ui-handler.ts | 20 ++++++++++ src/ui/menu-ui-handler.ts | 3 ++ src/ui/modifier-select-ui-handler.ts | 9 ++++- src/ui/starter-select-ui-handler.ts | 23 ++++++++---- src/ui/ui.ts | 8 +++- 8 files changed, 116 insertions(+), 23 deletions(-) diff --git a/src/battle-phases.ts b/src/battle-phases.ts index e3e600d54..bc89a53a9 100644 --- a/src/battle-phases.ts +++ b/src/battle-phases.ts @@ -630,11 +630,8 @@ export class EncounterPhase extends BattlePhase { this.scene.pushPhase(new CheckSwitchPhase(this.scene, 1, this.scene.currentBattle.double)); } } - - // TODO: Remove - //this.scene.unshiftPhase(new SelectModifierPhase(this.scene)); - super.end(); + handleTutorial(this.scene, Tutorial.Access_Menu).then(() => super.end()); } tryOverrideForBattleSpec(): boolean { diff --git a/src/tutorial.ts b/src/tutorial.ts index aa0abd735..ef9bda6ec 100644 --- a/src/tutorial.ts +++ b/src/tutorial.ts @@ -1,12 +1,14 @@ import BattleScene from "./battle-scene"; +import AwaitableUiHandler from "./ui/awaitable-ui-handler"; +import { Mode } from "./ui/ui"; export enum Tutorial { Intro = "INTRO", + Access_Menu = "ACCESS_MENU", Menu = "MENU", Starter_Select = "STARTER_SELECT", Select_Item = "SELECT_ITEM", - Gacha = "GACHA", - Egg_List = "EGG_LIST" + Egg_Gacha = "EGG_GACHA" } const tutorialHandlers = { @@ -17,19 +19,51 @@ const tutorialHandlers = { $The game is a work in progress, but fully playable.\nFor bug reports, please use the Discord community.`, null, () => resolve(), null, true); }); }, - [Tutorial.Menu]: (scene: BattleScene) => { + [Tutorial.Access_Menu]: (scene: BattleScene) => { return new Promise(resolve => { if (scene.enableTouchControls) return resolve(); - scene.ui.showText(`To access the menu, press M or Escape. The menu contains settings and various features.`, null, () => resolve(), null, true); + scene.showFieldOverlay(1000).then(() => scene.ui.showText(`To access the menu, press M or Escape while awaiting input.\nThe menu contains settings and various features.`, null, () => scene.hideFieldOverlay(1000).then(() => resolve()), null, true)); + }); + }, + [Tutorial.Menu]: (scene: BattleScene) => { + return new Promise(resolve => { + scene.gameData.saveTutorialFlag(Tutorial.Access_Menu, true); + scene.ui.showText(`From this menu you can access the settings. + $From the settings you can change game speed, window style, and other options. + $There are also various other features here, so be sure to check them all!`, null, () => scene.ui.showText('', null, () => resolve()), null, true); }); }, [Tutorial.Starter_Select]: (scene: BattleScene) => { return new Promise(resolve => { - scene.ui.showText(`From this screen, you can select the starters for your party. - $Each starter has a value. Your party can have up to 6 members as long as the total does not exceed 10. - $You can also select gender, ability, and form depending on the variants you've caught or hatched. - $The IVs for a species are also the best of every one you've caught, so try to get lots of the same species!`, null, () => resolve(), null, true); + scene.ui.showText(`From this screen, you can select your starters.\nThese are your initial party members. + $Each starter has a value. Your party can have up to\n6 members as long as the total does not exceed 10. + $You can also select gender, ability, and form depending on\nthe variants you've caught or hatched. + $The IVs for a species are also the best of every one you've\ncaught or hatched, so try to get lots of the same species!`, null, () => scene.ui.showText('', null, () => resolve()), null, true); + }); + }, + [Tutorial.Select_Item]: (scene: BattleScene) => { + return new Promise(resolve => { + scene.ui.setModeWithoutClear(Mode.MESSAGE).then(() => { + scene.ui.showText(`After every battle, you are given a choice of 3 random items.\nYou may only pick one. + $These range from consumables, to Pokémon held items, to passive permanent items. + $Most non-consumable item effects will stack in various ways. + $Some items will only show up if they can be used, such as evolution items. + $You may also choose to transfer a held item (and any duplicates) between Pokémon instead of choosing an item. + $The transfer option will appear in the bottom right once you have obtained a held item. + $You may purchase consumable items with money, and a larger variety will be available the further you get. + $Be sure to buy these before you pick your random item, as it will progress to the next battle once you do.`, null, () => scene.ui.showText('', null, () => scene.ui.setModeWithoutClear(Mode.MODIFIER_SELECT).then(() => resolve())), null, true); + }); + }); + }, + [Tutorial.Egg_Gacha]: (scene: BattleScene) => { + return new Promise(resolve => { + scene.ui.showText(`From this screen, you can redeem your vouchers for\nPokémon eggs. + $Eggs have to be hatched and get closer to hatching after\nevery battle. Rarer eggs take longer to hatch. + $Hatched Pokémon also won't be added to your party, they will\nbe added to your starters. + $Pokémon hatched from eggs generally have better IVs than\nwild Pokémon. + $Some Pokémon can only even be obtained from eggs. + $There are 3 different machines to pull from with different\nbonuses, so pick the one that suits you best!`, null, () => scene.ui.showText('', null, () => resolve()), null, true); }); }, }; @@ -42,8 +76,13 @@ export function handleTutorial(scene: BattleScene, tutorial: Tutorial): Promise< if (scene.gameData.getTutorialFlags()[tutorial]) return resolve(false); + const handler = scene.ui.getHandler(); + if (handler instanceof AwaitableUiHandler) + handler.tutorialActive = true; tutorialHandlers[tutorial](scene).then(() => { scene.gameData.saveTutorialFlag(tutorial, true); + if (handler instanceof AwaitableUiHandler) + handler.tutorialActive = false; resolve(true); }); }); diff --git a/src/ui/awaitable-ui-handler.ts b/src/ui/awaitable-ui-handler.ts index 079aca554..e8cc979e4 100644 --- a/src/ui/awaitable-ui-handler.ts +++ b/src/ui/awaitable-ui-handler.ts @@ -1,12 +1,26 @@ -import BattleScene from "../battle-scene"; +import BattleScene, { Button } from "../battle-scene"; import { Mode } from "./ui"; import UiHandler from "./ui-handler"; export default abstract class AwaitableUiHandler extends UiHandler { protected awaitingActionInput: boolean; protected onActionInput: Function; + public tutorialActive: boolean = false; constructor(scene: BattleScene, mode: Mode) { super(scene, mode); } + + processTutorialInput(button: Button): boolean { + if ((button === Button.ACTION || button === Button.CANCEL) && this.onActionInput) { + this.getUi().playSelect(); + const originalOnActionInput = this.onActionInput; + this.onActionInput = null; + originalOnActionInput(); + this.awaitingActionInput = false; + return true; + } + + return false; + } } \ No newline at end of file diff --git a/src/ui/egg-gacha-ui-handler.ts b/src/ui/egg-gacha-ui-handler.ts index 5a1eae12f..eaa03fe82 100644 --- a/src/ui/egg-gacha-ui-handler.ts +++ b/src/ui/egg-gacha-ui-handler.ts @@ -9,6 +9,7 @@ import { VoucherType, getVoucherTypeIcon } from "../system/voucher"; import { getPokemonSpecies } from "../data/pokemon-species"; import { Type } from "../data/type"; import { addWindow } from "./window"; +import { Tutorial, handleTutorial } from "../tutorial"; const defaultText = 'Select a machine.'; @@ -239,6 +240,8 @@ export default class EggGachaUiHandler extends MessageUiHandler { this.eggGachaContainer.setVisible(true); + handleTutorial(this.scene, Tutorial.Egg_Gacha); + return true; } @@ -477,6 +480,23 @@ export default class EggGachaUiHandler extends MessageUiHandler { }); } + showText(text: string, delay?: number, callback?: Function, callbackDelay?: number, prompt?: boolean, promptDelay?: number): void { + if (!text) + text = defaultText; + + if (text?.indexOf('\n') === -1) { + this.eggGachaMessageBox.setSize(320, 32); + this.eggGachaMessageBox.setY(0); + this.message.setY(8); + } else { + this.eggGachaMessageBox.setSize(320, 46); + this.eggGachaMessageBox.setY(-14); + this.message.setY(-6); + } + + super.showText(text, delay, callback, callbackDelay, prompt, promptDelay); + } + showError(text: string): void { this.showText(text, null, () => this.showText(defaultText), Utils.fixedInt(1500)); } diff --git a/src/ui/menu-ui-handler.ts b/src/ui/menu-ui-handler.ts index f1a9084a7..3d7e22c38 100644 --- a/src/ui/menu-ui-handler.ts +++ b/src/ui/menu-ui-handler.ts @@ -6,6 +6,7 @@ import { addWindow } from "./window"; import MessageUiHandler from "./message-ui-handler"; import { GameDataType } from "../system/game-data"; import { OptionSelectConfig } from "./abstact-option-select-ui-handler"; +import { Tutorial, handleTutorial } from "../tutorial"; export enum MenuOptions { GAME_SETTINGS, @@ -155,6 +156,8 @@ export default class MenuUiHandler extends MessageUiHandler { this.scene.playSound('menu_open'); + handleTutorial(this.scene, Tutorial.Menu); + return true; } diff --git a/src/ui/modifier-select-ui-handler.ts b/src/ui/modifier-select-ui-handler.ts index 7555b24fc..5d0cde552 100644 --- a/src/ui/modifier-select-ui-handler.ts +++ b/src/ui/modifier-select-ui-handler.ts @@ -5,6 +5,7 @@ import { addTextObject, getModifierTierTextTint, getTextColor, TextStyle } from import AwaitableUiHandler from "./awaitable-ui-handler"; import { Mode } from "./ui"; import { PokemonHeldItemModifier } from "../modifier/modifier"; +import { handleTutorial, Tutorial } from "../tutorial"; export const SHOP_OPTIONS_ROW_LIMIT = 6; @@ -163,8 +164,12 @@ export default class ModifierSelectUiHandler extends AwaitableUiHandler { this.setCursor(0); this.setRowCursor(1); - this.awaitingActionInput = true; - this.onActionInput = args[2]; + + handleTutorial(this.scene, Tutorial.Select_Item).then(() => { + this.setCursor(0); + this.awaitingActionInput = true; + this.onActionInput = args[2]; + }); }); return true; diff --git a/src/ui/starter-select-ui-handler.ts b/src/ui/starter-select-ui-handler.ts index 7412cc6c6..9be22375b 100644 --- a/src/ui/starter-select-ui-handler.ts +++ b/src/ui/starter-select-ui-handler.ts @@ -47,6 +47,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { private pokemonCaughtCountText: Phaser.GameObjects.Text; private genOptionsText: Phaser.GameObjects.Text; private instructionsText: Phaser.GameObjects.Text; + private starterSelectMessageBox: Phaser.GameObjects.NineSlice; private starterSelectMessageBoxContainer: Phaser.GameObjects.Container; private statsContainer: StatsContainer; @@ -291,12 +292,12 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.starterSelectMessageBoxContainer.setVisible(false); this.starterSelectContainer.add(this.starterSelectMessageBoxContainer); - const starterSelectMessageBox = addWindow(this.scene, 1, -1, 318, 28); - starterSelectMessageBox.setOrigin(0, 1); - this.starterSelectMessageBoxContainer.add(starterSelectMessageBox); + this.starterSelectMessageBox = addWindow(this.scene, 1, -1, 318, 28); + this.starterSelectMessageBox.setOrigin(0, 1); + this.starterSelectMessageBoxContainer.add(this.starterSelectMessageBox); - this.message = addTextObject(this.scene, 8, -8, '', TextStyle.WINDOW, { maxLines: 1 }); - this.message.setOrigin(0, 1); + this.message = addTextObject(this.scene, 8, 8, '', TextStyle.WINDOW, { maxLines: 2 }); + this.message.setOrigin(0, 0); this.starterSelectMessageBoxContainer.add(this.message); const date = new Date(); @@ -366,7 +367,7 @@ export default class StarterSelectUiHandler extends MessageUiHandler { this.setGenMode(true); this.setCursor(0); - //handleTutorial(this.scene, Tutorial.Starter_Select); + handleTutorial(this.scene, Tutorial.Starter_Select); return true; } @@ -377,7 +378,15 @@ export default class StarterSelectUiHandler extends MessageUiHandler { showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer) { super.showText(text, delay, callback, callbackDelay, prompt, promptDelay); - this.starterSelectMessageBoxContainer.setVisible(true); + if (text?.indexOf('\n') === -1) { + this.starterSelectMessageBox.setSize(318, 28); + this.message.setY(-22); + } else { + this.starterSelectMessageBox.setSize(318, 42); + this.message.setY(-37); + } + + this.starterSelectMessageBoxContainer.setVisible(!!text?.length); } processInput(button: Button): boolean { diff --git a/src/ui/ui.ts b/src/ui/ui.ts index c785f71b1..719b87b22 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -29,6 +29,7 @@ import RegistrationFormUiHandler from './registration-form-ui-handler'; import LoadingModalUiHandler from './loading-modal-ui-handler'; import * as Utils from "../utils"; import GameStatsUiHandler from './game-stats-ui-handler'; +import AwaitableUiHandler from './awaitable-ui-handler'; export enum Mode { MESSAGE, @@ -174,7 +175,12 @@ export default class UI extends Phaser.GameObjects.Container { if (this.overlayActive) return false; - return this.getHandler().processInput(button); + const handler = this.getHandler(); + + if (handler instanceof AwaitableUiHandler && handler.tutorialActive) + return handler.processTutorialInput(button); + + return handler.processInput(button); } showText(text: string, delay?: integer, callback?: Function, callbackDelay?: integer, prompt?: boolean, promptDelay?: integer): void {