///////////////////////////// // MenuTypingTest class MenuTypingTest { preload() { game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); game.load.image('space_invaders', '../../../resources/image/icon/space_invaders.png'); Animal.loadResources(); } create() { self = this; this.game.stage.backgroundColor = '#4d4d4d'; // typing app area let typingBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_APP, 1, 0, 60, GAME_SCREEN_SIZE.x, GAME_SCREEN_SIZE.y - 110 ); // korean app area // let koreanBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_KOREAN, 1, // 0, 60 + AppAreaBG.GAP_Y, // GAME_SCREEN_SIZE.x, 270 // ); // koreanBG.printText( // "한 글 타 자", // game.world.centerX, 320, // 36, "#000", 0.05 // ); // english app area // let englishBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_ENGLISH, 1, // 0, 340, // GAME_SCREEN_SIZE.x, 270 // ); // englishBG.printText( // "영 문 타 자", // game.world.centerX, 370, // 36, "#000", 0.05 // ); // top ui let screenTopUI = new ScreenTopUI(); screenTopUI.makeBackButton( () => { location.href = '../../web/client/menu_app.html'; }); screenTopUI.makeFullScreenButton(); // typing tab buttons let typingPracticeTabButton = new TypingTabButton( TypingTabButton.PRACTICE_BUTTON_POS_X, TypingTabButton.BUTTON_POS_Y, "", "타자 연습", () => { location.href = '../../web/client/menu_typing_practice.html'; } ); // typingPracticeTabButton.inputEnabled = false; let typingTestTabButton = new TypingTabButton( TypingTabButton.TEST_BUTTON_POS_X, TypingTabButton.BUTTON_POS_Y, "", "타자 시험", () => { location.href = '../../web/client/menu_typing_test.html'; } ); typingTestTabButton.inputEnabled = false; this.makeActiveTypingTestAppButtons(); // bottom ui let screenBottomUI = new ScreenBottomUI(); // screenBottomUI.printLeftText("게임 진행 정보"); screenBottomUI.printCenterText("메뉴 > 타자 시험"); screenBottomUI.printRightText(sessionStorageManager.playerName); } makeActiveTypingTestAppButtons() { let dbConnectManager = new DBConnectManager(); dbConnectManager.requestTypingTestAppList( sessionStorageManager.maestroID, sessionStorageManager.playerID, self.downloadListSucceeded, self.downloadListFailed ); } hasApp(appID, appList) { for(let i = 0; i < appList.length; i++) { if(appList[i].AppID === appID) return true; } return false; } getBestRecord(jsonList, appID) { let count = Object.keys(jsonList).length; for(let i = 0; i < count; i++) { if(jsonList[i].AppID === appID) return jsonList[i].BestRecord; } return 0; } getIconImage(jsonList, appID) { let bestRecord = this.getBestRecord(jsonList, appID); if(bestRecord === 0) return "snail_shadow"; let animalLevel = Animal.animalLevelIDByRecord(bestRecord, Animal.TYPE_TEST); return Animal.SPECIES_DATA[animalLevel].species + Animal.SPRITE_NAMES.icon; } downloadListSucceeded(replyJSON) { // console.log(replyJSON); let buttonWidthGap = TypingAppButton.BUTTON_WIDTH + MenuTypingTest.BUTTON_GAP; let koreanTypingPracticeAppCount = Object.keys(replyJSON.KoreanAppList).length; let englishTypingPracticeAppCount = Object.keys(replyJSON.EnglishAppList).length; for(let i = 0; i < koreanTypingPracticeAppCount; i++) { let activeApp = replyJSON.KoreanAppList[i]; let posX = self.getButtonPosX(i, koreanTypingPracticeAppCount); let posY = self.getButtonPosY(i, koreanTypingPracticeAppCount, TypingAppButton.BUTTON_UPPER_POS_Y ); let typingTestButton = new TypingAppButton( TypingAppButton.TYPE_TEST_KOREAN, posX, posY, self.getIconImage(replyJSON.KoreanHighScoreList, activeApp.AppID), activeApp.KoreanName, () => { sessionStorageManager.playingAppID = activeApp.AppID; sessionStorageManager.playingAppName = activeApp.AppName; sessionStorageManager.playingAppKoreanName = activeApp.KoreanName; location.href = '../../web/client/start.html'; } ); if(!self.hasApp(activeApp.AppID, replyJSON.KoreanActiveAppList)) typingTestButton.inputEnabled = false; } for(let i = 0; i < englishTypingPracticeAppCount; i++) { let activeApp = replyJSON.EnglishAppList[i]; let posX = self.getButtonPosX(i, englishTypingPracticeAppCount); let posY = self.getButtonPosY(i, englishTypingPracticeAppCount, TypingAppButton.BUTTON_LOWER_POS_Y ); let typingTestButton = new TypingAppButton( TypingAppButton.TYPE_TEST_ENGLISH, posX, posY, self.getIconImage(replyJSON.KoreanHighScoreList, activeApp.AppID), activeApp.KoreanName, () => { sessionStorageManager.playingAppID = activeApp.AppID; sessionStorageManager.playingAppName = activeApp.AppName; sessionStorageManager.playingAppKoreanName = activeApp.KoreanName; location.href = '../../web/client/start.html'; } ); if(!self.hasApp(activeApp.AppID, replyJSON.EnglishActiveAppList)) typingTestButton.inputEnabled = false; } } getButtonPosX(index, buttonCount) { let gap = TypingAppButton.BUTTON_WIDTH + TypingAppButton.BUTTON_GAP; let maxColumnNum = Math.floor( (game.world.width - TypingAppButton.MARGIN_VERTICAL) / gap ); // console.log("maxColumnNum : " + maxColumnNum); let rowCount = Math.ceil(buttonCount / maxColumnNum); // console.log("rowCount : " + rowCount); let columnIndex = index % maxColumnNum; // console.log("columnIndex : " + columnIndex); let rowIndex = Math.floor(index / maxColumnNum); // console.log("rowIndex : " + rowIndex); let columnCountForThisRow = 0; if(rowIndex < rowCount - 1) columnCountForThisRow = maxColumnNum; else columnCountForThisRow = buttonCount - (maxColumnNum * rowIndex); // console.log("columnCountForThisRow : " + columnCountForThisRow); let startX = game.world.width / 2 - ( (gap / 2) * (columnCountForThisRow - 1) ); return startX + gap * columnIndex; } getButtonPosY(index, buttonCount, startPosY) { let rowGap = TypingAppButton.BUTTON_HEIGHT + TypingAppButton.BUTTON_GAP; let columnGap = TypingAppButton.BUTTON_WIDTH + TypingAppButton.BUTTON_GAP; let maxColumnNum = Math.floor( (game.world.width - TypingAppButton.MARGIN_VERTICAL) / columnGap ); // console.log("maxColumnNum : " + maxColumnNum); // console.log("buttonCount : " + buttonCount); let rowCount = Math.ceil(buttonCount / maxColumnNum); // console.log("rowCount : " + rowCount); let rowIndex = Math.floor(index / maxColumnNum); // console.log("rowIndex : " + rowIndex); let startY = startPosY - ( (rowGap / 2) * (rowCount - 1) ); return startY + rowGap * rowIndex; } downloadListFailed(replyJSON) { console.log('download app list failed, jsonData : ' + JSON.stringify(replyJSON)); } }