///////////////////////////// // 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'; // mouse app area let mouseBG = new AppAreaBG(AppAreaBG.COLOR_MOUSE_APP, 1, 0, 60, GAME_SCREEN_SIZE.x, 280 ); mouseBG.printText( "마 우 스 연 습 앱", game.world.centerX, 320, 36, "#000", 0.05 ); // typing app area let typingBG = new AppAreaBG(AppAreaBG.COLOR_TYPING_APP, 1, 0, 340, GAME_SCREEN_SIZE.x, 378 ); typingBG.printText( "타 자 연 습 앱", game.world.centerX, 370, 36, "#000", 0.05 ); // top let backButton = new BackButton( () => { sessionStorageManager.clear(); location.href = '../../web/client/login.html'; }); let fullscreenButton = new FullscreenButton(); // bottom let screenBottom = new ScreenBottom(); // screenBottom.printBottomLeftText("게임 진행 정보"); // let playingAppName = appInfoManager.getAppNameKorean(sessionStorageManager.playingAppName); // screenBottom.printBottomCenterText(playingAppName); screenBottom.printBottomCenterText("메뉴"); screenBottom.printBottomRightText(sessionStorageManager.playerName); new WelcomePlayerText(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, replyJSON.MouseActiveAppList ); self.makeTypingButtons( replyJSON.TypingPracticeAppCount, replyJSON.TypingTestAppCount, replyJSON.TypingAppList, replyJSON.TypingActiveAppList ); } hasApp(appID, appList) { for(let i = 0; i < appList.length; i++) { if(appList[i].AppID === appID) return true; } return false; } makeMouseAppButtons(appList, activeAppList) { // console.log(appList); let mouseAppCount = Object.keys(appList).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 = appList[i]; let gameAppButton = new GameAppButton( posX, posY, GameAppButton.TYPE_MOUSE_APP, RoundRectButton.NONE_ICON, // "icon_fullscreen", app.KoreanName, () => { sessionStorageManager.playingAppID = app.AppID; sessionStorageManager.playingAppName = app.AppName; sessionStorageManager.playingAppKoreanName = app.KoreanName; location.href = '../../web/client/start.html'; } ); if(!self.hasApp(app.AppID, activeAppList)) gameAppButton.inputEnabled = false; } } makeTypingButtons(typingPracticeAppCount, typingTestAppCount, appList, activeAppList) { // console.log(typingPracticeAppCount); // console.log(typingTestAppCount); // console.log(appList); let isTypingPracticeAppExist = typingPracticeAppCount > 0 ? true : false; let isTypingTestAppExist = typingTestAppCount > 0 ? true : false; let typingAppTotalCount = Object.keys(appList).length; let typingAppIndex = 0; // typing tab buttons let typingPracticeTabButton = new TypingTabButton( TypingTabButton.PRACTICE_BUTTON_POS_X, TypingTabButton.BUTTON_POS_Y, "", "타자 연습", () => { location.href = '../../web/client/menu_typing_practice.html'; } ); if(typingPracticeAppCount === 0) typingPracticeTabButton.inputEnabled = false; let typingTestTabButton = new TypingTabButton( TypingTabButton.TEST_BUTTON_POS_X, TypingTabButton.BUTTON_POS_Y, "", "타자 시험", () => { location.href = '../../web/client/menu_typing_test.html'; } ); if(typingTestAppCount === 0) typingTestTabButton.inputEnabled = false; // typing app buttons for(let typingButtonIndex = 0; typingButtonIndex < typingAppTotalCount; typingButtonIndex++) { let posX = self.getButtonPosX( typingButtonIndex, typingAppTotalCount ); let posY = self.getButtonPosY( typingButtonIndex, typingAppTotalCount, GameAppButton.BUTTON_LOWER_POS_Y ); let app = appList[typingAppIndex]; let isKoreanTypingApp = app.AppID < 32 ? true : false; let gameAppButton = new GameAppButton( posX, posY, GameAppButton.TYPE_TYPING_APP, RoundRectButton.NONE_ICON, // "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'; } ); if(!self.hasApp(app.AppID, activeAppList)) gameAppButton.inputEnabled = false; 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)); } }