button refactor

This commit is contained in:
Mashy
2018-12-04 19:08:58 +10:00
parent 6e5b6c2c80
commit 89355075a4
3 changed files with 70 additions and 91 deletions
+33 -57
View File
@@ -1,13 +1,14 @@
const Phaser = require('phaser');
const Passives = require('./passives');
const Stats = require('./statsheet.stats');
const Skills = require('./statsheet.skills');
const { TEXT, POSITIONS: { STATS } } = require('./constants');
const { POSITIONS: { STATS } } = require('./constants');
const addButton = require('./statsheet.button');
const menuOrig = STATS.height() * 0.5;
const menuHeight = STATS.height() * 0.1;
const menuPad = STATS.height() * 0.01;
const menuWidth = STATS.width() * 0.25;
class StatSheet extends Phaser.Scene {
constructor() {
@@ -22,62 +23,37 @@ class StatSheet extends Phaser.Scene {
}
addControls(cryp) {
const menu = this.add
.rectangle(0, menuOrig, menuWidth, menuHeight, 0x222222)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
// Registry events won't get auto cleaned
this.registry.events.off('changedata', this.updateData, this);
this.scene.run('CrypList');
this.scene.remove('Skills');
this.scene.remove('Passives');
this.scene.remove();
});
const menuCback = () => {
this.registry.events.off('changedata', this.updateData, this);
this.scene.run('CrypList');
this.scene.remove('Skills');
this.scene.remove('Passives');
this.scene.remove();
};
const passiveCback = () => {
if (this.passives) return false;
this.removeSkills();
this.addPassives(cryp);
this.passives = true;
return true;
};
const skillCback = () => {
if (this.skills) return false;
this.removePassives();
this.addSkills(cryp);
this.skills = true;
return true;
};
const clearCback = () => {
this.removePassives();
this.removeSkills();
return true;
};
this.add.text(menu.getCenter().x, menu.getCenter().y, 'Main Menu', TEXT.HEADER)
.setOrigin(0.5, 0.5);
const passives = this.add
.rectangle(0, menuOrig + menuHeight + menuPad, menuWidth, menuHeight, 0x222222)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
if (this.passives) return false;
this.removeSkills();
this.addPassives(cryp);
this.passives = true;
return true;
});
this.add.text(passives.getCenter().x, passives.getCenter().y, 'View Passives', TEXT.HEADER)
.setOrigin(0.5, 0.5);
const skills = this.add
.rectangle(0, menuOrig + (menuHeight + menuPad) * 2, menuWidth, menuHeight, 0x222222)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
if (this.skills) return false;
this.removePassives();
this.addSkills(cryp);
this.skills = true;
return true;
});
this.add.text(skills.getCenter().x, skills.getCenter().y, 'View Skills', TEXT.HEADER)
.setOrigin(0.5, 0.5);
const clear = this.add
.rectangle(0, menuOrig + (menuHeight + menuPad) * 3, menuWidth, menuHeight, 0x222222)
.setInteractive()
.setOrigin(0)
.on('pointerdown', () => {
this.removePassives();
this.removeSkills();
return true;
});
this.add.text(clear.getCenter().x, clear.getCenter().y, 'View Cryp', TEXT.HEADER)
.setOrigin(0.5, 0.5);
addButton(this, 0, menuOrig, menuCback, 'Main Menu');
addButton(this, 0, menuOrig + (menuHeight + menuPad), passiveCback, 'View Passives');
addButton(this, 0, menuOrig + (menuHeight + menuPad) * 2, skillCback, 'View Skills');
addButton(this, 0, menuOrig + (menuHeight + menuPad) * 3, clearCback, 'View Cryp');
}
addSkills(cryp) {