Files
fc/dev/project/assets/Scripts/mod/acts/stepup/cmp/cmp.act.stepup.gift.item.js
T
2026-05-23 22:10:14 +08:00

86 lines
2.4 KiB
JavaScript

/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* StepUp禮包項
*
* 2018.05.18
******************************************************************/
const SVCItem = require( "nx.fx.sv.expand.item" );
const Payment = require( "payment.mod" );
cc.Class( {
extends: SVCItem,
properties: {
nodRewards: { default: null, type: cc.Node },
fabItem: { default: null, type: cc.Prefab },
nodCount: { default: null, type: cc.Node },
nodOps: { default: null, type: cc.Node },
},
// 设置
setData: function( _data ) {
// 重置
if( !this.data || this.data.id != _data.gift_id ) {
const DATA = game.configs.step_up_recruit_data.data_privilege_data;
this.data = nx.dt.objClone( DATA[ _data.gift_id ] );
this.freshBase();
}
// 次数刷新
this.data.buy_num = _data.buy_num;
this.freshTimes();
},
// 信息刷新
freshBase: function() {
let items = this.data ? this.data.item : [];
for( let i = 0; i < this.nodRewards.children.length; ++i ) {
let node = this.nodRewards.children[ i ];
if( node.children.length == 0 ) {
let item = cc.instantiate( this.fabItem );
item.parent = node;
item.position = cc.v2( 0, 0 );
}
let item = items[ i ];
if( nx.dt.arrEmpty( item ) ) {
node.children[ 0 ].active = false;
continue;
}
node.children[ 0 ].active = true;
let cmp = node.children[ 0 ].getComponent( "cmp.item.base" );
if( cmp ) {
cmp.setData( item[ 0 ], item[ 1 ] );
}
}
// 价格刷新
let price = Payment.getInstance().fmtPrice( this.data.price );
nx.gui.setString( this.nodOps, "buy/txt", price );
},
// 次数刷新
freshTimes: function() {
nx.gui.setString( this.nodCount, "txt", this.data.buy_num );
nx.gui.setActive( this.nodOps, "done", this.data.buy_num <= 0 );
nx.gui.setActive( this.nodOps, "buy", this.data.buy_num > 0 );
},
// 点击购买
onTouchBuy: function() {
Payment.getInstance().reqPayment( this.data.charge_id );
},
} );