Truncate names in battle info and party UI when too long
This commit is contained in:
parent
fa94db0939
commit
67ac5d3139
|
@ -2,7 +2,7 @@ import { default as Pokemon } from '../pokemon';
|
||||||
import { getLevelTotalExp, getLevelRelExp } from '../data/exp';
|
import { getLevelTotalExp, getLevelRelExp } from '../data/exp';
|
||||||
import * as Utils from '../utils';
|
import * as Utils from '../utils';
|
||||||
import { addTextObject, TextStyle } from './text';
|
import { addTextObject, TextStyle } from './text';
|
||||||
import { getGenderSymbol, getGenderColor } from '../data/gender';
|
import { getGenderSymbol, getGenderColor, Gender } from '../data/gender';
|
||||||
import { StatusEffect } from '../data/status-effect';
|
import { StatusEffect } from '../data/status-effect';
|
||||||
import BattleScene from '../battle-scene';
|
import BattleScene from '../battle-scene';
|
||||||
|
|
||||||
|
@ -117,12 +117,8 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
|
||||||
}
|
}
|
||||||
|
|
||||||
initInfo(pokemon: Pokemon) {
|
initInfo(pokemon: Pokemon) {
|
||||||
this.nameText.setText(pokemon.name);
|
this.updateNameText(pokemon);
|
||||||
this.lastName = pokemon.name;
|
const nameTextWidth = this.nameText.displayWidth;
|
||||||
|
|
||||||
const nameSizeTest = addTextObject(this.scene, 0, 0, pokemon.name, TextStyle.BATTLE_INFO);
|
|
||||||
const nameTextWidth = nameSizeTest.displayWidth;
|
|
||||||
nameSizeTest.destroy();
|
|
||||||
|
|
||||||
this.genderText.setText(getGenderSymbol(pokemon.gender));
|
this.genderText.setText(getGenderSymbol(pokemon.gender));
|
||||||
this.genderText.setColor(getGenderColor(pokemon.gender));
|
this.genderText.setColor(getGenderColor(pokemon.gender));
|
||||||
|
@ -204,14 +200,10 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lastName !== pokemon.name) {
|
if (this.lastName !== pokemon.name) {
|
||||||
this.nameText.setText(pokemon.name);
|
this.updateNameText(pokemon);
|
||||||
this.lastName = pokemon.name;
|
const nameTextWidth = this.nameText.displayWidth;
|
||||||
|
|
||||||
const nameSizeTest = addTextObject(this.scene, 0, 0, pokemon.name, TextStyle.BATTLE_INFO);
|
|
||||||
const nameTextWidth = nameSizeTest.displayWidth;
|
|
||||||
nameSizeTest.destroy();
|
|
||||||
|
|
||||||
this.genderText.setPositionRelative(this.nameText, nameTextWidth, 0);
|
this.genderText.setPositionRelative(this.nameText, nameTextWidth, 0);
|
||||||
|
this.splicedIcon.setPositionRelative(this.nameText, nameTextWidth + this.genderText.displayWidth + 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.lastStatus !== (pokemon.status?.effect || StatusEffect.NONE)) {
|
if (this.lastStatus !== (pokemon.status?.effect || StatusEffect.NONE)) {
|
||||||
|
@ -285,11 +277,30 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
updatePokemonExp(battler: Pokemon, instant?: boolean): Promise<void> {
|
updateNameText(pokemon: Pokemon): void {
|
||||||
|
let displayName = pokemon.name;
|
||||||
|
let nameTextWidth: number;
|
||||||
|
|
||||||
|
let nameSizeTest = addTextObject(this.scene, 0, 0, displayName, TextStyle.BATTLE_INFO);
|
||||||
|
nameTextWidth = nameSizeTest.displayWidth;
|
||||||
|
|
||||||
|
while (nameTextWidth > 60 - ((pokemon.gender !== Gender.GENDERLESS ? 6 : 0) + (pokemon.fusionSpecies ? 6 : 0) + (pokemon.isShiny() ? 8 : 0) + (Math.min(pokemon.level.toString().length, 3) - 3) * 8)) {
|
||||||
|
displayName = `${displayName.slice(0, displayName.endsWith('.') ? -2 : -1).trimEnd()}.`;
|
||||||
|
nameSizeTest.setText(displayName);
|
||||||
|
nameTextWidth = nameSizeTest.displayWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
nameSizeTest.destroy();
|
||||||
|
|
||||||
|
this.nameText.setText(displayName);
|
||||||
|
this.lastName = pokemon.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
updatePokemonExp(pokemon: Pokemon, instant?: boolean): Promise<void> {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const levelUp = this.lastLevel < battler.level;
|
const levelUp = this.lastLevel < pokemon.level;
|
||||||
const relLevelExp = getLevelRelExp(this.lastLevel + 1, battler.species.growthRate);
|
const relLevelExp = getLevelRelExp(this.lastLevel + 1, pokemon.species.growthRate);
|
||||||
const levelExp = levelUp ? relLevelExp : battler.levelExp;
|
const levelExp = levelUp ? relLevelExp : pokemon.levelExp;
|
||||||
let ratio = relLevelExp ? levelExp / relLevelExp : 0;
|
let ratio = relLevelExp ? levelExp / relLevelExp : 0;
|
||||||
if (this.lastLevel >= (this.scene as BattleScene).getMaxExpLevel(true)) {
|
if (this.lastLevel >= (this.scene as BattleScene).getMaxExpLevel(true)) {
|
||||||
if (levelUp)
|
if (levelUp)
|
||||||
|
@ -321,12 +332,12 @@ export default class BattleInfo extends Phaser.GameObjects.Container {
|
||||||
this.setLevel(this.lastLevel);
|
this.setLevel(this.lastLevel);
|
||||||
this.scene.time.delayedCall(500, () => {
|
this.scene.time.delayedCall(500, () => {
|
||||||
this.expBar.setScale(0, 1);
|
this.expBar.setScale(0, 1);
|
||||||
this.updateInfo(battler, instant).then(() => resolve());
|
this.updateInfo(pokemon, instant).then(() => resolve());
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
this.lastExp = battler.exp;
|
this.lastExp = pokemon.exp;
|
||||||
this.lastLevelExp = battler.levelExp;
|
this.lastLevelExp = pokemon.levelExp;
|
||||||
}
|
}
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
|
|
@ -759,7 +759,21 @@ class PartySlot extends Phaser.GameObjects.Container {
|
||||||
const slotInfoContainer = this.scene.add.container(0, 0);
|
const slotInfoContainer = this.scene.add.container(0, 0);
|
||||||
this.add(slotInfoContainer);
|
this.add(slotInfoContainer);
|
||||||
|
|
||||||
const slotName = addTextObject(this.scene, 0, 0, this.pokemon.name, TextStyle.PARTY);
|
let displayName = this.pokemon.name;
|
||||||
|
let nameTextWidth: number;
|
||||||
|
|
||||||
|
let nameSizeTest = addTextObject(this.scene, 0, 0, displayName, TextStyle.PARTY);
|
||||||
|
nameTextWidth = nameSizeTest.displayWidth;
|
||||||
|
|
||||||
|
while (nameTextWidth > (this.slotIndex ? 52 : 80)) {
|
||||||
|
displayName = `${displayName.slice(0, displayName.endsWith('.') ? -2 : -1).trimEnd()}.`;
|
||||||
|
nameSizeTest.setText(displayName);
|
||||||
|
nameTextWidth = nameSizeTest.displayWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
nameSizeTest.destroy();
|
||||||
|
|
||||||
|
const slotName = addTextObject(this.scene, 0, 0, displayName, TextStyle.PARTY);
|
||||||
slotName.setPositionRelative(slotBg, this.slotIndex >= battlerCount ? 21 : 24, this.slotIndex >= battlerCount ? 2 : 10);
|
slotName.setPositionRelative(slotBg, this.slotIndex >= battlerCount ? 21 : 24, this.slotIndex >= battlerCount ? 2 : 10);
|
||||||
slotName.setOrigin(0, 0);
|
slotName.setOrigin(0, 0);
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,6 @@ export default class PokemonIconAnimHandler {
|
||||||
if (this.icons.has(i) && this.icons.get(i) === mode)
|
if (this.icons.has(i) && this.icons.get(i) === mode)
|
||||||
continue;
|
continue;
|
||||||
if (this.toggled) {
|
if (this.toggled) {
|
||||||
console.log(i.frame)
|
|
||||||
const lastYDelta = this.icons.has(i)
|
const lastYDelta = this.icons.has(i)
|
||||||
? this.icons.get(i)
|
? this.icons.get(i)
|
||||||
: 0;
|
: 0;
|
||||||
|
|
Loading…
Reference in New Issue