123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425 |
- import auto_topMenu from "../../../ui/uidata/Interface/auto_topMenu";
- import UIBase from "../../../framework/ui/UIBase";
- import UIHelp from "../../../framework/ui/UIHelp";
- import AccountModel from "../../../data/Account/AccountModel";
- import { ATTACK_MODE, EVENT_TYPE, JOY_STATE } from "../../../gameLogic/utrl/gameEnum";
- import gameEventManager from "../../../gameLogic/utrl/gameEventManager";
- import UIPauseView from "./UIPauseView";
- import gameData from "../../../gameLogic/utrl/gameData";
- import levelManager from "../../../manager/levelManager";
- import bundleManager from "../../../manager/bundleManager";
- import Utils from "../../../framework/utils/utils";
- import EventManager from "../../../framework/event/EventManager";
- import { USER } from "../../../constant/constant-user";
- import UIWelfareView from "./UIWelfareView";
- import UIAirdropView from "./UIAirdropView";
- import UISignView from "./UISignView";
- import UIShopView from "./UIShopView";
- import SignUtil from "../../../framework/utils/signUtil";
- import show = cc.show;
- const { ccclass, menu, property } = cc._decorator;
- const needRefreshTime = 10 * 60;
- @ccclass
- @menu("UI/Interface/UITopMenu")
- export default class UITopMenu extends UIBase {
- ui: auto_topMenu = null;
- protected static prefabUrl = "Interface/topMenu";
- protected static className = "UITopMenu";
- private static _instance: UITopMenu;
- curAttackMode: string;
- startDayTime: number = null;
- reducePowerTime: number = null;
- maskOpacity: number = 0;
- maskNode: cc.Node;
- redWarn: cc.Node;
- houMenCount:number=0;
- // 食物检查
- isReducePowerViewed = false;
- cacheTimeByPower = 0;
- //子弹检查
- isReduceBulletViewed = false;
- cacheTimeByBullet = 0;
- //开启ui冷却时间
- isCool = false;
- public static getInstance(): UITopMenu {
- return UITopMenu._instance;
- }
- static setInstance(instance: UITopMenu) {
- UITopMenu._instance = instance;
- }
- onUILoad() {
- UITopMenu.setInstance(this);
- this.node.active = false;
- }
- _updateBulletNum(isSub) {
- this.ui.bullet_num.getComponent(cc.Label).string = gameData.curBulletNum.toString();
- this.scheduleOnce(() => {
- if (gameData.curBulletNum <= 0) {
- gameData.cur_attack_mode = ATTACK_MODE.close;
- gameEventManager.emit(EVENT_TYPE.attack_mode);
- UIHelp.ShowTips('Ammo depleted, switched to melee mode.');//当前子弹为0,已自动切换成近战模式...
- }
- }, 0.2)
- this.isRedLabel();
- this.tryShowAirdrop(isSub);
- }
- private tryShowAirdrop(isSub) {
- if (true) {
- //关闭
- return;
- }
- if (this.isCool){
- return;
- }
- if (!isSub){
- return;
- }
- if (!AccountModel.getInstance().first_dec_bullet) {
- AccountModel.getInstance().first_dec_bullet = true;
- this.clickAirDrop();
- this.isCool = true;
- this.scheduleOnce(() => {
- this.isCool = false;
- },30)
- return;
- }
- }
- _updatePeopleNum() {
- this.ui.role_num.getComponent(cc.Label).string = gameData.curPeopleNum.toString();
- if (gameData.curPeopleNum <= 0) {
- gameEventManager.emit(EVENT_TYPE.GAME_OVER);
- }
- }
- _updateDayNum() {
- this.ui.day_num.getComponent(cc.Label).string = gameData.curDay.toString();
- }
- _updateTiliNum() {
- this.ui.power_num.getComponent(cc.Label).string = gameData.curPowerNum.toString();
- if (gameData.curPowerNum <= 5) {
- this.redWarn.active = true;
- UIHelp.ShowTips('Low stamina, risk of death! Find food urgently!');//体力不足,即将阵亡,请尽快觅食充饥!!!
- } else {
- this.redWarn.active = false;
- }
- if (gameData.curPowerNum <= 0) {
- gameEventManager.emit(EVENT_TYPE.GAME_OVER);
- }
- }
- onStart() {
- //this.node.zIndex = cc.macro.MAX_ZINDEX;
- this.maskNode = cc.director.getScene().getChildByName('Canvas').getChildByName('maskNode');
- this.redWarn = cc.director.getScene().getChildByName('Canvas').getChildByName('redWarn');
- this.initData();
- }
- onShow() {
- this.ui = this.node.addComponent(auto_topMenu);
- //关闭阻塞
- this.unRegisterEvent(this.node, this.touchEvent, this);
- this.initEvent(EVENT_TYPE.UPDATE_BULLET_NUM, this._updateBulletNum);
- this.initEvent(EVENT_TYPE.UPDATE_PEOPLE_NUM, this._updatePeopleNum);
- this.initEvent(EVENT_TYPE.UPDATE_DAY_NUM, this._updateDayNum);
- this.initEvent(EVENT_TYPE.UPDATE_TILI_NUM, this._updateTiliNum);
- this.updateView();
- this.tipHandler();
- }
- initData() {
- this.startDayTime = Utils.getTimeStamp(); //开始计时天数的时间
- this.reducePowerTime = Utils.getTimeStamp(); //开始消耗体力的时间
- gameData.isDayTime = true;
- this.node.$Sun_sp.active = true;
- this.node.$Moon_sp.active = false;
- }
- updateView() {
- this.ui.role_num.getComponent(cc.Label).string = gameData.curPeopleNum.toString();
- this.ui.bullet_num.getComponent(cc.Label).string = gameData.curBulletNum.toString();
- this.ui.power_num.getComponent(cc.Label).string = gameData.curPowerNum.toString();
- this.ui.day_num.getComponent(cc.Label).string = gameData.curDay.toString();
- this.initSp();
- this.isRedLabel();
- }
- //子弹不足显示红字
- isRedLabel() {
- let curBullet = gameData.curBulletNum;
- if (curBullet <= 10) {
- this.ui.bullet_num.color = cc.Color.RED;
- } else {
- this.ui.bullet_num.color = cc.Color.WHITE;
- }
- }
- initSp() {
- if (this.curAttackMode == gameData.cur_attack_mode) {
- return;
- }
- if (gameData.cur_attack_mode == ATTACK_MODE.close) {
- this.curAttackMode = ATTACK_MODE.close;
- bundleManager.setBundleFrame('UI', 'topMenu/ren1', this.ui.role_sp)
- } else if (gameData.cur_attack_mode == ATTACK_MODE.remote) {
- this.curAttackMode = ATTACK_MODE.remote;
- bundleManager.setBundleFrame('UI', 'topMenu/ren2', this.ui.role_sp)
- }
- }
- inSun() {
- this.node.$Sun_sp.active = true;
- this.node.$Moon_sp.active = false;
- cc.tween(this.maskNode)
- .to(0.5, { opacity: 0 })
- .start()
- gameEventManager.emit(EVENT_TYPE.VIOLENT_ZOMBIE);
- }
- inNight() {
- this.node.$Sun_sp.active = false;
- this.node.$Moon_sp.active = true;
- cc.tween(this.maskNode)
- .to(0.5, { opacity: 255 })
- .start()
- gameEventManager.emit(EVENT_TYPE.VIOLENT_ZOMBIE);
- Utils.tipsSprite('main/tianheile', cc.director.getScene().getChildByName('Canvas'));
- }
- pause_btn() {
- cc.director.pause();
- UIHelp.ShowUI(UIPauseView);
- }
- onClose() {
- UIHelp.CloseUI(UITopMenu);
- }
- judgeDayState() {
- if (!this.startDayTime || !this.reducePowerTime) {
- return;
- }
- let curTime = Utils.getTimeStamp();
- let durTime = curTime - this.startDayTime;
- let isDayTime = gameData.isDayTime;
- // if (!isDayTime) {
- // this.maskNode.opacity -= 255 / (USER.nightTimes * 60);
- // } else {
- // this.maskNode.opacity += 255 / (USER.dayTimes * 60);
- // }
- //白变黑
- if (isDayTime && (durTime >= USER.dayTimes)) {
- //进入黑夜
- gameData.isDayTime = false;
- durTime = 0;
- this.startDayTime = Utils.getTimeStamp();
- this.inNight();
- }
- //黑变白
- if (!isDayTime && (durTime >= USER.nightTimes)) {
- //进入白天
- gameData.isDayTime = true;
- durTime = 0;
- this.startDayTime = Utils.getTimeStamp();
- gameData.curDay += 1;
- //增加英雄
- if (gameData.curDay % 7 == 0) {
- gameData.bAddBoss = true;
- gameEventManager.emit(EVENT_TYPE.ADD_BOSS);
- gameEventManager.emit(EVENT_TYPE.ADD_HERO);
- }
- //this._updateDayNum();
- this.inSun();
- }
- }
- update(dt) {
- this.reducePower()
- this.judgeDayState()
- }
- reducePower() {
- let curTime = Utils.getTimeStamp();
- let duringTime = curTime - this.reducePowerTime;
- if (duringTime >= 10) {
- this.reducePowerTime = Utils.getTimeStamp();
- if (gameData.curPowerNum > 0) {
- let reduceNum = 1 * gameData.curPeopleNum;
- gameData.curPowerNum -= reduceNum;
- this.ui.reducePower_num.active = true;
- this.ui.reducePower_num.getComponent(cc.Label).string = '-' + reduceNum;
- setTimeout(() => {
- this.ui.reducePower_num.active = false;
- }, 1000)
- this._updateTiliNum();
- }
- }
- }
- tipHandler() {
- this.notifyNode(this.ui.tip_drop);
- this.notifyNode(this.ui.tip_shop);
- this.notifyNode(this.ui.tip_welfare);
- this.notifyNode(this.ui.tip_sign);
- // 30秒,不用太精准
- this.schedule(() => {
- if (true) {
- //关闭
- return;
- }
- if (AccountModel.getInstance().curLevel) {
- this.checkUI();
- }
- },120);
- }
- checkUI(){
- this.checkShop();
- this.checkAirDrop();
- }
- checkAirDrop(){
- let airdrop_time = AccountModel.getInstance().airdrop_time;
- //不同时间戳
- let notTime = airdrop_time != this.cacheTimeByBullet;
- if (!airdrop_time) {
- this.clickAirDrop();
- return;
- }
- let curTime = Utils.getTimeStamp();
- let time = needRefreshTime - (curTime - airdrop_time);
- if (time <= 1
- &¬Time) {
- this.cacheTimeByBullet = airdrop_time;
- this.clickAirDrop();
- }
- }
- checkShop(){
- let shopTime = AccountModel.getInstance().shop_time;
- //不同时间戳
- let notTime = shopTime != this.cacheTimeByPower;
- if (!shopTime) {
- this.clickShop();
- return;
- }
- let curTime = Utils.getTimeStamp();
- //写死
- let time = 5 * 60 - (curTime - shopTime);
- if (time <= 1
- && notTime){
- this.cacheTimeByPower = shopTime;
- this.clickShop();
- }
- }
- notifyNode(node:cc.Node){
- cc.tween(node)
- .repeatForever(
- cc.tween(node)
- .to(0.8,{scale:0.5,opacity:0})
- .to(0.8,{scale:1,opacity:255})
- )
- .start();
- }
- checkSign() {
- const canSign = SignUtil.canSign();
- this.ui.tip_sign.active = canSign;
- if (canSign) {
- gameEventManager.on(EVENT_TYPE.OFF_SIGN_TIP, () => {
- this.ui.tip_sign.active = false;
- })
- }
- }
- checkWelfare(){
- const curWelfare = AccountModel.getInstance().curWelfare;
- this.ui.tip_welfare.active = curWelfare.length < 4;
- }
- clickAirDrop() {
- zjSdk?.sendEvent('界面曝光-空投')
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,true);
- UIHelp.ShowUI(UIAirdropView);
- }
- clickSign() {
- zjSdk?.sendEvent('界面曝光-签到')
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,true);
- UIHelp.ShowUI(UISignView);
- }
- clickShop() {
- zjSdk?.sendEvent('界面曝光-超市')
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,true);
- UIHelp.ShowUI(UIShopView);
- }
- clickWelfare() {
- zjSdk?.sendEvent('界面曝光-幸存者')
- gameEventManager.emit(EVENT_TYPE.CHANGE_STATUS,true);
- UIHelp.ShowUI(UIWelfareView);
- }
-
- //游戏后门
- clickZhDiyDebug() {
- let c = this.houMenCount;
- this.houMenCount =c+1;
- if(c<3){
- console.log('zh:后门第'+c+'次');
- return;
- }
-
-
- console.log('zh:点击了后门入口');
- //UIHelp.ShowTips('后门入口!');
-
- gameData.curBulletNum =9999;//子弹增加
- gameData.curPowerNum =999;
- AccountModel.getInstance().reliveNum=99;
-
- UIHelp.ShowTips('后门子弹\体力\复活次=99 ');
- // this.curDay = AccountModel.getInstance().curDay; //当前天数
- // this.curPowerNum = AccountModel.getInstance().curPower; //当前体力
- // this._curBulletNum = AccountModel.getInstance().curBullet;//当前子弹数
- // this.curPeopleNum = 0;//当前玩家数
- // this.peopleDieNum = 0;//玩家死亡数
- // this.curDiePeopleNum = 0; //当前死亡玩家数
- // this._curKillZomNum = AccountModel.getInstance().curKillZomNum; //当前已杀死的僵尸数
- // this.curKillBossNum = 0; //当前杀死的boss数
- // this.bAddBoss = false;
- // //-----------------------------以下切换副本界面需要用到的数据------------------------------------------------------//
- // this.playerDtList = [];
- // //this.isDayTime = true; //是否是白天
- // this.curInDungeonType = null; //当前进入的房间类型
- }
- }
|