var Ranking = { preload: function() { game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); }, create: function() { this.dbConnectManager = new DBConnectManager(); this.jsonData = null; this.timeType = Ranking.MODE_HOUR; this.refreshTimeSec = Ranking.REFRESH_TIME_SEC; this.showingPageIndex = 0; this.dateTime = null; this.date = ""; this.time = ""; this.recordArray = null; this.getDateTimeNow(); // bg this.game.stage.backgroundColor = '#4d4d4d'; var posY = 100; var bg = game.add.graphics(); bg.beginFill(0x545454, 1); bg.drawRect(0, 60, GAME_SCREEN_SIZE.x, 80); // keyboard shortcut this.keyboardShortcut = new KeyboardShortcut(); this.keyboardShortcut.addCallback( Phaser.KeyCode.ESC, // keyCode null, // keyDownHandler (function() { this.back(); }).bind(this), // keyUpHandler "ranking" // callerClassName ); // top ui var screenTopUI = new ScreenTopUI(); screenTopUI.makeBackButton( (function() { this.back(); }).bind(this) ); screenTopUI.makeFullScreenButton(); var resultTextStyle = textStyleBasic; resultTextStyle.font = "bold 42px Arial"; this.textTitle = game.add.text( GAME_SCREEN_SIZE.x / 2, 32, sessionStorageManager.getPlayingAppKoreanName() + " - 수업시간 순위", resultTextStyle ).setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); this.textTitle.anchor.set(0.5); this.textTitle.addColor("#ff6666", 0); // date time this.textDateTime = game.add.text(GAME_SCREEN_SIZE.x / 2, 104, "", resultTextStyle); this.textDateTime.fontSize = 34; this.textDateTime.fontWeight = "normal"; this.textDateTime.stroke = "#333333"; this.textDateTime.strokeThickness = 3; //.setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); this.textDateTime.anchor.set(0.5); // this.textDateTime.addColor("#ff6666", 0); // rank var rankAreaPositionX = 120; var rankAreaPositionY = 150; var style = { font: "32px Arial", fill: "#fff", tabs: [ 60, 200, 160 ] }; this.textRanking1to10 = game.add.text(rankAreaPositionX, rankAreaPositionY , '', style) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); this.textRanking11to20 = game.add.text(rankAreaPositionX + 460, rankAreaPositionY, '', style) .setShadow(3, 3, 'rgba(0, 0, 0, 0.5)', 2); var buttonOffsetX = 300; var buttonPositionY = 100; this.buttonPrevDate = this.makeArrowButton( buttonOffsetX, buttonPositionY, 50, 50, "<", (function() { console.log("prev date time"); }).bind(this) ); // this.buttonPrevDate.inputEnabled = false; this.buttonNextDate = this.makeArrowButton( GAME_SCREEN_SIZE.x - buttonOffsetX, buttonPositionY, 50, 50, ">", (function() { console.log("next date time"); }).bind(this) ); // this.buttonNextDate.inputEnabled = false; buttonOffsetX = 30; buttonPositionY = 370; this.buttonPrevRanking = this.makeArrowButton( buttonOffsetX, buttonPositionY, 50, 400, "<", (function() { this.onClickPrevRanking(); }).bind(this) ); // this.buttonPrevRanking.setInputEnabled(false); this.buttonNextRanking = this.makeArrowButton( GAME_SCREEN_SIZE.x - buttonOffsetX, buttonPositionY, 50, 400, ">", (function() { this.onClickNextRanking() }).bind(this) ); // this.buttonNextRanking.setInputEnabled(false); buttonPositionY = 650; var buttonHour = this.makeTextButton( game.world.centerX - 220, buttonPositionY, "수업시간 순위", (function() { this.showRankingHour(); }).bind(this) ); // buttonHour.setInputEnabled(false); var buttonDay = this.makeTextButton( game.world.centerX, buttonPositionY, "오늘의 순위", (function() { this.showRankingDay(); }).bind(this) ); // buttonDay.setInputEnabled(false); var buttonMonth = this.makeTextButton( game.world.centerX + 220, buttonPositionY, "이달의 순위", (function() { this.showRankingMonth(); }).bind(this) ); // buttonMonth.setInputEnabled(false); // bottom ui this.screenBottomUI = new ScreenBottomUI(); // ScreenBottomUI.printLeftText("게임 진행 정보"); // var playingAppName = appInfoManager.getAppNameKorean(sessionStorageManager.getPlayingAppName()); // ScreenBottomUI.printCenterText(playingAppName); // this.screenBottomUI.printCenterText("수업시간 순위"); this.screenBottomUI.printRightText(sessionStorageManager.getPlayerName()); this.getRecordToRankingServer(); game.time.events.loop(Phaser.Timer.SECOND * this.refreshTimeSec, this.getRecordToRankingServer, this); }, back: function() { location.href = '../../web/client/start.html'; }, makeArrowButton: function(x, y, width, height, buttonText, eventListener) { var setting = new RoundRectButtonSetting(x, y, width, height); setting.fontStyle.fontWeight = "bold"; setting.strokeColors = { out: 0x444444, // 0xdddddd, over: 0x333333, // 0xcccccc, down: 0x222222, // 0xbbbbbb, disabled: 0x333333 }; setting.buttonColors = { out: 0x666666, // 0xffffff, over: 0x444444, // 0xdddddd, down: 0x333333, // 0xcccccc, disabled: 0x333333 }; setting.textColors = { out: "#fff", // "#000", over: "#000", down: "#000", disabled: "#999" }; return new RoundRectButton(setting, RoundRectButton.NONE_ICON, buttonText, eventListener); }, makeTextButton: function(x, y, buttonText, eventListener) { var setting = new RoundRectButtonSetting(x, y, 200, 100); setting.fontStyle.fontWeight = "bold"; switch(buttonText) { case "수업시간 순위": setting.strokeColors = { out: 0xddcccc, over: 0xccaaaa, down: 0xbb9999, disabled: 0x333333 }; setting.buttonColors = { out: 0xffeeee, over: 0xddcccc, down: 0xccaaaa, disabled: 0x333333 }; setting.textColors = { out: "#f00", over: "#f00", down: "#f00", disabled: "#999" }; break; case "오늘의 순위": setting.strokeColors = { out: 0xccccdd, over: 0xaaaacc, down: 0x9999bb, disabled: 0x333333 }; setting.buttonColors = { out: 0xeeeeff, over: 0xccccdd, down: 0xaaaacc, disabled: 0x333333 }; setting.textColors = { out: "#00f", over: "#00f", down: "#00f", disabled: "#999" }; break; case "이달의 순위": setting.strokeColors = { out: 0xccddcc, over: 0xaaccaa, down: 0x99bb99, disabled: 0x333333 }; setting.buttonColors = { out: 0xeeffee, over: 0xccddcc, down: 0xaaccaa, disabled: 0x333333 }; setting.textColors = { out: "#0f0", over: "#0f0", down: "#0f0", disabled: "#999" }; break; } return new RoundRectButton(setting, RoundRectButton.NONE_ICON, buttonText, eventListener); }, getDateTimeType: function() { var dateTimeType = -1; switch(this.timeType) { case Ranking.MODE_HOUR: dateTimeType = DBConnectManager.TYPE_MY_RANKING_HOUR; break; case Ranking.MODE_DAY: dateTimeType = DBConnectManager.TYPE_MY_RANKING_DAY; break; case Ranking.MODE_MONTH: dateTimeType = DBConnectManager.TYPE_MY_RANKING_MONTH; break; } return dateTimeType; }, getRecordToRankingServer: function() { this.dbConnectManager.requestRanking( this.getDateTimeType(), sessionStorageManager.getMaestroID(), this.date, this.time, (type, rankingRecordManager) => { this.showRanking(rankingRecordManager); } ); }, showRankingHour: function() { this.timeType = Ranking.MODE_HOUR; this.textTitle.text = sessionStorageManager.getPlayingAppKoreanName() + " - 수업시간 순위"; this.textTitle.addColor("#ff6666", 0); this.getRecordToRankingServer(); }, showRankingDay: function() { this.timeType = Ranking.MODE_DAY; this.textTitle.text = sessionStorageManager.getPlayingAppKoreanName() + " - 오늘의 순위"; this.textTitle.addColor("#9999ff", 0); this.getRecordToRankingServer(); }, showRankingMonth: function() { this.timeType = Ranking.MODE_MONTH; this.textTitle.text = sessionStorageManager.getPlayingAppKoreanName() + " - 이달의 순위"; this.textTitle.addColor("#99ff99", 0); this.getRecordToRankingServer(); }, showRanking: function(rankingRecordManager) { // console.log(rankingRecordManager); if(sessionStorageManager.getMaestroAccountType() == 101) { this.recordArray = this.getDummyRankList(); this.printRanking(); return; } if(rankingRecordManager.rankingRecords.length === 0) { var rankEmpty = [ ]; this.textRanking1to10.parseList(rankEmpty); this.textRanking11to20.parseList(rankEmpty); return; } var rankingListCount = rankingRecordManager.rankingRecords.length; this.recordArray = []; for(var i = 0; i < rankingListCount; i++) { var bestRecordRow = []; // bestRecordRow[0] = jsonRankingList[i]['UserID']; bestRecordRow[0] = i + 1; bestRecordRow[1] = rankingRecordManager.rankingRecords[i]['playerName']; bestRecordRow[2] = RecordUtil.getRecordValueWithUnit( rankingRecordManager.rankingRecords[i]['bestRecord'], sessionStorageManager.getPlayingAppID() ); // console.log("$BestRecordRow : " + bestRecordRow[0] + ", " + bestRecordRow[1] + ", " + bestRecordRow[2]); this.recordArray.push(bestRecordRow); } this.printDateTime(); this.printRanking(); }, printRanking: function() { var recordTop10 = []; var recordTop20 = []; // timezone changed (ex: 2pm -> 3pm) if(this.showingPageIndex * 20 > this.recordArray.length) this.showingPageIndex = 0; // prepare ranking list - top10 / top20 for(var i = 0; i < 10; i++) { var index = this.showingPageIndex * 20 + i; if(index < this.recordArray.length) recordTop10.push(this.recordArray[index]); if(index + 10 < this.recordArray.length) recordTop20.push(this.recordArray[index + 10]); } // print this.textRanking1to10.parseList(recordTop10); this.textRanking11to20.parseList(recordTop20); this.updateRankingNavigationButtons(); }, updateRankingNavigationButtons: function() { // console.log(this.recordArray); if(this.recordArray == null) { this.buttonPrevRanking.text.text = "X"; this.buttonNextRanking.text.text = "X"; return; } if(this.showingPageIndex > 0) this.buttonPrevRanking.text.text = "<"; else this.buttonPrevRanking.text.text = "X"; if((this.showingPageIndex + 1) * 20 < this.recordArray.length) this.buttonNextRanking.text.text = ">"; else this.buttonNextRanking.text.text = "X"; }, getDummyRankList: function() { var dummyRankList = [ [ '1', 'test1', '600' ], [ '2', 'test2', '500' ], [ '3', 'test3', '450' ], [ '4', 'test4', '400' ], [ '5', 'test5', '350' ], [ '6', 'test6', '300' ], [ '7', 'test7', '250' ], [ '8', 'test8', '200' ], [ '9', 'test9', '150' ], [ '10', 'test10', '100' ], [ '11', 'test11', '90' ], [ '12', 'test12', '80' ], [ '13', 'test13', '70' ], [ '14', 'test14', '60' ], [ '15', 'test15', '50' ], [ '16', 'test16', '45' ], [ '17', 'test17', '40' ], [ '18', 'test18', '35' ], [ '19', 'test19', '30' ], [ '20', 'test20', '25' ], [ '21', 'test21', '20' ], [ '22', 'test22', '15' ], [ '23', 'test23', '10' ], [ '24', 'test24', '9' ], [ '25', 'test25', '8' ], [ '26', 'test26', '7' ], [ '27', 'test27', '6' ], [ '28', 'test28', '5' ], [ '29', 'test29', '4' ], [ '30', 'test30', '3' ], [ '31', 'test31', '2' ], [ '32', 'test32', '1' ], ]; return dummyRankList; }, getDateTimeNow: function() { var now = new Date(); var hourTimeText = DateUtil.getYYYYMMDD(now) + "T" + now.getHours() + ":00:00"; this.dateTime = new Date(hourTimeText); this.date = DateUtil.getYYYYMMDD(this.dateTime); this.time = DateUtil.getHHMMSS(this.dateTime); if(runMode == MODE_DEBUG) { this.date = "2018-08-23"; this.time = "15:53:00"; this.dateTime = new Date(this.date + "T" + this.time); } }, increaseDateTime: function() { }, decreaseDateTime: function() { }, getDatetimeHour: function() { return this.dateTime.getHours(); }, getDatetimeHourWith2Digits: function() { return ("0" + this.dateTime.getHours()).slice(-2); }, getYYYYMMDDHHText: function() { return DateUtil.getFullYear(this.dateTime) + "년 " + DateUtil.getFullMonth(this.dateTime) + "월 " + DateUtil.getFullDate(this.dateTime) + "일, " + DateUtil.getFullHours(this.dateTime) + "시"; }, getYYYYMMDDText: function() { return DateUtil.getFullYear(this.dateTime) + "년 " + DateUtil.getFullMonth(this.dateTime) + "월 " + DateUtil.getFullDate(this.dateTime) + "일"; }, getYYYYMMText: function() { return DateUtil.getFullYear(this.dateTime) + "년 " + DateUtil.getFullMonth(this.dateTime) + "월 "; }, printDateTime: function() { console.log(this.timeType); switch(this.timeType) { case Ranking.MODE_HOUR: this.textDateTime.text = this.getYYYYMMDDHHText(); break; case Ranking.MODE_DAY: this.textDateTime.text = this.getYYYYMMDDText(); break; case Ranking.MODE_MONTH: this.textDateTime.text = this.getYYYYMMText(); break; } }, onClickPrevRanking: function() { if(this.recordArray == null) return; this.showingPageIndex--; if(this.showingPageIndex < 0) this.showingPageIndex = 0; this.printRanking(); }, onClickNextRanking: function() { if(this.recordArray == null) return; if((this.showingPageIndex + 1) * 20 < this.recordArray.length) this.showingPageIndex++; this.printRanking(); }, } Ranking.MODE_HOUR = "mode_hour"; Ranking.MODE_DAY = "mode_day"; Ranking.MODE_MONTH = "mode_month"; Ranking.REFRESH_TIME_SEC = 10;