379 lines
10 KiB
JavaScript
379 lines
10 KiB
JavaScript
|
|
"use strict";
|
||
|
|
cc._RF.push(module, 'f92fcnvzipH/5AKBV+hXc2C', 'cmp.summon.crystal.shop.item');
|
||
|
|
// Scripts/mod/summon/crystal/cmp.summon.crystal.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 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: "星级"
|
||
|
|
},
|
||
|
|
nodMat: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Node,
|
||
|
|
displayName: "购买材料"
|
||
|
|
},
|
||
|
|
nodPrice: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Node,
|
||
|
|
displayName: "价值"
|
||
|
|
},
|
||
|
|
tipSelf: {
|
||
|
|
"default": true,
|
||
|
|
displayName: "点击提示"
|
||
|
|
},
|
||
|
|
nodCamp: {
|
||
|
|
"default": null,
|
||
|
|
type: cc.Node,
|
||
|
|
displayName: "售罄节点"
|
||
|
|
},
|
||
|
|
nodLeft: {
|
||
|
|
"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,
|
||
|
|
// 可以购买
|
||
|
|
left: "" // 左上标
|
||
|
|
};
|
||
|
|
|
||
|
|
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;
|
||
|
|
info.type = _dataf.type || 0;
|
||
|
|
info.order = _dataf.order || 0;
|
||
|
|
info.icon = gdata("item_data", "data_unit1", info.item_id).icon || gdata("item_data", "data_unit2", info.item_id).icon || gdata("item_data", "data_unit6", info.item_id).icon || gdata("item_data", "data_unit7", info.item_id).icon;
|
||
|
|
info.count = _dataf.item_num;
|
||
|
|
info.name = _dataf.item_name || gdata("item_data", "data_unit1", info.item_id).name || gdata("item_data", "data_unit2", info.item_id).name || gdata("item_data", "data_unit6", 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.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") : "";
|
||
|
|
info.left = _dataf.camp ? cc.path.join("coms/images", "camps" + _dataf.camp) : "";
|
||
|
|
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);
|
||
|
|
if (this.nodLeft) {
|
||
|
|
nx.gui.setSpriteFrame(this.nodLeft, "", this.info.left);
|
||
|
|
}
|
||
|
|
},
|
||
|
|
// 单设:品质
|
||
|
|
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) {},
|
||
|
|
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 ? this.info.discount : this.info.price);
|
||
|
|
nx.bridge.setIconS(this.nodMat, "", icon);
|
||
|
|
},
|
||
|
|
setDiscount: function setDiscount() {},
|
||
|
|
// 开启详情跳转
|
||
|
|
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();
|