Add: company button, subject button

This commit is contained in:
2018-12-11 17:16:34 +09:00
parent 087079db50
commit 0733a79630
2 changed files with 170 additions and 25 deletions
+163 -18
View File
@@ -49,7 +49,7 @@ function InputScore(chart) {
this.passwordText = this.makeInputText(game.world.centerX + 260, this.inputScorePosY + 10, passwordTextSetting);
// set timer buttons
// save button
setting.x = GAME_SCREEN_SIZE.x - 60;
setting.y = this.inputScorePosY + 35;
setting.width = 100;
@@ -60,8 +60,10 @@ function InputScore(chart) {
(function() { this.onClickSendToServerButton(); }).bind(this)
);
this.makeLicenseCompanyPanel();
this.loadLicenseCompanySubjectData();
this.makeLicenseCompanySubjectPanel();
this.setVisibleLicenseCompanyPanel(false);
this.setVisibleLicenseSubjectPanel(false, "");
}
InputScore.prototype.initVariables = function() {
@@ -106,31 +108,105 @@ InputScore.prototype.makeInputText = function(x, y, setting) {
InputScore.prototype.onClickSubjectButton = function() {
if(!this.licenseCompanyPanel.visible)
this.setVisibleLicenseCompanyPanel(true);
else
else {
this.setVisibleLicenseCompanyPanel(false);
this.setVisibleLicenseSubjectPanel(false, "");
}
}
InputScore.prototype.makeLicenseCompanyPanel = function() {
this.licenseCompanyPanel = this.makePanelSprite(0, 300, 400, 400, 0xffffff);
InputScore.prototype.loadLicenseCompanySubjectData = function() {
this.licenseCompanies = [];
this.licenseCompanySubjects = [];
// 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.licenseCompanySubjects.push(licenseCompnaySubjectItem);
}
}
if(subjectCount > this.maxSubjectCount)
this.maxSubjectCount = subjectCount;
}
// console.log(this.licenseCompanies);
// console.log(this.licenseCompanySubjects);
// console.log(this.maxSubjectCount);
}
InputScore.prototype.makeLicenseCompanySubjectPanel = function() {
var buttonStackCount = Math.floor(licenseCompanySubjectList.length / 7) + 1;
var gapWidth = 10;
var licenseCompanyPanelWidth = gapWidth + (InputScore.LICENSE_COMPANY_BUTTON_WIDTH + gapWidth) * buttonStackCount;
// license company panel
this.licenseCompanyPanel = this.makePanelSprite(0, 300, licenseCompanyPanelWidth, 398, 0x000000);
// 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.strokeWidthPx = 5;
setting.x = 90;
setting.width = 160;
setting.x = -100;
setting.y = -100;
setting.height = 50;
setting.strokeWidthPx = 5;
setting.roundAmount = 10;
setting.fontStyle.fontSize = 24;
setting.fontStyle.fontWeight = "bold";
// license company buttons
for(var i = 0; i < licenseCompanySubjectList.length; i++) {
setting.y = this.inputScorePosY - 40 - 60 * i;
var licenseCompanyButton = new RoundRectButton(
setting,
null, licenseCompanySubjectList[i].companyName,
(function() { console.log(licenseCompanySubjectList[i].companyName); }).bind(this)
);
setting.width = InputScore.LICENSE_COMPANY_BUTTON_WIDTH;
this.licenseCompanyButtonList[i] = licenseCompanyButton;
var self = this;
var companyName = licenseCompanySubjectList[i].companyName;
this.licenseCompanyButtonList[i] = new RoundRectButton(
setting, null, companyName,
(function() { self.setVisibleLicenseSubjectPanel(true, this.text.text); })
);
}
// license subject buttons
for(var i = 0; i < this.licenseCompanySubjects.length; i++) {
setting.width = InputScore.LICENSE_SUBJECT_BUTTON_WIDTH;
var companySubjectData = this.licenseCompanySubjects[i];
var companySubjectName = companySubjectData.companyName + " " + companySubjectData.subjectName;
this.licenseSubjectButtonList[i] = new RoundRectButton(setting, null, companySubjectName, null);
}
}
@@ -138,16 +214,70 @@ InputScore.prototype.setVisibleLicenseCompanyPanel = function(flag) {
this.licenseCompanyPanel.visible = flag;
if(flag) {
for(var i = 0; i < licenseCompanySubjectList.length; i++) {
this.licenseCompanyButtonList[i].move(90, this.inputScorePosY - 40 - 60 * i);
for(var i = 0; i < this.licenseCompanyButtonList.length; i++) {
this.licenseCompanyButtonList[i].move(
this.licenseCompanyButtonStartPosX,
this.inputScorePosY - 40 - InputScore.LICENSE_BUTTON_GAP_HEIGHT * i
);
}
} else {
for(var i = 0; i < licenseCompanySubjectList.length; i++) {
for(var i = 0; i < this.licenseCompanyButtonList.length; i++) {
this.licenseCompanyButtonList[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;
}
InputScore.prototype.getLicenseSubjectButtonPosY = function(index) {
var colIndex = index % InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT;
return this.inputScorePosY - 40 - InputScore.LICENSE_BUTTON_GAP_HEIGHT * colIndex;
}
InputScore.prototype.setVisibleLicenseSubjectPanel = function(flag, companyName) {
this.licenseSubjectPanel.visible = flag;
for(var i = 0; i < this.licenseSubjectButtonList.length; i++) {
this.licenseSubjectButtonList[i].move(-100, 900);
}
if(!flag)
return;
var buttonIndex = 0;
for(var i = 0; i < this.licenseCompanySubjects.length; i++) {
var subjectData = this.licenseCompanySubjects[i];
if(subjectData.companyName == companyName) {
var button = this.licenseSubjectButtonList[buttonIndex];
var buttonName = companyName + " " + subjectData.subjectName;
button.text.text = buttonName;
button.move(
this.getLicenseSubjectButtonPosX(buttonIndex),
this.getLicenseSubjectButtonPosY(buttonIndex)
);
var self = this;
button.clickEvent = (function() {
self.onClickCompanySubjectButton(this.text.text);
});
buttonIndex++;
}
}
}
InputScore.prototype.onClickCompanySubjectButton = function(companySubjectName) {
console.log(companySubjectName);
// this.subjectText.setText(companySubjectName);
}
InputScore.prototype.makePanelSprite = function(x, y, width, height, color) {
var btnTexture = new Phaser.Graphics()
.beginFill(color, 0.5)
@@ -167,3 +297,18 @@ InputScore.prototype.onClickSendToServerButton = function() {
InputScore.INPUT_SCORE_GROUP_OFFSET_Y = 70;
InputScore.LICENSE_COMPANY_BUTTON_WIDTH = 160;
InputScore.LICENSE_SUBJECT_BUTTON_WIDTH = 260;
InputScore.LICENSE_BUTTON_GAP_HEIGHT = 64;
InputScore.LICENSE_SUBJECT_BUTTON_MAX_COUNT = 6;
function LicenseCompanySubjectData(companyName, subjectName, timeLimit, maxScore, gradeList) {
this.companyName = companyName;
this.subjectName = subjectName;
this.timeLimit = timeLimit;
this.maxScore = maxScore;
this.gradeList = gradeList;
}
@@ -3,9 +3,9 @@ var licenseCompanySubjectList = [
companyName: "ITQ",
subjectData: [
{
time: 40,
timeLimit: 60,
maxScore: 500,
grade: {
gradeList: {
A: 400,
B: 300,
C: 200
@@ -28,9 +28,9 @@ var licenseCompanySubjectList = [
companyName: "DIAT",
subjectData: [
{
time: 40,
timeLimit: 40,
maxScore: 200,
grade: {
gradeList: {
고급: 160,
중급: 120,
초급: 80
@@ -44,9 +44,9 @@ var licenseCompanySubjectList = [
},
{
time: 40,
timeLimit: 40,
maxScore: 100,
grade: {
gradeList: {
고급: 80,
중급: 60,
초급: 40