/* * @Author: your name * @Date: 2021-09-12 12:41:49 * @LastEditTime: 2021-09-29 22:30:24 * @LastEditors: Please set LastEditors * @Description: In User Settings Edit * @FilePath: \zombiefood\assets\script\ui\uiview\Interface\UIMenu.ts */ import auto_menu from "../../../ui/uidata/Interface/auto_menu"; import UIBase from "../../../framework/ui/UIBase"; import UIHelp from "../../../framework/ui/UIHelp"; import bundleManager from "../../../manager/bundleManager"; import levelManager from "../../../manager/levelManager"; import AccountModel from "../../../data/Account/AccountModel"; import zombieActionMgr from "../../../manager/zombieActionMgr"; import Utils from "../../../framework/utils/utils"; import UITopMenu from "./UITopMenu"; import { EVENT_TYPE } from "../../../gameLogic/utrl/gameEnum"; import gameEventManager from "../../../gameLogic/utrl/gameEventManager"; import JoyStick from "../../../gameLogic/utrl/joy_stick"; import AudioManager from "../../../framework/music/AudioManager"; import UIWelfareView from "./UIWelfareView"; import SignUtil from "../../../framework/utils/signUtil"; import UISignView from "./UISignView"; import UIGameScene from "../scene/UIGameScene"; import { SingletonFactory } from "../../../framework/utils/SingletonFactory"; import EventManager from "../../../framework/event/EventManager"; import dynamicAtlasManager = cc.dynamicAtlasManager; import UICrazyAwardView from "./UICrazyAwardView"; import { GameEvent } from "../../../constant/constant-game"; import { USER } from "../../../constant/constant-user"; import { Log, LOG_TAG } from "../../../framework/log/Log"; import array = cc.js.array; import UIMng from "../../../framework/ui/UIMng"; const { ccclass, menu, property } = cc._decorator; @ccclass @menu("UI/Interface/UIMenu") export default class UIMenu extends UIBase { ui: auto_menu = null; protected static prefabUrl = "Interface/menu"; protected static className = "UIMenu"; npcID: number; roleSpine: any; isLoadRes: boolean = false; bClick: boolean = true; progressBar: cc.ProgressBar; onUILoad() { this.ui = this.node.addComponent(auto_menu); this.isNewUser(); this.progressBar = this.ui.progress.getComponent(cc.ProgressBar); zjSdk?.showMain({ y: -50, }); bundleManager.loadSimpleSubpk('level3', () => { bundleManager.loadSimpleSubpk('level4'); }); } isNewUser() { let playerDt = AccountModel.getInstance().playerDtList; if (playerDt.length > 0) { AccountModel.getInstance().is_new = 0; } if (AccountModel.getInstance().is_new == 1) { zjSdk?.sendEvent('主界面曝光-新') } else { zjSdk?.sendEvent('主界面曝光-旧') } } start_btn() { if (!this.bClick) { return }; if (!this.bloadRes()) { UIHelp.ShowTips('资源加载中......') return; } this.bClick = false; zjSdk?.sendEvent('点击开始按钮'); console.log('zh:1') zjSdk?.gameBegin(() => { console.log('zh:2') zjSdk?.hideMain(); if (zjSdk?.hasOwnProperty('ZjGmData')) { if (zjSdk?.ZjGmData.instance.gameConfig.isShowInnerCrazyAward == '1') { GameEvent.isShowInnerCrazyAward = true; } if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('firstCrazyByZombieNum')) { GameEvent.firstCrazyByZombieNum = parseInt(zjSdk?.ZjGmData.instance.gameConfig.firstCrazyByZombieNum) } if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyByZombieNumTimes')) { GameEvent.crazyByZombieNumTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyByZombieNumTimes) } if (zjSdk?.ZjGmData.instance.gameConfig.hasOwnProperty('crazyAwardPopMaxTimes')) { GameEvent.crazyAwardPopMaxTimes = parseInt(zjSdk?.ZjGmData.instance.gameConfig.crazyAwardPopMaxTimes) } } console.log('zh:3') let curLevel = AccountModel.getInstance().curLevel; if (curLevel == 1 && AccountModel.getInstance().is_new == 1) { console.log('zh:4') this.onClose(); gameEventManager.emit(EVENT_TYPE.playStoryAni, (node) => { console.log('zh:5') levelManager.open(curLevel, () => { cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0; UITopMenu.getInstance().node.active = true; this.tryShowUI(); node.destroy(); }) }); return; } console.log('zh:6') levelManager.open(curLevel, () => { console.log('zh:7') cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode').opacity = 0; UITopMenu.getInstance().node.active = true; this.onClose(); this.tryShowUI(false); console.log('zh:8') }) }) } tryShowUI(isNewBee = true) { //调用签到 const callSign = () => { if (!SignUtil.canSign()) { return false; } const openSign = () => { if (SignUtil.canSign()) { gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true); UIHelp.ShowUI(UISignView, null, isNewBee); } } uiRoot.getComponent(UIGameScene).scheduleOnce(async () => { if (UIMng.getInstance().UILock) { EventManager.once(EVENT_TYPE.unLockUI, () => { this.scheduleOnce(() => { if (SignUtil.canSign()) { gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true); UIHelp.ShowUI(UISignView, null, isNewBee); } }, 1) }) } openSign(); }, isNewBee ? 30 : 0); return true; } //调用福利 const callWelfare = (delay) => { const openWelfare = () => { if (isNewBee && AccountModel.getInstance().curWelfare.length != 0) { return } gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS, true); UIHelp.ShowUI(UIWelfareView, null, isNewBee); } if (AccountModel.getInstance().curWelfare.length !== 4) { uiRoot.getComponent(UIGameScene).scheduleOnce(() => { if (UIMng.getInstance().UILock) { EventManager.once(EVENT_TYPE.unLockUI, () => { this.scheduleOnce(() => { openWelfare(); }, 1) }) return; } //新手点击过不要跳了 openWelfare(); }, delay); } }; let uiRoot = cc.director.getScene().getChildByName('Canvas'); const isShowSign = callSign(); //新手 if (isNewBee) { EventManager.once(EVENT_TYPE.closeSign, () => { callWelfare(30); }) } else if (isShowSign) { EventManager.once(EVENT_TYPE.closeSign, () => { callWelfare(0); }) } else { callWelfare(0); } } bloadRes() { if (bundleManager.localResIsload == true && bundleManager.getBunleTotal() == bundleManager.bundleTotal) { return true; } return false; } update(dt) { if (this.bloadRes() && !this.isLoadRes) { this.node.$loading_lb.getComponent(cc.Label).string = '加载完成'; this.progressBar.progress = 1; this.scheduleOnce(() => { this.ui.progress.active = false; this.node.$loading_lb.active = false; this.ui.start_btn.active = true; }, 0.2) this.isLoadRes = true; this.addSprite(); setTimeout(() => { AudioManager.play('bg', 1, true, 'BGM'); }, 50); levelManager.preLoadLevel(AccountModel.getInstance().curLevel); } if (!this.bloadRes()) { this.node.$loading_lb.getComponent(cc.Label).string = '正在加载中......'; if (this.progressBar.progress < 1) { this.progressBar.progress += dt * 0.5; } } } addSprite() { this.initRedWarn(); } initRedWarn() { let redWarn = new cc.Node; redWarn.name = "redWarn"; redWarn.setContentSize(cc.size(1800, 2000)); redWarn.addComponent(cc.Sprite); bundleManager.setBundleFrame('UI', 'main/hjianbianBG', redWarn); redWarn.active = false; redWarn.parent = cc.director.getScene().getChildByName('Canvas'); cc.tween(redWarn) .repeatForever(cc.tween().to(0.5, { opacity: 0 }).to(0.5, { opacity: 255 })) .start(); } onClose() { UIHelp.CloseUI(UIMenu); } }