import { BaseView } from "../lightMVC/core/base/BaseView"; import SDK from "./sdk/SDK"; import hallSceneMediator from "./hallSceneMediator"; import { App } from "./Manager/App"; import { SoundManager } from "./Manager/SoundManager"; import TimeControl from "./TimeControl"; import ChooseLevelPanel from "./view/chooseLevel/ChooseLevelPanel"; import ChooseLevelPanelMediator from "./view/chooseLevel/ChooseLevelPanelMediator"; import ChooseSkinPanel from "./view/chooseSkin/ChooseSkinPanel"; import ChooseSkinPanelMediator from "./view/chooseSkin/ChooseSkinPanelMediator"; import InsufficientPanel from "./view/insufficientPanel/InsufficientPanel"; import InsufficientPanelMediator from "./view/insufficientPanel/InsufficientPanelMediator"; import MissionPanel from "./view/missionPanel/MissionPanel"; import MissionPanelMediator from "./view/missionPanel/MissionPanelMediator"; import SetNormalPanel from "./view/setNormal/SetNormalPanel"; import SetNormalPanelMediator from "./view/setNormal/SetNormalPanelMediator"; import ShopPanel from "./view/shopView/ShopPanel"; import ShopPanelMediator from "./view/shopView/ShopPanelMediator"; import TipPanel from "./view/tipPanel/TipPanel"; import TipPanelMediator from "./view/tipPanel/TipPanelMediator"; const { ccclass, property } = cc._decorator; @ccclass export default class hallScene extends BaseView { public static _instance; @property(cc.Button) public startGameBtn: cc.Button = null; @property(cc.Button) public setNormalBtn: cc.Button = null; // @property(cc.Button) // public chooseSkinBtn: cc.Button = null; @property(cc.Button) public missionBtn: cc.Button = null; // @property(cc.Button) // public btnVideo: cc.Button = null; // @property(cc.Button) // public btnShop: cc.Button = null; @property(cc.Button) public btnLeft: cc.Button = null; @property(cc.Button) public btnRight: cc.Button = null; @property(cc.PageView) public pageView: cc.PageView = null; @property(cc.Label) public labelTili: cc.Label = null; @property(cc.Label) public physicalTime: cc.Label = null; @property(cc.Label) public labelCoin: cc.Label = null; @property(cc.Label) public labelDiamond: cc.Label = null; private loadSceneName: string = "gameScene"; private currientView = 0; public static get instance() { return hallScene._instance; } public static set instance(value) { hallScene._instance = value; } onLoad() { // cc.sys.localStorage.clear(); hallScene.instance = this; this.registerMediator(hallSceneMediator, this, "主界面"); SDK.Instance.showBanner(); } start() { this.startGameBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this); this.setNormalBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this); this.btnLeft.node.on(cc.Node.EventType.TOUCH_END, this.ClickLeft, this); this.btnRight.node.on(cc.Node.EventType.TOUCH_END, this.ClickRight, this); // this.btnVideo.node.on(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this); this.missionBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this); // this.chooseSkinBtn.node.on(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this); // this.btnShop.node.on(cc.Node.EventType.TOUCH_END, this.ClickShop, this); // console.log('----------', TimeControl.instance.currentTili); // App.DataManager.TimeCountJudge();//全局倒计时判断 // if (App.DataManager.TimeFlag) { // let data = { "isShow": true, 'timeStr': App.DataManager.TimeChange(TimeControl.instance.currentTimeCount) }; // this.TiliCountShow(data); // } this.ShowPhysicalValue(); this.ShowUserCoinValue(); this.ShowUserDiamondValue(); App.SoundManager.playBGM(SoundManager.hallBgm[0]); } public ClickOpenMission() { App.Facade.popView(MissionPanelMediator, MissionPanel, "打开任务界面", false); } /** * 体力显示设置 */ public ShowPhysicalValue(): void { console.log('############', TimeControl.instance.currentTili) if(hallScene.instance.labelTili){ hallScene.instance.labelTili.string = TimeControl.instance.currentTili + "/" + TimeControl.instance.tiliMax; } } // 显示玩家金币 public ShowUserCoinValue(): void { if(hallScene.instance.labelCoin){ hallScene.instance.labelCoin.string = App.DataManager.UserCoin.toString(); } } // 钻石 public ShowUserDiamondValue(): void { if(hallScene.instance.labelDiamond){ hallScene.instance.labelDiamond.string = App.DataManager.UserDiamond.toString(); } } /** * 体力倒计时显示设置 */ public TiliCountShow(data: any): void { if (!this.physicalTime) return; this.physicalTime.node.active = data.isShow; if (data.timeStr) this.physicalTime.string = data.timeStr; } /** * 开始游戏 */ public StartGame(intoLevel: number) { console.log("aaa--------intoLevel----------", intoLevel); App.DataManager.UpdateTili(TimeControl.instance.consumeTili, (success) => { App.DataManager.CurrentIntoLevel = intoLevel; App.DataManager.PlayLevel = App.DataManager.CurrentIntoLevel; App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_playLevel, App.DataManager.PlayLevel); if (success) App.Facade.runBundleScene("gameScene",this.loadSceneName); else App.Facade.popView(InsufficientPanelMediator, InsufficientPanel, "体力不足", false); }); } /** * 点击开始游戏按钮直接开始 */ private ClickStartGame() { if(this.pageView.getCurrentPageIndex() == 1){ App.Facade.popView(TipPanelMediator, TipPanel, "敬请期待!", false); } else{ App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", false); } } /** * 点击观看视频加体力 */ private ClickAddTili() { console.log('点击观看视频加体力~'); SoundManager.getInstance().VideoStartStop(); SDK.Instance.showRewardVideo(() => { TimeControl.instance.currentTili = TimeControl.instance.tiliMax; this.ShowPhysicalValue(); App.LocalStorageUtil.setNumber(App.LocalStorageUtil.lst_Tili, TimeControl.instance.currentTili); SoundManager.getInstance().VideoEndOpen(); }, () => { SoundManager.getInstance().VideoEndOpen(); }, () => { SoundManager.getInstance().VideoEndOpen(); }); } // 商城 private ClickShop() { App.Facade.popView(ShopPanelMediator, ShopPanel, "商城", false); } /** * 打开关卡选择界面 */ private ClickChooseLevel() { App.Facade.popView(ChooseLevelPanelMediator, ChooseLevelPanel, "关卡选择", true); } /** * 打开选择皮肤界面 */ private ClickChooseSkin() { App.Facade.popView(ChooseSkinPanelMediator, ChooseSkinPanel, "皮肤选择", false); } /** * 打开设置界面 */ private ClickSetNormal() { App.Facade.popView(SetNormalPanelMediator, SetNormalPanel, "设置", false); } private ClickLeft(){ this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0; this.pageView.scrollToPage(this.currientView, 0.5); } private ClickRight(){ this.currientView = this.pageView.getCurrentPageIndex() == 0 ? 1 : 0; this.pageView.scrollToPage(this.currientView, 0.5); } onDisable() { this.startGameBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickStartGame, this); this.setNormalBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickSetNormal, this); this.btnLeft.node.off(cc.Node.EventType.TOUCH_END, this.ClickLeft, this); this.btnRight.node.off(cc.Node.EventType.TOUCH_END, this.ClickRight, this); this.missionBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickOpenMission, this); // this.btnVideo.node.off(cc.Node.EventType.TOUCH_END, this.ClickAddTili, this); // this.btnShop.node.off(cc.Node.EventType.TOUCH_END, this.ClickShop, this); // this.chooseSkinBtn.node.off(cc.Node.EventType.TOUCH_END, this.ClickChooseSkin, this); } // update (dt) {} }