From cf959c6e1b4befd9561dcdc2cdb5c9b47c5799e2 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 21 Mar 2024 13:12:05 -0400 Subject: [PATCH] Add proper title screen and logo --- public/images/logo.png | Bin 0 -> 1250 bytes src/battle-scene.ts | 19 ++++---- src/phases.ts | 27 ++++++----- src/pipelines/field-sprite.ts | 2 +- src/system/game-data.ts | 19 +++++--- src/ui/daily-run-scoreboard.ts | 10 +--- src/ui/save-slot-select-ui-handler.ts | 2 +- src/ui/title-ui-handler.ts | 65 ++++++++++++++++++++++++++ src/ui/ui.ts | 4 ++ 9 files changed, 108 insertions(+), 40 deletions(-) create mode 100644 public/images/logo.png create mode 100644 src/ui/title-ui-handler.ts diff --git a/public/images/logo.png b/public/images/logo.png new file mode 100644 index 0000000000000000000000000000000000000000..16e559d9c3884a8d5d1210898c1ee6d1f6122ed2 GIT binary patch literal 1250 zcmV<81ReW{P)sA|(wc$P7cVO*$^IU8=nR2jCnWfD61TT`rOCH7OVdIyxH43{AFKF+#|) zB-`&97FP_hEq&5w{RO)4Z#`UHokGUC*zdcLxg;HO?{5KLDZS^?#j^VA^UHU||NQ#x zH$Vud5}-L9hQqE1*cR|v3B~C=wJt7V!4J1juVDx~w*%nJLkK4iU`+6m3+|m8UkO5S zy0l8L{_f?z!^RIGWIMoW{92^K>t=QKDFRM~&q6ATPE(QH9kDREN)W83@x6os3~!Im zVS602B3KQ4R#LTU?@y`l?&ZFt(Ss69Tf4kHK8MY69UiXc1Iwk9x5wuXds@MlLn>Hv z+dE1u4Z&h-2)hpvVeZ8_O44gid>T^W=7rk}I<-WuzT{;skgBF$Q{w|dVdB&D-Kx!# z#KJ|dlqw{ErDrj*nbgI8|6VIfBMOiWds7%w_`G* zsOF5mJ&vOBysa|656j&i$8ddqd7{O7Y94m8I&SDj|QuT_bJ&)m|I@gd5^={5c2J6K=tdw3}T>TuRqKXY6 z{X!*D-9EjlJ1gALrDRH^!cMnzbub!8$)@+m_JO^vjR7SpH?r{Hg7bYTQel9W))^eV zU5%=A%#liy&gj{cOsS^wlFEXYtDUrKdmK%q;zlT5TyVbkl8U|*c!9A(m}{A}1+hdb zZJTa!48}*#X^Z0=yp#Zzda8D}tHsslC_xxmL2WmG6+J=I0QjVlG6&o=kofX$yNVQ8zXL<2**x?Ki z%-V#+bo1V&{ew$)S136Ne__kLz8D}(gxLIuJ4a<=r{Fs!nK|i&i#S@m`0E*|CM=~F zj094n3dxUJoAy(M%^HO|japoXGgq3h$OcE&)Hk;=vEo{&+FWB>3?WksMl+L=^uRJL zLqseyb-zY-4qmIBQw>3`Uf%Oi0xYCf*U}by9jzgiWXR2O9d1@~bj@_@h%laTSdgb^L|2}D8ECjdB+}|T{LqScdnc}~6Qt6H2 zgtj?l1B;U-Lg(6`v|b)Rnu>SJ>$dFAso`qNynTB8@MxrSrDWf|+;^6{Qu}lD$~|uy zH)!WQQY0!(R9dfiWolC%XM-Aet#{SXE9boVpGqO*#!}%|Uw~6e53SjtMZL@eQg|8P zb!lF5t2Ss!ug>!_JR$zOMYPsz(3)P0@Uwo_+{F4{qtsWhL2G*b1;rTe>f}>>CIA2c M07*qoM6N<$f=C8obN~PV literal 0 HcmV?d00001 diff --git a/src/battle-scene.ts b/src/battle-scene.ts index d9a8ab31251..ffb8c90f03a 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -54,7 +54,6 @@ import CharSprite from './ui/char-sprite'; import DamageNumberHandler from './field/damage-number-handler'; import PokemonInfoContainer from './ui/pokemon-info-container'; import { biomeDepths } from './data/biomes'; -import { DailyRunScoreboard } from './ui/daily-run-scoreboard'; export const bypassLogin = false; @@ -124,8 +123,8 @@ export default class BattleScene extends Phaser.Scene { public pbTrayEnemy: PokeballTray; public abilityBar: AbilityBar; public partyExpBar: PartyExpBar; - public arenaBg: Phaser.GameObjects.Sprite; - public arenaBgTransition: Phaser.GameObjects.Sprite; + public arenaBg: Phaser.GameObjects.NineSlice; + public arenaBgTransition: Phaser.GameObjects.NineSlice; public arenaPlayer: ArenaBase; public arenaPlayerTransition: ArenaBase; public arenaEnemy: ArenaBase; @@ -139,7 +138,6 @@ export default class BattleScene extends Phaser.Scene { public pokeballCounts: PokeballCounts; public money: integer; public pokemonInfoContainer: PokemonInfoContainer; - public dailyRunScoreboard: DailyRunScoreboard; private party: PlayerPokemon[]; private waveCountText: Phaser.GameObjects.Text; private moneyText: Phaser.GameObjects.Text; @@ -316,6 +314,8 @@ export default class BattleScene extends Phaser.Scene { this.loadImage('default_bg', 'arenas'); + this.loadImage('logo', ''); + // Load arena images Utils.getEnumValues(Biome).map(bt => { const btKey = Biome[bt].toLowerCase(); @@ -480,12 +480,14 @@ export default class BattleScene extends Phaser.Scene { } launchBattle() { - this.arenaBg = this.addFieldSprite(0, 0, 'plains_bg', null, 0); - this.arenaBgTransition = this.addFieldSprite(0, 0, `plains_bg`, null, 1); + this.arenaBg = this.add.nineslice(0, 0, 'plains_bg', null, 320, 180, 0, 0, 132, 0); + this.arenaBgTransition = this.add.nineslice(0, 0, 'plains_bg', null, 320, 180, 0, 0, 132, 0); [ this.arenaBgTransition, this.arenaBg ].forEach(a => { + a.setPipeline(this.fieldSpritePipeline); a.setScale(6); a.setOrigin(0); + a.setSize(320, 240); }); const field = this.add.container(0, 0); @@ -569,11 +571,6 @@ export default class BattleScene extends Phaser.Scene { this.fieldUI.add(this.pokemonInfoContainer); - this.dailyRunScoreboard = new DailyRunScoreboard(this, 1, -(this.game.canvas.height / 6) + 1); - this.dailyRunScoreboard.setup(); - - this.fieldUI.add(this.dailyRunScoreboard); - this.party = []; let loadPokemonAssets = []; diff --git a/src/phases.ts b/src/phases.ts index 6094c2bb8ec..c87c6e7c276 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -43,7 +43,7 @@ import { EggHatchPhase } from "./egg-hatch-phase"; import { Egg } from "./data/egg"; import { vouchers } from "./system/voucher"; import { loggedInUser, updateUserInfo } from "./account"; -import { GameDataType, PlayerGender } from "./system/game-data"; +import { GameDataType, PlayerGender, SessionSaveData } from "./system/game-data"; import { addPokeballCaptureStars, addPokeballOpenParticles } from "./field/anims"; import { SpeciesFormChangeActiveTrigger, SpeciesFormChangeManualTrigger, SpeciesFormChangeMoveLearnedTrigger, SpeciesFormChangeMoveUsedTrigger } from "./data/pokemon-forms"; import { battleSpecDialogue, getCharVariantFromDialogue } from "./data/dialogue"; @@ -127,6 +127,7 @@ export class LoginPhase extends Phase { export class TitlePhase extends Phase { private loaded: boolean; + private lastSessionData: SessionSaveData; constructor(scene: BattleScene) { super(scene); @@ -142,7 +143,13 @@ export class TitlePhase extends Phase { this.scene.fadeOutBgm(0, false); - this.showOptions(); + this.scene.gameData.getSession(loggedInUser.lastSessionSlot).then(sessionData => { + this.lastSessionData = sessionData; + const biomeKey = getBiomeKey(sessionData.arena.biome); + const bgTexture = `${biomeKey}_bg`; + this.scene.arenaBg.setTexture(bgTexture); + this.showOptions(); + }); } showOptions(): void { @@ -150,7 +157,7 @@ export class TitlePhase extends Phase { if (loggedInUser?.lastSessionSlot > -1) { options.push({ label: 'Continue', - handler: () => this.loadSaveSlot(loggedInUser.lastSessionSlot) + handler: () => this.loadSaveSlot(-1) }); } options.push({ @@ -178,18 +185,16 @@ export class TitlePhase extends Phase { }); const config: OptionSelectConfig = { options: options, - noCancel: true + noCancel: true, + yOffset: 47 }; - this.scene.ui.setMode(Mode.OPTION_SELECT, config); - - this.scene.dailyRunScoreboard.showAndUpdate(); + this.scene.ui.setMode(Mode.TITLE, config); } loadSaveSlot(slotId: integer): void { - this.scene.sessionSlotId = slotId; + this.scene.sessionSlotId = slotId > -1 ? slotId : loggedInUser.lastSessionSlot; this.scene.ui.setMode(Mode.MESSAGE); - this.scene.dailyRunScoreboard.hide(); - this.scene.gameData.loadSession(this.scene, slotId).then((success: boolean) => { + this.scene.gameData.loadSession(this.scene, slotId, slotId === -1 ? this.lastSessionData : null).then((success: boolean) => { if (success) { this.loaded = true; this.scene.ui.showText('Session loaded successfully.', null, () => this.end()); @@ -256,8 +261,6 @@ export class TitlePhase extends Phase { } end(): void { - this.scene.dailyRunScoreboard.hide(); - if (!this.loaded && !this.scene.gameMode.isDaily) { this.scene.arena.preloadBgm(); this.scene.pushPhase(new SelectStarterPhase(this.scene)); diff --git a/src/pipelines/field-sprite.ts b/src/pipelines/field-sprite.ts index 22a2ba31994..80e3037a601 100644 --- a/src/pipelines/field-sprite.ts +++ b/src/pipelines/field-sprite.ts @@ -109,7 +109,7 @@ vec3 hsl2rgb(vec3 hsl) { rgb.r = hue2rgb(f1, f2, hsl.x + (1.0/3.0)); rgb.g = hue2rgb(f1, f2, hsl.x); - rgb.b= hue2rgb(f1, f2, hsl.x - (1.0/3.0)); + rgb.b = hue2rgb(f1, f2, hsl.x - (1.0/3.0)); } return rgb; diff --git a/src/system/game-data.ts b/src/system/game-data.ts index afad63067c8..e4f59f3e890 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -537,10 +537,10 @@ export class GameData { }); } - loadSession(scene: BattleScene, slotId: integer): Promise { + loadSession(scene: BattleScene, slotId: integer, sessionData?: SessionSaveData): Promise { return new Promise(async (resolve, reject) => { try { - this.getSession(slotId).then(async sessionData => { + const initSessionFromData = async sessionData => { console.debug(sessionData); scene.setSeed(sessionData.seed || scene.game.config.seed[0]); @@ -614,10 +614,17 @@ export class GameData { scene.updateModifiers(false); Promise.all(loadPokemonAssets).then(() => resolve(true)); - }).catch(err => { - reject(err); - return; - }); + }; + if (sessionData) + initSessionFromData(sessionData); + else { + this.getSession(slotId) + .then(data => initSessionFromData(data)) + .catch(err => { + reject(err); + return; + }); + } } catch (err) { reject(err); return; diff --git a/src/ui/daily-run-scoreboard.ts b/src/ui/daily-run-scoreboard.ts index ada896e1c67..2e7bc4810ea 100644 --- a/src/ui/daily-run-scoreboard.ts +++ b/src/ui/daily-run-scoreboard.ts @@ -40,8 +40,6 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { this.loadingLabel.setVisible(false); this.add(this.loadingLabel); - - this.setVisible(false); } updateRankings(rankings: RankingEntry[]) { @@ -72,7 +70,7 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { }); } - showAndUpdate() { + update() { this.rankingsContainer.removeAll(true); this.loadingLabel.setText('Loading…'); @@ -87,12 +85,6 @@ export class DailyRunScoreboard extends Phaser.GameObjects.Container { } else this.loadingLabel.setText('No Rankings'); }); - - this.setVisible(true); - } - - hide() { - this.setVisible(false); } } diff --git a/src/ui/save-slot-select-ui-handler.ts b/src/ui/save-slot-select-ui-handler.ts index 4a3030fceb4..bc9064b2f8e 100644 --- a/src/ui/save-slot-select-ui-handler.ts +++ b/src/ui/save-slot-select-ui-handler.ts @@ -290,7 +290,7 @@ class SessionSlot extends Phaser.GameObjects.Container { this.hasData = true; await this.setupWithData(sessionData); resolve(true); - }) + }); }); } } diff --git a/src/ui/title-ui-handler.ts b/src/ui/title-ui-handler.ts new file mode 100644 index 00000000000..20f126ae7b3 --- /dev/null +++ b/src/ui/title-ui-handler.ts @@ -0,0 +1,65 @@ +import BattleScene from "../battle-scene"; +import { DailyRunScoreboard } from "./daily-run-scoreboard"; +import OptionSelectUiHandler from "./option-select-ui-handler"; +import { Mode } from "./ui"; +import * as Utils from "../utils"; + +export default class TitleUiHandler extends OptionSelectUiHandler { + private titleContainer: Phaser.GameObjects.Container; + private dailyRunScoreboard: DailyRunScoreboard; + + constructor(scene: BattleScene, mode: Mode = Mode.TITLE) { + super(scene, mode); + } + + setup() { + super.setup(); + + const ui = this.getUi(); + + this.titleContainer = this.scene.add.container(0, -(this.scene.game.canvas.height / 6)); + this.titleContainer.setAlpha(0); + ui.add(this.titleContainer); + + const logo = this.scene.add.image((this.scene.game.canvas.width / 6) / 2, 8, 'logo'); + logo.setOrigin(0.5, 0); + this.titleContainer.add(logo); + + this.dailyRunScoreboard = new DailyRunScoreboard(this.scene, 1, 49); + this.dailyRunScoreboard.setup(); + + this.titleContainer.add(this.dailyRunScoreboard); + } + + show(args: any[]): boolean { + const ret = super.show(args); + + if (ret) { + const ui = this.getUi(); + + this.dailyRunScoreboard.update(); + + this.scene.tweens.add({ + targets: [ this.titleContainer, ui.getMessageHandler().bg ], + duration: Utils.fixedInt(325), + alpha: (target: any) => target === this.titleContainer ? 1 : 0, + ease: 'Sine.easeInOut' + }); + } + + return ret; + } + + clear(): void { + super.clear(); + + const ui = this.getUi(); + + this.scene.tweens.add({ + targets: [ this.titleContainer, ui.getMessageHandler().bg ], + duration: Utils.fixedInt(325), + alpha: (target: any) => target === this.titleContainer ? 0 : 1, + ease: 'Sine.easeInOut' + }); + } +} \ No newline at end of file diff --git a/src/ui/ui.ts b/src/ui/ui.ts index c3391cc2f2e..c30cd9fbe90 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -31,9 +31,11 @@ import * as Utils from "../utils"; import GameStatsUiHandler from './game-stats-ui-handler'; import AwaitableUiHandler from './awaitable-ui-handler'; import SaveSlotSelectUiHandler from './save-slot-select-ui-handler'; +import TitleUiHandler from './title-ui-handler'; export enum Mode { MESSAGE, + TITLE, COMMAND, FIGHT, BALL, @@ -73,6 +75,7 @@ const transitionModes = [ ]; const noTransitionModes = [ + Mode.TITLE, Mode.CONFIRM, Mode.OPTION_SELECT, Mode.MENU, @@ -107,6 +110,7 @@ export default class UI extends Phaser.GameObjects.Container { this.modeChain = []; this.handlers = [ new BattleMessageUiHandler(scene), + new TitleUiHandler(scene), new CommandUiHandler(scene), new FightUiHandler(scene), new BallUiHandler(scene),