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);
var titleTextStyle = { font: "36px Arial", fill: "#fff", align: "center"};
this.titleText = game.add.text(440, this.inputScorePosY + 40, "점수", titleTextStyle);
this.titleText.anchor.set(0, 0.5);
var scoreTitleText = game.add.text(440, this.inputScorePosY + 40, "점수", titleTextStyle);
scoreTitleText.anchor.set(0, 0.5);
var recordTextSetting = this.makeInputTextSetting(150, "점수 입력");
this.recordText = this.makeInputText(game.world.centerX, this.inputScorePosY + 10, recordTextSetting);
var scoreTextSetting = this.makeInputTextSetting(150, "점수 입력");
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);
this.titleText.anchor.set(0, 0.5);
var passwordTitleText = game.add.text(game.world.centerX + 190, this.inputScorePosY + 40, "마에", titleTextStyle);
passwordTitleText.anchor.set(0, 0.5);
var passwordTextSetting = this.makeInputTextSetting(110, "비밀번호");
passwordTextSetting.type = PhaserInput.InputType.password;
@@ -62,9 +65,10 @@ function InputScore(chart) {
);
// this.loadLicenseCompanySubjectData();
this.makeLicenseCompanySubjectPanel();
this.setVisibleLicenseCompanyPanel(false);
this.setVisibleLicenseSubjectPanel(false, "");
this.makeCompanyPanel();
this.makeSubjectPanel();
this.setVisibleCompanyPanel(false);
this.setVisibleSubjectPanel(false, "");
}
InputScore.prototype.initVariables = function() {
@@ -73,7 +77,7 @@ InputScore.prototype.initVariables = function() {
this.subjectFullname = "ITQ 파워포인트";
this.recentSubject = this.subjectFullname;
this.licenseCompanyButtonList = [];
this.companyButtonList = [];
this.licenseSubjectButtonList = [];
}
@@ -111,81 +115,30 @@ InputScore.prototype.setSubjectFullname = function(fullname) {
}
InputScore.prototype.onClickSubjectButton = function() {
if(!this.licenseCompanyPanel.visible)
this.setVisibleLicenseCompanyPanel(true);
if(!this.companyPanel.visible)
this.setVisibleCompanyPanel(true);
else {
this.setVisibleLicenseCompanyPanel(false);
this.setVisibleLicenseSubjectPanel(false, "");
this.setVisibleCompanyPanel(false);
this.setVisibleSubjectPanel(false, "");
}
}
/*
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() {
InputScore.prototype.makeCompanyPanel = function() {
var companyCount = this.licenseDataManager.getCompanyCount();
var buttonStackCount = Math.floor(companyCount / 7) + 1;
var gapWidth = 10;
var licenseCompanyPanelWidth = gapWidth + (InputScore.LICENSE_COMPANY_BUTTON_WIDTH + gapWidth) * buttonStackCount;
var companyPanelWidth =
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
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);
setting.x = -100;
@@ -198,58 +151,85 @@ InputScore.prototype.makeLicenseCompanySubjectPanel = function() {
// license company buttons
for(var i = 0; i < companyCount; i++) {
setting.width = InputScore.LICENSE_COMPANY_BUTTON_WIDTH;
setting.width = InputScore.COMPANY_BUTTON_WIDTH;
var self = this;
var companyName = this.licenseDataManager.getCompanyName(i);
this.licenseCompanyButtonList[i] = new RoundRectButton(
this.companyButtonList[i] = new RoundRectButton(
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
var subjectCount = this.licenseDataManager.getSubjectCount();
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 companySubjectName = companySubjectData.companyName + " " + companySubjectData.subjectName;
this.licenseSubjectButtonList[i] = new RoundRectButton(setting, null, companySubjectName, null);
var subjectData = this.licenseDataManager.getSubjectDataByIndex(i);
var subjectData = subjectData.companyName + " " + subjectData.subjectName;
this.licenseSubjectButtonList[i] = new RoundRectButton(setting, null, subjectData, null);
}
}
InputScore.prototype.setVisibleLicenseCompanyPanel = function(flag) {
this.licenseCompanyPanel.visible = flag;
InputScore.prototype.setVisibleCompanyPanel = function(flag) {
this.companyPanel.visible = flag;
if(flag) {
for(var i = 0; i < this.licenseCompanyButtonList.length; i++) {
this.licenseCompanyButtonList[i].move(
this.licenseCompanyButtonStartPosX,
this.inputScorePosY - 40 - InputScore.LICENSE_BUTTON_GAP_HEIGHT * i
for(var i = 0; i < this.companyButtonList.length; i++) {
this.companyButtonList[i].move(
this.companyButtonStartPosX,
this.inputScorePosY - 40 - InputScore.BUTTON_GAP_HEIGHT * i
);
}
} else {
for(var i = 0; i < this.licenseCompanyButtonList.length; i++) {
this.licenseCompanyButtonList[i].move(-100, 900);
for(var i = 0; i < this.companyButtonList.length; i++) {
this.companyButtonList[i].move(-100, 900);
}
}
}
InputScore.prototype.getLicenseSubjectButtonPosX = function(index) {
var rowCount = Math.floor(index / InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT);
var gapWidth = 10;
return this.licenseSubjectButtonStartPosX
+ (InputScore.LICENSE_SUBJECT_BUTTON_WIDTH + gapWidth) * rowCount;
var rowCount = Math.floor(index / InputScore.SUBJECT_BUTTON_MAX_COUNT);
return this.subjectButtonStartPosX
+ (InputScore.SUBJECT_BUTTON_WIDTH + InputScore.BUTTON_GAP_WIDTH) * rowCount;
}
InputScore.prototype.getLicenseSubjectButtonPosY = function(index) {
var colIndex = index % InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT;
return this.inputScorePosY - 40 - InputScore.LICENSE_BUTTON_GAP_HEIGHT * colIndex;
var colIndex = index % InputScore.SUBJECT_BUTTON_MAX_COUNT;
return this.inputScorePosY - 40 - InputScore.BUTTON_GAP_HEIGHT * colIndex;
}
InputScore.prototype.setVisibleLicenseSubjectPanel = function(flag, companyName) {
this.licenseSubjectPanel.visible = flag;
InputScore.prototype.setVisibleSubjectPanel = function(flag, companyName) {
this.subjectPanel.visible = flag;
for(var i = 0; i < this.licenseSubjectButtonList.length; i++) {
this.licenseSubjectButtonList[i].move(-100, 900);
@@ -282,14 +262,15 @@ InputScore.prototype.setVisibleLicenseSubjectPanel = function(flag, companyName)
}
}
InputScore.prototype.onClickCompanySubjectButton = function(companySubjectName) {
this.setSubjectFullname(companySubjectName);
InputScore.prototype.onClickCompanySubjectButton = function(subjectName) {
this.setSubjectFullname(subjectName);
this.selectedSubjectData = this.licenseDataManager.getSubjectDataByName(subjectName);
}
InputScore.prototype.makePanelSprite = function(x, y, width, height, color) {
var btnTexture = new Phaser.Graphics()
.beginFill(color, 0.5)
.beginFill(color, 0.8)
.drawRect(0, 0, width, height)
.endFill()
.generateTexture();
@@ -301,17 +282,21 @@ InputScore.prototype.makePanelSprite = function(x, y, width, height, color) {
InputScore.prototype.onClickSendToServerButton = function() {
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.LICENSE_COMPANY_BUTTON_WIDTH = 160;
InputScore.LICENSE_SUBJECT_BUTTON_WIDTH = 260;
InputScore.COMPANY_BUTTON_WIDTH = 160;
InputScore.SUBJECT_BUTTON_WIDTH = 260;
InputScore.LICENSE_BUTTON_GAP_HEIGHT = 64;
InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT = 6;
InputScore.BUTTON_GAP_WIDTH = 10;
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) {
this.companyName = companyName;
this.subjectName = subjectName;
this.subjectFullname = companyName + " " + subjectName;
this.timeLimit = timeLimit;
this.maxScore = maxScore;
this.gradeList = gradeList;
}
LicenseCompanySubjectData.prototype.isNameOf = function(companySubjectName) {
var name = this.companyName + " " + this.subjectName;
if(name == companySubjectName)
return true;
LicenseCompanySubjectData.prototype.getGrade = function(score) {
var count = this.gradeList.length;
for(var i = 0; i < count; i++) {
if(score >= this.gradeList[i].score)
return this.gradeList[i].grade;
}
return false;
return "-";
}
function LicenseDataManager() {
this.licenseCompanies = [];
this.licenseSubjects = [];
this.companies = [];
this.subjects = [];
// console.log(licenseCompanySubjectList);
this.maxSubjectCount = 0;
for(var i = 0; i < licenseCompanySubjectList.length; i++) {
this.licenseCompanies[i] = licenseCompanySubjectList[i].companyName;
this.companies[i] = licenseCompanySubjectList[i].companyName;
var subjectCount = 0;
var companyData = licenseCompanySubjectList[i];
@@ -35,14 +37,14 @@ function LicenseDataManager() {
for(var k = 0; k < subjectList.length; k++) {
var licenseCompnaySubjectItem = new LicenseCompanySubjectData(
this.licenseCompanies[i],
this.companies[i],
subjectList[k],
companyData.subjectData[j].timeLimit,
companyData.subjectData[j].maxScore,
companyData.subjectData[j].gradeList
);
this.licenseSubjects.push(licenseCompnaySubjectItem);
this.subjects.push(licenseCompnaySubjectItem);
}
}
@@ -51,14 +53,14 @@ function LicenseDataManager() {
this.maxSubjectCount = subjectCount;
}
// console.log(this.licenseCompanies);
// console.log(this.licenseSubjects);
// console.log(this.companies);
// console.log(this.subjects);
// console.log(this.maxSubjectCount);
}
LicenseDataManager.prototype.getCompanyCount = function() {
return this.licenseCompanies.length;
return this.companies.length;
}
LicenseDataManager.prototype.getCompanyList = function() {
@@ -66,12 +68,12 @@ LicenseDataManager.prototype.getCompanyList = function() {
}
LicenseDataManager.prototype.getCompanyName = function(index) {
return this.licenseCompanies[index];
return this.companies[index];
}
LicenseDataManager.prototype.hasCompany = function(companyName) {
for(var i = 0; i < this.licenseCompanies.length; i++) {
if(this.licenseCompanies[i].companyName == companyName)
for(var i = 0; i < this.companies.length; i++) {
if(this.companies[i].companyName == companyName)
return true;
}
@@ -79,25 +81,25 @@ LicenseDataManager.prototype.hasCompany = function(companyName) {
}
LicenseDataManager.prototype.getSubjectCount = function() {
return this.licenseSubjects.length;
return this.subjects.length;
}
LicenseDataManager.prototype.getSubjectDataByIndex = function(index) {
return this.licenseSubjects[index];
return this.subjects[index];
}
LicenseDataManager.prototype.getSubjectDataByName = function(companySubjectName) {
for(var i = 0; i < this.licenseSubjects.length; i++) {
var subjectData = this.licenseSubjects[i];
if(subjectData.isNameOf(companyName))
LicenseDataManager.prototype.getSubjectDataByName = function(subjectFullname) {
for(var i = 0; i < this.subjects.length; i++) {
var subjectData = this.subjects[i];
if(subjectData.subjectFullname == subjectFullname)
return subjectData;
}
return null;
}
LicenseDataManager.prototype.getGrade = function(companySubjectName, score) {
var companySubjectData = this.getCompanySubjectData(companySubjectName);
LicenseDataManager.prototype.getGrade = function(subjectData) {
var companySubjectData = this.getCompanySubjectData(subjectName);
console.log(companySubjectData);
// if(companySubjectData != null) {
// if(score > companySubjectData.gradeList[0].)