274 lines
8.4 KiB
JavaScript
274 lines
8.4 KiB
JavaScript
// /******************************************************************
|
|
// *
|
|
// * 首充禮包
|
|
// *
|
|
// ******************************************************************/
|
|
|
|
const BasePage = require( "act.page.base" );
|
|
const NxTogs = require( "nx.fx.togs" );
|
|
const NxSpine = require( "nx.fx.spine" );
|
|
const PathTool = require( "pathtool" );
|
|
const Payment = require( "payment.mod" );
|
|
|
|
const FID_TOP_BG = {
|
|
[ 1 ]: "bg_charge_3_9",
|
|
[ 2 ]: "bg_charge_2_9",
|
|
};
|
|
const FID_CHONG = {
|
|
[ 1 ]: "bg_charge_6",
|
|
[ 2 ]: "bg_charge_7",
|
|
};
|
|
const FID_CURVAL_BG = {
|
|
[ 1 ]: "bg_charge_9",
|
|
[ 2 ]: "bg_charge_8",
|
|
};
|
|
|
|
cc.Class( {
|
|
|
|
extends: BasePage,
|
|
|
|
properties: {
|
|
frontBgs: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
behindBgs: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
togs: {
|
|
default: null,
|
|
type: NxTogs
|
|
},
|
|
topTar: {//頂層標題背景
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
topNd: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
chongTar: {//充字標題背景
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
curTar: {//當前價格背景
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
totalVal: {//原來的總價值
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
curVal: {//當前的價值
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
rechangeVal: {//此時的充值價值
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
list: {
|
|
default: null,
|
|
type: cc.Node
|
|
},
|
|
items: {
|
|
default: [],
|
|
type: [ cc.Node ]
|
|
},
|
|
role1: {
|
|
default: null,
|
|
type: NxSpine
|
|
},
|
|
role2: {
|
|
default: null,
|
|
type: NxSpine
|
|
},
|
|
btnBuy: {
|
|
default: null,
|
|
type: cc.Node
|
|
}
|
|
},
|
|
|
|
// 初始化
|
|
build: function( _data ) {
|
|
|
|
this._super( _data );
|
|
|
|
// 无效
|
|
if( !this.mod ) {
|
|
return;
|
|
}
|
|
|
|
this.charge_data = game.configs.charge_data.data_new_first_charge_data3;
|
|
this.select_index = 1;//fid
|
|
this.togs.posTog = this.onTogMenu.bind( this );
|
|
this.togs.togTo( 0 );
|
|
// 活动监听
|
|
this.mod.vbind( this, [
|
|
[ "firstCharge", this.freshInfos.bind( this ) ],
|
|
] );
|
|
|
|
// 请求信息
|
|
this.setMainInfo();
|
|
},
|
|
|
|
onEnable() {
|
|
let nds = this.togs.togs;
|
|
let idx = 1;
|
|
for( let i = 0; i < nds.length; i++ ) {
|
|
let nd = nds[ i ];
|
|
for( let j in this.charge_data ) {
|
|
if( this.charge_data[ j ].fid == idx ) {
|
|
nx.gui.setString( nd, "off/txt", this.charge_data[ j ].desc );
|
|
nx.gui.setString( nd, "on/txt", this.charge_data[ j ].desc );
|
|
|
|
//tip
|
|
let dot = nx.gui.getComponent( nd, "tip", "nx.vb.visible" );
|
|
if( !dot ) {
|
|
nx.gui.setActive( dot, "", false );
|
|
} else {
|
|
let key = this.mod.getTipKey( this.mod.tipKeys()[ i ] );
|
|
dot.setTarget( nx.mTip, key );
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
idx++;
|
|
}
|
|
|
|
this.scheduleOnce( () => {
|
|
let res_path1 = PathTool.getSpinePath( "H30100", "show", false );
|
|
this.role1.load( res_path1, ( _e ) => {
|
|
if( !_e ) {
|
|
this.role1.action( "action1", true );
|
|
} else {
|
|
this.role1.stop();
|
|
}
|
|
} );
|
|
let res_path2 = PathTool.getSpinePath( "H30099", "show", false );
|
|
this.role2.load( res_path2, ( _e ) => {
|
|
if( !_e ) {
|
|
this.role2.action( "action1", true );
|
|
} else {
|
|
this.role2.stop();
|
|
}
|
|
} );
|
|
}, 0.2 );
|
|
},
|
|
|
|
// 销毁
|
|
onDestroy: function() {
|
|
|
|
// 活动监听解除
|
|
if( this.mod ) {
|
|
this.mod.vunbind( this );
|
|
}
|
|
|
|
this._super();
|
|
},
|
|
|
|
onTogMenu( _index ) {
|
|
this.select_index = _index + 1;
|
|
this.setMainInfo();
|
|
let gfits = this.mod.vget( "firstCharge" );
|
|
this.freshInfos( gfits );
|
|
},
|
|
|
|
freshInfos( _data ) {
|
|
if( nx.dt.arrEmpty( _data ) ) return;
|
|
let cur_list = [];
|
|
let is_buy = false;
|
|
for( let i in this.charge_data ) {
|
|
if( this.charge_data[ i ].fid == this.select_index ) {
|
|
let award_status = 0;
|
|
for( let id in _data ) {
|
|
is_buy = _data[ id ].status == 0;
|
|
if( _data[ id ].id == this.charge_data[ i ].id ) {
|
|
award_status = _data[ id ].status;
|
|
break;
|
|
}
|
|
}
|
|
cur_list.push( { cfg: this.charge_data[ i ], status: award_status } );
|
|
}
|
|
}
|
|
|
|
cur_list.sort( ( a, b ) => {
|
|
return a.cfg.day - b.cfg.day;
|
|
} );
|
|
this.refreshItems( cur_list );
|
|
nx.gui.setActive( this.btnBuy, "", is_buy );
|
|
},
|
|
|
|
refreshItems( cur_list ) {
|
|
nx.bridge.NodeChidrenDestroy(this.list);
|
|
let fab = this.items[ this.select_index - 1 ];
|
|
if( fab ) {
|
|
for( let i = 0; i < cur_list.length; i++ ) {
|
|
let item = cc.instantiate( fab );
|
|
item.parent = this.list;
|
|
item.x = 0;
|
|
let cmp = nx.gui.getComponent( item, "", "cmp.act.firstcharge.item" );
|
|
if( cmp ) {
|
|
cmp.rebind( i, cur_list[ i ], this.mod );
|
|
}
|
|
}
|
|
}
|
|
},
|
|
|
|
setMainInfo() {
|
|
let use_data = null;
|
|
for( let i in this.charge_data ) {
|
|
if( this.charge_data[ i ].fid == this.select_index ) {
|
|
use_data = this.charge_data[ i ];
|
|
break;
|
|
}
|
|
}
|
|
|
|
nx.gui.setActive( this.frontBgs, "1", this.select_index == 1 );
|
|
// nx.gui.setActive(this.behindBgs,"1",this.select_index == 1);
|
|
nx.gui.setActive( this.frontBgs, "2", this.select_index == 2 );
|
|
nx.gui.setActive( this.behindBgs, "2", this.select_index == 2 );
|
|
nx.gui.setActive( this.topNd, "ti1", this.select_index == 1 );
|
|
nx.gui.setActive( this.topNd, "ti2", this.select_index == 2 );
|
|
nx.gui.setActive( this, "tnd1", this.select_index == 1 );
|
|
nx.gui.setActive( this, "tnd2", this.select_index == 2 );
|
|
nx.gui.setActive( this.role1.node, "", this.select_index == 2 );
|
|
nx.gui.setActive( this.role2.node, "", this.select_index == 1 );
|
|
|
|
if( !use_data ) return;
|
|
nx.gui.setSpriteFrame( this.topTar, "", cc.js.formatStr( "prefab/acts/firstcharge/ui/%s", FID_TOP_BG[ this.select_index ] ) );
|
|
nx.gui.setSpriteFrame( this.chongTar, "", cc.js.formatStr( "prefab/acts/firstcharge/ui/%s", FID_CHONG[ this.select_index ] ) );
|
|
nx.gui.setSpriteFrame( this.curTar, "", cc.js.formatStr( "prefab/acts/firstcharge/ui/%s", FID_CURVAL_BG[ this.select_index ] ) );
|
|
let yprice = Payment.getInstance().fmtPrice( use_data.desc1 );
|
|
nx.gui.setString( this.totalVal, "", yprice );
|
|
let cprice = Payment.getInstance().fmtPrice( use_data.desc2 );
|
|
nx.gui.setString( this.curVal, "", cprice );
|
|
// if( this.select_index == 1 ) {
|
|
// this.curVal.color = new cc.Color( 108, 247, 6 );
|
|
// } else {
|
|
// this.curVal.color = new cc.Color( 108, 247, 6 );
|
|
// }
|
|
|
|
//充值总金额
|
|
let total = nx.bridge.vget( "TotalCharge" );
|
|
let show = Payment.getInstance().fmtPrice( total );
|
|
nx.gui.setString( this.rechangeVal, "", show );
|
|
},
|
|
|
|
onClickBuy() {
|
|
let charge_id = null;
|
|
for( let i in this.charge_data ) {
|
|
if( this.charge_data[ i ].fid == this.select_index ) {
|
|
charge_id = this.charge_data[ i ].need_exp;
|
|
break;
|
|
}
|
|
}
|
|
if( charge_id == null ) return;
|
|
if( this.select_index == 1 ) {
|
|
Payment.getInstance().reqPayment( charge_id );
|
|
} else if( this.select_index == 2 ) {
|
|
Payment.getInstance().reqPayment( charge_id );
|
|
}
|
|
},
|
|
} ); |