mirror of
https://github.com/pagefaultgames/pokerogue.git
synced 2024-11-26 00:36:25 +00:00
Add move description text scrolling and summary sprite
This commit is contained in:
parent
860c1a5c11
commit
b743a44f4b
@ -159,13 +159,18 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
Promise.allSettled(moveIds.map(m => initAnim(m)))
|
Promise.allSettled(moveIds.map(m => initAnim(m)))
|
||||||
.then(() => {
|
.then(() => {
|
||||||
loadMoveAnimAssets(this.scene as BattleScene, moveIds);
|
loadMoveAnimAssets(this.scene as BattleScene, moveIds);
|
||||||
(this.scene as BattleScene).loadAtlas(this.getSpriteKey(), 'pokemon', this.getAtlasPath());
|
(this.scene as BattleScene).loadAtlas(this.getSpriteKey(), 'pokemon', this.getSpriteAtlasPath());
|
||||||
|
if (this.isPlayer())
|
||||||
|
(this.scene as BattleScene).loadAtlas(this.getBattleSpriteKey(), 'pokemon', this.getBattleSpriteAtlasPath());
|
||||||
this.scene.load.audio(this.species.speciesId.toString(), `audio/cry/${this.species.speciesId}.mp3`);
|
this.scene.load.audio(this.species.speciesId.toString(), `audio/cry/${this.species.speciesId}.mp3`);
|
||||||
this.scene.load.once(Phaser.Loader.Events.COMPLETE, () => {
|
this.scene.load.once(Phaser.Loader.Events.COMPLETE, () => {
|
||||||
const originalWarn = console.warn;
|
const originalWarn = console.warn;
|
||||||
// Ignore warnings for missing frames, because there will be a lot
|
// Ignore warnings for missing frames, because there will be a lot
|
||||||
console.warn = () => {};
|
console.warn = () => {};
|
||||||
const frameNames = this.scene.anims.generateFrameNames(this.getSpriteKey(), { zeroPad: 4, suffix: ".png", start: 1, end: 256 });
|
const frameNames = this.scene.anims.generateFrameNames(this.getSpriteKey(), { zeroPad: 4, suffix: ".png", start: 1, end: 256 });
|
||||||
|
const battleFrameNames = this.isPlayer()
|
||||||
|
? this.scene.anims.generateFrameNames(this.getBattleSpriteKey(), { zeroPad: 4, suffix: ".png", start: 1, end: 256 })
|
||||||
|
: null;
|
||||||
console.warn = originalWarn;
|
console.warn = originalWarn;
|
||||||
this.scene.anims.create({
|
this.scene.anims.create({
|
||||||
key: this.getSpriteKey(),
|
key: this.getSpriteKey(),
|
||||||
@ -173,6 +178,14 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
frameRate: 12,
|
frameRate: 12,
|
||||||
repeat: -1
|
repeat: -1
|
||||||
});
|
});
|
||||||
|
if (this.isPlayer()) {
|
||||||
|
this.scene.anims.create({
|
||||||
|
key: this.getBattleSpriteKey(),
|
||||||
|
frames: battleFrameNames,
|
||||||
|
frameRate: 12,
|
||||||
|
repeat: -1
|
||||||
|
});
|
||||||
|
}
|
||||||
this.playAnim();
|
this.playAnim();
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
@ -182,18 +195,30 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getAtlasPath(): string {
|
getSpriteAtlasPath(): string {
|
||||||
return this.getSpriteId().replace(/\_{2}/g, '/');
|
return this.getSpriteId().replace(/\_{2}/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBattleSpriteAtlasPath(): string {
|
||||||
|
return this.getBattleSpriteId().replace(/\_{2}/g, '/');
|
||||||
|
}
|
||||||
|
|
||||||
getSpriteId(): string {
|
getSpriteId(): string {
|
||||||
return `${this.isPlayer() ? 'back__' : ''}${this.shiny ? 'shiny__' : ''}${this.species.genderDiffs && !this.gender ? 'female__' : ''}${this.species.speciesId}`;
|
return `${this.shiny ? 'shiny__' : ''}${this.species.genderDiffs && !this.gender ? 'female__' : ''}${this.species.speciesId}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
getBattleSpriteId(): string {
|
||||||
|
return `${this.isPlayer() ? 'back__' : ''}${this.getSpriteId()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
getSpriteKey(): string {
|
getSpriteKey(): string {
|
||||||
return `pkmn__${this.getSpriteId()}`;
|
return `pkmn__${this.getSpriteId()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getBattleSpriteKey(): string {
|
||||||
|
return `pkmn__${this.getBattleSpriteId()}`;
|
||||||
|
}
|
||||||
|
|
||||||
getIconAtlasKey(): string {
|
getIconAtlasKey(): string {
|
||||||
return `pokemon_icons_${this.species.generation}`;
|
return `pokemon_icons_${this.species.generation}`;
|
||||||
}
|
}
|
||||||
@ -219,9 +244,9 @@ export default abstract class Pokemon extends Phaser.GameObjects.Container {
|
|||||||
}
|
}
|
||||||
|
|
||||||
playAnim() {
|
playAnim() {
|
||||||
this.getSprite().play(this.getSpriteKey());
|
this.getSprite().play(this.getBattleSpriteKey());
|
||||||
this.getTintSprite().play(this.getSpriteKey());
|
this.getTintSprite().play(this.getBattleSpriteKey());
|
||||||
this.getZoomSprite().play(this.getSpriteKey());
|
this.getZoomSprite().play(this.getBattleSpriteKey());
|
||||||
}
|
}
|
||||||
|
|
||||||
calculateStats() {
|
calculateStats() {
|
||||||
|
@ -21,6 +21,7 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
private summaryUiMode: SummaryUiMode;
|
private summaryUiMode: SummaryUiMode;
|
||||||
|
|
||||||
private summaryContainer: Phaser.GameObjects.Container;
|
private summaryContainer: Phaser.GameObjects.Container;
|
||||||
|
private pokemonSprite: Phaser.GameObjects.Sprite;
|
||||||
private summaryPageContainer: Phaser.GameObjects.Container;
|
private summaryPageContainer: Phaser.GameObjects.Container;
|
||||||
private movesContainer: Phaser.GameObjects.Container;
|
private movesContainer: Phaser.GameObjects.Container;
|
||||||
private moveDescriptionText: Phaser.GameObjects.Text;
|
private moveDescriptionText: Phaser.GameObjects.Text;
|
||||||
@ -30,6 +31,7 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
private extraMoveRowContainer: Phaser.GameObjects.Container;
|
private extraMoveRowContainer: Phaser.GameObjects.Container;
|
||||||
private summaryPageTransitionContainer: Phaser.GameObjects.Container;
|
private summaryPageTransitionContainer: Phaser.GameObjects.Container;
|
||||||
|
|
||||||
|
private moveDescriptionScrollTween: Phaser.Tweens.Tween;
|
||||||
private moveCursorBlinkTimer: Phaser.Time.TimerEvent;
|
private moveCursorBlinkTimer: Phaser.Time.TimerEvent;
|
||||||
|
|
||||||
private pokemon: PlayerPokemon;
|
private pokemon: PlayerPokemon;
|
||||||
@ -56,6 +58,9 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
summaryBg.setOrigin(0, 1);
|
summaryBg.setOrigin(0, 1);
|
||||||
this.summaryContainer.add(summaryBg);
|
this.summaryContainer.add(summaryBg);
|
||||||
|
|
||||||
|
this.pokemonSprite = this.scene.add.sprite(56, -106, `pkmn__sub`);
|
||||||
|
this.summaryContainer.add(this.pokemonSprite);
|
||||||
|
|
||||||
const getSummaryPageBg = () => {
|
const getSummaryPageBg = () => {
|
||||||
const ret = this.scene.add.sprite(0, 0, this.getPageKey(0));
|
const ret = this.scene.add.sprite(0, 0, this.getPageKey(0));
|
||||||
ret.setOrigin(0, 1);
|
ret.setOrigin(0, 1);
|
||||||
@ -85,6 +90,7 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
this.summaryContainer.setVisible(true);
|
this.summaryContainer.setVisible(true);
|
||||||
this.cursor = -1;
|
this.cursor = -1;
|
||||||
|
|
||||||
|
this.pokemonSprite.play(this.pokemon.getSpriteKey());
|
||||||
this.pokemon.cry();
|
this.pokemon.cry();
|
||||||
|
|
||||||
switch (this.summaryUiMode) {
|
switch (this.summaryUiMode) {
|
||||||
@ -116,9 +122,10 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
if (this.summaryUiMode === SummaryUiMode.LEARN_MOVE)
|
if (this.summaryUiMode === SummaryUiMode.LEARN_MOVE)
|
||||||
this.moveSelectFunction(this.moveCursor);
|
this.moveSelectFunction(this.moveCursor);
|
||||||
else {
|
else {
|
||||||
if (this.selectedMoveIndex === -1)
|
if (this.selectedMoveIndex === -1) {
|
||||||
this.selectedMoveIndex = this.moveCursor;
|
this.selectedMoveIndex = this.moveCursor;
|
||||||
else {
|
this.setCursor(this.moveCursor);
|
||||||
|
} else {
|
||||||
if (this.selectedMoveIndex !== this.moveCursor) {
|
if (this.selectedMoveIndex !== this.moveCursor) {
|
||||||
const tempMove = this.pokemon.moveset[this.selectedMoveIndex];
|
const tempMove = this.pokemon.moveset[this.selectedMoveIndex];
|
||||||
this.pokemon.moveset[this.selectedMoveIndex] = this.pokemon.moveset[this.moveCursor];
|
this.pokemon.moveset[this.selectedMoveIndex] = this.pokemon.moveset[this.moveCursor];
|
||||||
@ -198,6 +205,27 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
const selectedMove = this.getSelectedMove();
|
const selectedMove = this.getSelectedMove();
|
||||||
|
|
||||||
this.moveDescriptionText.setText(selectedMove?.effect || '');
|
this.moveDescriptionText.setText(selectedMove?.effect || '');
|
||||||
|
const moveDescriptionLineCount = Math.floor(this.moveDescriptionText.displayHeight / 14.83);
|
||||||
|
|
||||||
|
if (this.moveDescriptionScrollTween) {
|
||||||
|
this.moveDescriptionScrollTween.remove();
|
||||||
|
this.moveDescriptionScrollTween = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (moveDescriptionLineCount > 3) {
|
||||||
|
this.moveDescriptionText.setY(84);
|
||||||
|
this.moveDescriptionScrollTween = this.scene.tweens.add({
|
||||||
|
targets: this.moveDescriptionText,
|
||||||
|
delay: 2000,
|
||||||
|
loop: -1,
|
||||||
|
loopDelay: 2000,
|
||||||
|
duration: (moveDescriptionLineCount - 3) * 2000,
|
||||||
|
y: `-=${14.83 * (moveDescriptionLineCount - 3)}`,
|
||||||
|
onLoop: () => {
|
||||||
|
this.moveDescriptionText.setY(84);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.moveCursorObj) {
|
if (!this.moveCursorObj) {
|
||||||
@ -210,6 +238,7 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
|
|
||||||
if (this.moveCursorBlinkTimer)
|
if (this.moveCursorBlinkTimer)
|
||||||
this.moveCursorBlinkTimer.destroy();
|
this.moveCursorBlinkTimer.destroy();
|
||||||
|
this.moveCursorObj.setVisible(true);
|
||||||
this.moveCursorBlinkTimer = this.scene.time.addEvent({
|
this.moveCursorBlinkTimer = this.scene.time.addEvent({
|
||||||
loop: true,
|
loop: true,
|
||||||
delay: 600,
|
delay: 600,
|
||||||
@ -321,15 +350,14 @@ export default class SummaryUiHandler extends UiHandler {
|
|||||||
this.movesContainer.add(this.moveDescriptionText);
|
this.movesContainer.add(this.moveDescriptionText);
|
||||||
|
|
||||||
const maskRect = this.scene.make.graphics({});
|
const maskRect = this.scene.make.graphics({});
|
||||||
|
maskRect.setScale(6);
|
||||||
maskRect.fillStyle(0xFFFFFF);
|
maskRect.fillStyle(0xFFFFFF);
|
||||||
maskRect.beginPath();
|
maskRect.beginPath();
|
||||||
maskRect.fillRect(2, 83, 149, 46);
|
maskRect.fillRect(112, 130, 150, 46);
|
||||||
|
|
||||||
const moveDescriptionTextMask = maskRect.createGeometryMask();
|
const moveDescriptionTextMask = maskRect.createGeometryMask();
|
||||||
|
|
||||||
this.moveDescriptionText.setMask(moveDescriptionTextMask);
|
this.moveDescriptionText.setMask(moveDescriptionTextMask);
|
||||||
|
|
||||||
console.log(this.moveDescriptionText.displayHeight);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user