Files
fc/dev/project/assets/Scripts/mod/backpack/cmps/cmp.sell.wnd.js
T
2026-05-23 22:10:14 +08:00

125 lines
3.5 KiB
JavaScript

/******************************************************************
*
* 出售界面
*
******************************************************************/
const ItemBase = require( "cmp.item.base" );
const BridgeWindow = require( "bridge.window" );
const SliderProgress = require( "cmp.slider.prog.selector" );
const BackPackConst = require( "backpack_const" );
const BackPackController = require( "backpack_controller" );
const BBC = BackPackConst.Bag_Code;
const BTT = BackPackConst.item_sub_type;
cc.Class( {
extends: BridgeWindow,
properties: {
cmpItem: { default: null, type: ItemBase },
cmpCounter: { default: null, type: SliderProgress },
nodResult: { default: null, type: cc.Node },
},
// 重载:参数打开
onOpenConfigs: function( _params ) {
this.item = _params[ 0 ];
this.config = this.item ? this.item.config : null;
if( !this.item || !this.config ) {
nx.error( "[SELL]出售失败,参数无效!" );
return;
}
// 特殊转换,背包中的装备要走装备库
this.bagCode = _params[ 1 ] || 1;
if( this.bagCode == BBC.BACKPACK &&
( this.config.sub_type == BTT.EQUIPS || this.config.sub_type == BTT.HOLYEQUIPMENT ) ) {
this.bagCode = BBC.EQUIPS;
}
// 重建
this.rebuild();
},
// 重建
rebuild: function() {
// 道具信息
this.cmpItem.setData( this.item );
// 数量范围&&默认
let Bag = BackPackController.getInstance().getModel();
let count = game.configs.item_data.data_unit3[ this.config.id ] ? 1 : Bag.getPackItemNumByBid( this.bagCode, this.config.id );
// 设置滚动条
this.cmpCounter.build( 1, count, count, ( _count ) => {
this.changeCount( _count );
} );
if( game.configs.item_data.data_unit3[ this.config.id ] ){
nx.gui.setActive( this.cmpCounter, "", false );
}else{
// 数量为1不显示计数条
nx.gui.setActive( this.cmpCounter, "", count > 1 );
}
// 计算价格
this.changeCount( count );
},
// 数量改变
changeCount: function( _count ) {
if( this.cur == _count ||
!nx.dt.numPositive( _count, false ) ) {
return;
}
this.cur = _count;
this.cmpItem.setCount( _count );
// 价值信息获取
if( !nx.dt.numPositive( this.price, false ) ) {
if( nx.dt.arrEmpty( this.config.value[ 0 ] ) ) {
nx.error( "[ITEM]售卖失败,价值缺失!", this.config.id );
return;
}
let cost = this.config.value[ 0 ];
this.price = cost[ 1 ];
if( !nx.dt.numPositive( this.price, false ) ) {
nx.error( "[ITEM]售卖失败,价值无效!", this.config.id );
return;
}
let icon = gdata( "item_data","data_unit1", cost[ 0 ] );
// 等价物
nx.bridge.setIcon( this.nodResult, "price/ico", icon.icon );
}
let total = this.cur * this.price;
nx.gui.setString( this.nodResult, "price/txt", Math.floor( total ) );
},
// 点击出售
onTouchSell: function() {
let BagC = BackPackController.getInstance();
let args = {
id: this.item.id,
bid: this.item.base_id,
num: this.cur
};
BagC.sender10522( this.bagCode, [ args ] );
BagC.openItemSellPanel( false );
},
} );