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

348 lines
12 KiB
JavaScript

/******************************************************************
*
* 定制页面
*
******************************************************************/
const mod = require( "act.sevencustom.mod" );
const ActPopup = require( "act.popup.base" );
const Payment = require( "payment.mod" );
const TipsController = require( "tips_controller" );
cc.Class( {
extends: ActPopup,
properties: {
nodContent : {default: null, type: cc.Node },
nodCost : { default: null, type: cc.Node },
preItem : { default: null, type: cc.Prefab },
nodTime : { default: null, type: cc.Node }
},
// 初始化
onOpenConfigs: function( _params ) {
this._super( _params );
this.mod = mod.getInstance();
if( !this.mod ){
this.delayClose();
return;
}
let cfgs = gdata( this.mod.data.config, "data_optional_cfg" );
let rewards = gdata( this.mod.data.config, "data_optional_reward" );
let charge = game.configs.charge_data.data_charge_data;
let chd = this.nodCost.children;
let itemnod = this.nodContent.children[0];
this.first = [];
this.second = [];
for (let i in cfgs ) {
let cfg = cfgs[i];
let price = cfg.charge_id > 0 ? Payment.getInstance().fmtPrice( charge[cfg.charge_id].val ) : nx.text.getKey( "Free" );
let nod = chd[cfg.id - 1];
let reward = rewards[i];
let len = Object.keys( reward ).length;
let rewardnod = nx.gui.find( itemnod, "reward" ).children[cfg.id - 1];
rewardnod.children.forEach( _nod => {
nx.gui.setActive( _nod, "", false );
});
for (let u = 0; u < len; u++) {
let rnod = rewardnod.children[u];
nx.gui.setActive( rnod, "", true );
nx.gui.setActive( rnod, "change", false );
nx.gui.setActive( rnod, "cannot", false );
nx.gui.setActive( rnod, "focus", false );
nx.gui.setActive( rnod, "get", false );
nx.gui.setActive( rnod, "canget", false );
}
for (let j in reward ) {
let item = reward[j];
if( j == 1 ){
item.forEach( _item=>{
this.first.push( _item[0] );
} )
}else{
if( j == 2 ){
item.forEach( _item=>{
this.second.push( _item[0] );
} )
}
}
}
// if( u == 0 ){
// this.first.push( )
// }
nx.gui.setString( nod, "txt", price );
nx.gui.setActive( nod, "focus", false );
}
let days = gdata( this.mod.data.config, "data_const" ).act_days.val;
nx.gui.gocChildren( this.nodContent, "", days );
let nods = this.nodContent.children;
for (let n = 0; n < nods.length; n++) {
let nod = nods[n];
nx.gui.setActive( nod, "empty", false );
nx.gui.setString( nod, "day", "0" + ( n + 1 ) );
}
// 视图监听
this.mod.vbind( this, [
[ "sevenCustom", this.freshDayReward.bind( this ) ],
] );
this.mod.reqOptionalGiftData();
// // this.mod.reqBaseData();
// nx.debug( "$ActPage onEnable");
// 获取指定主题信息
},
onEnable: function(){
this.unscheduleAllCallbacks();
},
// 销毁
onDestroy: function() {
// 活动监听解除
if( this.mod ) {
this.mod.vunbind( this );
}
delete this.mod;
this._super();
},
// 倒计时
updateDate: function() {
let txt = nx.bridge.time.cdSimple( this.mod.data.end_time > 0 ? this.mod.data.end_time : 0 );
txt = nx.text.getKey( txt || "已结束" );
nx.gui.setString( this.nodTime, "time", txt );
},
freshDayReward : function( _cdata ){
if( !_cdata || !this.nodContent ){
return;
}
let time = new Date();
let left = this.mod.data.end_time > 0 ? ( this.mod.data.end_time - ( time / 1000 ) ) : 0.1;
nx.gui.setCdTxt( this.nodTime, "time", left, () => {
nx.gui.setString( this.nodTime, "time", nx.text.getKey( "lab_planesafk_main_have_over" ) );
} );
this.custominfo = _cdata;
let chd = this.nodContent.children;
let payed = _cdata.data_list;
let lchd = this.nodCost.children;
// let reward = _cdata.data_list;
for (let p = 0; p < payed.length; p++) {
let nod = lchd[p];
nx.gui.setActive( nod, "focus", false );
nx.gui.setActive( nod, "normal", true );
let cmp = nx.gui.getComponent( nod, "", cc.Button );
if( cmp ){
cmp.interactable = this.custominfo.data_list[p].is_activate == 0 && p != 0;
nx.gui.setOutlineColor( nod, "txt", this.custominfo.data_list[p].is_activate == 0 && p != 0 ? new cc.color( "#b85833" ) : cc.Color.BLACK );
}
}
for (let c = 0; c < chd.length; c++) {
let nod = chd[c];
let cmp = nod.getComponent( "cmp.act.custom.item" );
nx.gui.setActive( nod, "day", c <= ( _cdata.day - 1) );
if( c <= ( _cdata.day - 1) ){
cmp.freshInfo( {
active : true,
day : c,
config : this.mod.data.config,
rewards : payed
} )
}else{
cmp.freshInfo( {
active : false,
day : c,
config : this.mod.data.config,
rewards : payed
} )
}
}
this.setRewardInfo( payed );
this.freshTip( _cdata );
this.setBuyTimes();
},
setRewardInfo : function( _rewards ){
let self = this;
let rewards = _rewards;
for ( let r = 0; r < rewards.length; r++ ) {
let reward = rewards[r].reward_list;
if( nx.dt.arrNEmpty( reward ) ){
reward.forEach( _r =>{
let nod = self.nodContent.children[ _r.day - 1 ];
let status = _r.status;
let rnod = nx.gui.find( nod, "reward" ).children[r];
for (let n = 0; n < rnod.children.length; n++) {
let pnod = rnod.children[n];
let count = 0;
// nx.gui.setActive( pnod, "change", false );
let nodParent = nx.gui.find( pnod, "item" );
if( pnod.active ){
// _r.item_list.sort( ( a, b ) => {
// return a.item_id - b.item_id;
// } )
let rewards = [];
let data = _r.item_list[ pnod.touchId - 1 ];
if( data ){
let nod = cc.instantiate( self.preItem );
// nod.getComponent( "cmp.item.base" ).setDate( data );
let show = {
bid : data.item_id,
num : data.num
}
rewards.push( show );
// nod.name = "item";
// nod.setParent( nodParent );
let cmp = nx.gui.getComponent( nodParent, "", "cmp.common.itemlayout" );
if( cmp ){
// cmp.tipSelf = false;
cmp.rebuild( rewards );
}
nx.gui.setActive( pnod, "tip", false );
}
} //
nx.gui.setActive( pnod, "change", nodParent.children.length > 0 && status == 0 );
nx.gui.setActive( pnod, "focus", false );
nx.gui.setActive( pnod, "canget", rewards[r].is_activate == 1 && _r.day <= this.custominfo.day && nodParent.children.length > 0 && status == 1 );
nx.gui.setActive( pnod, "cannot", status == 3 );
nx.gui.setActive( pnod, "get", status == 2 );
}
let touch = nx.gui.getComponent( rnod, "", cc.Button );
if( touch ){
if( status ){
touch.interactable = status == 1 && rewards[r].is_activate == 1;
}else{
touch.interactable = false;
}
}
// rnod.children.forEach( _nod =>{
// } )
} )
}
}
},
setBuyTimes: function(){
let buyinfo = this.custominfo.data_list;
buyinfo.forEach( _nod =>{
if( _nod.is_activate == 1 ){
}
} )
},
freshTip : function( _data ){
let count = 0;
let self = this;
let day = _data.day;
let list = _data.data_list;
let nod = self.nodContent.children[ _data.day - 1 ];
list.forEach( _item =>{
if( _item.cate == 1 ){
if( !_item.reward_list[ day - 1 ] ){
count++;
}
}
} )
let nods = nx.gui.find( nod, "reward/free" ).children;
nods.forEach( _nod => {
if( _nod.active ){
nx.gui.setActive( _nod, "tip", count++ );
}
} )
// nx.gui.setActive( nods, "reward/free" )
// this.openTip( "reward", count > 0 );
},
onTouchBuy: function( _idx ){
let buyinfo = this.custominfo.data_list;
let count = 0;
let buy = [];
buyinfo.forEach( _nod =>{
if( _nod.is_activate == 1 && _idx == _nod.cate ){
count++;
}
if( _idx == _nod.cate ){
buy = _nod.reward_list;
}
} )
if( count > 0 ){
nx.tbox( "CustomBuyTip" );
return;
}
if( buy.length < this.nodContent.children.length ){
nx.tbox( "ActSevenCustom" );
return;
}
let cfgs = gdata( this.mod.data.config, "data_optional_cfg" );
if( cfgs[_idx].charge_id > 0 ){
let msg = "pay " + cfgs[_idx].charge_id;
Payment.getInstance().reqPayment( cfgs[_idx].charge_id );
}
},
onTouchHelp: function(){
let TC = TipsController.getInstance();
let explain = gdata( this.mod.data.config, "data_desc" )[1];
TC.showTextPanel( explain.name, explain.desc );
},
} );
/**{"day":5,"data_list":[
* {"cate":1,"is_activate":1,"reward_list":[{"day":5,"status":0,"item_list":[{"item_id":11403,"num":1}]},{"day":2,"status":0,"item_list":[{"item_id":11403,"num":1}]}]},
* {"cate":2,"is_activate":0,"reward_list":[]},
* {"cate":3,"is_activate":0,"reward_list":[]},
* {"cate":4,"is_activate":0,"reward_list":[]}]}
/***/