58c2d9ab-bfe0-4c89-952c-d49d68efd726.js 17.8 KB
"use strict";
cc._RF.push(module, '58c2dmrv+BMiZUs1J1o79cm', 'UIBattle');
// scripts/ui/uiView/UIBattle.ts

"use strict";
// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var SaveDataManager_1 = require("../../component/SaveDataManager");
var SoundManager_1 = require("../../component/SoundManager");
var Global_1 = require("../../Global");
var BattleConst_1 = require("../../kernel/battle/BattleConst");
var BattleManager_1 = require("../../kernel/battle/BattleManager");
var MapUtil_1 = require("../../kernel/battle/map/MapUtil");
var UserSkillShurikenData_1 = require("../../kernel/battle/userSkill/UserSkillShurikenData");
var UIBase_1 = require("../UIBase");
var UIManager_1 = require("../UIManager");
var UIBattleUserSkillBtn_1 = require("./UIBattleUserSkillBtn");
var UICommonNoticeEnableParam_1 = require("./UICommonNoticeEnableParam");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var UIBattle = /** @class */ (function (_super) {
    __extends(UIBattle, _super);
    function UIBattle() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._starList = [];
        return _this;
        //#endregion
    }
    // private _collecting: boolean = false;
    //#region  LIFE-CYCLE CALLBACKS:
    UIBattle.prototype.onLoad = function () {
        this._useCloseEffect = false;
        this._usePopUpEffect = false;
        this._cancelNode = this.node.getChildByName('bottom').getChildByName('nodeCancel');
        this._skillNode = this.node.getChildByName('bottom').getChildByName('skillNode');
        this._roundingNode = this.node.getChildByName('bottom').getChildByName('roundingNode');
        this._roundingNode.active = false;
        this._pauseNode = this.node.getChildByName('pauseNode');
        this._pauseNode.active = false;
        for (var i = 1; i <= 3; ++i) {
            this._starList.push(this.node.getChildByName('top').getChildByName('prgStar').getChildByName('star' + i.toString()));
        }
        this._noticeParam = new UICommonNoticeEnableParam_1.UICommonNoticeEnableParam();
        this._noticeParam.desc = '您想重新开始游戏吗?';
        this._noticeParam.callBackThisObj = this;
        this._noticeParam.doneCallBack = this.onNoticeRestartDoneClick;
        BattleManager_1.BattleManager.ins.eventNode.once(BattleConst_1.BattleEvent.BATTLE_START, this.onBattleStart, this);
        BattleManager_1.BattleManager.ins.eventNode.on(BattleConst_1.BattleEvent.BLOCK_COMBO, this.onBlockCombo, this);
        BattleManager_1.BattleManager.ins.eventNode.on(BattleConst_1.BattleEvent.ROUND_END, this.onRoundEnd, this);
        BattleManager_1.BattleManager.ins.eventNode.on(BattleConst_1.BattleEvent.ROUND_START, this.onRoundStart, this);
        BattleManager_1.BattleManager.ins.eventNode.on(BattleConst_1.BattleEvent.SKILL_START, this.onSkillStart, this);
    };
    UIBattle.prototype.start = function () {
        this.node.getComponent(cc.Widget).updateAlignment(); //必须先根据舞台调整尺寸
        var dis = this.node.height / 2 + this.node.getChildByName('bottom').y;
        var nodeRounding = this.node.getChildByName('bottom').getChildByName('roundingNode');
        nodeRounding.y -= (nodeRounding.height + dis);
        nodeRounding.active = true;
    };
    UIBattle.prototype.onEnable = function () {
        // this.schedule(this.onLazyUpdate, 1 / 20);
    };
    UIBattle.prototype.onDisable = function () {
        // this.unschedule(this.onLazyUpdate);
    };
    UIBattle.prototype.onDestroy = function () {
        // cc.Tween.stopAllByTarget(this._tobj);
        this.unschedule(this.onLazyUpdate);
        // BattleManager.ins.eventNode.off(BattleEvent.BATTLE_START, this.onBattleStart, this);
        // BattleManager.ins.eventNode.off(BattleEvent.BLOCK_COMBO, this.onBlockCombo, this);
        // BattleManager.ins.eventNode.off(BattleEvent.ROUND_START, this.onRoundStart, this);
        // BattleManager.ins.eventNode.off(BattleEvent.ROUND_END, this.onRoundEnd, this);
        BattleManager_1.BattleManager.ins.eventNode.targetOff(this);
    };
    //#endregion
    //#region public method
    UIBattle.prototype.setCancelNodeVisible = function (value) {
        this._cancelNode.active = value;
    };
    UIBattle.prototype.setCancelNodeHit = function (value) {
        this._cancelNode.opacity = (value ? 255 : 153);
    };
    //#endregion
    //#region private method
    UIBattle.prototype.onLazyUpdate = function () {
        var battle = BattleManager_1.BattleManager.ins.curBattle;
        if (battle) {
            var rate = (battle.doubleShoot ? 2 : 1);
            this.node.getChildByName('bottom').getChildByName('txtMarblesNum').getComponent(cc.Label).string = "弹球:" + (battle.marblesNum * rate).toString();
            if (battle.mapData) {
                this.node.getChildByName('top').getChildByName('nodeScore').getComponentInChildren(cc.Label).string = battle.mapData.curScore.toString();
                this.node.getChildByName('top').getChildByName('prgStar').getComponent(cc.ProgressBar).progress = battle.mapData.curScore / MapUtil_1.MapUtil.getThreeStarScore(battle.mapData);
                var starRate = MapUtil_1.MapUtil.getStarRate(battle.mapData);
                var _loop_1 = function (i) {
                    var get = (i + 1 <= starRate);
                    var enableNode = this_1._starList[i].getChildByName('enable');
                    if (enableNode.active == false && get) {
                        enableNode.active = get;
                        var spine_1 = enableNode.getComponent(sp.Skeleton);
                        spine_1.setAnimation(0, 'animation2', false);
                        spine_1.setCompleteListener(function () {
                            spine_1.setAnimation(0, 'animation3', true);
                        });
                        SoundManager_1.SoundManager.ins.playEffect(Global_1.SoundName.GET_STAR);
                    }
                    else {
                        enableNode.active = get;
                    }
                };
                var this_1 = this;
                for (var i = 0; i < 3; ++i) {
                    _loop_1(i);
                }
            }
            var nodeSpeedUp = this.node.getChildByName('nodeSpeedUp');
            if (battle.roundRunning && battle.speedUp) {
                if (nodeSpeedUp.active == false) {
                    nodeSpeedUp.active = true;
                    nodeSpeedUp.getComponentInChildren(cc.Animation).play();
                }
            }
            else {
                nodeSpeedUp.getComponentInChildren(cc.Animation).stop();
                nodeSpeedUp.active = false;
            }
            var now = Date.now();
            var goldenAimLeftTime = SaveDataManager_1.SaveDataManager.ins.runtimeData.goldenAimEndTime - Date.now();
            var txtGoldenAim = cc.find('top/btnGoldenAim/txtTime', this.node);
            if (goldenAimLeftTime > 0) {
                txtGoldenAim.active = true;
                var timeStr = slib.StringUtil.formatTimeBySecs(goldenAimLeftTime / 1000);
                timeStr = timeStr.slice(3, timeStr.length);
                txtGoldenAim.getComponent(cc.Label).string = timeStr;
            }
            else {
                txtGoldenAim.active = false;
            }
        }
    };
    UIBattle.prototype.tweenTarget = function (node, up) {
        var dis = this.node.height / 2 - Math.abs(this.node.getChildByName('bottom').y);
        // if (node == this.node.getChildByName('bottom').getChildByName('roundingNode') && !up) {
        //     //回收栏下降时 添加额外的回调
        //     cc.tween(node).to(0.3, { position: cc.v3(node.x, up ? 0 : -dis - 200, node.z) }, { easing: 'backOut' }).call(() => { this._collecting = false; })
        //         .start();
        // }
        // else {
        cc.tween(node).to(0.3, { position: cc.v3(node.x, up ? 0 : -dis - 200, node.z) }, { easing: 'backOut' })
            .start();
        // }
    };
    //#endregion
    //#region events
    UIBattle.prototype.onBattleStart = function () {
        var spineNode = this.node.getChildByName('spineGameStart');
        spineNode.active = true;
        var spine = spineNode.getComponent(sp.Skeleton);
        spine.setCompleteListener(function () { spineNode.active = false; BattleManager_1.BattleManager.ins.shootTouchEnable = true; });
        spine.setAnimation(0, 'animation', false);
        for (var i = 0; i < 4; ++i) {
            this._skillNode.getChildByName('skill' + (i + 1).toString()).getComponent(UIBattleUserSkillBtn_1.default).setId(i + 1);
            // this._skillNode.getChildByName('skill' + (i + 1).toString()).getComponent(UIBattleUserSkillBtn).setLock(false);
        }
        this.schedule(this.onLazyUpdate, 1 / 20);
    };
    // private _tobj = { progress: 0 };
    UIBattle.prototype.onBlockCombo = function (combo) {
        var nodeCombo = this.node.getChildByName('nodeCombo');
        var txtNum = nodeCombo.getChildByName('txtNum').getComponent(cc.Label);
        if (nodeCombo.active == false) {
            nodeCombo.active = true;
        }
        txtNum.string = combo.toString();
        nodeCombo.getComponent(cc.Animation).play();
        //连击描述
        var nodeComboTip = this.node.getChildByName('nodeComboTip');
        var frame = nodeComboTip.getChildByName('UI_fx_bksy').getChildByName('UI_fx_bksy02').getComponent(cc.Sprite);
        var showTip = true;
        if (combo == 5) {
            //很棒
            cc.resources.load('ui/battle/UI_yxz_hb', cc.SpriteFrame, function (error, asset) { frame.spriteFrame = asset; });
        }
        else if (combo == 10) {
            //了不起
            cc.resources.load('ui/battle/UI_yxz_lbq', cc.SpriteFrame, function (error, asset) { frame.spriteFrame = asset; });
        }
        else if (combo == 15) {
            //真了不起    
            cc.resources.load('ui/battle/UI_yxz_zlbq', cc.SpriteFrame, function (error, asset) { frame.spriteFrame = asset; });
        }
        else if (combo == 20) {
            //完美
            cc.resources.load('ui/battle/UI_yxz_wm', cc.SpriteFrame, function (error, asset) { frame.spriteFrame = asset; });
        }
        else if (combo == 25) {
            //太疯狂了
            cc.resources.load('ui/battle/UI_yxz_tfkl', cc.SpriteFrame, function (error, asset) { frame.spriteFrame = asset; });
        }
        else if (combo == 30) {
            //不可思议
            cc.resources.load('ui/battle/UI_yxz_bksy', cc.SpriteFrame, function (error, asset) { frame.spriteFrame = asset; });
        }
        else {
            showTip = false;
        }
        if (showTip) {
            // cc.Tween.stopAllByTarget(this._tobj);
            nodeComboTip.active = true;
            nodeComboTip.getChildByName('UI_fx_bksy').getComponent(cc.Animation).once('finished', function () { nodeComboTip.active = false; }, this);
            nodeComboTip.getChildByName('UI_fx_bksy').getComponent(cc.Animation).play('UI_fx_bksy');
            // this._tobj.progress = 0.618;
            // nodeComboTip.setScale(0.618, 0.618);
            // cc.tween(this._tobj).to(0.2, { progress: 1 }, {
            //     onUpdate: (target: { progress: number }) => {
            //         nodeComboTip.setScale(target.progress, target.progress);
            //     },
            // }).delay(1).to(0.2, { progress: 0 }, {
            //     onUpdate: (target: { progress: number }) => {
            //         nodeComboTip.setScale(target.progress, target.progress);
            //     },
            // }).call(() => { nodeComboTip.active = false; }).start();
        }
    };
    UIBattle.prototype.onRoundStart = function () {
        var nodeSkill = this.node.getChildByName('bottom').getChildByName('skillNode');
        var nodeRounding = this.node.getChildByName('bottom').getChildByName('roundingNode');
        this.tweenTarget(nodeSkill, false);
        this.tweenTarget(nodeRounding, true);
    };
    UIBattle.prototype.onRoundEnd = function () {
        var nodeCombo = this.node.getChildByName('nodeCombo');
        nodeCombo.active = false;
        var nodeSkill = this.node.getChildByName('bottom').getChildByName('skillNode');
        var nodeRounding = this.node.getChildByName('bottom').getChildByName('roundingNode');
        this.tweenTarget(nodeSkill, true);
        this.tweenTarget(nodeRounding, false);
    };
    UIBattle.prototype.onSkillStart = function (skillId) {
        var _this = this;
        if (skillId == BattleConst_1.UserSkill.BOMB) {
            var spNode_1 = this.node.getChildByName('userSkillBombSpine');
            spNode_1.active = true;
            spNode_1.getComponent(sp.Skeleton).setCompleteListener(function () { spNode_1.active = false; });
            spNode_1.getComponent(sp.Skeleton).setAnimation(0, 'animation', false);
        }
        else if (skillId == BattleConst_1.UserSkill.SHURIKEN) {
            var spNode_2 = this.node.getChildByName('userSkillShuriken');
            spNode_2.active = true;
            spNode_2.getComponent(sp.Skeleton).setCompleteListener(function () {
                if (spNode_2.getComponent(sp.Skeleton).animation == 'in') {
                    spNode_2.getComponent(sp.Skeleton).setAnimation(0, 'att', false);
                    //调整位置
                    var p = BattleManager_1.BattleManager.ins.curBattle.mapData.getPixelPosByGridPos(cc.v2(0, UserSkillShurikenData_1.UserSkillShurikenData.maxY));
                    BattleManager_1.BattleManager.ins.curBattle.mapView.convertToWorldSpaceAR(p, p);
                    _this.node.convertToNodeSpaceAR(p, p);
                    spNode_2.setPosition(0, p.y);
                }
                else {
                    spNode_2.active = false;
                }
            });
            spNode_2.getComponent(sp.Skeleton).setAnimation(0, 'in', false);
        }
    };
    UIBattle.prototype.onBtnPauseClick = function () {
        // BattleManager.ins.leaveBattle();
        // UIManager.ins.openScene('Main');
        // UIManager.ins.openWindow(WindowName.PAUSE);
        this._pauseNode.active = true;
        BattleManager_1.BattleManager.ins.paused = true;
        this.refreshSoundBtn();
    };
    UIBattle.prototype.onBtnCollectClick = function () {
        // if (!this._collecting) {
        //     this._collecting = true;
        BattleManager_1.BattleManager.ins.curBattle.collectAll();
        // }
    };
    UIBattle.prototype.onBtnPauseCloseClick = function () {
        this._pauseNode.active = false;
        BattleManager_1.BattleManager.ins.paused = false;
    };
    UIBattle.prototype.onBtnMusicClick = function () {
        SaveDataManager_1.SaveDataManager.ins.setMusicMute(!SaveDataManager_1.SaveDataManager.ins.runtimeData.musicMute);
        this.refreshSoundBtn();
        if (SaveDataManager_1.SaveDataManager.ins.runtimeData.musicMute) {
            SoundManager_1.SoundManager.ins.stopMusic();
        }
        else {
            SoundManager_1.SoundManager.ins.playMusic();
        }
    };
    UIBattle.prototype.onBtnMuteClick = function () {
        SaveDataManager_1.SaveDataManager.ins.setSoundEffectMute(!SaveDataManager_1.SaveDataManager.ins.runtimeData.SEMute);
        this.refreshSoundBtn();
    };
    UIBattle.prototype.onBtnRestartClick = function () {
        UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.COMMON_NOTICE, this._noticeParam);
    };
    UIBattle.prototype.onGoldenAimClick = function () {
        UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.GOLDEN_AIM);
    };
    UIBattle.prototype.onNoticeRestartDoneClick = function () {
        // this.leave();
        BattleManager_1.BattleManager.ins.leaveBattle();
        UIManager_1.UIManager.ins.openScene('Battle');
        // UIManager.ins.closeWindow(WindowName.PAUSE, () => {
        //     BattleManager.ins.leaveBattle();
        //     UIManager.ins.openScene('Main');
        // });
    };
    UIBattle.prototype.refreshSoundBtn = function () {
        cc.find('New Layout/btnMusic/Background/disable', this._pauseNode).active = SaveDataManager_1.SaveDataManager.ins.runtimeData.musicMute;
        cc.find('New Layout/btnVol/Background/disable', this._pauseNode).active = SaveDataManager_1.SaveDataManager.ins.runtimeData.SEMute;
    };
    UIBattle.prototype.onBtnHomeClick = function () {
        BattleManager_1.BattleManager.ins.leaveBattle();
        UIManager_1.UIManager.ins.openScene('Main');
    };
    UIBattle = __decorate([
        ccclass
    ], UIBattle);
    return UIBattle;
}(UIBase_1.UIBase));
exports.default = UIBattle;

cc._RF.pop();