9a37031c-ec87-41da-bb84-2b9f2b84131d.js
7.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"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();