"use strict"; cc._RF.push(module, '16ae4H9zvBGk54/3uYE3OrT', 'cmp.sync.center.slot'); // Scripts/mod/home/sync_center/cmp.sync.center.slot.js "use strict"; /****************************************************************** * * 同步中心 卡槽 * ******************************************************************/ var SVCItem = require("nx.fx.sv.expand.item"); var HeroController = require("hero_controller"); var RootWnd = require("cmp.sync.center.wnd"); var TimeTool = require("timetool"); cc.Class({ "extends": SVCItem, properties: { cmpRoot: { "default": null, type: RootWnd } }, // 数据重置 rebind: function rebind(_idx, _data, _key) { this._super(_idx, _data, _key); // 刷新 this.setData(_data); }, // 显示 onEnable: function onEnable() {}, // 关闭 onDisable: function onDisable() { this.unscheduleAllCallbacks(); }, // 置空 setEmpty: function setEmpty() { this.unscheduleAllCallbacks(); nx.gui.setActive(this, "partner", false); nx.gui.setActive(this, "add", false); nx.gui.setActive(this, "cd", false); nx.gui.setActive(this, "lock", false); nx.gui.setActive(this, "locked", true); }, // 重置 setData: function setData(_data) { // 无效锁定 if (nx.dt.objEmpty(_data)) { this.setEmpty(); return; } // 有伙伴 if (nx.dt.numPositive(_data.id, false)) { this.setPartner(_data.id); return; } // 倒计时 this.unscheduleAllCallbacks(); if (nx.dt.numPositive(_data.cool_time, false)) { this.setCD(_data.cool_time); return; } // 可添加 if (nx.dt.numPositive(_data.pos, false)) { nx.gui.setActive(this, "partner", false); nx.gui.setActive(this, "add", true); nx.gui.setActive(this, "cd", false); nx.gui.setActive(this, "lock", false); nx.gui.setActive(this, "locked", false); return; } // 置空 nx.gui.setActive(this, "partner", false); nx.gui.setActive(this, "add", false); nx.gui.setActive(this, "cd", false); nx.gui.setActive(this, "lock", _data.canUnlock); nx.gui.setActive(this, "locked", !_data.canUnlock); }, // 设置伙伴 setPartner: function setPartner(_pid) { nx.gui.setActive(this, "add", false); nx.gui.setActive(this, "cd", false); nx.gui.setActive(this, "lock", false); nx.gui.setActive(this, "locked", false); nx.gui.setActive(this, "partner", true); var HC = HeroController.getInstance(); var role = HC.getModel().getHeroById(_pid); var item = nx.gui.getComponent(this, "partner", "cmp.partner.inbag"); if (!item || !role) { return; } // 基本信息 item.setData(role); }, // 设置倒计时 setCD: function setCD(_time) { nx.gui.setActive(this, "partner", false); nx.gui.setActive(this, "add", false); nx.gui.setActive(this, "lock", false); nx.gui.setActive(this, "locked", false); nx.gui.setActive(this, "cd", false); if (!nx.dt.numPositive(_time, false)) { return; } nx.gui.setActive(this, "cd", true); var self = this; var tick = function tick() { var time = self.mdata.cool_time - client.socket.getTime(); if (time > 0) { var txt = TimeTool.getTimeFormat(time); nx.gui.setString(self, "cd/txt", txt); } else { self.setData({ pos: self.mdata.pos, id: 0, cool_time: 0, canUnlock: self.mdata.canUnlock }); } }; this.unscheduleAllCallbacks(); this.schedule(tick, 1, cc.macro.REPEAT_FOREVER); tick(); }, // 点击下阵 onTouchFree: function onTouchFree() { if (this.cmpRoot && nx.dt.objNEmpty(this.mdata)) { this.cmpRoot.onFreePartner(this.mdata); } }, // 点击添加 onTouchJoin: function onTouchJoin() { if (this.cmpRoot && nx.dt.objNEmpty(this.mdata)) { this.cmpRoot.onJoinPartner(this.mdata.pos); } }, // 点击冷却 onTouchCD: function onTouchCD() { if (this.cmpRoot && nx.dt.objNEmpty(this.mdata)) { this.cmpRoot.onTouchCD(this.mdata.pos); } }, // 点击解锁 onTouchUnlock: function onTouchUnlock() { if (this.cmpRoot && nx.dt.objNEmpty(this.mdata)) { this.cmpRoot.onTouchExpand(this.mdata); } } }); cc._RF.pop();