123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 |
- 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<cc.Texture2D>(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()
- }
- }
|