From b32b802ab45fe08cc5756354a17526bb26ca13c9 Mon Sep 17 00:00:00 2001 From: Greenlamp2 <44787002+Greenlamp2@users.noreply.github.com> Date: Fri, 10 May 2024 15:54:14 +0200 Subject: [PATCH] QOL - Settings to choose party Exp display at the end of fight (#488) * added settings to manage how to display party experience at the end of fight * added back stats changes support when setting is on but ignored when on skip * removed a useless parameter * added new level in the text * only Lv. UP if level is greated than 200 * cleanup * added some comment * TSDoc comment block * EXP_Party -> EXP_Party_Display, Only Up -> Level Up Notification * better duration for the level up notification * typo Co-authored-by: Samuel H --------- Co-authored-by: Samuel H --- src/battle-scene.ts | 13 +++++++++++++ src/phases.ts | 31 ++++++++++++++++++++++++------- src/system/settings.ts | 6 ++++++ src/ui/party-exp-bar.ts | 14 ++++++++++++-- 4 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/battle-scene.ts b/src/battle-scene.ts index 28a09a24d..9a51950a5 100644 --- a/src/battle-scene.ts +++ b/src/battle-scene.ts @@ -101,6 +101,19 @@ export default class BattleScene extends SceneBase { public experimentalSprites: boolean = false; public moveAnimations: boolean = true; public expGainsSpeed: integer = 0; + /** + * Defines the experience gain display mode. + * + * @remarks + * The `expParty` can have several modes: + * - `0` - Default: The normal experience gain display, nothing changed. + * - `1` - Level Up Notification: Displays the level up in the small frame instead of a message. + * - `2` - Skip: No level up frame nor message. + * + * Modes `1` and `2` are still compatible with stats display, level up, new move, etc. + * @default 0 - Uses the default normal experience gain display. + */ + public expParty: integer = 0; public hpBarSpeed: integer = 0; public fusionPaletteSwaps: boolean = true; public enableTouchControls: boolean = false; diff --git a/src/phases.ts b/src/phases.ts index e2532c1c0..b697f7acb 100644 --- a/src/phases.ts +++ b/src/phases.ts @@ -3745,11 +3745,20 @@ export class ShowPartyExpBarPhase extends PlayerPartyMemberPokemonPhase { this.scene.unshiftPhase(new HidePartyExpBarPhase(this.scene)); pokemon.updateInfo(); - if (this.scene.expGainsSpeed < 3) { - this.scene.partyExpBar.showPokemonExp(pokemon, exp.value).then(() => { - if (newLevel > lastLevel) - this.end(); - else + if (this.scene.expParty === 2) { // 2 - Skip - no level up frame nor message + this.end(); + } else if (this.scene.expParty === 1) { // 1 - Only level up - we display the level up in the small frame instead of a message + if (newLevel > lastLevel) { // this means if we level up + // instead of displaying the exp gain in the small frame, we display the new level + // we use the same method for mode 0 & 1, by giving a parameter saying to display the exp or the level + this.scene.partyExpBar.showPokemonExp(pokemon, exp.value, this.scene.expParty === 1, newLevel).then(() => { + setTimeout(() => this.end(), 800 / Math.pow(2, this.scene.expGainsSpeed/2)); + }); + } else { + this.end(); + } + } else if (this.scene.expGainsSpeed < 3) { + this.scene.partyExpBar.showPokemonExp(pokemon, exp.value, this.scene.expParty === 1, newLevel).then(() => { setTimeout(() => this.end(), 500 / Math.pow(2, this.scene.expGainsSpeed)); }); } else { @@ -3780,6 +3789,7 @@ export class LevelUpPhase extends PlayerPartyMemberPokemonPhase { this.lastLevel = lastLevel; this.level = level; + this.scene = scene; } start() { @@ -3794,8 +3804,15 @@ export class LevelUpPhase extends PlayerPartyMemberPokemonPhase { const prevStats = pokemon.stats.slice(0); pokemon.calculateStats(); pokemon.updateInfo(); - this.scene.playSound('level_up_fanfare'); - this.scene.ui.showText(i18next.t('battle:levelUp', { pokemonName: this.getPokemon().name, level: this.level }), null, () => this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false).then(() => this.end()), null, true); + if (this.scene.expParty === 0) { // 0 - default - the normal exp gain display, nothing changed + this.scene.playSound('level_up_fanfare'); + this.scene.ui.showText(i18next.t('battle:levelUp', { pokemonName: this.getPokemon().name, level: this.level }), null, () => this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false).then(() => this.end()), null, true); + } else if (this.scene.expParty === 2) { // 2 - Skip - no level up frame nor message + this.end(); + } else { // 1 - Only level up - we display the level up in the small frame instead of a message + // we still want to display the stats if activated + this.scene.ui.getMessageHandler().promptLevelUpStats(this.partyMemberIndex, prevStats, false).then(() => this.end()); + } if (this.level <= 100) { const levelMoves = this.getPokemon().getLevelMoves(this.lastLevel + 1); for (let lm of levelMoves) diff --git a/src/system/settings.ts b/src/system/settings.ts index 680fadb1e..4b2c9eda1 100644 --- a/src/system/settings.ts +++ b/src/system/settings.ts @@ -21,6 +21,7 @@ export enum Setting { Move_Animations = "MOVE_ANIMATIONS", Show_Stats_on_Level_Up = "SHOW_LEVEL_UP_STATS", EXP_Gains_Speed = "EXP_GAINS_SPEED", + EXP_Party_Display = "EXP_PARTY_DISPLAY", HP_Bar_Speed = "HP_BAR_SPEED", Fusion_Palette_Swaps = "FUSION_PALETTE_SWAPS", Player_Gender = "PLAYER_GENDER", @@ -53,6 +54,7 @@ export const settingOptions: SettingOptions = { [Setting.Move_Animations]: [ 'Off', 'On' ], [Setting.Show_Stats_on_Level_Up]: [ 'Off', 'On' ], [Setting.EXP_Gains_Speed]: [ 'Normal', 'Fast', 'Faster', 'Skip' ], + [Setting.EXP_Party_Display]: [ 'Normal', 'Level Up Notification', 'Skip' ], [Setting.HP_Bar_Speed]: [ 'Normal', 'Fast', 'Faster', 'Instant' ], [Setting.Fusion_Palette_Swaps]: [ 'Off', 'On' ], [Setting.Player_Gender]: [ 'Boy', 'Girl' ], @@ -77,6 +79,7 @@ export const settingDefaults: SettingDefaults = { [Setting.Move_Animations]: 1, [Setting.Show_Stats_on_Level_Up]: 1, [Setting.EXP_Gains_Speed]: 0, + [Setting.EXP_Party_Display]: 0, [Setting.HP_Bar_Speed]: 0, [Setting.Fusion_Palette_Swaps]: 1, [Setting.Player_Gender]: 0, @@ -134,6 +137,9 @@ export function setSetting(scene: BattleScene, setting: Setting, value: integer) case Setting.EXP_Gains_Speed: scene.expGainsSpeed = value; break; + case Setting.EXP_Party_Display: + scene.expParty = value; + break; case Setting.HP_Bar_Speed: scene.hpBarSpeed = value; break; diff --git a/src/ui/party-exp-bar.ts b/src/ui/party-exp-bar.ts index a5451c5f2..93c69ce2c 100644 --- a/src/ui/party-exp-bar.ts +++ b/src/ui/party-exp-bar.ts @@ -29,7 +29,7 @@ export default class PartyExpBar extends Phaser.GameObjects.Container { this.shown = false; } - showPokemonExp(pokemon: Pokemon, expValue: integer): Promise { + showPokemonExp(pokemon: Pokemon, expValue: integer, showOnlyLevelUp: boolean, newLevel: number): Promise { return new Promise(resolve => { if (this.shown) return resolve(); @@ -39,7 +39,17 @@ export default class PartyExpBar extends Phaser.GameObjects.Container { this.add(this.pokemonIcon); - this.expText.setText(`+${expValue.toString()}`); + // if we want to only display the level in the small frame + if (showOnlyLevelUp) { + if (newLevel > 200) { // if the level is greater than 200, we only display Lv. UP + this.expText.setText('Lv. UP'); + } else { // otherwise we display Lv. Up and the new level + this.expText.setText(`Lv. UP: ${newLevel.toString()}`); + } + } else { + // if we want to display the exp + this.expText.setText(`+${expValue.toString()}`); + } this.bg.width = this.expText.displayWidth + 28;