406 lines
10 KiB
JavaScript
406 lines
10 KiB
JavaScript
const SVCItem = require( "nx.fx.sv.expand.item" );
|
|
const BackPackConst = require( "backpack_const" );
|
|
const TipsController = require( "tips_controller" );
|
|
const NXSpine = require( "nx.fx.spine" );
|
|
const { data2Icon } = require( "bridge.utils.item" );
|
|
|
|
const BIST = BackPackConst.item_sub_type;
|
|
|
|
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: "忽略单个" },
|
|
shortCount: { default: false, displayName: "数量简化显示", },
|
|
lenName: { default: 0, displayName: "名字长度(字节)" },
|
|
nodName: { default: null, type: cc.Label, displayName: "名字" },
|
|
nodType: { default: null, type: cc.Label, displayName: "类型" },
|
|
nodDesc: { default: null, type: cc.RichText, displayName: "描述" },
|
|
nodStar: { default: null, type: cc.Node, displayName: "星级" },
|
|
imgLT: { default: null, type: cc.Sprite, displayName: "左上角标" },
|
|
imgRT: { default: null, type: cc.Sprite, displayName: "右上角标" },
|
|
nodFocus: { default: null, type: cc.Sprite, displayName: "聚焦框" },
|
|
spRare: { default: null, type: NXSpine },
|
|
tipSelf: { default: true, displayName: "点击提示" },
|
|
mutexStarCount: { default: true, displayName: "星量互斥" },
|
|
},
|
|
|
|
// 显示
|
|
onEnable: function() {
|
|
|
|
this.openTip( this.tipSelf );
|
|
|
|
},
|
|
|
|
// 数据重置
|
|
rebind: function( _idx, _data, _key ) {
|
|
|
|
this._super( _idx, _data, _key );
|
|
|
|
// 刷新
|
|
this.setData( _data );
|
|
|
|
},
|
|
|
|
// 聚焦获得
|
|
onFocus: function() {
|
|
|
|
if( this.nodFocus &&
|
|
nx.dt.objNEmpty( this.info ) ) {
|
|
this.nodFocus.node.active = true;
|
|
}
|
|
|
|
},
|
|
|
|
// 聚焦失去
|
|
outFocus: function() {
|
|
|
|
if( this.nodFocus ) {
|
|
this.nodFocus.node.active = false;
|
|
}
|
|
|
|
},
|
|
|
|
|
|
// 置空
|
|
setEmpty: function() {
|
|
|
|
this.outFocus();
|
|
this.setQuality( -1 );
|
|
this.setIcon( 0 );
|
|
this.setName( "" );
|
|
this.setDescribe( "" );
|
|
this.setStars( 0 );
|
|
this.freshLT();
|
|
this.freshRT();
|
|
this.setRareEft( 0 );
|
|
nx.gui.setString( this.nodCount, "", "" );
|
|
|
|
},
|
|
|
|
// 重置
|
|
setData: function( _data, _count ) {
|
|
|
|
|
|
this.mdata = _data;
|
|
// 统一道具信息格式
|
|
this.info = _data ? data2Icon( _data ) : null;
|
|
if( !this.info ) {
|
|
this.mdata = {};
|
|
this.setEmpty();
|
|
return;
|
|
}
|
|
|
|
// 数量
|
|
if( nx.dt.numGood( _count ) ) {
|
|
this.info.count = _count;
|
|
}
|
|
|
|
// 刷新
|
|
this.freshAll();
|
|
},
|
|
|
|
// 重置(不定参覆盖)
|
|
setDataEx: function( _data, _params ) {
|
|
|
|
this.mdata = _data;
|
|
|
|
// 统一道具信息格式
|
|
this.info = 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() {
|
|
|
|
// 置空
|
|
if( nx.dt.objEmpty( this.info ) ) {
|
|
this.setEmpty();
|
|
return;
|
|
}
|
|
|
|
// 基本信息
|
|
this.setQuality( this.info.quality );
|
|
this.setIcon( this.info.icon );
|
|
this.setName( this.info.name );
|
|
this.setDescribe( this.info.desc );
|
|
this.setRareEft( this.info.mark );
|
|
|
|
// 星级/数量是否互斥
|
|
if( !this.mutexStarCount ) {
|
|
this.setCount( this.info.count );
|
|
this.setStars( this.info.stars || this.info.eqm_jie );
|
|
}
|
|
else {
|
|
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( 0 );
|
|
}
|
|
}
|
|
|
|
// 角标
|
|
this.freshLT();
|
|
this.freshRT();
|
|
},
|
|
|
|
setRareEft: function( _play ) {
|
|
if( !this.spRare ) return;
|
|
if( _play == 0 ) {
|
|
this.spRare.stop();
|
|
} else if( _play == 1 ) {
|
|
let res_path = PathTool.getSpinePath( "E80048", null, false );
|
|
this.spRare.load( res_path, ( _e ) => {
|
|
if( !_e ) {
|
|
this.spRare.action( "action", true );
|
|
} else {
|
|
this.spRare.stop();
|
|
}
|
|
} );
|
|
}
|
|
},
|
|
|
|
// 单设:品质
|
|
setQuality: function( _qa ) {
|
|
|
|
if( this.nodBG ) {
|
|
let qa = null;
|
|
if( nx.dt.numPositive( _qa ) ) {
|
|
let _show = _qa < BackPackConst.quality.golden ? _qa : BackPackConst.quality.red;
|
|
qa = cc.path.join( "coms/images", "bg_qa" + _show );
|
|
}
|
|
|
|
nx.gui.setSpriteFrame( this.nodBG, "", qa );
|
|
if( !qa ) {
|
|
nx.gui.getComponent( this.nodBG, "", cc.Sprite ).curKey = "";
|
|
}
|
|
}
|
|
|
|
if( this.nodName ) {
|
|
let color = BackPackConst.quality_color( _qa );
|
|
let cur = this.nodName.node.color;
|
|
cur.fromHEX( color );
|
|
this.nodName.node.color = cur;
|
|
}
|
|
|
|
},
|
|
|
|
// 单设:图标
|
|
setIcon: function( _icon ) {
|
|
|
|
if( !this.nodIcon ) {
|
|
return;
|
|
}
|
|
|
|
// 置空
|
|
let 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( _count ) {
|
|
|
|
if( !this.nodCount ) {
|
|
return;
|
|
}
|
|
|
|
let count = parseInt( _count ) || 0;
|
|
if( this.ignoreOne && count <= 1 ) {
|
|
this.nodCount.string = "";
|
|
return;
|
|
}
|
|
|
|
if( this.shortCount ) {
|
|
count = nx.dt.shortCount( count );
|
|
}
|
|
|
|
this.nodCount.string = "" + count;
|
|
|
|
},
|
|
|
|
// 单设:名字
|
|
setName: function( _name ) {
|
|
|
|
if( !this.nodName ) {
|
|
return;
|
|
}
|
|
|
|
let txt = nx.text.getKey( _name );
|
|
if( this.lenName > 0 ) {
|
|
txt = nx.dt.strCut( txt, this.lenName );
|
|
}
|
|
this.nodName.string = txt;
|
|
|
|
},
|
|
|
|
// 单设:描述
|
|
setDescribe: function( _desc ) {
|
|
|
|
if( !this.nodDesc ) {
|
|
return;
|
|
}
|
|
|
|
this.nodDesc.string = nx.text.getKey( _desc );
|
|
},
|
|
|
|
// 单设:星级
|
|
setStars: function( _stars ) {
|
|
|
|
if( !this.nodStar ) {
|
|
return;
|
|
}
|
|
|
|
if( !nx.dt.numPositive( _stars, false ) ) {
|
|
nx.gui.setSpriteFrame( this.nodStar, "", null );
|
|
return;
|
|
}
|
|
|
|
let path = cc.path.join( "coms/images", "star" + _stars );
|
|
nx.gui.setSpriteFrame( this.nodStar, "", path );
|
|
|
|
},
|
|
|
|
// 设置阵营
|
|
setCamp: function( _camp ) {
|
|
|
|
if( !this.imgLT ) {
|
|
return;
|
|
}
|
|
|
|
let sf = cc.path.join( "coms/images/camps" + _camp );
|
|
nx.gui.setSpriteFrame( this.imgLT, "", sf );
|
|
},
|
|
|
|
// 左上角标更新
|
|
freshLT: function() {
|
|
|
|
if( !this.imgLT ) {
|
|
return;
|
|
}
|
|
|
|
let sf = null;
|
|
|
|
// 区别处理
|
|
if( nx.dt.objNEmpty( this.info ) ) {
|
|
|
|
// 伙伴阵营
|
|
if( nx.dt.numPositive( this.info.camp_type, false ) ) {
|
|
this.setCamp( this.info.camp_type );
|
|
return;
|
|
}
|
|
|
|
// 神装类型
|
|
if( !sf && BackPackConst.checkIsHolyEquipment( this.info.type ) ) {
|
|
if( nx.dt.numPositive( this.info.eqm_set, false ) ) {
|
|
let lv = Math.floor( this.info.eqm_set / 100 );
|
|
sf = cc.path.join( "coms/images/eqm_set" + lv );
|
|
}
|
|
}
|
|
|
|
// 精灵等级
|
|
if( !sf && this.info.type == BackPackConst.item_type.ELFIN ) {
|
|
let sfg = gdata( "sprite_data", "data_elfin_data", this.info.item_id );
|
|
if( sfg.skill ) {
|
|
let data = gskilldata( 'data_get_skill', sfg.skill );
|
|
sf = cc.path.join( "coms/images/ico_lv" + data.level );
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
nx.gui.setSpriteFrame( this.imgLT, "", sf );
|
|
|
|
},
|
|
|
|
// 右上角标更新
|
|
freshRT: function() {
|
|
|
|
if( !this.imgRT ) {
|
|
return;
|
|
}
|
|
|
|
|
|
// 区别处理
|
|
let sf = null;
|
|
let ssf = "";
|
|
if( nx.dt.objNEmpty( this.info ) ) {
|
|
|
|
// 碎片展示
|
|
if( !sf && this.info.type == BackPackConst.item_type.PARTNER_DEBRIS ) {
|
|
sf = cc.path.join( "coms/images", "ico_frag" );
|
|
};
|
|
|
|
// 神装评价
|
|
if( !sf && BackPackConst.checkIsHolyEquipment( this.info.type ) ) {
|
|
if( this.info.eqm_jie >= 0 ) {
|
|
let eq = this.info.eqm_jie >= BackPackConst.quality.purple ? BackPackConst.quality.purple : this.info.eqm_jie;
|
|
sf = cc.path.join( "coms/images/eqm_jie" + ( eq + 1 ) );
|
|
}
|
|
}
|
|
|
|
if( this.info.type == BackPackConst.item_type.ProductsGift ) {
|
|
ssf = this.info.desc_client;
|
|
};
|
|
|
|
//雇佣兵
|
|
// if ( !sf && (this.mdata.is_employ || (this.mdata.is_flag == 1)) ) {
|
|
// sf = cc.path.join( "coms/images/assist" );
|
|
// }
|
|
}
|
|
nx.gui.setString( this.imgRT.node.parent, "time/txt", ssf );
|
|
nx.gui.setSpriteFrame( this.imgRT, "", sf );
|
|
nx.gui.setActive( this.imgRT.node.parent, "time", nx.dt.strNEmpty( ssf ) );
|
|
},
|
|
|
|
// 开启详情跳转
|
|
openTip: function( _open ) {
|
|
|
|
this.tipSelf = !!_open;
|
|
|
|
let btn = nx.gui.getComponent( this, "bg", "nx.fx.button" );
|
|
if( btn ) {
|
|
btn.lock( !this.tipSelf );
|
|
}
|
|
|
|
},
|
|
|
|
// 点击
|
|
onTouchTip: function() {
|
|
|
|
const TC = TipsController.getInstance();
|
|
if( TC && this.info ) {
|
|
TC.showItemTips( this.info );
|
|
}
|
|
|
|
},
|
|
|
|
} ); |