import { SaveUtil } from "../help/SaveUtil"; import EventMgr from "../game/EventMgr"; import { GameEvent } from "../game/GameEvent"; import { GameMode } from "../game/GameMode"; import { GameState } from "../game/GameState"; import Main from "../game/Main"; import { SDKIpt } from "../game/SDKIpt"; import SoundMgr from "../game/SoundMgr"; import rankPanel from "./rankPanel"; import { SDK as sdk} from '../game/sdk'; import Button from "../game/Button"; const {ccclass, property} = cc._decorator; @ccclass export default class mainView extends cc.Component { @property({type:rankPanel}) private rankPanel:rankPanel = null; /**开始游戏 */ @property(cc.Button) returnMainView: cc.Button = null; @property(cc.Button) returnPlay: cc.Button = null; @property(cc.Button) returnReopen: cc.Button = null; @property(cc.Button) btnNormalMode: cc.Button = null; @property(cc.Button) btnEndlessMode: cc.Button = null; @property(cc.Button) btnAudio: cc.Button = null; @property(cc.Button) btnMusic: cc.Button = null; @property(cc.Slider) sliderAudio:cc.Slider = null @property(cc.Slider) sliderMusic:cc.Slider = null @property(cc.Label) percentAudioLabel:cc.Label = null @property(cc.Label) percentMusicLabel:cc.Label = null @property(cc.Button) btnRank: cc.Button = null; @property(cc.Button) btnSetting: cc.Button = null; @property(cc.Sprite) userAvatar: cc.Sprite = null; @property(cc.Label) userName: cc.Label = null; @property([cc.Node]) private mainNodes: cc.Node[] = []; // @property(cc.Node) // private confirnReturnMainPanel: cc.Node = null; // @property(cc.Button) // private returnMainConfirn: cc.Button = null; // @property(cc.Button) // private returnMainCancel: cc.Button = null; @property(cc.Node) private mainPanel: cc.Node = null; @property(cc.Node) private pausePanel: cc.Node = null; @property(cc.Node) private settingPanel: cc.Node = null; @property(cc.Node) private gameRank:cc.Node = null private get isActive(): boolean { return this.node.active; } private rankState: number = 0; private gamePauseIndex: number = 0; start () { let me =this; // this.btnAudio.node.on("click",function(){ // SoundMgr.Instance.ToogleEffectMute(); // me.btnAudio.node.getChildByName("closeTag").active = SoundMgr.Instance.EffMute; // },this); // this.btnMusic.node.on("click",function(){ // SoundMgr.Instance.ToogleMusicMute(); // me.btnMusic.node.getChildByName("closeTag").active = SoundMgr.Instance.MusicMute; // },this); this.btnRank.node.on("click",function(){ // if(me.rankState % 3 == 0){ // me.rankPanel.node.active = true; // }else if(me.rankState % 3 == 1){ // me.rankPanel.ToggleShow(); // }else if(me.rankState % 3 == 2){ // me.rankPanel.node.active = false; // } // me.rankState++; this.node.active = false; this.gameRank.getComponent('gameRank').openRankDialog() // this.rankPanel.node.active = !this.rankPanel.node.active; },this); this.returnMainView.node.on("click",()=>{ // for(let item of this.pausePanel.children){ // console.log(item.getComponent(Button).selected()); // } this._ButtonPauseActive(this.gamePauseIndex=2) EventMgr.Instance.dispatch_event(GameEvent.SDK_UI_IPT,SDKIpt.rightFoot); }); this.returnPlay.node.on("click",function(){ this._ButtonPauseActive(this.gamePauseIndex=0) EventMgr.Instance.dispatch_event(GameEvent.SDK_UI_IPT,SDKIpt.rightFoot); },this); this.returnReopen.node.on("click",function(){ this._ButtonPauseActive(this.gamePauseIndex=1) EventMgr.Instance.dispatch_event(GameEvent.SDK_UI_IPT,SDKIpt.rightFoot); },this); cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, function(event){ if (!this.isActive) { return; } switch (event.keyCode) { case cc.macro.KEY.num4: if (Main.Ins.State == GameState.inMain){ Main.Ins.Mode = Main.Ins.Mode===GameMode.normal?GameMode.endless:GameMode.normal this._ButtonMainActive(Number(Main.Ins.Mode!==GameMode.normal)); Main.Ins.Map.changeMap(Number(Main.Ins.Mode===GameMode.normal)); } if (Main.Ins.State == GameState.inGame) { this.gamePauseIndex = this.gamePauseIndex>0?this.gamePauseIndex-1:2 this._ButtonPauseActive(this.gamePauseIndex) } break; case cc.macro.KEY.num1: if (Main.Ins.State == GameState.inMain){ Main.Ins.Mode = Main.Ins.Mode===GameMode.endless?GameMode.normal:GameMode.endless this._ButtonMainActive(Number(Main.Ins.Mode===GameMode.endless)); Main.Ins.Map.changeMap(Number(Main.Ins.Mode!==GameMode.endless)); } if (Main.Ins.State == GameState.inGame) { this.gamePauseIndex = this.gamePauseIndex<2?this.gamePauseIndex+1:0 this._ButtonPauseActive(this.gamePauseIndex) } break; default: break; } }, this); this.btnNormalMode.node.on("click",function(){ Main.Ins.Mode = GameMode.normal; this._ButtonMainActive(0); Main.Ins.Map.changeMap(1); Main.Ins.PlayGame(); },this); this.btnEndlessMode.node.on("click",function(){ Main.Ins.Mode = GameMode.endless; this._ButtonMainActive(1); Main.Ins.Map.changeMap(0); Main.Ins.PlayGame(); },this); // 音效设置点击事件 this.btnSetting.node.on("click",function(){ me.settingPanel.active = true; //显示 },this); this.settingPanel.getChildByName("settingConfirm").on("click",function(){ me.settingPanel.active = false; //隐藏 },this); // this.returnMainConfirn.node.on("click",function(){ // EventMgr.Instance.dispatch_event(GameEvent.SDK_UI_IPT,SDKIpt.rightFoot); // },this); // this.returnMainCancel.node.on("click",function(){ // EventMgr.Instance.dispatch_event(GameEvent.SDK_UI_IPT,SDKIpt.leftFoot); // },this); this.setAudioVolume({progress:Number(SaveUtil.get("music_volume", "1"))},'audio') this.setAudioVolume({progress:Number(SaveUtil.get("effect_volume", "1"))},'music') this.setSliderProgress(Number(SaveUtil.get("music_volume", "1")),'audio') this.setSliderProgress(Number(SaveUtil.get("effect_volume", "1")),'music') // this.btnAudio.node.getChildByName("closeTag").active = SoundMgr.Instance.EffMute; // this.btnMusic.node.getChildByName("closeTag").active = SoundMgr.Instance.MusicMute; EventMgr.Instance.add_event_listenner(GameEvent.SDK_UI_IPT,this,this.ON_SDK_UI_IPT); this.initQuitPanel(); this.rankPanel.Hide(); this._ButtonMainActive(0); sdk.getUserInfo((info) => { cc.assetManager.loadRemote(info['avatar'], function (error, texture) { me.userAvatar.spriteFrame = new cc.SpriteFrame(texture); }); me.userName.string = info['nickname']; }); // sdk.on(CMD.BACK_LEFT.toString(), , this); } ON_SDK_UI_IPT(SDK_UI_IPT: GameEvent, ipt: SDKIpt, ON_SDK_UI_IPT: any) { console.error("mainview 收到 sdk 动作:"+ipt+" 界面是否激活:"+this.isActive + " " + Main.Ins.State); if (!this.isActive) { return; } switch (ipt) { case SDKIpt.left: if (Main.Ins.State == GameState.inGame) { this.gamePauseIndex = this.gamePauseIndex>0?this.gamePauseIndex-1:2 this._ButtonPauseActive(this.gamePauseIndex) } else if (Main.Ins.State == GameState.inMain) { Main.Ins.Mode = Main.Ins.Mode===GameMode.normal?GameMode.endless:GameMode.normal this._ButtonMainActive(Number(Main.Ins.Mode!==GameMode.normal)); Main.Ins.Map.changeMap(Number(Main.Ins.Mode===GameMode.normal)); } break; case SDKIpt.right: if (Main.Ins.State == GameState.inGame) { this.gamePauseIndex = this.gamePauseIndex<2?this.gamePauseIndex+1:0 this._ButtonPauseActive(this.gamePauseIndex) } else if (Main.Ins.State == GameState.inMain) { Main.Ins.Mode = Main.Ins.Mode===GameMode.endless?GameMode.normal:GameMode.endless this._ButtonMainActive(Number(Main.Ins.Mode===GameMode.endless)); Main.Ins.Map.changeMap(Number(Main.Ins.Mode!==GameMode.endless)); } break; case SDKIpt.rightFoot://主界面确认进入游戏//y if (Main.Ins.State == GameState.inGame) { if (this.pausePanel.active == true){ //继续游戏 if(this.gamePauseIndex===0){ Main.Ins.ReturnPlayGame(); this.node.active = false; }else if(this.gamePauseIndex===1){ Main.Ins.PlayGame(); this.node.active = false; }else{ Main.Ins.ShowMainView(); } // this.onReturnPlay(); } } else if (Main.Ins.State == GameState.inMain) { if (Main.Ins.IsGuide) {return; } Main.Ins.PlayGame(); } break; case SDKIpt.leftFoot: // if (Main.Ins.State == GameState.inGame) { // if (this.pausePanel.active == true)//暂停返回大厅 // { // Main.Ins.ShowMainView(); // } // } // else if (Main.Ins.State == GameState.inMain) { this.openGameQuitDialog() // EventMgr.Instance.dispatch_event(GameEvent.SDK_QUIT); } break; default: break; } } _ButtonMainActive(index:number){ if(index == 0){ this.btnNormalMode.node.getComponent(Button).selected() this.btnEndlessMode.node.getComponent(Button).unselected(); }else{ this.btnNormalMode.node.getComponent(Button).unselected() this.btnEndlessMode.node.getComponent(Button).selected(); } } _ButtonPauseActive(index:number){ if(index == 0){ this.returnPlay.node.getComponent(Button).selected(); this.returnReopen.node.getComponent(Button).unselected() this.returnMainView.node.getComponent(Button).unselected() }else if(index==1){ this.returnPlay.node.getComponent(Button).unselected(); this.returnReopen.node.getComponent(Button).selected(); this.returnMainView.node.getComponent(Button).unselected() }else{ this.returnPlay.node.getComponent(Button).unselected(); this.returnReopen.node.getComponent(Button).unselected(); this.returnMainView.node.getComponent(Button).selected() } } public Show(){ this.node.active = true; } public Hide(){ this.node.active = false; } public ShowPauseGame(){ this.node.active = true; this._ButtonPauseActive(this.gamePauseIndex=0) // this.returnPlay.node.active = true; this.setShowMainNodes(false); this.setShowPauseNodes(true); } public ShowMainGame(){ this.node.active = true; // this.returnPlay.node.active = false; this.setShowMainNodes(true); this.setShowPauseNodes(false); this.btnEndlessMode.interactable = !Main.Ins.IsGuide; // this.tmpBtnPlay.node.active =cc.sys.isBrowser;//浏览器界面显示 } public hideMainPause(){ this.setShowMainNodes(false); this.setShowPauseNodes(false); } private setShowMainNodes(isShow:boolean){ for (let i = 0; i < this.mainNodes.length; i++) { const element = this.mainNodes[i]; element.active = isShow; } this.mainPanel.active = isShow; } private setShowPauseNodes(isShow:boolean){ // for (let i = 0; i < this.pauseNodes.length; i++) { // const element = this.pauseNodes[i]; // element.active = isShow; // } this.pausePanel.active = isShow; } //设置百分比文本与声音大小 private setAudioVolume(event:any,type:string){ let progress:any = event.progress if(type==='audio'){ this.percentAudioLabel.string = parseInt((progress*100)+'') + '%' SoundMgr.Instance.set_music_volume(progress) } if(type==='music'){ this.percentMusicLabel.string = parseInt((progress*100)+'') + '%' SoundMgr.Instance.set_effect_volume(progress) } } //改变声音进度条样式 private setSliderProgress(value,type){ if(type==='audio') this.sliderAudio.progress = value if(type==='music') this.sliderMusic.progress = value } //退出游戏 /**退出游戏 */ @property(cc.Node) private gameQuit:cc.Node = null @property(cc.Button) btnQuit: cc.Button = null; private initQuitPanel(){ this.btnQuit.node.on("click",this.openGameQuitDialog,this); } openGameQuitDialog(){ this.node.active = false; this.gameQuit.getComponent('gameQuit').openDialog() } }