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

234 lines
7.5 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 RoleController = require( "role_controller" );
cc.Class({
extends: BasePage,
properties: {
list : { default: null, type: cc.Node },
nodCharge: { default: null, type: cc.Node },
nodNormalCharge: { default: null, type: cc.Node },
video: { default: null,type: cc.VideoPlayer },
nodCtl : { default: null, type: cc.Node },
nodRole : { default: null, type: NxSpine },
nodTitle : { default: null, type: cc.Node },
nodMenus : { default: null, type: NxTogs },
nodRightDesc : { default: null, type: cc.Node },
},
// 初始化
build: function( _data ) {
this._super( _data );
this.charge = 0;
this.normalCharge = 0;
// this.default = 0;
// 无效
if( !this.mod ) {
return;
}
let ccfg = gdata( this.data.config, "data_constant" ).spine_charge.val;
// nx.gui.setActive( this, "op/btn_buy", false );
// nx.gui.setActive( this.video.node.parent, "", false );
this.charge_data = gdata( this.data.config, "data_new_first_charge_data3" ); //game.configs.charge_data.data_new_first_charge_data3;
let fids = [];
this.fidsss = [];
for (let i in this.charge_data) {
let fid = this.charge_data[i];
if( !nx.dt.arrMember( fids, fid.fid ) ){
fids.push( fid.fid );
this.fidsss.push( { fid : fid.fid, cost : fid.desc1, price :fid.desc2, model : fid.desc3 , desc : fid.desc , leftdesc : fid.desc5, rightdesc : fid.desc4 } );
}
}
this.fidsss.sort( Utils.tableLowerSorter( ["fid"] ) );
// fids.sort( );
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 ) ],
] );
nx.gui.gocChildren( this.nodMenus, "", fids.length );
let chd = this.nodMenus.node.children;
for (let c = 0; c < chd.length; c++) {
let nod = chd[c];
let info = this.fidsss[c];
nx.gui.setString( nod, "on/txt", info.desc );
nx.gui.setString( nod, "off/txt", info.desc );
}
// nx.gui.gocChildren( this.nodMenus, "", fids.length );
this.nodMenus.posTog = this.onTogMenu.bind( this );
this.nodMenus.togTo( 0 );
this.onTogMenu( 0 );
let firstop = true;
// let open = nx.storage.get( "openvideovol" + role.rid );
// if( open ){
// firstop = open == 1;
// }
// this.video.volume = firstop ? 0 : 1;
// this.nodCtl.getComponent( cc.Toggle ).isChecked = firstop;
// let desc = firstop ? nx.text.getKey( "ActSeeVideoDefaultTips" ) : nx.text.getKey( "ActSeeVideoOpenTips" ) ;
// nx.gui.setString( this.nodCtl, "tips", desc );
this.mod.reqFirstData();
// this.setMainInfo();
},
// 销毁
onDestroy: function() {
// nx.gui.setActive( this, "op/btn_buy", false );
// nx.gui.setActive( this.video, "", false );
// 活动监听解除
if( this.mod ) {
this.mod.vunbind( this );
}
this._super();
},
onEnable: function(){
},
freshInfos: function( _data ){
if( nx.dt.arrEmpty( _data ) || !_data ) return;
nx.gui.hideAllChildren( this.nodCharge, "cost" );
let rewards = [];
let count = 0;
for (let i = 0; i < _data.length; i++) {
let gift = _data[i];
let cfgc = this.charge_data[ gift.id ];
let award_status = _data[ i ].status;
if( cfgc.fid == this.select ){
if( award_status == 1 || award_status == 2 ){
count++;
}
rewards.push( { cfg: cfgc, status: award_status } );
this.charge = cfgc.desc2;
this.normalCharge = cfgc.desc1;
}
}
// 请求信息
let price = Payment.getInstance().transPrice( this.charge );
let normalPrice = Payment.getInstance().transPrice( this.normalCharge );
let path = "cost/" + "num" + price;
nx.gui.setString( this.nodCharge, path, price );
nx.gui.setActive( this.nodCharge, path, true );
nx.gui.setString( this.nodNormalCharge, "", normalPrice );
rewards.sort( ( a, b ) => {
return a.cfg.day - b.cfg.day;
} );
nx.gui.setString( this, "op/btn_buy/txt", count > 0 ? nx.text.getKey( "Charged" ) : nx.text.getKey( "Buy" ) );
let cmp = nx.gui.getComponent( this, "op/btn_buy", cc.Button );
if( cmp ){
cmp.interactable = ( count == 0 );
}
// nx.gui.setActive( this.video, "", true );
// nx.tween.fadeIn( this, "op/btn_buy", 0.5 );
nx.tween.fadeIn( this, "op/btn_buy", 0.3 );
this.refreshItems( rewards );
// nx.gui.setActive( this.btnBuy, "", is_buy );
},
refreshItems( cur_list ) {
nx.gui.gocChildren( this.list, "", cur_list.length );
for (let i = 0; i < this.list.children.length; i++) {
let nod = this.list.children[i];
let cmp = nx.gui.getComponent( nod, "", "cmp.act.firstcharge.item" );
if( cmp ) {
cmp.rebind( i, cur_list[ i ], this.mod );
}
}
},
onClickBuy() {
let charge_id = null;
for( let i in this.charge_data ) {
if( this.charge_data[ i ].fid == this.select ) {
charge_id = this.charge_data[ i ].need_exp;
break;
}
}
if( charge_id == null ) return;
Payment.getInstance().reqPayment( charge_id );
},
onTouchVideo: function(){
this.video.play();
},
onTouchVolCtl: function( _nod ){
let role = RoleController.getInstance().getRoleVo();
let nod = _nod;
let select = nod.getComponent( cc.Toggle ).isChecked;
let desc = select ? nx.text.getKey( "ActSeeVideoDefaultTips" ) : nx.text.getKey( "ActSeeVideoOpenTips" ) ;
nx.gui.setString( nod, "tips", desc );
this.video.volume = select ? 0 : 1 ;
nx.storage.set( "openvideovol" + role.rid, select ? 1 : 0 );
},
onTogMenu: function( _idx ){
let cfg = this.fidsss[_idx];
this.select = parseInt( _idx ) + 1;
let dataa = this.mod.vget( "firstCharge" );
let model = cfg.model;
this.nodRole.load( "resDB/models/" + model + "/show", ( _e ) => {
if( !_e ) {
this.nodRole.action( "action1", true );
} else {
this.nodRole.stop();
}
} );
let uipath = cc.path.join( "locals/{lang}/images/acts", cfg.rightdesc );
nx.gui.setSpriteFrame( this.nodRightDesc, "", nx.res.fmtPath( uipath ) );
if( nx.dt.strNEmpty( cfg.leftdesc ) ){
let uipath = cc.path.join( "locals/{lang}/images/acts", cfg.leftdesc );
nx.gui.setSpriteFrame( this.nodTitle, "", nx.res.fmtPath( uipath ) );
}else{
nx.gui.setSpriteFrame( this.nodTitle, "", null );
}
this.freshInfos( dataa );
},
});