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

209 lines
6.5 KiB
JavaScript

/******************************************************************
*
* 開服百抽
*
******************************************************************/
const ActPage = require( "act.page.base" );
const NxSpine = require( "nx.fx.spine" );
const Payment = require( "payment.mod" );
cc.Class({
extends: ActPage,
properties: {
nodRewards: { type: cc.Node, default : null },
spRole : { type: NxSpine, default : null },
nodOp: { type: cc.Node, default : null },
},
// 初始化
build: function( _data ) {
this._super( _data );
// 无效
if( !this.mod ) {
return;
}
// nx.gui.setActive( this.spRole, "", false );
this.spRole.load( "resDB/models/H30083/show", ( _e ) => {
if( !_e ) {
this.spRole.action( "drama1", true );
} else {
this.spRole.stop();
}
} );
// 獲取相關的配置
let cfg = gdata( this.mod.data.config, "data_news_draws_data" );
let count = Object.keys( cfg ).length;
nx.gui.gocChildren( this.nodRewards, "", count );
for (let i in cfg ) {
let info = cfg[i];
let nod = this.nodRewards.children[info.id - 1];
let free = nx.gui.find( nod, "free/buy" );
nx.gui.setActive( nod, "free/focus", false );
nx.gui.setActive( nod, "free/got", false );
nx.gui.setActive( nod, "cost/got", false );
nx.gui.setActive( nod, "cost/focus", false );
nx.gui.setString( nod, "day/txt", info.id < 10 ? "0" + info.id : info.id );
let cmp = nx.gui.getComponent( free, "", "cmp.common.itemlayout" );
if( cmp ){
cmp.rebuild( info.reward );
}
let buy = nx.gui.find( nod, "cost/buy" );
let bcmp = nx.gui.getComponent( buy, "", "cmp.common.itemlayout" );
if( bcmp ){
bcmp.rebuild( info.unlock_reward );
}
}
let charge = gdata( this.mod.data.config, "data_const" ).charge_id;
this.charge_id = charge.val;
let cinfo = game.configs.charge_data.data_charge_data[charge.val];
nx.gui.setString( this.nodOp, "charge/txt", nx.text.format( "NeedPayUnlock", Payment.getInstance().fmtPrice( cinfo.val ) ) );
this.needpay = cinfo.val;
nx.gui.setActive( this.nodOp, "free/tip", false );
nx.gui.setActive( this.nodOp, "charge/tip", false );
// // 活动监听
this.mod.vbind( this, [
[ "HundredDraw", this.freshInfo.bind( this ) ],
] );
/*******
* {"status_list":[
* {"day":10,"status1":0,"status2":0},
* {"day":9,"status1":0,"status2":0},
* {"day":8,"status1":0,"status2":0},
* {"day":7,"status1":0,"status2":0},
* {"day":6,"status1":0,"status2":0},
* {"day":5,"status1":0,"status2":0},
* {"day":4,"status1":0,"status2":0},
* {"day":3,"status1":1,"status2":0},
* {"day":2,"status1":1,"status2":0},
* {"day":1,"status1":1,"status2":0}
* ],"is_charge":0}
*/
},
onEnable: function(){
this.mod.reqBaseData();
},
// 刷新相關的數據顯示 主要包含當前的領取數據
freshInfo: function( _data ){
if( !_data || !this.nodRewards ){
return;
}
let chd = this.nodRewards.children;
this.buyInfo = _data;
let list = _data.status_list;
this.canGetFree = [];
this.canGetPay = [];
for (let i = 0; i < list.length; i++) {
let info = list[i];
let nod = chd[i];
if( info.day == ( i + 1 ) ){
let free = nx.gui.find( nod, "free" );
let cost = nx.gui.find( nod, "cost" );
nx.gui.setActive( free, "focus", info.status1 == 1 );
nx.gui.setActive( cost, "focus", info.status2 == 1 );
nx.gui.setActive( free, "got", info.status1 == 2 );
nx.gui.setActive( cost, "got", info.status2 == 2 );
nx.gui.setActive( cost, "lock", _data.is_charge == 0 );
}
if( info.status1 == 1 ){
this.canGetFree.push( info.day );
}
if( info.status2 == 1 ){
this.canGetPay.push( info.day );
}
}
nx.gui.setActive( this.nodOp, "free/tip", nx.dt.arrNEmpty( this.canGetFree ) );
nx.gui.setActive( this.nodOp, "charge/tip", nx.dt.arrNEmpty( this.canGetPay ) );
nx.gui.setString( this.nodOp, "charge/txt", this.buyInfo.is_charge == 0 ? nx.text.format( "NeedPayUnlock", Payment.getInstance().fmtPrice( this.needpay ) ) : nx.text.getKey( "ActPayGet" ) );
let cmp = nx.gui.getComponent( this.nodOp, "free", cc.Button );
let pcmp = nx.gui.getComponent( this.nodOp, "charge", cc.Button );
if( cmp ){
cmp.interactable = nx.dt.arrNEmpty( this.canGetFree );
}
if( pcmp && this.buyInfo.is_charge == 1 ){
pcmp.interactable = nx.dt.arrNEmpty( this.canGetPay );
}
},
// 點擊免費 打卡領取
onTouchGet: function(){
if( nx.dt.arrEmpty( this.canGetFree ) ){
nx.tbox( "ActHundredGetTip" );
return;
}
if( !this.buyInfo ){
return;
}
let day = this.canGetFree.shift();
let info = {
day : day,
type : 0,
}
this.mod.reqGetDailyReward( info );
},
// 點擊購買
onTouchBuy: function(){
if( !this.buyInfo ){
return;
}
// 判斷當前的禮包購買狀態,若未購買則提示
let self = this;
let ischarge = this.buyInfo.is_charge;
if( ischarge == 0 ){
let tip = nx.text.format( "ActHundredBuyTip", Payment.getInstance().fmtPrice( this.needpay ) );
nx.mbox( tip, [ 'cancel', 'confirm' ], ( _key, _box ) => {
_box.close();
if( _key == "confirm" ) {
// this.reqSummon( _args.type, _times, _args );
Payment.getInstance().reqPayment( self.charge_id );
}
} );
}else{
let day = this.canGetPay.shift();
let info = {
day : day,
type : 1,
}
this.mod.reqGetDailyReward( info );
}
},
});