Add: ShowNotifyTimeOver, CancelNotifyTimeOver

This commit is contained in:
2018-12-10 10:29:44 +09:00
parent 2eea30f574
commit 75041a8b1e
2 changed files with 73 additions and 39 deletions
+72 -38
View File
@@ -11,17 +11,17 @@ function Timer() {
var timerCenterY = 183;
this.timeHourText = this.makeTimerTextContent(timerCenterX - 240, timerCenterY, 160, "00");
this.timeHourMinuteSeperator = this.makeTimerTextContent(timerCenterX - 120, timerCenterY, 160, ":");
this.timeHourMinuteSeperator = this.makeTimerTextContent(timerCenterX - 185, timerCenterY, 160, ":");
this.timeMinuteText = this.makeTimerTextContent(timerCenterX, timerCenterY, 160, "00");
this.timeMinuteSecondSeperator = this.makeTimerTextContent(timerCenterX + 110, timerCenterY + 20, 100, ":");
this.timeSecondText = this.makeTimerTextContent(timerCenterX + 190, timerCenterY + 20, 100, "00");
this.timeMinuteSecondSeperator = this.makeTimerTextContent(timerCenterX + 40, timerCenterY + 20, 100, ":");
this.timeSecondText = this.makeTimerTextContent(timerCenterX + 160, timerCenterY + 20, 100, "00");
// buttons
var hour10PosX = timerCenterX - 285;
var hour1PosX = timerCenterX - 195;
var hour10PosX = timerCenterX - 285 - 90;
var hour1PosX = timerCenterX - 195 - 90;
var minute10PosX = timerCenterX - 45;
var minute1PosX = timerCenterX + 45;
var minute10PosX = timerCenterX - 45 - 90;
var minute1PosX = timerCenterX + 45 - 90;
var plusPosY = timerCenterY - 82;
var minusPosY = timerCenterY + 75;
@@ -32,14 +32,14 @@ function Timer() {
);
// this.hourPlus10Button.setInputEnabled(false);
this.hourMinus10Button = this.makeTimeMinusButton(hour10PosX, minusPosY, "▼",
(function() { this.timeMinus(-10, Timer.TYPE_HOUR); }).bind(this)
(function() { this.timeMinus(10, Timer.TYPE_HOUR); }).bind(this)
);
this.hourPlus1Button = this.makeTimePlusButton(hour1PosX, plusPosY, "▲",
(function() { this.timePlus(1, Timer.TYPE_HOUR); }).bind(this)
);
this.hourMinus1Button = this.makeTimeMinusButton(hour1PosX, minusPosY, "▼",
(function() { this.timeMinus(-1, Timer.TYPE_HOUR); }).bind(this)
(function() { this.timeMinus(1, Timer.TYPE_HOUR); }).bind(this)
);
// minute button
@@ -47,14 +47,14 @@ function Timer() {
(function() { this.timePlus(10, Timer.TYPE_MINUTE); }).bind(this)
);
this.minuteMinus10Button = this.makeTimeMinusButton(minute10PosX, minusPosY, "▼",
(function() { this.timeMinus(-10, Timer.TYPE_MINUTE); }).bind(this)
(function() { this.timeMinus(10, Timer.TYPE_MINUTE); }).bind(this)
);
this.minutePlus1Button = this.makeTimePlusButton(minute1PosX, plusPosY, "▲",
(function() { this.timePlus(1, Timer.TYPE_MINUTE); }).bind(this)
);
this.minuteMinus1Button = this.makeTimeMinusButton(minute1PosX, minusPosY, "▼",
(function() { this.timeMinus(-1, Timer.TYPE_MINUTE); }).bind(this)
(function() { this.timeMinus(1, Timer.TYPE_MINUTE); }).bind(this)
);
this.startTimer();
@@ -70,28 +70,36 @@ Timer.prototype.initVariables = function() {
}
Timer.prototype.startTimer = function() {
this.timeLeft = Timer.TIME_DEFAULT_SEC;
this.updateTimeText();
this.timerEvent = game.time.events.loop(1000, this.tickTimeLeft, this);
}
Timer.prototype.restartTimer = function() {
// this.timeLeft = Timer.TIME_DEFAULT_SEC;
// this.updateTimeText();
ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS);
this.prevTime = this.getNowTime();
this.timerEvent = game.time.events.loop(1000, this.tickTimeLeft, this);
}
Timer.prototype.tickTimeLeft = function() {
var outFocusedTime = this.getOutFocusedTime();
Timer.prototype.pauseTimer = function() {
this.updateTimeText();
if(outFocusedTime > 2)
CancelNotifyTimeOver();
game.time.events.remove(this.timerEvent);
}
Timer.prototype.tickTimeLeft = function() {
this.timeLeft--;
var outFocusedTime = this.getOutFocusedTime();
if(outFocusedTime > 2) {
this.timeLeft -= outFocusedTime - 1;
this.timeLeft--;
if(this.timeLeft > 0) {
CancelNotifyTimeOver();
ShowNotifyTimeOver(this.timeLeft * Timer.TIME_MILLISECONDS);
}
}
this.updateTimeText();
if(this.timeLeft < 0)
@@ -138,7 +146,7 @@ Timer.prototype.makeTimerTextContent = function(x, y, sizePx, content) {
// text
var timerText = game.add.text(x, y, content, timerTextStyle);
timerText.anchor.set(0.5);
timerText.anchor.set(1, 0.5);
timerText.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2);
return timerText;
@@ -213,25 +221,49 @@ Timer.prototype.makeTimeButton = function(setting, buttonText, eventHandler) {
return button;
}
Timer.prototype.timePlus = function(amount, type) {
console.log(amount + type);
Timer.prototype.timePlus = function(timePlusSecond, type) {
console.log(timePlusSecond + type);
var timeAmount = 0;
switch(type) {
case Timer.TYPE_HOUR:
timeAmount = timePlusSecond * Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE;
break;
case Timer.TYPE_MINUTE:
timeAmount = timePlusSecond * Timer.TIME_SECONDS_FOR_MINUTE;
break;
}
console.log(timeAmount);
this.timeLeft += timeAmount;
var maxTime = 99 * Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE * Timer.TIME_SECONDS_FOR_MINUTE;
if(this.timeLeft > maxTime)
this.timeLeft = maxTime;
// if(type == Timer.TYPE_HOUR)
this.timeLeft += amount * 60;
this.updateTimeText();
this.sendTimeLeftToServer();
}
Timer.prototype.timeMinus = function(amount, type) {
console.log(amount + type);
Timer.prototype.timeMinus = function(timeMinusSecond, type) {
console.log(timeMinusSecond + type);
// if(type == Timer.TYPE_HOUR) {
// var totalMinusMinute = amount * Timer.TIME_MINUTES_FOR_HOUR;
// if(totalMinusMinute - )
// }
this.timeLeft -= amount * 60;
var timeAmount = 0;
switch(type) {
case Timer.TYPE_HOUR:
timeAmount = timeMinusSecond * Timer.TIME_MINUTES_FOR_HOUR * Timer.TIME_SECONDS_FOR_MINUTE;
break;
case Timer.TYPE_MINUTE:
timeAmount = timeMinusSecond * Timer.TIME_SECONDS_FOR_MINUTE;
break;
}
console.log(timeAmount);
this.timeLeft -= timeAmount;
if(this.timeLeft < 0)
this.timeLeft = 0;
this.updateTimeText();
this.sendTimeLeftToServer();
}
@@ -269,9 +301,11 @@ Timer.prototype.updateTimeText = function() {
var timeLeftMinute = parseInt((this.timeLeft % secondsForHour) / Timer.TIME_SECONDS_FOR_MINUTE);
var timeLeftSecond = this.timeLeft % Timer.TIME_SECONDS_FOR_MINUTE;
this.timeHourText.text = this.getTimeWithTimeFormat(timeLeftHour);
this.timeMinuteText.text = this.getTimeWithTimeFormat(timeLeftMinute);
this.timeSecondText.text = this.getTimeWithTimeFormat(timeLeftSecond);
this.timeHourText.text = this.getTimeWithTimeFormat(timeLeftHour, Timer.TYPE_HOUR);
// console.log(this.timeLeft);
// console.log(this.timeHourText.text);
this.timeMinuteText.text = this.getTimeWithTimeFormat(timeLeftMinute, Timer.TYPE_MINUTE);
this.timeSecondText.text = this.getTimeWithTimeFormat(timeLeftSecond, Timer.TYPE_SECOND);
// this.updateTimeVariables();
// this.timerText.text = this.getTimeWithTimeFormat();
}
@@ -314,7 +348,7 @@ Timer.prototype.sendTimeLeftToServer = function() {
Timer.Timer_CENTER_OFFSET_X = 40;
Timer.Timer_CENTER_OFFSET_X = 130;
Timer.TIME_MILLISECONDS = 1000;
+1 -1
View File
@@ -82,7 +82,7 @@
var timeOutEventID;
function ShowNotifyTimeOver(timeLeft) {
timeOutEventID = setTimeout(function() {
alert("!!! 60분 시험 시간 종료 !!!\n작업을 중단하고 선생님을 불러주세요.");
alert("!!! 시험 시간 종료 !!!\n작업을 중단하고 선생님을 불러주세요.");
// notify("시험 시간이 끝났습니다!!!");
}, timeLeft);
}