Files
fc/dev/project/library/imports/1d/1d30bad8-ec42-46a4-b809-311af1c1bf82.js
T

471 lines
12 KiB
JavaScript
Raw Normal View History

2026-05-24 10:21:26 +08:00
"use strict";
cc._RF.push(module, '1d30brY7EJGpLgJMRrxwb+C', 'cmp.shop.item');
// Scripts/mod/shop/cmp/cmp.shop.item.js
"use strict";
var SVCItem = require("nx.fx.sv.expand.item");
var BackPackConst = require("backpack_const");
var TipsController = require("tips_controller");
var BridgeItem = require("bridge.utils.item");
var PathTool = require("pathtool");
var MallController = require("mall_controller");
var data2Icon = require("bridge.utils.item");
var BIST = BackPackConst.item_sub_type;
var limitDesc = {
vip: "tips_vipBuy",
day: "Daily Purchase Limit",
week: "Weekly Purchase Limit",
month: "Monthly Purchase Limit",
count: "Purchase Limit",
none: "msg_bagsMax"
};
var gold = 3;
cc.Class({
"extends": SVCItem,
properties: {
nodBG: {
"default": null,
type: cc.Sprite,
displayName: "品质"
},
nodIcon: {
"default": null,
type: cc.Node,
displayName: "图标"
},
nodCount: {
"default": null,
type: cc.Label,
displayName: "数量"
},
ignoreOne: {
"default": true,
displayName: "忽略单个"
},
lenName: {
"default": 0,
displayName: "名字长度(字节)"
},
nodName: {
"default": null,
type: cc.Label,
displayName: "名字"
},
nodStar: {
"default": null,
type: cc.Node,
displayName: "星级"
},
nodLimit: {
"default": null,
type: cc.Node,
displayName: "限购"
},
nodMat: {
"default": null,
type: cc.Node,
displayName: "购买材料"
},
nodPrice: {
"default": null,
type: cc.Node,
displayName: "价值"
},
nodRate: {
"default": null,
type: cc.Node,
displayName: "折扣"
},
tipSelf: {
"default": true,
displayName: "点击提示"
},
nodSellout: {
"default": null,
type: cc.Node,
displayName: "售罄节点"
},
nodCamp: {
"default": null,
type: cc.Node,
displayName: "售罄节点"
}
},
// 显示
onEnable: function onEnable() {
this.openTip(this.tipSelf);
},
// 数据重置
rebind: function rebind(_idx, _data, _key) {
this._super(_idx, _data, _key);
// 刷新
this.setData(_data);
},
// 聚焦获得
onFocus: function onFocus() {
if (this.nodFocus && nx.dt.objNEmpty(this.info)) {
this.nodFocus.node.active = true;
}
},
// 聚焦失去
outFocus: function outFocus() {
if (this.nodFocus) {
this.nodFocus.node.active = false;
}
},
// 置空
setEmpty: function setEmpty() {
this.outFocus();
this.setQuality(-1);
this.setIcon(0);
this.setCount(0);
this.setName("");
this.setStars(0);
this.setLimit(0);
},
// 重置
setData: function setData(_data, _count) {
if (!_data) {
return;
}
// 必要数据
var info = {
_flag: "",
// 数据来源
id: 0,
// 伙伴序列
order: 0,
// 伙伴序列
bid: 0,
// 伙伴编号
item_id: 0,
// 物品编号
quality: 0,
// 品质
icon: 0,
// 图标
count: 0,
// 数量
name: "",
// 名字
stars: 0,
// 星级
has_buy: 0,
// 已买
camp_type: 0,
// 阵营
type: 0,
// 物品类型
discount: 0,
// 折扣相关
pay_type: "",
// 支付方式
price: 0,
// 价值
limit_count: 0,
limit_vip: 0,
// 会员限制
limit_day: 0,
// 会员限制
limit_week: 0,
// 会员限制
limit_month: 0,
// 会员限制
level: [],
// 等级限制
can_buy: 0 // 可以购买
};
var tfgs = game.configs.item_data.data_assets_id2label;
var dealShow = function dealShow(_txt) {
var icon = 0;
var num = parseInt(_txt);
if (nx.dt.numGood(num)) {
icon = num;
return icon;
}
for (var i in tfgs) {
var item = tfgs[i];
if (item == _txt) {
icon = i;
return icon;
}
}
};
var dealCanbuy = function dealCanbuy(_day, _week, _month, _count, _has_buy) {
var cannotBuy = 0;
if (_day > 0) {
cannotBuy = _has_buy >= _day ? 1 : 0;
}
if (_week > 0) {
cannotBuy = _has_buy >= _week ? 1 : 0;
}
if (_month > 0) {
cannotBuy = _has_buy >= _month ? 1 : 0;
}
if (_count > 0) {
cannotBuy = _has_buy >= _count ? 1 : 0;
}
return cannotBuy;
};
var dealData = function dealData(_dataf) {
info.id = _dataf.id;
info.item_id = _dataf.item_bid || _dataf.item_id;
info.quality = gdata("item_data", "data_unit1", info.item_id).quality || gdata("item_data", "data_unit2", info.item_id).quality || gdata("item_data", "data_unit6", info.item_id).quality || gdata("item_data", "data_unit9", info.item_id).quality;
info.type = _dataf.type || 0;
info.order = _dataf.order || 0;
info.icon = gitemdata(info.item_id).icon;
info.count = _dataf.item_num;
info.name = gitemdata(info.item_id).name;
info.stars = gdata("item_data", "data_unit1", info.item_id).star || gdata("item_data", "data_unit2", info.item_id).name || gdata("item_data", "data_unit6", info.item_id).eqm_jie || 0;
info.has_buy = _dataf.has_buy || 0;
info.pay_type = dealShow(_dataf.pay_type);
info.price = _dataf.price;
info.discount = _dataf.discount;
info.disshow = _dataf.label || _dataf.discount_type;
info.limit_count = _dataf.limit_count || -1;
info.limit_vip = _dataf.limit_vip;
info.limit_day = _dataf.limit_day;
info.limit_week = _dataf.limit_week;
info.limit_month = _dataf.limit_month;
info.level = _dataf.lev;
info.can_buy = dealCanbuy(_dataf.limit_day, _dataf.limit_week, _dataf.limit_month, _dataf.limit_count, _dataf.has_buy || 0);
info.camp_type = gdata("item_data", "data_unit6", info.item_id).type == BackPackConst.item_type.PARTNER_DEBRIS ? cc.path.join("coms/images", "ico_frag") : "";
return info;
};
this.mdata = _data;
// 统一道具信息格式
this.info = dealData(_data);
if (!this.info) {
this.mdata = {};
this.setEmpty();
return;
}
// // 刷新
this.freshAll();
},
// 重置(不定参覆盖)
setDataEx: function setDataEx(_data, _params) {
this.mdata = _data;
// 统一道具信息格式
this.info = BridgeItem.data2Icon(_data);
if (!this.info) {
this.mdata = {};
this.setEmpty();
return;
}
// 不定参覆盖
if (nx.dt.objNEmpty(_params)) {
Object.assign(this.info, _params);
}
// 刷新
this.freshAll();
},
//----------结构
// {bid:xxxx,num:xxxx,config:object}
// 刷新
freshAll: function freshAll() {
// 置空
if (nx.dt.objEmpty(this.info)) {
this.setEmpty();
return;
}
// 基本信息
this.setQuality(this.info.quality);
this.setIcon(this.info.icon);
this.setName(this.info.name);
// 伙伴显示星级 其他显示数量
// if( this.info.sub_type == BIST.HERO ) {
if (this.ignoreOne && this.info.count <= 1) {
this.setCount(0);
this.setStars(this.info.stars || this.info.eqm_jie);
} else {
this.setCount(this.info.count);
this.setStars(this.info.stars);
}
this.setPrice();
this.setLimit();
this.setDiscount();
nx.gui.setSpriteFrame(this.nodCamp, "", this.info.camp_type);
},
// 单设:品质
setQuality: function setQuality(_qa) {
if (this.nodBG) {
var qa = null;
if (nx.dt.numPositive(_qa)) {
qa = cc.path.join("coms/images", "bg_qa" + _qa);
}
nx.gui.setSpriteFrame(this.nodBG, "", qa);
}
},
// 单设:图标
setIcon: function setIcon(_icon) {
if (!this.nodIcon) {
return;
}
// 置空
var icon = _icon + "";
if (nx.dt.strEmpty(icon) || icon == "0") {
nx.gui.setActive(this.nodIcon, "", false);
return;
}
nx.gui.setActive(this.nodIcon, "", true);
// 图标设置
nx.bridge.setIcon(this.nodIcon, "", _icon);
},
// 单设:数量
setCount: function setCount(_count) {
if (!this.nodCount) {
return;
}
var count = parseInt(_count) || 0;
if (this.ignoreOne && count <= 1) {
this.nodCount.string = "";
return;
}
this.nodCount.string = "" + count;
},
// 单设:名字
setName: function setName(_name) {
if (!this.nodName) {
return;
}
var txt = nx.text.getKey(_name);
if (this.lenName > 0) {
txt = nx.dt.strCut(txt, this.lenName);
}
this.nodName.string = txt;
},
// 单设:星级
setStars: function setStars(_stars) {
if (!this.nodStar) {
return;
}
if (!nx.dt.numPositive(_stars, false)) {
nx.gui.setSpriteFrame(this.nodStar, "", null);
return;
}
var path = cc.path.join("coms/images", "star" + _stars);
nx.gui.setSpriteFrame(this.nodStar, "", path);
},
setLimit: function setLimit(_data) {
if (_data == 0) {
nx.gui.setString(this.nodLimit, "desc", "");
nx.gui.setString(this.nodLimit, "txt", "");
nx.gui.setActive(this.nodSellout, "", false);
return;
}
var self = this;
var normal = function normal() {
var cannotBuy = false;
if (self.info.limit_day > 0) {
desc = limitDesc.day;
txt = self.info.has_buy + "/" + self.info.limit_day;
cannotBuy = self.info.has_buy >= self.info.limit_day;
// dcfg = dcfgs[self.index].limit_day;
}
if (self.info.limit_month > 0) {
desc = limitDesc.month;
txt = self.info.has_buy + "/" + self.info.limit_month;
cannotBuy = self.info.has_buy >= self.info.limit_month;
// dcfg = dcfgs[self.index].limit_month;
}
if (self.info.limit_week > 0) {
desc = limitDesc.week;
txt = self.info.has_buy + "/" + self.info.limit_week;
cannotBuy = self.info.has_buy >= self.info.limit_week;
// dcfg = dcfgs[self.index].limit_week;
}
if (cannotBuy) {
desc = limitDesc.none;
txt = "";
// dcfg = "";
nx.gui.setActive(self.nodSellout, "", true);
nx.gui.setString(self.nodLimit, "desc", nx.text.getKey(desc));
nx.gui.setString(self.nodLimit, "txt", "");
return;
}
};
var dealDesc = function dealDesc(_desc, _txt) {
if (self.info.limit_vip > 0) {
normal();
desc = nx.text.format(limitDesc.vip, self.info.limit_vip);
// dcfg = dcfgs[self.index].limit_day;
} else {
normal();
}
};
var desc = "";
var txt = "";
// let dcfgs = MallController.getInstance().getModel().getAllDefault();
var dcfg = 0;
nx.gui.setActive(this.nodSellout, "", false);
if (this.key == "expedition_medal" || this.key == "elite_coin" || this.key == "arena_cent") {
dealDesc(desc, txt);
txt = txt != "" ? txt : "";
}
if (self.info.limit_vip > 0) {
dealDesc(desc, txt);
} else {
if (self.info.limit_count != -1) {
if (self.info.has_buy > 0) {
desc = limitDesc.none;
txt = "";
dcfg = "";
nx.gui.setActive(this.nodSellout, "", true);
} else {
desc = limitDesc.count;
txt = self.info.limit_count;
// dcfg = dcfgs[self.index].limit_day;
}
} else {
dealDesc(desc, txt);
}
}
nx.gui.setString(this.nodLimit, "desc", nx.text.getKey(desc));
nx.gui.setString(this.nodLimit, "txt", txt);
},
setPrice: function setPrice() {
// console.log( "转换显示 " + JSON.stringify( gconfig( "item_data","data_assets_id2label", this.info.pay_type ) ) );
var icon = this.info.pay_type == "gold" ? 3 : parseInt(this.info.pay_type);
nx.gui.setString(this.nodPrice, "", this.info.discount > 0 ? nx.dt.shortCount(this.info.discount) : nx.dt.shortCount(this.info.price));
nx.bridge.setIconS(this.nodMat, "", icon);
},
setDiscount: function setDiscount() {
if (this.info.discount > 0) {
nx.gui.setString(this.nodRate, "rate", "-" + (10 - this.info.disshow) * 10 + "%");
nx.gui.setActive(this.nodRate, "", true);
} else {
nx.gui.setActive(this.nodRate, "", false);
}
},
// 开启详情跳转
openTip: function openTip(_open) {
this.tipSelf = !!_open;
var btn = nx.gui.getComponent(this, "bg", "nx.fx.button");
if (btn) {
btn.lock(!this.tipSelf);
}
},
// 点击
onTouchTip: function onTouchTip() {
var TC = TipsController.getInstance();
if (TC && this.info) {
TC.showItemTips(this.info.item_id);
}
}
});
cc._RF.pop();