|
@@ -1,32 +1,69 @@
|
|
|
import * as PIXI from 'pixi.js'
|
|
|
-class Text extends PIXI.Container{
|
|
|
+import GuiableContainer from '../../helpers/Guiable'
|
|
|
+
|
|
|
+class Text extends GuiableContainer{
|
|
|
constructor(props) {
|
|
|
- super();
|
|
|
+ super(props);
|
|
|
let {
|
|
|
text,
|
|
|
- GameLayer,
|
|
|
- Gui
|
|
|
+ style
|
|
|
} = props;
|
|
|
|
|
|
this.text = text || '';
|
|
|
- if(Gui) {
|
|
|
- this.Gui = Gui;
|
|
|
- this.folder = Gui.addFolder("Text");
|
|
|
- this.controller = this.folder.add(this, 'text').onFinishChange((v) => this.setText(v));
|
|
|
- }
|
|
|
+ this.style = style || '';
|
|
|
+
|
|
|
+ this.addFolder("Text");
|
|
|
+ this.addToFolder('Text', this, 'text').onFinishChange((v) => this.setText(v));
|
|
|
+
|
|
|
+ this.addToFolder('Text', this, 'style', TextStylesNames).onFinishChange((v) => this.setStyle(v));
|
|
|
|
|
|
- this.textNode = new PIXI.Text(text,{fontFamily : 'Arial', fontSize: 28, fill : 0x000000, align : 'center'});
|
|
|
+ this.construct();
|
|
|
+ }
|
|
|
+
|
|
|
+ construct() {
|
|
|
+ this.textNode = new PIXI.Text(this.text,TextStyles[this.style]);
|
|
|
this.textNode.anchor.set(0.5,0.5);
|
|
|
this.addChild(this.textNode);
|
|
|
}
|
|
|
|
|
|
- _kill() {
|
|
|
- this.controller.remove();
|
|
|
- this.Gui.removeFolder('Text');
|
|
|
- this.destroy();
|
|
|
+ getAsJSON = () => {
|
|
|
+ return {
|
|
|
+ component: 'Text',
|
|
|
+ text: this.text,
|
|
|
+ style: this.style
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- setText = (args) => this.textNode.setText(args);
|
|
|
+ setText = (args) => {
|
|
|
+ this.text = args;
|
|
|
+ this.textNode.text = args;
|
|
|
+ }
|
|
|
+ setStyle = (args) => {
|
|
|
+ this.style = args;
|
|
|
+ this.textNode.style = TextStyles[args];
|
|
|
+ }
|
|
|
+
|
|
|
+ static get styles() { return 1; }
|
|
|
}
|
|
|
|
|
|
-export default Text;
|
|
|
+let TextStylesNames = {
|
|
|
+ Normal: 'Normal',
|
|
|
+ Light: 'Light',
|
|
|
+ Heavy: 'Heavy',
|
|
|
+ Comic: 'Comic',
|
|
|
+ Info: 'Info'
|
|
|
+};
|
|
|
+
|
|
|
+let TextStyles = {
|
|
|
+ Normal: new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 21, fill : 0x000000, align : 'center'}),
|
|
|
+ Light: new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 22, fill : 0x000000, align : 'center'}),
|
|
|
+ Heavy: new PIXI.TextStyle({fontFamily : 'Tahoma', fontSize: 25, fill : 0x022005, align : 'center'}),
|
|
|
+ Comic: new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 28, fill : 0x000000, align : 'Left'}),
|
|
|
+ Info: new PIXI.TextStyle({fontFamily : 'Arial', fontSize: 28, fill : 0x000000, align : 'center'})
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+export {
|
|
|
+ TextStyles
|
|
|
+};
|
|
|
+export default Text;
|