///////////////////////////// // MenuApp class MenuApp { preload() { game.load.image('icon_fullscreen', '../../../resources/image/icon/fullscreen_white.png'); game.load.image('space_invaders', '../../../resources/image/icon/space_invaders.png'); } create() { self = this; this.game.stage.backgroundColor = '#4d4d4d'; // top let backButton = new BackButton( () => { sessionStorageManager.clear(); location.href = '../../web/client/login.html'; }); let fullscreenButton = new FullscreenButton(this.game); // bottom let screenBottom = new ScreenBottom(); screenBottom.makeBottomLine(); // screenBottom.printBottomLeftText("게임 진행 정보"); // let playingAppName = appInfoManager.getAppNameKorean(sessionStorageManager.playingAppName); // screenBottom.printBottomCenterText(playingAppName); screenBottom.printBottomCenterText("메뉴"); screenBottom.printBottomRightText(sessionStorageManager.playerName); this.loadAppData(); } loadAppData() { let dbConnectManager = new DBConnectManager(); dbConnectManager.requestMenuAppList( sessionStorageManager.maestroID, self.loadSucceeded, self.loadFailed ); } loadSucceeded(replyJSON) { // console.log(replyJSON); self.makeMouseAppButtons(replyJSON.MouseAppList); self.makeTypingButtons( replyJSON.TypingPracticeAppCount, replyJSON.TypingTestAppCount, replyJSON.TypingAppList ); } makeMouseAppButtons(mouseAppJSON) { // console.log(mouseAppJSON); let mouseAppCount = Object.keys(mouseAppJSON).length; for(let i = 0; i < mouseAppCount; i++) { let posX = self.getButtonPosX(i, mouseAppCount); let posY = self.getButtonPosY(i, mouseAppCount, GameAppButton.BUTTON_UPPER_POS_Y); let app = mouseAppJSON[i]; new GameAppButton( posX, posY, AppButton.TYPE_MOUSE_APP, "icon_fullscreen", app.KoreanName, () => { sessionStorageManager.playingAppID = app.AppID; sessionStorageManager.playingAppName = app.AppName; sessionStorageManager.playingAppKoreanName = app.KoreanName; location.href = '../../web/client/start.html'; } ); } } makeTypingButtons(typingPracticeAppCount, typingTestAppCount, typingAppJSON) { // console.log(typingPracticeAppCount); // console.log(typingTestAppCount); // console.log(typingAppJSON); let isTypingPracticeAppExist = typingPracticeAppCount > 0 ? true : false; let isTypingTestAppExist = typingTestAppCount > 0 ? true : false; let typingAppTotalCount = Object.keys(typingAppJSON).length + (isTypingPracticeAppExist ? 1 : 0) + (isTypingTestAppExist ? 1 : 0); let typingAppIndex = 0; for(let typingButtonIndex = 0; typingButtonIndex < typingAppTotalCount; typingButtonIndex++) { let posX = self.getButtonPosX( typingButtonIndex, typingAppTotalCount ); let posY = self.getButtonPosY( typingButtonIndex, typingAppTotalCount, GameAppButton.BUTTON_LOWER_POS_Y ); if(isTypingPracticeAppExist) { isTypingPracticeAppExist = false; new GameAppButton( posX, posY, AppButton.TYPE_TYPING_PRACTICE, "", "타자 연습", () => { location.href = '../../web/client/menu_typing_practice.html'; } ); continue; } if(isTypingTestAppExist) { isTypingTestAppExist = false; new GameAppButton( posX, posY, AppButton.TYPE_TYPING_PRACTICE, "", "타자 시험", () => { location.href = '../../web/client/menu_typing_test.html'; } ); continue; } let app = typingAppJSON[typingAppIndex]; let isKoreanTypingApp = app.AppID < 32 ? true : false; new GameAppButton( posX, posY, AppButton.TYPE_TYPING_APP, "icon_fullscreen", // (isKoreanTypingApp ? "(한글)" : "(영문)") + "\n" + app.KoreanName, app.KoreanName, () => { sessionStorageManager.playingAppID = app.AppID; sessionStorageManager.playingAppName = app.AppName; sessionStorageManager.playingAppKoreanName = app.KoreanName; location.href = '../../web/client/start.html'; } ); typingAppIndex++; } } getButtonPosX(index, buttonCount) { let gap = GameAppButton.BUTTON_WIDTH + GameAppButton.BUTTON_GAP; let maxColumnNum = Math.floor( (game.world.width - GameAppButton.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 gap = GameAppButton.BUTTON_HEIGHT + GameAppButton.BUTTON_GAP; let maxColumnNum = Math.floor( (game.world.width - GameAppButton.MARGIN_VERTICAL) / gap ); // console.log("maxColumnNum : " + maxColumnNum); let rowCount = Math.ceil(buttonCount / maxColumnNum); // console.log("rowCount : " + rowCount); let rowIndex = Math.floor(index / maxColumnNum); // console.log("rowIndex : " + rowIndex); let startY = startPosY - ( (gap / 2) * (rowCount - 1) ); return startY + gap * rowIndex; } loadFailed(replyJSON) { // console.log('login failed, jsonData : ' + JSON.stringify(replyJSON)); } }