"use strict"; cc._RF.push(module, '9a370Mc7IdB2ruEK58rhBMd', 'BlockView'); // scripts/prefabs/BlockView.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 BattleConst_1 = require("../kernel/battle/BattleConst"); var BlcokSkillFireworkView_1 = require("./BlcokSkillFireworkView"); var BlockSkillBombView_1 = require("./BlockSkillBombView"); var BlockSkillSwitcherView_1 = require("./BlockSkillSwitcherView"); var ObjBaseView_1 = require("./ObjBaseView"); var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property; var BlockView = /** @class */ (function (_super) { __extends(BlockView, _super); function BlockView() { var _this = _super !== null && _super.apply(this, arguments) || this; _this._imgSkillIcon = null; _this._imgEffect = null; _this._txt = null; _this._light = null; _this._mapView = null; _this._txtOffset = new cc.Vec2(); _this._skillView = null; return _this; //#endregion } Object.defineProperty(BlockView.prototype, "owner", { get: function () { return this._owner; }, enumerable: false, configurable: true }); //#region interface BlockView.prototype.onHit = function () { _super.prototype.onHit.call(this); var ani = this._txt.getComponent(cc.Animation); ani && !ani.getAnimationState('fx_block_txt_hit').isPlaying && ani.play('fx_block_txt_hit', 0); if (this._light) { var lightAni = this._light.getComponent(cc.Animation); lightAni && !lightAni.getAnimationState('fx_block_light_hit').isPlaying && lightAni.play('fx_block_light_hit', 0) && (this._light.active = true); } this._skillView && this._skillView.onCollision(); }; BlockView.prototype.onDead = function () { this._mapView.playBlockParticle(this.node); this._skillView && this._skillView.onDead(); this._imgEffect.destroy(); this._imgSkillIcon.destroy(); this._txt.destroy(); this._light && this._light.destroy(); _super.prototype.onDead.call(this); }; //#endregion //#region life cycle BlockView.prototype.init = function (owner, mapView) { this._imgSkillIcon = this.node.getChildByName('imgIcon'); this._imgEffect = this.node.getChildByName('imgEffect'); this._imgEffect.active = false; this._txt = this.node.getChildByName('txt'); this._txtOffset.x = this._txt.x; this._txtOffset.y = this._txt.y; this._mapView = mapView; this._light = this.node.getChildByName('light'); this._light && (this._light.active = false); _super.prototype.init.call(this, owner, mapView); //分层显示 this._imgEffect.removeFromParent(); this._txt.removeFromParent(); this._imgSkillIcon.removeFromParent(); this._light && this._light.removeFromParent(); mapView.effectLayer.addChild(this._imgEffect); mapView.txtLayer.addChild(this._txt); mapView.blockIconLayer.addChild(this._imgSkillIcon); this._light && mapView.lightLayer.addChild(this._light); if (owner.skill && owner.skill.skillId == BattleConst_1.BlockSkill.BOMB) { this._skillView = new BlockSkillBombView_1.BlockSkillBombView(this, this._mapView); } else if (owner.skill && owner.skill.skillId >= BattleConst_1.BlockSkill.FIREWORK_VERTICAL && owner.skill.skillId <= BattleConst_1.BlockSkill.FIREWORK_DOUBLE) { this._skillView = new BlcokSkillFireworkView_1.BlockSkillFireworkView(this, this._mapView); } else if (owner.skill && owner.skill.skillId == BattleConst_1.BlockSkill.SWITCHER) { this._skillView = new BlockSkillSwitcherView_1.BlockSkillSwitcherView(this, mapView); } this.updateSkillIcon(); // this.onVisibleChange() }; BlockView.prototype.onPreview = function () { _super.prototype.onPreview.call(this); this._txt.active = false; }; BlockView.prototype.onDestroy = function () { _super.prototype.onDestroy.call(this); this._skillView && this._skillView.onDestroy(); this._skillView = null; this._imgEffect = null; this._imgSkillIcon = null; this._txt = null; }; //#endregion //#region override method BlockView.prototype.onPositionChange = function (x, y) { _super.prototype.onPositionChange.call(this, x, y); this._imgEffect.setPosition(x, y); this._txt.setPosition(x + this._txtOffset.x, y + this._txtOffset.y); this._imgSkillIcon.setPosition(x, y); this._light && this._light.setPosition(x, y); this._skillView && this._skillView.onPositionChange(x, y); }; BlockView.prototype.onLazyUpdate = function () { this._txt.getComponent(cc.Label).string = this.owner.hp.toString(); }; BlockView.prototype.onVisibleChange = function () { _super.prototype.onVisibleChange.call(this); this._imgEffect.active = this._visible; this._imgEffect.active = false; //暂时屏蔽 this._imgSkillIcon.active = (this._visible && this.owner.skill && this.owner.skill.skillImg != ''); this._txt.active = this._visible && this.owner.hp > 0; }; //#endregion //#region private method BlockView.prototype.updateSkillIcon = function () { var _this = this; if (this.owner.skill && this.owner.skill.skillImg != "") { // this._imgSkillIcon.active = true; cc.resources.load("battle/" + this.owner.skill.skillImg, cc.SpriteFrame, function (err, spf) { // const frame = (spf as cc.SpriteAtlas).getSpriteFrame(this._owner.iconName); if (!err && _this.isValid) { //有可能销毁后进入回调,增加判断 isValid _this._imgSkillIcon.getComponent(cc.Sprite).spriteFrame = spf; } else { // console.error(err.message); } }); } else { this._imgSkillIcon.active = false; } }; BlockView = __decorate([ ccclass ], BlockView); return BlockView; }(ObjBaseView_1.default)); exports.default = BlockView; cc._RF.pop();