"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();