Files
fc/dev/project/library/imports/76/76effbc0-65a6-4b55-af45-2ba95a2089af.js
T
2026-05-24 10:21:26 +08:00

382 lines
10 KiB
JavaScript

"use strict";
cc._RF.push(module, '76effvAZaZLVa9FK6laIImv', 'wnd.summon.crystal.swap');
// Scripts/mod/summon/crystal/wnd.summon.crystal.swap.js
"use strict";
/******************************************************************
*
* 水晶卡牌召喚
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var FxTogs = require("nx.fx.togs");
var FxSVC = require("nx.fx.sv.expand");
var HeroConst = require("hero_const");
var HeroEvent = require("hero_event");
var HeroControl = require("hero_controller");
var BackpackController = require("backpack_controller");
var TipsController = require("tips_controller");
var CRYModel = require("summon.crystal.mod");
var HCT = HeroConst.CampType;
cc.Class({
"extends": BridgeWindow,
properties: {
togCamp: {
"default": null,
type: FxTogs
},
svcList: {
"default": null,
type: FxSVC
},
nodFrom: {
"default": null,
type: cc.Node
},
nodTo: {
"default": null,
type: cc.Node
},
nodEmpty: {
"default": null,
type: cc.Node
},
nodReady: {
"default": null,
type: cc.Node
},
nodResult: {
"default": null,
type: cc.Node
},
lockResult: {
"default": null,
type: cc.Node
}
},
// 重载:参数打开
onOpenConfigs: function onOpenConfigs(_params) {
var _this = this;
this.curCamp = -1;
this.partners = [];
this.partner = null;
this.targetBid = 0;
// 事件监听
this.bindGEvent(HeroEvent.Del_Hero_Event, this.onPartnerChanged.bind(this));
this.bindGEvent(HeroEvent.Hero_Data_Add, this.onPartnerChanged.bind(this));
// Tog监听
this.togCamp.posTog = this.onTogCamp.bind(this);
this.togCamp.togTo(0);
this.onTogCamp(HCT.eNone);
// 置空
this.setEmpty();
// 现场恢复
CRYModel.getInstance().reqSwapRecord(function (_ret, _data) {
if (!_ret || !_data || !nx.dt.numPositive(_data.partner_id, false)) {
return;
}
// 设置当前
for (var i = 0; i < _this.partners.length; ++i) {
var pt = _this.partners[i];
if (pt && pt.id == _data.partner_id) {
_this.onFocusChanged({
index: i,
mdata: pt
});
_this.setTarget(_data.new_partner_bid);
return;
}
}
});
},
// 重载:关闭前
onPreClosed: function onPreClosed() {
this.svcList.rebuild([]);
},
// 置空
setEmpty: function setEmpty() {
this.setPartner(null);
},
// 设置当前伙伴
setPartner: function setPartner(_partner) {
this.partner = _partner;
this.setTarget(0);
// 置空
if (!this.partner) {
this.svcList.cleanFocus();
var _spine = nx.gui.getComponent(this.nodFrom, "smod", "nx.fx.spine");
if (_spine) {
_spine.stop();
}
nx.gui.setActive(this.nodFrom, "smod", false);
nx.gui.setActive(this.nodFrom, "infos", false);
return;
}
// 模型
var key = this.partner.bid + "_" + this.partner.star;
var cfg = gdata("partner_data", "data_partner_star", key);
var spine = nx.gui.getComponent(this.nodFrom, "smod", "nx.fx.spine");
if (cfg && spine) {
var path = PathTool.getSpinePath(cfg.res_id, cfg.res_id, false);
spine.load(path, function (_e) {
if (!_e) {
spine.action("stand2", true);
} else {
spine.stop();
}
});
}
nx.gui.setActive(this.nodFrom, "smod", true);
// 信息
var infos = nx.gui.setActive(this.nodFrom, "infos", true);
var sf = cc.path.join("coms/images/camps" + this.partner.camp_type);
nx.gui.setSpriteFrame(infos, "camp", sf);
nx.gui.setString(infos, "lv", "Lv." + this.partner.lev);
nx.gui.setString(infos, "name", nx.text.getKey(this.partner.name));
var st = cc.path.join("coms/images", "star" + this.partner.star);
nx.gui.setSpriteFrame(infos, "star", st);
},
// 更新目标
setTarget: function setTarget(_bid) {
this.targetBid = _bid;
this.freshOps();
// 置空
if (!nx.dt.numPositive(this.targetBid, false)) {
// 模型
nx.gui.setActive(this.nodTo, "empty", true);
nx.gui.setActive(this.nodTo, "smod", false);
var _spine2 = nx.gui.getComponent(this.nodTo, "smod", "nx.fx.spine");
if (_spine2) {
_spine2.stop();
}
if (!this.partner) {
nx.gui.setActive(this.nodTo, "infos", false);
} else {
// 信息
var _infos = nx.gui.setActive(this.nodTo, "infos", true);
var sf = cc.path.join("coms/images/camps" + this.partner.camp_type);
nx.gui.setSpriteFrame(_infos, "camp", sf);
nx.gui.setString(_infos, "lv", "Lv." + this.partner.lev);
nx.gui.setString(_infos, "name", nx.text.getKey("????"));
var st = cc.path.join("coms/images", "star" + this.partner.star);
nx.gui.setSpriteFrame(_infos, "star", st);
}
return;
}
// 模型
nx.gui.setActive(this.nodTo, "empty", false);
nx.gui.setActive(this.nodTo, "smod", true);
var key = this.targetBid + "_" + this.partner.star;
var cfg = gdata("partner_data", "data_partner_star", key);
var spine = nx.gui.getComponent(this.nodTo, "smod", "nx.fx.spine");
if (cfg && spine) {
var path = PathTool.getSpinePath(cfg.res_id, cfg.res_id, false);
spine.load(path, function (_e) {
if (!_e) {
spine.action("stand2", true);
} else {
spine.stop();
}
});
}
// 名字
var infos = nx.gui.setActive(this.nodTo, "infos", true);
var base = game.configs.partner_data.data_partner_base[this.targetBid];
nx.gui.setString(infos, "name", nx.text.getKey(base ? base.name : ""));
// 特效
var spine2 = nx.gui.getComponent(this.nodTo, "show", "nx.fx.spine");
if (spine2) {
var spine_path = PathTool.getSpinePath("E80009", "action", false);
spine2.play(spine_path, "action1_blue", function () {}, false);
}
},
// 整体刷新
freshList: function freshList(_reset) {
if (_reset === void 0) {
_reset = false;
}
var HC = HeroControl.getInstance();
var mod = HC.getModel();
// 符合条件判断
var camp = this.curCamp;
var good = function good(_hero) {
// 4,5星过滤
if (!_hero || _hero.is_in_form > 0 || _hero.star < 4 || _hero.star > 5) {
return false;
}
// 全阵营(除光暗)
if (camp == HCT.eNone) {
if (_hero.camp_type != HCT.eLight && _hero.camp_type != HCT.eDark) {
return true;
}
return false;
}
return camp == _hero.camp_type;
};
// 阵营伙伴统计
this.partners = [];
var heros = mod.getHeroList();
for (var id in heros) {
var hero = heros[id];
if (good(hero)) {
this.partners.push(hero);
}
}
// 排序
this.partners.sort(function (_a, _b) {
return _b.star - _a.star;
});
this.svcList.rebuild(this.partners);
this.setPartner(null);
},
// 伙伴增删
onPartnerChanged: function onPartnerChanged() {
// console.log( "刷新伙伴信息" );
this.setEmpty();
this.freshList(true);
},
// 阵营切换
onTogCamp: function onTogCamp(_index) {
var idx = parseInt(_index) || 0;
if (this.curCamp == idx) {
return;
}
nx.debug("[Hero]\u9635\u8425\u5207\u6362:" + this.curCamp + " -> " + idx);
this.curCamp = idx;
// 整体刷新
this.freshList();
},
// 选中切换
onFocusChanged: function onFocusChanged(_item) {
// 空
if (nx.dt.objEmpty(_item) || nx.dt.objEmpty(_item.mdata)) {
return;
}
nx.audio.playSFX("audios/effects/touchitem");
// 聚焦
this.svcList.cleanFocus();
this.svcList.addFocus(_item.index);
this.setPartner(_item.mdata);
},
// -------------------------------------------------------
// 操作相关
// -------------------------------------------------------
// 操作更新
freshOps: function freshOps() {
// 空
if (!this.partner) {
this.nodEmpty.active = true;
this.nodReady.active = false;
this.nodResult.active = false;
this.lockResult.active = false;
return;
}
// 准备
if (this.partner && !nx.dt.numPositive(this.targetBid, false)) {
this.nodEmpty.active = false;
this.nodResult.active = false;
this.lockResult.active = false;
this.nodReady.active = true;
// 花费
var DATA = game.configs.recruit_high_data.data_seerpalace_const;
var key = "hero_change" + this.partner.star;
var val = DATA[key].val[0];
nx.bridge.setIconS(this.nodReady, "cost/icon", val[0]);
nx.gui.setString(this.nodReady, "cost/txt", val[1]);
var BC = BackpackController.getInstance();
var have = BC.getModel().getItemNumByBid(val[0]);
var btn = nx.gui.getComponent(this.nodReady, "convert", "nx.fx.button");
btn.lock(have < val[1]);
return;
}
// 保存确认
this.nodEmpty.active = false;
this.nodReady.active = false;
this.nodResult.active = true;
this.lockResult.active = true;
},
// 点击置换
onTouchConvert: function onTouchConvert() {
var _this2 = this;
if (!this.partner) {
return;
}
var CRY = CRYModel.getInstance();
CRY.reqSwap(this.partner.id, function (_ret, _data) {
if (!_ret) {
nx.tbox(_data);
return;
}
_this2.setTarget(_data.new_partner_bid);
_this2.freshOps();
});
},
// 点击取消
onTouchCancel: function onTouchCancel() {
var _this3 = this;
if (!this.partner) {
return;
}
var CRY = CRYModel.getInstance();
CRY.reqSwapCancel(this.partner.id, function (_ret, _data) {
if (!_ret) {
nx.tbox(_data);
return;
}
_this3.setPartner(_this3.partner);
});
},
// 点击保存
onTouchSave: function onTouchSave() {
var _this4 = this;
if (!this.partner) {
return;
}
var CRY = CRYModel.getInstance();
CRY.reqSwapSave(this.partner.id, function (_ret, _data) {
if (!_ret) {
nx.tbox(_data);
return;
}
_this4.setPartner(null);
});
},
// 点击保存锁定区
onTouchLockArea: function onTouchLockArea() {
nx.tbox("转换保存提醒");
},
// 点击帮助
onTouchHelp: function onTouchHelp() {
var TC = TipsController.getInstance();
if (TC) {
var DATA = game.configs.recruit_high_data.data_seerpalace_const;
var txt = DATA.game_rule2.desc;
TC.showTextPanel("tip", nx.text.getKey(txt));
}
}
});
cc._RF.pop();