From 075db8ae0c3e8a8e8693a23a29a4cc3fc0ebf373 Mon Sep 17 00:00:00 2001 From: Flashfyre Date: Thu, 4 Apr 2024 10:16:29 -0400 Subject: [PATCH] Show icon when saving data --- .../{vice-grip.json => vise-grip.json} | 0 public/images/ui/legacy/saving_icon.png | Bin 0 -> 293 bytes public/images/ui/saving_icon.png | Bin 0 -> 293 bytes src/loading-scene.ts | 2 + src/system/game-data.ts | 8 +- src/ui/saving-icon-handler.ts | 76 ++++++++++++++++++ src/ui/ui.ts | 7 ++ 7 files changed, 92 insertions(+), 1 deletion(-) rename public/battle-anims/{vice-grip.json => vise-grip.json} (100%) create mode 100644 public/images/ui/legacy/saving_icon.png create mode 100644 public/images/ui/saving_icon.png create mode 100644 src/ui/saving-icon-handler.ts diff --git a/public/battle-anims/vice-grip.json b/public/battle-anims/vise-grip.json similarity index 100% rename from public/battle-anims/vice-grip.json rename to public/battle-anims/vise-grip.json diff --git a/public/images/ui/legacy/saving_icon.png b/public/images/ui/legacy/saving_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..fddff8c2d39e4c8910e34480b9f4c76eea06df36 GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCilKdb&7P%EP~x z#d&lT7$>Aj>?p`IpVBHT@nUCF=7f3Qd9oGR6qsi)B{2$5QIk&C(Ga13;6TCWL+6g( z<$1SpX@FcALr^o%0ZvapJ&9AQyf#%^rhPJS@H}PkAWOgJq3DFmW1W(vb49YkN^Mx literal 0 HcmV?d00001 diff --git a/public/images/ui/saving_icon.png b/public/images/ui/saving_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..fddff8c2d39e4c8910e34480b9f4c76eea06df36 GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCilKdb&7P%EP~x z#d&lT7$>Aj>?p`IpVBHT@nUCF=7f3Qd9oGR6qsi)B{2$5QIk&C(Ga13;6TCWL+6g( z<$1SpX@FcALr^o%0ZvapJ&9AQyf#%^rhPJS@H}PkAWOgJq3DFmW1W(vb49YkN^Mx literal 0 HcmV?d00001 diff --git a/src/loading-scene.ts b/src/loading-scene.ts index f7535ed3074..e23b1d72467 100644 --- a/src/loading-scene.ts +++ b/src/loading-scene.ts @@ -97,6 +97,8 @@ export class LoadingScene extends SceneBase { this.loadImage('select_gen_cursor', 'ui'); this.loadImage('select_gen_cursor_highlight', 'ui'); + this.loadImage('saving_icon', 'ui'); + this.loadImage('default_bg', 'arenas'); // Load arena images Utils.getEnumValues(Biome).map(bt => { diff --git a/src/system/game-data.ts b/src/system/game-data.ts index 2591eb9a8d3..0810e8a6271 100644 --- a/src/system/game-data.ts +++ b/src/system/game-data.ts @@ -223,9 +223,12 @@ export class GameData { public saveSystem(): Promise { return new Promise(resolve => { + this.scene.ui.savingIcon.show(); updateUserInfo().then((success: boolean) => { - if (!success) + if (!success) { + this.scene.ui.savingIcon.hide(); return resolve(false); + } const data: SystemSaveData = { trainerId: this.trainerId, secretId: this.secretId, @@ -250,6 +253,7 @@ export class GameData { Utils.apiPost(`savedata/update?datatype=${GameDataType.SYSTEM}`, systemData) .then(response => response.text()) .then(error => { + this.scene.ui.savingIcon.hide(); if (error) { console.error(error); return resolve(false); @@ -261,6 +265,8 @@ export class GameData { localStorage.setItem('data', btoa(systemData)); + this.scene.ui.savingIcon.hide(); + resolve(true); } }); diff --git a/src/ui/saving-icon-handler.ts b/src/ui/saving-icon-handler.ts new file mode 100644 index 00000000000..71d9a11fb47 --- /dev/null +++ b/src/ui/saving-icon-handler.ts @@ -0,0 +1,76 @@ +import BattleScene from "#app/battle-scene"; +import * as Utils from "../utils"; + +export default class SavingIconHandler extends Phaser.GameObjects.Container { + private icon: Phaser.GameObjects.Sprite; + + private animActive: boolean; + private shown: boolean; + + constructor(scene: BattleScene) { + super(scene, scene.game.canvas.width / 6 - 4, scene.game.canvas.height / 6 - 4); + } + + setup(): void { + this.icon = this.scene.add.sprite(0, 0, 'saving_icon'); + this.icon.setOrigin(1, 1); + + this.add(this.icon); + + this.animActive = false; + this.shown = false; + + this.setAlpha(0); + this.setVisible(false); + } + + show(): void { + this.shown = true; + + if (this.animActive) + return; + + this.animActive = true; + + this.scene.tweens.add({ + targets: this, + alpha: 1, + duration: Utils.fixedInt(250), + ease: 'Sine.easeInOut', + onComplete: () => { + this.scene.time.delayedCall(Utils.fixedInt(500), () => { + this.animActive = false; + if (!this.shown) + this.hide(); + }); + } + }); + + this.setVisible(true); + this.shown = true; + } + + hide(): void { + this.shown = false; + + if (this.animActive) + return; + + this.animActive = true; + + this.scene.tweens.add({ + targets: this, + alpha: 0, + duration: Utils.fixedInt(250), + ease: 'Sine.easeInOut', + onComplete: () => { + this.animActive = false; + this.setVisible(false); + if (this.shown) + this.show(); + } + }); + + this.shown = false; + } +} \ No newline at end of file diff --git a/src/ui/ui.ts b/src/ui/ui.ts index dd8fcc12fba..3a044255811 100644 --- a/src/ui/ui.ts +++ b/src/ui/ui.ts @@ -32,6 +32,7 @@ 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'; +import SavingIconHandler from './saving-icon-handler'; export enum Mode { MESSAGE, @@ -95,6 +96,7 @@ export default class UI extends Phaser.GameObjects.Container { private handlers: UiHandler[]; private overlay: Phaser.GameObjects.Rectangle; public achvBar: AchvBar; + public savingIcon: SavingIconHandler; private tooltipContainer: Phaser.GameObjects.Container; private tooltipBg: Phaser.GameObjects.NineSlice; @@ -152,6 +154,11 @@ export default class UI extends Phaser.GameObjects.Container { this.achvBar.setup(); (this.scene as BattleScene).uiContainer.add(this.achvBar); + + this.savingIcon = new SavingIconHandler(this.scene as BattleScene); + this.savingIcon.setup(); + + (this.scene as BattleScene).uiContainer.add(this.savingIcon); } private setupTooltip() {