81 lines
3.1 KiB
JavaScript
81 lines
3.1 KiB
JavaScript
/*
|
|
* Copyright (c) 2020. Antonio Martinez Casadesus and Pascal Syma.
|
|
* All rights reserved.
|
|
*/
|
|
|
|
export default class TextElement {
|
|
constructor(scene, item) {
|
|
this.scene = scene;
|
|
this.text = scene.add.text(Math.ceil(item.x), Math.ceil(item.y), item.text.text, {
|
|
fontFamily: item.text.fontfamily || "Consolas",
|
|
fontSize: item.text.pixelsize || 16,
|
|
align: item.text.halign || "center",
|
|
fontStyle: item.text.bold ? "strong" : "",
|
|
fixedHeight: item.height,
|
|
fixedWidth: item.width,
|
|
color: item.text.color || "#000000",
|
|
wordWrap: {
|
|
width: item.width,
|
|
useAdvancedWrap: item.text.wrap
|
|
}
|
|
})
|
|
|
|
if (item.name === "action") {
|
|
this.text.setInteractive(new Phaser.Geom.Rectangle(0, 0, this.text.width, this.text.height), Phaser.Geom.Rectangle.Contains)
|
|
.on('pointerover', () => {
|
|
this.scene.sound.play('menu_hover', {volume: 0.3});
|
|
})
|
|
.on('pointerdown', () => {
|
|
this.scene.sound.play('menu_click', {volume: 0.5});
|
|
let action = item.properties.filter(obj => obj.name === "action");
|
|
if (action.length <= 0)
|
|
return;
|
|
|
|
action = action[0].value;
|
|
|
|
switch (action) {
|
|
case "pause_resume":
|
|
this.endMyself();
|
|
scene.scene.resume('Game');
|
|
this.scene.scene.get('Game').music.play();
|
|
break;
|
|
case "pause_exit":
|
|
this.endMyself();
|
|
scene.scene.stop('Game');
|
|
|
|
scene.scene.start('GUI', {key: 'MainMenu'});
|
|
break;
|
|
case "main_tutorial":
|
|
this.endMyself();
|
|
if (this.scene.textures.exists('char'))
|
|
this.scene.textures.removeKey('char');
|
|
|
|
this.scene.textures.addSpriteSheet('char', this.scene.textures.get('charA').getSourceImage(), {
|
|
frameWidth: 79,
|
|
frameHeight: 63,
|
|
margin: 1,
|
|
spacing: 2
|
|
});
|
|
|
|
this.scene.anims.remove('idle');
|
|
|
|
|
|
this.scene.anims.create({
|
|
key: 'idle',
|
|
frames: this.scene.anims.generateFrameNumbers('char', {start: 126, end: 131}),
|
|
frameRate: 10,
|
|
repeat: -1
|
|
});
|
|
scene.scene.start('Game', {level: 'tutorial'});
|
|
break;
|
|
}
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
endMyself() {
|
|
this.scene.scene.stop();
|
|
this.scene.scene.setVisible(false);
|
|
}
|
|
} |