You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.5 KiB
84 lines
2.5 KiB
class AddNode extends Phaser.Scene {
|
|
constructor(father, game, selected) {
|
|
super('AddNode');
|
|
this.father = father;
|
|
this.gameR = game;
|
|
this.selected = selected;
|
|
this.lCategory = [];
|
|
}
|
|
|
|
create(son) {
|
|
let height = HEIGHT_WINDOW / (4 / 3);
|
|
this.add.rectangle(0, 0, WIDTH_WINDOW, HEIGHT_WINDOW, 0x000000).setOrigin(0, 0).setAlpha(0.5);
|
|
this.add.rectangle(0, HEIGHT_WINDOW / 2, WIDTH_WINDOW, height, 0x35363A).setOrigin(0, 0.5);
|
|
this.createButtonCancel();
|
|
console.log(son);
|
|
this.createButtonAdd(son);
|
|
}
|
|
|
|
|
|
addButton(x, y, width, height, texture, category = new Category(), value) {
|
|
let btn = this.createButton(x, y, width, height, texture);
|
|
btn.on('pointerdown', () => this.click(btn, category, value));
|
|
return btn;
|
|
}
|
|
|
|
createButton(x, y, width, height, texture) {
|
|
let btn = this.add.image(x, y, texture).setOrigin(0.5, 0.5).setInteractive();
|
|
btn.on('pointerover', () => btn.setFrame(1));
|
|
btn.on('pointerout', () => btn.setFrame(0));
|
|
|
|
btn.displayHeight = height;
|
|
if (width === null) {
|
|
btn.scaleX = btn.scaleY;
|
|
} else {
|
|
btn.displayWidth = width;
|
|
}
|
|
return btn;
|
|
}
|
|
|
|
click(btn, category, value) {
|
|
if (btn.isTinted) {
|
|
category.remove(btn);
|
|
} else {
|
|
category.add(btn, value);
|
|
}
|
|
}
|
|
|
|
newCategory(name, single, obligatory) {
|
|
let c = new Category(name, single, obligatory);
|
|
this.lCategory.push(c);
|
|
return c;
|
|
}
|
|
|
|
addTitle(x, y, title) {
|
|
let sizeText = HEIGHT_WINDOW / 12;
|
|
let style = {font: sizeText.toString() + 'px stencil', fill: "#e2e2e2"};
|
|
this.add.text(x, y, title, style).setOrigin(0.5, 0.5);
|
|
}
|
|
|
|
createButtonCancel() {
|
|
this.createButton(WIDTH_WINDOW / 3, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'cancel')
|
|
.on('pointerdown', () => this.cancel());
|
|
}
|
|
|
|
createButtonAdd(son) {
|
|
this.createButton(WIDTH_WINDOW / 1.5, HEIGHT_WINDOW / (16 / 15), null, HEIGHT_WINDOW / 9, 'add')
|
|
.on('pointerdown', () => son.addNode());
|
|
}
|
|
|
|
verifyCategory() {
|
|
for (let i = 0; i < this.lCategory.length; i++) {
|
|
if (!this.lCategory[i].validate()) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
cancel() {
|
|
this.scene.resume('Game');
|
|
this.scene.stop('AddNode');
|
|
this.father.scene.remove('AddNode');
|
|
}
|
|
} |