Fix: revised code

This commit is contained in:
2018-12-12 00:37:45 +09:00
parent 750887d5d1
commit f3a0c469b6
2 changed files with 116 additions and 129 deletions
+89 -104
View File
@@ -36,14 +36,17 @@ function InputScore(chart) {
this.setSubjectFullname(this.subjectFullname); this.setSubjectFullname(this.subjectFullname);
var titleTextStyle = { font: "36px Arial", fill: "#fff", align: "center"}; var titleTextStyle = { font: "36px Arial", fill: "#fff", align: "center"};
this.titleText = game.add.text(440, this.inputScorePosY + 40, "점수", titleTextStyle); var scoreTitleText = game.add.text(440, this.inputScorePosY + 40, "점수", titleTextStyle);
this.titleText.anchor.set(0, 0.5); scoreTitleText.anchor.set(0, 0.5);
var recordTextSetting = this.makeInputTextSetting(150, "점수 입력"); var scoreTextSetting = this.makeInputTextSetting(150, "점수 입력");
this.recordText = this.makeInputText(game.world.centerX, this.inputScorePosY + 10, recordTextSetting); scoreTextSetting.min = 0;
scoreTextSetting.max = 9999;
scoreTextSetting.type = PhaserInput.InputType.number;
this.scoreText = this.makeInputText(game.world.centerX, this.inputScorePosY + 10, scoreTextSetting);
this.titleText = game.add.text(game.world.centerX + 190, this.inputScorePosY + 40, "마에", titleTextStyle); var passwordTitleText = game.add.text(game.world.centerX + 190, this.inputScorePosY + 40, "마에", titleTextStyle);
this.titleText.anchor.set(0, 0.5); passwordTitleText.anchor.set(0, 0.5);
var passwordTextSetting = this.makeInputTextSetting(110, "비밀번호"); var passwordTextSetting = this.makeInputTextSetting(110, "비밀번호");
passwordTextSetting.type = PhaserInput.InputType.password; passwordTextSetting.type = PhaserInput.InputType.password;
@@ -62,9 +65,10 @@ function InputScore(chart) {
); );
// this.loadLicenseCompanySubjectData(); // this.loadLicenseCompanySubjectData();
this.makeLicenseCompanySubjectPanel(); this.makeCompanyPanel();
this.setVisibleLicenseCompanyPanel(false); this.makeSubjectPanel();
this.setVisibleLicenseSubjectPanel(false, ""); this.setVisibleCompanyPanel(false);
this.setVisibleSubjectPanel(false, "");
} }
InputScore.prototype.initVariables = function() { InputScore.prototype.initVariables = function() {
@@ -73,7 +77,7 @@ InputScore.prototype.initVariables = function() {
this.subjectFullname = "ITQ 파워포인트"; this.subjectFullname = "ITQ 파워포인트";
this.recentSubject = this.subjectFullname; this.recentSubject = this.subjectFullname;
this.licenseCompanyButtonList = []; this.companyButtonList = [];
this.licenseSubjectButtonList = []; this.licenseSubjectButtonList = [];
} }
@@ -111,81 +115,30 @@ InputScore.prototype.setSubjectFullname = function(fullname) {
} }
InputScore.prototype.onClickSubjectButton = function() { InputScore.prototype.onClickSubjectButton = function() {
if(!this.licenseCompanyPanel.visible) if(!this.companyPanel.visible)
this.setVisibleLicenseCompanyPanel(true); this.setVisibleCompanyPanel(true);
else { else {
this.setVisibleLicenseCompanyPanel(false); this.setVisibleCompanyPanel(false);
this.setVisibleLicenseSubjectPanel(false, ""); this.setVisibleSubjectPanel(false, "");
} }
} }
/* InputScore.prototype.makeCompanyPanel = function() {
InputScore.prototype.loadLicenseCompanySubjectData = function() {
this.licenseCompanies = [];
this.licenseSubjects = [];
// console.log(licenseCompanySubjectList);
this.maxSubjectCount = 0;
for(var i = 0; i < licenseCompanySubjectList.length; i++) {
this.licenseCompanies[i] = licenseCompanySubjectList[i].companyName;
var subjectCount = 0;
var companyData = licenseCompanySubjectList[i];
// console.log(companyData);
var subjectData = companyData.subjectData;
// console.log(subjectData);
for(var j = 0; j < subjectData.length; j++) {
var subjectList = subjectData[j].subjects;
subjectCount += subjectList.length;
for(var k = 0; k < subjectList.length; k++) {
var licenseCompnaySubjectItem = new LicenseCompanySubjectData(
this.licenseCompanies[i],
subjectList[k],
companyData.subjectData[j].timeLimit,
companyData.subjectData[j].maxScore,
companyData.subjectData[j].gradeList
);
this.licenseSubjects.push(licenseCompnaySubjectItem);
}
}
if(subjectCount > this.maxSubjectCount)
this.maxSubjectCount = subjectCount;
}
// console.log(this.licenseCompanies);
// console.log(this.licenseSubjects);
// console.log(this.maxSubjectCount);
}
*/
InputScore.prototype.makeLicenseCompanySubjectPanel = function() {
var companyCount = this.licenseDataManager.getCompanyCount(); var companyCount = this.licenseDataManager.getCompanyCount();
var buttonStackCount = Math.floor(companyCount / 7) + 1; var buttonStackCount = Math.floor(companyCount / 7) + 1;
var gapWidth = 10; var companyPanelWidth =
var licenseCompanyPanelWidth = gapWidth + (InputScore.LICENSE_COMPANY_BUTTON_WIDTH + gapWidth) * buttonStackCount; InputScore.BUTTON_GAP_WIDTH
+ (InputScore.COMPANY_BUTTON_WIDTH
+ InputScore.BUTTON_GAP_WIDTH) * buttonStackCount;
this.companyButtonStartPosX = InputScore.COMPANY_BUTTON_WIDTH / 2
+ InputScore.BUTTON_GAP_WIDTH;
// license company panel // license company panel
this.licenseCompanyPanel = this.makePanelSprite(0, 300, licenseCompanyPanelWidth, 398, 0x000000); this.companyPanel = this.makePanelSprite(0, 300, companyPanelWidth, 398, 0x303030);
// license subject panel
this.licenseSubjectPanel = this.makePanelSprite(
licenseCompanyPanelWidth, 300,
game.world.width - licenseCompanyPanelWidth, 398, 0xffffff);
var roundRectButtonOffsetX = 50;
this.licenseCompanyButtonStartPosX =
InputScore.LICENSE_COMPANY_BUTTON_WIDTH / 2
+ gapWidth + roundRectButtonOffsetX;
this.licenseSubjectButtonStartPosX =
licenseCompanyPanelWidth + InputScore.LICENSE_SUBJECT_BUTTON_WIDTH / 2
+ gapWidth;
var setting = new RoundRectButtonSetting(0, 0, 0, 0); var setting = new RoundRectButtonSetting(0, 0, 0, 0);
setting.x = -100; setting.x = -100;
@@ -198,58 +151,85 @@ InputScore.prototype.makeLicenseCompanySubjectPanel = function() {
// license company buttons // license company buttons
for(var i = 0; i < companyCount; i++) { for(var i = 0; i < companyCount; i++) {
setting.width = InputScore.LICENSE_COMPANY_BUTTON_WIDTH; setting.width = InputScore.COMPANY_BUTTON_WIDTH;
var self = this; var self = this;
var companyName = this.licenseDataManager.getCompanyName(i); var companyName = this.licenseDataManager.getCompanyName(i);
this.licenseCompanyButtonList[i] = new RoundRectButton( this.companyButtonList[i] = new RoundRectButton(
setting, null, companyName, setting, null, companyName,
(function() { self.setVisibleLicenseSubjectPanel(true, this.text.text); }) (function() { self.setVisibleSubjectPanel(true, this.text.text); })
); );
} }
}
InputScore.prototype.makeSubjectPanel = function() {
var companyCount = this.licenseDataManager.getCompanyCount();
var buttonStackCount = Math.floor(companyCount / 7) + 1;
var companyPanelWidth =
InputScore.BUTTON_GAP_WIDTH
+ (InputScore.COMPANY_BUTTON_WIDTH
+ InputScore.BUTTON_GAP_WIDTH) * buttonStackCount;
// license subject panel
this.subjectPanel = this.makePanelSprite(
companyPanelWidth, 300,
game.world.width - companyPanelWidth, 398, 0x202020);
this.subjectButtonStartPosX =
companyPanelWidth + InputScore.SUBJECT_BUTTON_WIDTH / 2
+ InputScore.BUTTON_GAP_WIDTH;
var setting = new RoundRectButtonSetting(0, 0, 0, 0);
setting.x = -100;
setting.y = -100;
setting.height = 50;
setting.strokeWidthPx = 5;
setting.roundAmount = 10;
setting.fontStyle.fontSize = 24;
setting.fontStyle.fontWeight = "bold";
// license subject buttons // license subject buttons
var subjectCount = this.licenseDataManager.getSubjectCount(); var subjectCount = this.licenseDataManager.getSubjectCount();
for(var i = 0; i < subjectCount; i++) { for(var i = 0; i < subjectCount; i++) {
setting.width = InputScore.LICENSE_SUBJECT_BUTTON_WIDTH; setting.width = InputScore.SUBJECT_BUTTON_WIDTH;
var companySubjectData = this.licenseDataManager.getSubjectDataByIndex(i); var subjectData = this.licenseDataManager.getSubjectDataByIndex(i);
var companySubjectName = companySubjectData.companyName + " " + companySubjectData.subjectName; var subjectData = subjectData.companyName + " " + subjectData.subjectName;
this.licenseSubjectButtonList[i] = new RoundRectButton(setting, null, companySubjectName, null); this.licenseSubjectButtonList[i] = new RoundRectButton(setting, null, subjectData, null);
} }
} }
InputScore.prototype.setVisibleLicenseCompanyPanel = function(flag) { InputScore.prototype.setVisibleCompanyPanel = function(flag) {
this.licenseCompanyPanel.visible = flag; this.companyPanel.visible = flag;
if(flag) { if(flag) {
for(var i = 0; i < this.licenseCompanyButtonList.length; i++) { for(var i = 0; i < this.companyButtonList.length; i++) {
this.licenseCompanyButtonList[i].move( this.companyButtonList[i].move(
this.licenseCompanyButtonStartPosX, this.companyButtonStartPosX,
this.inputScorePosY - 40 - InputScore.LICENSE_BUTTON_GAP_HEIGHT * i this.inputScorePosY - 40 - InputScore.BUTTON_GAP_HEIGHT * i
); );
} }
} else { } else {
for(var i = 0; i < this.licenseCompanyButtonList.length; i++) { for(var i = 0; i < this.companyButtonList.length; i++) {
this.licenseCompanyButtonList[i].move(-100, 900); this.companyButtonList[i].move(-100, 900);
} }
} }
} }
InputScore.prototype.getLicenseSubjectButtonPosX = function(index) { InputScore.prototype.getLicenseSubjectButtonPosX = function(index) {
var rowCount = Math.floor(index / InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT); var rowCount = Math.floor(index / InputScore.SUBJECT_BUTTON_MAX_COUNT);
var gapWidth = 10; return this.subjectButtonStartPosX
return this.licenseSubjectButtonStartPosX + (InputScore.SUBJECT_BUTTON_WIDTH + InputScore.BUTTON_GAP_WIDTH) * rowCount;
+ (InputScore.LICENSE_SUBJECT_BUTTON_WIDTH + gapWidth) * rowCount;
} }
InputScore.prototype.getLicenseSubjectButtonPosY = function(index) { InputScore.prototype.getLicenseSubjectButtonPosY = function(index) {
var colIndex = index % InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT; var colIndex = index % InputScore.SUBJECT_BUTTON_MAX_COUNT;
return this.inputScorePosY - 40 - InputScore.LICENSE_BUTTON_GAP_HEIGHT * colIndex; return this.inputScorePosY - 40 - InputScore.BUTTON_GAP_HEIGHT * colIndex;
} }
InputScore.prototype.setVisibleLicenseSubjectPanel = function(flag, companyName) { InputScore.prototype.setVisibleSubjectPanel = function(flag, companyName) {
this.licenseSubjectPanel.visible = flag; this.subjectPanel.visible = flag;
for(var i = 0; i < this.licenseSubjectButtonList.length; i++) { for(var i = 0; i < this.licenseSubjectButtonList.length; i++) {
this.licenseSubjectButtonList[i].move(-100, 900); this.licenseSubjectButtonList[i].move(-100, 900);
@@ -282,14 +262,15 @@ InputScore.prototype.setVisibleLicenseSubjectPanel = function(flag, companyName)
} }
} }
InputScore.prototype.onClickCompanySubjectButton = function(companySubjectName) { InputScore.prototype.onClickCompanySubjectButton = function(subjectName) {
this.setSubjectFullname(companySubjectName); this.setSubjectFullname(subjectName);
this.selectedSubjectData = this.licenseDataManager.getSubjectDataByName(subjectName);
} }
InputScore.prototype.makePanelSprite = function(x, y, width, height, color) { InputScore.prototype.makePanelSprite = function(x, y, width, height, color) {
var btnTexture = new Phaser.Graphics() var btnTexture = new Phaser.Graphics()
.beginFill(color, 0.5) .beginFill(color, 0.8)
.drawRect(0, 0, width, height) .drawRect(0, 0, width, height)
.endFill() .endFill()
.generateTexture(); .generateTexture();
@@ -301,17 +282,21 @@ InputScore.prototype.makePanelSprite = function(x, y, width, height, color) {
InputScore.prototype.onClickSendToServerButton = function() { InputScore.prototype.onClickSendToServerButton = function() {
console.log("send data to server"); console.log("send data to server");
console.log(this.subjectFullname);
console.log(this.scoreText.value);
console.log(this.passwordText.value);
} }
InputScore.INPUT_SCORE_GROUP_OFFSET_Y = 70; InputScore.INPUT_SCORE_GROUP_OFFSET_Y = 70;
InputScore.LICENSE_COMPANY_BUTTON_WIDTH = 160; InputScore.COMPANY_BUTTON_WIDTH = 160;
InputScore.LICENSE_SUBJECT_BUTTON_WIDTH = 260; InputScore.SUBJECT_BUTTON_WIDTH = 260;
InputScore.LICENSE_BUTTON_GAP_HEIGHT = 64; InputScore.BUTTON_GAP_WIDTH = 10;
InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT = 6; InputScore.BUTTON_GAP_HEIGHT = 64;
InputScore.SUBJECT_BUTTON_MAX_COUNT = 6;
/* /*
+27 -25
View File
@@ -1,28 +1,30 @@
function LicenseCompanySubjectData(companyName, subjectName, timeLimit, maxScore, gradeList) { function LicenseCompanySubjectData(companyName, subjectName, timeLimit, maxScore, gradeList) {
this.companyName = companyName; this.companyName = companyName;
this.subjectName = subjectName; this.subjectName = subjectName;
this.subjectFullname = companyName + " " + subjectName;
this.timeLimit = timeLimit; this.timeLimit = timeLimit;
this.maxScore = maxScore; this.maxScore = maxScore;
this.gradeList = gradeList; this.gradeList = gradeList;
} }
LicenseCompanySubjectData.prototype.isNameOf = function(companySubjectName) { LicenseCompanySubjectData.prototype.getGrade = function(score) {
var name = this.companyName + " " + this.subjectName; var count = this.gradeList.length;
if(name == companySubjectName) for(var i = 0; i < count; i++) {
return true; if(score >= this.gradeList[i].score)
return this.gradeList[i].grade;
}
return false; return "-";
} }
function LicenseDataManager() { function LicenseDataManager() {
this.licenseCompanies = []; this.companies = [];
this.licenseSubjects = []; this.subjects = [];
// console.log(licenseCompanySubjectList); // console.log(licenseCompanySubjectList);
this.maxSubjectCount = 0; this.maxSubjectCount = 0;
for(var i = 0; i < licenseCompanySubjectList.length; i++) { for(var i = 0; i < licenseCompanySubjectList.length; i++) {
this.licenseCompanies[i] = licenseCompanySubjectList[i].companyName; this.companies[i] = licenseCompanySubjectList[i].companyName;
var subjectCount = 0; var subjectCount = 0;
var companyData = licenseCompanySubjectList[i]; var companyData = licenseCompanySubjectList[i];
@@ -35,14 +37,14 @@ function LicenseDataManager() {
for(var k = 0; k < subjectList.length; k++) { for(var k = 0; k < subjectList.length; k++) {
var licenseCompnaySubjectItem = new LicenseCompanySubjectData( var licenseCompnaySubjectItem = new LicenseCompanySubjectData(
this.licenseCompanies[i], this.companies[i],
subjectList[k], subjectList[k],
companyData.subjectData[j].timeLimit, companyData.subjectData[j].timeLimit,
companyData.subjectData[j].maxScore, companyData.subjectData[j].maxScore,
companyData.subjectData[j].gradeList companyData.subjectData[j].gradeList
); );
this.licenseSubjects.push(licenseCompnaySubjectItem); this.subjects.push(licenseCompnaySubjectItem);
} }
} }
@@ -51,14 +53,14 @@ function LicenseDataManager() {
this.maxSubjectCount = subjectCount; this.maxSubjectCount = subjectCount;
} }
// console.log(this.licenseCompanies); // console.log(this.companies);
// console.log(this.licenseSubjects); // console.log(this.subjects);
// console.log(this.maxSubjectCount); // console.log(this.maxSubjectCount);
} }
LicenseDataManager.prototype.getCompanyCount = function() { LicenseDataManager.prototype.getCompanyCount = function() {
return this.licenseCompanies.length; return this.companies.length;
} }
LicenseDataManager.prototype.getCompanyList = function() { LicenseDataManager.prototype.getCompanyList = function() {
@@ -66,12 +68,12 @@ LicenseDataManager.prototype.getCompanyList = function() {
} }
LicenseDataManager.prototype.getCompanyName = function(index) { LicenseDataManager.prototype.getCompanyName = function(index) {
return this.licenseCompanies[index]; return this.companies[index];
} }
LicenseDataManager.prototype.hasCompany = function(companyName) { LicenseDataManager.prototype.hasCompany = function(companyName) {
for(var i = 0; i < this.licenseCompanies.length; i++) { for(var i = 0; i < this.companies.length; i++) {
if(this.licenseCompanies[i].companyName == companyName) if(this.companies[i].companyName == companyName)
return true; return true;
} }
@@ -79,25 +81,25 @@ LicenseDataManager.prototype.hasCompany = function(companyName) {
} }
LicenseDataManager.prototype.getSubjectCount = function() { LicenseDataManager.prototype.getSubjectCount = function() {
return this.licenseSubjects.length; return this.subjects.length;
} }
LicenseDataManager.prototype.getSubjectDataByIndex = function(index) { LicenseDataManager.prototype.getSubjectDataByIndex = function(index) {
return this.licenseSubjects[index]; return this.subjects[index];
} }
LicenseDataManager.prototype.getSubjectDataByName = function(companySubjectName) { LicenseDataManager.prototype.getSubjectDataByName = function(subjectFullname) {
for(var i = 0; i < this.licenseSubjects.length; i++) { for(var i = 0; i < this.subjects.length; i++) {
var subjectData = this.licenseSubjects[i]; var subjectData = this.subjects[i];
if(subjectData.isNameOf(companyName)) if(subjectData.subjectFullname == subjectFullname)
return subjectData; return subjectData;
} }
return null; return null;
} }
LicenseDataManager.prototype.getGrade = function(companySubjectName, score) { LicenseDataManager.prototype.getGrade = function(subjectData) {
var companySubjectData = this.getCompanySubjectData(companySubjectName); var companySubjectData = this.getCompanySubjectData(subjectName);
console.log(companySubjectData); console.log(companySubjectData);
// if(companySubjectData != null) { // if(companySubjectData != null) {
// if(score > companySubjectData.gradeList[0].) // if(score > companySubjectData.gradeList[0].)