import SKUIUtil from "./gear_2.3.4/util/SKUIUtil"; import FGUtil from "./gear_2.3.4/fgui/FGUtil"; import MsgAlert from "./game/msg/MsgAlert"; import GameModel from "./core/GameModel"; import SKLocalUtil from "./gear_2.3.4/util/SKLocalUtil"; import AudioManager from "./gear_2.3.4/manager/AudioManager"; import SKSocket from "./gear_2.3.4/net/SKSocket"; const { ccclass, property } = cc._decorator; @ccclass export default class Set extends cc.Component { /** * 單例實例 */ public static Instance: Set = null; /** * 主面板 */ mainPanel: fgui.GComponent = null; /** * 畫面面板 */ imgView: fgui.GComponent = null; /** * 聲音面板 */ soundView: fgui.GComponent = null; /** * 遊戲面板 */ gameView: fgui.GComponent = null; /** * 戰鬥面板 */ battleView: fgui.GComponent = null; /** * 快捷面板 */ eazyView: fgui.GComponent = null; loginOutMainPanel: fgui.GComponent = null; safePWPanel: fgui.GComponent = null; loginOutTime: number = 0; onLoad() { if (Set.Instance === null) { Set.Instance = this; } else { this.destroy(); return; } } openSetMainPanel() { if (!SKUIUtil.isFGUIValid(this.mainPanel)) { this.mainPanel = FGUtil.create("main_ui", "set_panel"); FGUtil.root().addChild(this.mainPanel); this.mainPanel.makeFullScreen(); } console.log( FGUtil.getComponent(this.mainPanel, "alart/title"), 111) FGUtil.getComponent(this.mainPanel, "mask").onClick(this.closeAll, this); FGUtil.getButton(this.mainPanel, "alert/close").onClick(this.closeAll, this); FGUtil.getButton(this.mainPanel, "alert/loginOut").onClick(this.onLogoutBtnClicked, this); FGUtil.getComponent(this.mainPanel, "alert/n53").onClick(this.toPage1, this); // FGUtil.getComponent(this.mainPanel, "alert/n53").text = "shezhi" FGUtil.getComponent(this.mainPanel, "alert/n54").onClick(this.toPage2, this); var listMenu = FGUtil.getList(this.mainPanel, "alert/menuList"); listMenu.getChildAt(0).onClick(this.openImgView, this) listMenu.getChildAt(1).onClick(this.openSoundView, this) listMenu.getChildAt(2).onClick(this.openGameView, this) this.openImgView(); FGUtil.getLoader(this.mainPanel, "alert/head").texture = GameModel.getRoleHead(GameModel.player.resid); FGUtil.getTextField(this.mainPanel, "alert/name").text = GameModel.player.name; FGUtil.getTextField(this.mainPanel, "alert/id").text = GameModel.player.roleid; FGUtil.getTextField(this.mainPanel, "alert/server").text = GameModel.serverData.servername; this.initSafeCom() } initSafeCom() { if (!SKUIUtil.isFGUIValid(this.mainPanel)) return let has_password = (GameModel.player.safe_password.length > 0); let has_lock = (GameModel.player.safe_lock == 1); var safeNode = FGUtil.getComponent(this.mainPanel, "alert/safeCom") FGUtil.getControl(safeNode, "locked").selectedIndex = has_password ? 1 : 0 FGUtil.getControl(safeNode, "locked2").selectedIndex = has_lock ? 1 : 0 FGUtil.getButton(safeNode, "n2").onClick(this.openChangeSetSafePW, this) FGUtil.getButton(safeNode, "n3").onClick(this.openSetSafePW, this) FGUtil.getButton(safeNode, "n4").onClick(this.onLockClick, this) FGUtil.getButton(safeNode, "n5").onClick(this.onUnLockClick, this) } openSetSafePW() { FGUtil.dispose(this.safePWPanel) if (!SKUIUtil.isFGUIValid(this.safePWPanel)) { this.safePWPanel = FGUtil.create("main_ui", "setSafePWPanel"); FGUtil.root().addChild(this.safePWPanel); this.safePWPanel.makeFullScreen(); } var alert = FGUtil.getComponent(this.safePWPanel, "alert") FGUtil.getControl(alert, "change").selectedIndex = 0 FGUtil.getButton(alert, "n6").onClick(this.closeSafePanel, this) FGUtil.getButton(alert, "n7").clearClick(); FGUtil.getButton(alert, "n7").onClick(this.sureSafePW, this) } sureSafePW() { var pwd1 = FGUtil.getTextField(this.safePWPanel, "alert/n9").text; var pwd2 = FGUtil.getTextField(this.safePWPanel, "alert/n10").text; if (pwd1 != pwd2) { MsgAlert.addMsg('兩次密碼不一致!'); return; } if (!this.verifyPassword(pwd1)) { MsgAlert.addMsg('密碼格式錯誤!'); return; } GameModel.send('c2s_safepass_msg', { pass: pwd1, lock: 0, }); FGUtil.dispose(this.safePWPanel) } openChangeSetSafePW() { FGUtil.dispose(this.safePWPanel) if (!SKUIUtil.isFGUIValid(this.safePWPanel)) { this.safePWPanel = FGUtil.create("main_ui", "setSafePWPanel"); FGUtil.root().addChild(this.safePWPanel); this.safePWPanel.makeFullScreen(); } var alert = FGUtil.getComponent(this.safePWPanel, "alert") FGUtil.getControl(alert, "change").selectedIndex = 1 FGUtil.getButton(alert, "n6").onClick(this.closeSafePanel, this) FGUtil.getButton(alert, "n7").clearClick(); FGUtil.getButton(alert, "n7").onClick(this.sureChangeSafePW, this) } sureChangeSafePW() { var pwd1 = FGUtil.getTextField(this.safePWPanel, "alert/n9").text; var pwd2 = FGUtil.getTextField(this.safePWPanel, "alert/n10").text; var pwd3 = FGUtil.getTextField(this.safePWPanel, "alert/n13").text; if (pwd1 != pwd2) { MsgAlert.addMsg('兩次密碼不一致!'); return; } if (pwd3 != GameModel.player.safe_password) { MsgAlert.addMsg('輸入密碼錯誤!'); return; } if (!this.verifyPassword(pwd1)) { MsgAlert.addMsg('密碼格式錯誤!'); return; } GameModel.send('c2s_safepass_msg', { pass: pwd1, lock: GameModel.player.safe_lock || 0, }); FGUtil.dispose(this.safePWPanel) } /* * 上鎖 */ onLockClick() { if (GameModel.player.safe_lock == 0 && GameModel.player.safe_password.length > 0) { GameModel.send('c2s_safepass_msg', { pass: GameModel.player.safe_password, lock: 1, }); } } /* * 解鎖 */ onUnLockClick() { FGUtil.dispose(this.safePWPanel) if (!SKUIUtil.isFGUIValid(this.safePWPanel)) { this.safePWPanel = FGUtil.create("main_ui", "setSafePWPanel"); FGUtil.root().addChild(this.safePWPanel); this.safePWPanel.makeFullScreen(); } var alert = FGUtil.getComponent(this.safePWPanel, "alert") FGUtil.getControl(alert, "change").selectedIndex = 2 FGUtil.getButton(alert, "n6").onClick(this.closeSafePanel, this) FGUtil.getButton(alert, "n7").clearClick(); FGUtil.getButton(alert, "n7").onClick(this.sureUnLock, this) FGUtil.getButton(alert, "n19").onClick(this.changeDelMode, this) } changeDelMode() { if (!SKUIUtil.isFGUIValid(this.safePWPanel)) return var ctr = FGUtil.getControl(this.safePWPanel, "alert/n19/selected").selectedIndex if (ctr == 0) FGUtil.getControl(this.safePWPanel, "alert/n19/selected").selectedIndex = 1 else FGUtil.getControl(this.safePWPanel, "alert/n19/selected").selectedIndex = 0 } sureUnLock() { var pwd1 = FGUtil.getTextField(this.safePWPanel, "alert/n9").text; var pwd2 = FGUtil.getTextField(this.safePWPanel, "alert/n10").text; if (pwd1 != pwd2) { MsgAlert.addMsg('兩次密碼不一致!'); return; } if (!this.verifyPassword(pwd1)) { MsgAlert.addMsg('密碼格式錯誤!'); return; } if (pwd1 != GameModel.player.safe_password) { MsgAlert.addMsg('密碼錯誤!'); return; } var del = FGUtil.getControl(this.safePWPanel, "alert/n19/selected").selectedIndex == 1; if (del) { GameModel.send('c2s_safepass_msg', { pass: '', lock: 0, }); FGUtil.dispose(this.safePWPanel) return } GameModel.send('c2s_safepass_msg', { pass: pwd1, lock: 0, }); FGUtil.dispose(this.safePWPanel) } closeSafePanel() { FGUtil.dispose(this.safePWPanel) this.safePWPanel = null; } toPage1() { if (!SKUIUtil.isFGUIValid(this.mainPanel)) return FGUtil.getControl(this.mainPanel, "alert/page").selectedIndex = 0 } toPage2() { if (!SKUIUtil.isFGUIValid(this.mainPanel)) return FGUtil.getControl(this.mainPanel, "alert/page").selectedIndex = 1 } openImgView() { this.hideOther(); if (!SKUIUtil.isFGUIValid(this.imgView)) { // 獲取主面板 var pView = FGUtil.getComponent(this.mainPanel, "alert/box"); this.imgView = FGUtil.create("main_ui", "view_set"); pView.addChild(this.imgView); } else { this.imgView.visible = true; } FGUtil.getControl(this.imgView, "n31/selected").selectedIndex = GameModel.hideNotTeam ? 1 : 0; FGUtil.getButton(this.imgView, "n31").onClick(this.changeShowOhterRole, this) } openSoundView() { this.hideOther(); if (!SKUIUtil.isFGUIValid(this.soundView)) { // 獲取主面板 var pView = FGUtil.getComponent(this.mainPanel, "alert/box"); this.soundView = FGUtil.create("main_ui", "sound_set"); pView.addChild(this.soundView);; } else { this.soundView.visible = true; } this.setVoiceVal() FGUtil.getButton(this.soundView, "n2").onClick(this.closeAllVoice, this); FGUtil.getButton(this.soundView, "n6").onClick(this.openMusic, this); FGUtil.getButton(this.soundView, "n8").onClick(this.openEffect, this); FGUtil.getButton(this.soundView, "n10").onClick(this.openVoice, this); FGUtil.getComponent(this.soundView, "n4").asSlider.on(fgui.Event.STATUS_CHANGED, this.setVoiceValBySlider, this); FGUtil.getComponent(this.soundView, "n11").asSlider.on(fgui.Event.STATUS_CHANGED, this.setVoiceValBySlider, this); FGUtil.getComponent(this.soundView, "n12").asSlider.on(fgui.Event.STATUS_CHANGED, this.setVoiceValBySlider, this); } openGameView() { this.hideOther(); if (!SKUIUtil.isFGUIValid(this.gameView)) { // 獲取主面板 var pView = FGUtil.getComponent(this.mainPanel, "alert/box"); this.gameView = FGUtil.create("main_ui", "game_set"); pView.addChild(this.gameView); } else { this.gameView.visible = true; } FGUtil.getButton(this.gameView, "n16").onClick(this.openEditMode, this); FGUtil.getButton(this.gameView, "n17").onClick(this.closeEditMode, this); FGUtil.getButton(this.gameView, "n18").onClick(this.openSaveLeave, this); FGUtil.getButton(this.gameView, "reduce").onClick(this.subLoginOutTime, this); FGUtil.getButton(this.gameView, "add").onClick(this.addLoginOutTime, this); this.loginOutTime = parseInt(GameModel.player.offlinetime); FGUtil.getTextField(this.gameView, "n5").text = `${this.loginOutTime}` } openBattleView() { this.hideOther(); if (!SKUIUtil.isFGUIValid(this.battleView)) { // 獲取主面板 var pView = FGUtil.getComponent(this.mainPanel, "alert/box"); this.battleView = FGUtil.create("main_ui", "battle_set"); pView.addChild(this.battleView); } else { this.battleView.visible = true; } } openEazyView() { this.hideOther(); if (!SKUIUtil.isFGUIValid(this.eazyView)) { // 獲取主面板 var pView = FGUtil.getComponent(this.mainPanel, "alert/box"); this.eazyView = FGUtil.create("main_ui", "eazy_set"); pView.addChild(this.eazyView); } else { this.eazyView.visible = true; } } hideOther() { if (!SKUIUtil.isFGUIValid(this.mainPanel)) return; var pView = FGUtil.getComponent(this.mainPanel, "alert/box"); for (let i = 0; i < pView._children.length; i++) { var item = pView.getChildAt(i); item.visible = false } } closeAll() { this.closeView(this.mainPanel) this.closeView(this.imgView) this.closeView(this.soundView) this.closeView(this.gameView) this.closeView(this.battleView) this.closeView(this.eazyView) } closeView(view) { if (view) { FGUtil.dispose(view); view = null; } } changeShowOhterRole() { GameModel.hideNotTeam = !GameModel.hideNotTeam; var ctr = FGUtil.getControl(this.imgView, "n31/selected"); ctr.selectedIndex = GameModel.hideNotTeam ? 1 : 0; SKLocalUtil.setBool(GameModel.hideNotTeam, "setting_hide_not_team"); let logic = cc.find('Canvas').getComponent('GameLogic'); if (logic) { logic.setAllPlayerActive(); } } closeAllVoice() { if (!SKUIUtil.isFGUIValid(this.soundView)) return var ctr = FGUtil.getControl(this.soundView, "n2/selected"); if (ctr.selectedIndex == 0) { AudioManager.setMusicVolume(0); AudioManager.setEffectVolume(0); AudioManager.setVoiceVolume(0); ctr.selectedIndex = 1 } else { AudioManager.setMusicVolume(1); AudioManager.setEffectVolume(1); AudioManager.setVoiceVolume(1); ctr.selectedIndex = 0 } this.setVoiceVal(); } openMusic() { if (!SKUIUtil.isFGUIValid(this.soundView)) return var ctr = FGUtil.getControl(this.soundView, "n6/selected"); if (ctr.selectedIndex == 0) { AudioManager.setMusicVolume(0); ctr.selectedIndex = 1 } else { AudioManager.setMusicVolume(1); ctr.selectedIndex = 0 } this.setVoiceVal(); } openEffect() { if (!SKUIUtil.isFGUIValid(this.soundView)) return var ctr = FGUtil.getControl(this.soundView, "n8/selected"); if (ctr.selectedIndex == 0) { AudioManager.setEffectVolume(0); ctr.selectedIndex = 1 } else { AudioManager.setEffectVolume(1); ctr.selectedIndex = 0 } this.setVoiceVal(); } openVoice() { if (!SKUIUtil.isFGUIValid(this.soundView)) return var ctr = FGUtil.getControl(this.soundView, "n10/selected"); if (ctr.selectedIndex == 0) { AudioManager.setVoiceVolume(0); ctr.selectedIndex = 1 } else { AudioManager.setVoiceVolume(1); ctr.selectedIndex = 0 } this.setVoiceVal(); } setVoiceVal() { let mn = AudioManager.getMusicVolume(); let en = AudioManager.getEffectVolume(); let vn = AudioManager.getVoiceVolume(); FGUtil.getComponent(this.soundView, "n4").asSlider.value = mn * 100; FGUtil.getComponent(this.soundView, "n11").asSlider.value = en * 100; FGUtil.getComponent(this.soundView, "n12").asSlider.value = vn * 100; FGUtil.getControl(this.soundView, "n6/selected").selectedIndex = mn == 0 ? 0 : 1 FGUtil.getControl(this.soundView, "n8/selected").selectedIndex = en == 0 ? 0 : 1 FGUtil.getControl(this.soundView, "n10/selected").selectedIndex = vn == 0 ? 0 : 1 if (mn == 0 && en == 0 && vn == 0) FGUtil.getControl(this.soundView, "n2/selected").selectedIndex = 1 else FGUtil.getControl(this.soundView, "n2/selected").selectedIndex = 0 } setVoiceValBySlider() { if (!SKUIUtil.isFGUIValid(this.soundView)) return var mn = FGUtil.getComponent(this.soundView, "n4").asSlider.value / 100 var en = FGUtil.getComponent(this.soundView, "n11").asSlider.value / 100 var vn = FGUtil.getComponent(this.soundView, "n12").asSlider.value / 100 AudioManager.setMusicVolume(mn); AudioManager.setEffectVolume(en); AudioManager.setVoiceVolume(vn); this.setVoiceVal() } openEditMode() { if (!SKUIUtil.isFGUIValid(this.gameView)) return FGUtil.getControl(this.gameView, "edit").selectedIndex = 1 } closeEditMode() { if (!SKUIUtil.isFGUIValid(this.gameView)) return FGUtil.getControl(this.gameView, "edit").selectedIndex = 0 } openSaveLeave() { this.closeEditMode(); GameModel.player.offlinetime = this.loginOutTime; GameModel.send("c2s_set_offlinetime", { roleid: GameModel.player.roleid, offtime: this.loginOutTime }) } addLoginOutTime() { if (this.loginOutTime >= 12) return; this.loginOutTime++; FGUtil.getTextField(this.gameView, "n5").text = `${this.loginOutTime}` } subLoginOutTime() { if (this.loginOutTime <= 0) return; this.loginOutTime--; FGUtil.getTextField(this.gameView, "n5").text = `${this.loginOutTime}` } onLogoutBtnClicked() { FGUtil.dispose(this.loginOutMainPanel); this.loginOutMainPanel = FGUtil.create("main_ui", "login_out"); let alert = FGUtil.getComponent(this.loginOutMainPanel, "alert"); let setBtn = FGUtil.getButton(alert, "cancel_btn"); let sureBtn = FGUtil.getButton(alert, "sure_btn") let msg = "您的帳號將[color=#ff0000]立即下線[/color],確認登出當前賬號?"; if (GameModel.player.offlinetime != 0) { msg = `您的帳號當前設置離線時間為[color=#ff0000]${GameModel.player.offlinetime}小時[/color]\n點擊按鈕[color=#ff0000]立即退出[/color]將離線保護[color=#ff0000]${GameModel.player.offlinetime}小時[/color],確認登出當前賬號? ` } FGUtil.getTextField(alert, "title").text = msg; FGUtil.root().addChild(this.loginOutMainPanel); FGUtil.fitScreen(this.loginOutMainPanel); sureBtn.clearClick() sureBtn.onClick(() => { SKSocket.disconnectBlock = null; SKSocket.close(); SKUIUtil.loadScene("LoginScene", null, (sceneName) => { GameModel.currentScene = sceneName; }); }) setBtn.clearClick() setBtn.onClick(() => { FGUtil.getControl(this.mainPanel, "alert/page").selectedIndex = 0; this.openGameView() FGUtil.dispose(this.loginOutMainPanel); this.loginOutMainPanel = null }) } /* * 驗證密碼 */ verifyPassword(pass) { if (pass.length < 4 || pass.length > 12) { MsgAlert.addMsg('密碼長度不對!'); return false; } let regx = /^[a-zA-Z\d]+$/; if (!regx.test(pass)) { MsgAlert.addMsg('密碼必須為字母或數字!'); return false; } return true; } }