667cdcc3-e067-4a69-8dce-ac129b8c4b85.js
6.11 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
"use strict";
cc._RF.push(module, '667cdzD4GdKaY3OrBKbjEuF', 'UIBattleUserSkillBtn');
// scripts/ui/uiView/UIBattleUserSkillBtn.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 Global_1 = require("../../Global");
var BattleConst_1 = require("../../kernel/battle/BattleConst");
var BattleManager_1 = require("../../kernel/battle/BattleManager");
var TableDefine_1 = require("../../kernel/table/TableDefine");
var UIManager_1 = require("../UIManager");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var UIBattleUserSkillBtn = /** @class */ (function (_super) {
__extends(UIBattleUserSkillBtn, _super);
function UIBattleUserSkillBtn() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this._locked = true;
_this._skillConfig = null;
return _this;
//#endregion
}
//#region LIFE-CYCLE CALLBACKS:
UIBattleUserSkillBtn.prototype.onLoad = function () {
this._icon = this.node.getChildByName('icon').getComponent(cc.Sprite);
this._lockNode = this.node.getChildByName('imgLock');
this._numNode = this.node.getChildByName('nodeNum');
this._txtNum = this._numNode.getComponentInChildren(cc.Label);
};
UIBattleUserSkillBtn.prototype.onEnable = function () {
BattleConst_1.getGlobalNode().on(Global_1.GlobalEvent.SKILL_NUM_CHANGE, this.onSkillNumChange, this);
};
UIBattleUserSkillBtn.prototype.onDisable = function () {
BattleConst_1.getGlobalNode().off(Global_1.GlobalEvent.SKILL_NUM_CHANGE, this.onSkillNumChange, this);
};
// update (dt) {}
//#endregion
//#region public method
UIBattleUserSkillBtn.prototype.setId = function (skillId) {
var _this = this;
this._skillConfig = Global_1.tMgr.getConfig(TableDefine_1.TableName.USER_SKILL, skillId);
if (this._skillConfig) {
// this.setlo
cc.resources.load('ui/battle/' + this._skillConfig.Icon, cc.SpriteFrame, function (error, asset) {
if (!error) {
_this._icon.spriteFrame = asset;
}
});
this._locked = BattleManager_1.BattleManager.ins.curBattle.levelId < this._skillConfig.UnlockLevel;
if (BattleManager_1.BattleManager.ins.curBattle.levelId == 0) {
this._locked = false;
}
this._icon.node.active = !this._locked;
this._numNode.active = !this._locked;
this._lockNode.active = this._locked;
var free = (BattleManager_1.BattleManager.ins.curBattle.levelId == this._skillConfig.UnlockLevel);
this.node.getChildByName('hand').active = free;
if (!this._locked || free) {
this.updateNum(free);
}
}
};
// setLock(value: boolean) {
// this._locked = value;
// this._icon.node.active = !value;
// this._addNode.active = !value;
// this._numNode.active = !value;
// this._lockNode.active = value;
// }
//#endregion
//#region event
UIBattleUserSkillBtn.prototype.onClick = function () {
if (!this._locked) {
var free = (BattleManager_1.BattleManager.ins.curBattle.levelId == this._skillConfig.UnlockLevel);
if (this.node.getChildByName('hand').active) {
this.node.getChildByName('hand').active = false;
}
var num = SaveDataManager_1.SaveDataManager.ins.getUserSkillNum(this._skillConfig.ID);
if (num > 0 || free) {
BattleManager_1.BattleManager.ins.curBattle.useSkill(this._skillConfig.ID, free);
}
else {
UIManager_1.UIManager.ins.openWindow(Global_1.WindowName.USER_SKILL_INFO, this._skillConfig.ID);
}
}
};
UIBattleUserSkillBtn.prototype.onSkillNumChange = function (skillId) {
if (skillId == this._skillConfig.ID) {
this.updateNum(false);
}
};
//#endregion
//#region private method
UIBattleUserSkillBtn.prototype.updateNum = function (free) {
//读取本地存档
var num = SaveDataManager_1.SaveDataManager.ins.getUserSkillNum(this._skillConfig.ID);
this._numNode.active = (num > 0 || free);
this._txtNum.string = num.toString();
this._numNode.getChildByName('txtNum').active = !free;
this._numNode.getChildByName('imgFree').active = free;
};
UIBattleUserSkillBtn = __decorate([
ccclass
], UIBattleUserSkillBtn);
return UIBattleUserSkillBtn;
}(cc.Component));
exports.default = UIBattleUserSkillBtn;
cc._RF.pop();