Files
fc/dev/project/library/imports/2a/2a7462ad-1505-4bbb-a353-47673e539465.js
T
2026-05-24 10:21:26 +08:00

205 lines
6.9 KiB
JavaScript

"use strict";
cc._RF.push(module, '2a746KtFQVLu6NTR2c+U5Rl', 'cmp.hallows.wnd.trace');
// Scripts/mod/partner/hallows/cmp/cmp.hallows.wnd.trace.js
"use strict";
/******************************************************************
*
* 行星武器奖励弹窗
*
******************************************************************/
var BridgeWindow = require("bridge.window");
var HallowsController = require("hallows_controller");
var BackpackController = require("backpack_controller");
cc.Class({
"extends": BridgeWindow,
properties: {
good_item: {
"default": null,
type: cc.Prefab
},
can_use_label: {
"default": null,
type: cc.RichText
},
slider: {
"default": null,
type: cc.Slider
},
s_progress: {
"default": null,
type: cc.ProgressBar
},
need_num: {
"default": null,
type: cc.Label
},
attr_lb_list: {
"default": [],
type: [cc.Label]
},
attr_list: {
"default": [],
type: [cc.Node]
}
},
onLoad: function onLoad() {
var _this = this;
this.slider.node.on("slide", function () {
_this.setComposeNumByPercent(_this.slider.progress);
_this.s_progress.progress = _this.slider.progress;
});
},
// 重载:参数打开
onOpenConfigs: function onOpenConfigs(data) {
this.this_use_num = 0;
this.cost_config = game.configs.hallows_data.data_const.id_stone;
this.attr_config = game.configs.hallows_data.data_const.stone_attribute;
this.ctrl = HallowsController.getInstance();
this.model = this.ctrl.getModel();
this.data = data;
if (data && data.vo && this.cost_config) {
this.had_use_num = data.vo.seal; // 当前使用的数量
this.use_max_num = this.getUseMaxNum(); // 当前最高可使用数量
//数据异常
if (this.use_max_num == 0) return;
var max_step = game.configs.hallows_data.data_max_lev[this.data.id];
if (max_step == null) return;
var step = this.data.vo.step;
//没吃满,都显示可以使用的
if (this.had_use_num < this.use_max_num) {
this.can_use_label.string = cc.js.formatStr(nx.text.getKey("lab_hallows_trace_window_tip4"), this.had_use_num, this.use_max_num);
} else {
if (step >= max_step) {
//已经满级的
this.can_use_label.string = cc.js.formatStr(nx.text.getKey("lab_hallows_trace_window_tip5"), this.had_use_num, this.use_max_num);
} else {
//找出下一阶的
var next_config = gdata("hallows_data", "data_trace_cost", Utils.getNorKey(this.data.id, step + 1));
if (next_config) {
this.can_use_label.string = cc.js.formatStr(nx.text.getKey("lab_hallows_trace_window_tip6"), step + 1, next_config.num - this.had_use_num);
}
}
}
this.can_use_num = this.use_max_num - this.had_use_num; // 当前剩余可使用数量
if (this.can_use_num < 0) {
this.can_use_num = 0;
}
//当前背包中数量
this.had_max_num = BackpackController.getInstance().getModel().getItemNumByBid(this.cost_config.val); // 背包中总数量
var itemVo = {
bid: this.cost_config.val,
num: this.had_max_num
};
if (!this.cost_item) {
this.cost_item = cc.instantiate(this.good_item);
this.cost_item.parent = this.node.getChildByName("main");
this.cost_item.position = cc.v2(-27, 0);
}
var cmp = this.cost_item.getComponent("cmp.item.base");
cmp.rebind(0, itemVo, "");
this.this_use_num = Math.min(this.can_use_num, this.had_max_num); //这次最多可使用的数量
this.num = this.this_use_num; // 当前数量
this.setComposeNum(this.num);
this.setBaseAttrList();
}
},
//返回当前阶数最大可使用的数量的配置表
getUseMaxNum: function getUseMaxNum() {
if (this.data == null || this.data.vo == null) return;
var trace_cost_config = gdata("hallows_data", "data_trace_cost", Utils.getNorKey(this.data.id, this.data.vo.step));
if (trace_cost_config) {
return trace_cost_config.num;
}
return 0;
},
setComposeNum: function setComposeNum(num) {
this.num = num;
var percent = this.num / this.this_use_num || 0;
this.slider.progress = percent;
this.s_progress.progress = this.slider.progress;
this.fileNum(num);
},
setComposeNumByPercent: function setComposeNumByPercent(percent) {
this.num = Math.floor(percent * this.this_use_num);
this.fileNum(this.num);
},
fileNum: function fileNum(num) {
if (this.had_max_num == null) return;
this.need_num.string = cc.js.formatStr("%s: %s", nx.text.getKey("HallowsNeed"), num);
},
//设置当前圣印总属性
setBaseAttrList: function setBaseAttrList() {
if (this.cost_config == null || this.attr_config == null) return;
if (this.had_use_num == null) {
this.had_use_num = 0;
}
for (var i in this.attr_list) {
this.attr_list[i].active = false;
}
for (var j in this.attr_config.val) {
var v = this.attr_config.val[j];
var attr_key = v[0];
var attr_val = v[1] * this.had_use_num;
var attr_name = game.configs.attr_data.data_key_to_name[attr_key];
if (attr_name) {
// var attr_icon = PathTool.getAttrIconRes(attr_key);
var attr_str = cc.js.formatStr(" %s +%s", attr_name, attr_val);
var object = this.attr_list[parseInt(j)];
if (object) {
object.active = true;
this.attr_lb_list[parseInt(j)].string = attr_str;
// nx.gui.setSpriteFrame( icon, "", attr_icon );
// object.label.string = attr_str;
}
}
}
},
slideHldEvent: function slideHldEvent(event) {
// this.setComposeNumByPercent(this.slider.progress);
// this.progress.progress = this.slider.progress;
},
onClickLevUp: function onClickLevUp() {
if (this.data) {
if (this.this_use_num == 0) {
nx.tbox("lab_hallows_trace_window_tip3");
this.ctrl.openHallowsTraceWindow(false);
} else {
if (this.num == 0) {
nx.tbox("lab_hallows_trace_window_tip3");
} else {
this.ctrl.requestUseTraceItem(this.data.id, this.num);
}
}
}
},
onClickMax: function onClickMax() {
var percent = this.slider.progress;
if (percent == 1) return;
if (this.this_use_num == 0) return;
if (this.num >= this.this_use_num) return;
this.num = this.this_use_num;
this.setComposeNum(this.num);
},
onClickPlus: function onClickPlus() {
var percent = this.slider.progress;
if (percent == 1) return;
if (this.this_use_num == 0) return;
if (this.num >= this.this_use_num) return;
this.num = this.num + 1;
this.setComposeNum(this.num);
},
onClickMin: function onClickMin() {
var percent = this.slider.progress;
if (percent == 0) return;
if (this.num == 0) return;
if (this.this_use_num == 0) return;
this.num = this.num - 1;
this.setComposeNum(this.num);
}
});
cc._RF.pop();