123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- const nameState = {
-
- create: function () {
- renderBackground('plain');
-
- game.add.text(
- context.canvas.width / 2,
- context.canvas.height / 2 - 150,
- game.lang.insert_name,
- { ...textStyles.h1_, fill: colors.green }
- );
- this.warningEmptyName = game.add.text(
- context.canvas.width / 2,
- context.canvas.height / 2 - 80,
- '',
- { ...textStyles.p_, fill: colors.red }
- );
- this.okBtn = game.add.geom.rect(
- context.canvas.width / 2,
- context.canvas.height / 2 + 93 + 44,
- 300,
- 100,
- colors.green
- );
- this.okBtn.anchor(0.5, 0.5);
-
- this.okBtnText = game.add.text(
- context.canvas.width / 2,
- context.canvas.height / 2 + 152,
- game.lang.ready,
- textStyles.btn
- );
-
- document.querySelector('.ifr-input__container').style.visibility =
- 'visible';
-
- document
- .querySelector('.ifr-input')
- .addEventListener('keypress', function (e) {
- const keycode = e.key || e.code;
- if (keycode == 'Enter') {
- if (self.checkEmptyName()) self.saveName();
- game.render.all();
- }
- });
- game.event.add('click', this.onInputDown);
- game.event.add('mousemove', this.onInputOver);
- if (isDebugMode && debugState.name.skip) {
-
- document.querySelector('.ifr-input').value =
- debugState.name.name || 'My User Name';
- this.saveName();
- }
- },
-
- checkEmptyName: function () {
-
- if (document.querySelector('.ifr-input').value == '') {
- self.warningEmptyName.name = game.lang.empty_name;
- return false;
- }
- return true;
- },
-
- saveName: function () {
-
- playerName = document.querySelector('.ifr-input').value;
-
- document.querySelector('.ifr-input__container').style.visibility = 'hidden';
- document.querySelector('.ifr-input').value = '';
- if (audioStatus) game.audio.popSound.play();
- if (isDebugMode) console.log('Username: ' + playerName);
-
-
- if (!moodle) game.state.start('menu');
- },
-
- onInputDown: function (mouseEvent) {
- const x = game.math.getMouse(mouseEvent).x;
- const y = game.math.getMouse(mouseEvent).y;
- const cur = self.okBtn;
- if (game.math.isOverIcon(x, y, cur)) {
- if (self.checkEmptyName()) {
- self.saveName();
- }
- }
- game.render.all();
- },
-
- onInputOver: function (mouseEvent) {
- const x = game.math.getMouse(mouseEvent).x;
- const y = game.math.getMouse(mouseEvent).y;
- const cur = self.okBtn;
- if (game.math.isOverIcon(x, y, cur)) {
- document.body.style.cursor = 'pointer';
- cur.scale = 1.1;
- self.okBtnText.style = textStyles.btnLg;
- } else {
- document.body.style.cursor = 'auto';
- cur.scale = 1;
- self.okBtnText.style = textStyles.btn;
- }
- game.render.all();
- },
- };
|