Add: global - Login
This commit is contained in:
@@ -0,0 +1,149 @@
|
||||
/////////////////////////////
|
||||
// Login
|
||||
|
||||
var Login = {
|
||||
|
||||
create: function() {
|
||||
var self = this;
|
||||
|
||||
this.game.stage.backgroundColor = '#4d4d4d';
|
||||
|
||||
var phaser = game.add.image(game.world.centerX, game.world.centerY, 'phaser');
|
||||
phaser.anchor.set(0.5);
|
||||
phaser.alpha = 0.1;
|
||||
game.stage.backgroundColor = '#4d4d4d';
|
||||
|
||||
// name
|
||||
var textX = this.game.world.centerX - 360;
|
||||
var inputX = this.game.world.centerX + 60;
|
||||
var nameTextY = 340;
|
||||
game.add.text(textX, nameTextY, "이름 :", textStyleBasic)
|
||||
.setTextBounds(0, 0, 200, 0)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
|
||||
.boundsAlignH = 'right';
|
||||
|
||||
this.inputTextName = new InputTypeText(inputX, nameTextY);
|
||||
this.inputTextName.anchor.set(0.5);
|
||||
this.inputTextName.canvasInput.value('');
|
||||
if(isDebugMode()) {
|
||||
this.inputTextName.canvasInput.value('박지상');
|
||||
}
|
||||
this.inputTextName.canvasInput._onkeyup = function() {
|
||||
if(event.keyCode == Phaser.Keyboard.ENTER) {
|
||||
self.startMenu();
|
||||
}
|
||||
}
|
||||
|
||||
// birthday
|
||||
var birthdayTextY = 400;
|
||||
game.add.text(textX, birthdayTextY, "생년월일 :", textStyleBasic)
|
||||
.setTextBounds(0, 0, 200, 0)
|
||||
.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2)
|
||||
.boundsAlignH = 'right';
|
||||
|
||||
this.inputTextBirthday = new InputTypeText(inputX, birthdayTextY);
|
||||
this.inputTextBirthday.anchor.set(0.5);
|
||||
this.inputTextBirthday.canvasInput.value('');
|
||||
if(isDebugMode()) {
|
||||
this.inputTextBirthday.canvasInput.value('760621');
|
||||
}
|
||||
this.inputTextBirthday.canvasInput._onkeyup = function() {
|
||||
if(event.keyCode == Phaser.Keyboard.ENTER) {
|
||||
self.startMenu();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
this.inputTextName.canvasInput.focus();
|
||||
// this.inputTextBirthday.canvasInput.focus();
|
||||
|
||||
// start button
|
||||
/*
|
||||
var textStyle = { font: "bold 32px Arial", fill: "#fff", align: "center", boundsAlignH: "center", boundsAlignV: "middle" };
|
||||
var buttonText = game.add.text(0, 0, "시작", textStyle);
|
||||
buttonText.addColor("#a0d", 0);
|
||||
buttonText.anchor.setTo(0.5, 0.4);
|
||||
|
||||
var startButton = game.add.button(game.world.centerX, game.world.centerY + 140, 'button', this.startMenu, this, 2, 1, 0);
|
||||
startButton.anchor.set(0.5);
|
||||
startButton.inputEnabled = true;
|
||||
startButton.input.priorityId = 1;
|
||||
startButton.input.useHandCursor = true;
|
||||
startButton.addChild(buttonText);
|
||||
*/
|
||||
|
||||
let setting = new RoundRectButtonSetting(200, 100);
|
||||
setting.fontStyle = {
|
||||
fontSize: "30px",
|
||||
align: "center",
|
||||
fontWeight: "",
|
||||
stroke: "red",
|
||||
strokeThickness: 5
|
||||
};
|
||||
|
||||
let startButton = new RoundRectButton(setting, "둥근 모서리\n버튼", this.startMenu);
|
||||
startButton.move(game.world.centerX, game.world.centerY + 140);
|
||||
},
|
||||
|
||||
startMenu: function() {
|
||||
var self = this;
|
||||
|
||||
playerName = this.inputTextName.canvasInput._value;
|
||||
var birthday = this.inputTextBirthday.canvasInput._value;
|
||||
|
||||
xhr = new XMLHttpRequest();
|
||||
xhr.onreadystatechange = function() {
|
||||
// console.log("onreadystatechange : " + xhr);
|
||||
// console.log("xhr.readyState : " + xhr.readyState);
|
||||
// console.log("xhr.status : " + xhr.status);
|
||||
if(xhr.readyState == 4 && xhr.status == 200) {
|
||||
// console.log(xhr.responseText);
|
||||
var jsonData = JSON.parse(xhr.responseText);
|
||||
// console.log(JSON.stringify(jsonData));
|
||||
|
||||
// console.log(jsonData);
|
||||
if(jsonData != null && jsonData["UserID"] != null) {
|
||||
// login successed
|
||||
self.loginSucceeded(jsonData);
|
||||
} else {
|
||||
// login failed
|
||||
self.loginFailed(jsonData);
|
||||
}
|
||||
}
|
||||
}
|
||||
xhr.open('POST', 'login.php', true);
|
||||
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
||||
var param = 'name=' + playerName + '&birthday=' + birthday;
|
||||
// console.log(param);
|
||||
xhr.send(param);
|
||||
|
||||
/*
|
||||
var params = {
|
||||
'name': this.inputTextName.canvasInput._value,
|
||||
'birthday': this.inputTextBirthday.canvasInput._value
|
||||
};
|
||||
console.log(params);
|
||||
console.log(JSON.stringify(params));
|
||||
|
||||
xhr.setRequestHeader("Content-type", "application/json");
|
||||
// var data = JSON.stringify({"name":"박지상","birthday":"760621","test":101});
|
||||
xhr.send(data);
|
||||
xhr.send(JSON.stringify(params));
|
||||
|
||||
// xhr.send(null);
|
||||
*/
|
||||
},
|
||||
|
||||
loginSucceeded: function(jsonData) {
|
||||
playerUserID = jsonData['UserID'];
|
||||
// console.log('playerUserID : ' + playerUserID);
|
||||
|
||||
this.state.start('Menu');
|
||||
},
|
||||
|
||||
loginFailed: function(jsonData) {
|
||||
// show retry message
|
||||
console.log('login failed, jsonData : ' + JSON.stringify(jsonData));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user