Files
fc/dev/project/assets/Scripts/mod/acts/treasure/cmp/cmp.act.treasure.js
T

320 lines
10 KiB
JavaScript
Raw Normal View History

2026-05-23 22:10:14 +08:00
const BasePage = require( "act.page.base" );
const BackPackController = require( "backpack_controller" );
const TipsController = require( "tips_controller" );
const XSpine = require( "nx.fx.spine" );
const FID = require( "bridge.function.ids" );
/***
*
* 探宝活动
*/
cc.Class({
extends: BasePage,
properties: {
nodReward:{
default: null,
type : cc.Node,
},
nodPeriod: {
default: null,
type : cc.Node,
displayName: "轮次显示"
},
nodMat: {
default: null,
type : cc.Node,
displayName: "材料显示"
},
nodItem: {
default: null,
type : cc.Node
},
nodFocus: {
default: null,
type : cc.Node
},
nodChange: {
default: null,
type : XSpine,
}
},
// 初始化
build: function( _data ) {
this._super( _data );
let chd = this.nodReward.children;
for (let i = 0; i < chd.length; i++) {
let nod = chd[i];
let item = nx.gui.find( nod, "item" );
let nodItem = cc.instantiate( this.nodItem );
nodItem.parent = item;
nx.gui.setActive( nod, "focus", false );
}
this.effect = nx.gui.getComponent( this.nodFocus, "", "nx.fx.spine" );
this.mod.vbind( this, [
[ "treasureInfo", this.freshTreasureInfo.bind( this ) ],
[ "treasurePeriodChange", this.freshTreasurePeriod.bind( this ) ],
] );
// this.mod.reqDailyFChargeData();
},
// 销毁
onDestroy: function() {
// 活动监听解除
if( this.mod ) {
this.mod.vunbind( this );
}
this._super();
},
onEnable: function(){
this.mod.reqTreasureData();
// this.mod.freshTips();
},
freshTreasurePeriod: function( _data ){
if( !_data || nx.dt.objEmpty( _data ) ){
return;
}
if( this.tween ){
this.tween.stop();
}
this.nodChange.load( "resDB/effects/E80044/action", ( _e ) => {
if( !_e ) {
this.nodChange.action( "action", false );
} else {
this.nodChange.stop();
}
} );
let period = _data.period;
let datac = nx.dt.objClone( this.mod.vget( "treasureInfo" ) ) ;
datac.period = period;
datac.reward_list = [];
this.freshTreasureInfo( datac );
},
freshTreasureInfo: function( _data ){
if( !_data || nx.dt.objEmpty( _data ) ){
return;
}
this.index = 0; //当前光环在哪个奖品上
this.nodFocus.position = this.nodReward.children[this.index].position; //初始化光环位置
this.delayTime = 0.3; //开始的时候延迟调用的时间(最小时间间隔)
this.delayTime_max = 1.5; //最大时间间隔
this.addOrSub = false; //增加还是减少的bool值
this.loopCount = 0; //循环次数
this.circleCount = 2; //前面循环的圈数(效果圈,只为效果,和奖品无关)
let setGray = function( _nod,_mat ){
let nod = _nod;
let sp = nx.gui.getComponent( nod, "qa", cc.Sprite );
let isp = nx.gui.getComponent( nod, "icon", cc.Sprite );
let ssp = nx.gui.getComponent( nod, "star", cc.Sprite );
let rt = nx.gui.getComponent( nod, "rt/img", cc.Sprite );
let material = _mat == 1 ? cc.Material.getBuiltinMaterial( '2d-gray-sprite' ) : cc.Material.getBuiltinMaterial( '2d-sprite' ) ;
sp.setMaterial( 0,material );
isp.setMaterial( 0,material );
ssp.setMaterial( 0,material );
rt.setMaterial( 0,material );
}
let BC = BackPackController.getInstance();
let period = _data.period;
this.period = period;
let cfgs = gdata( this.data.config, "data_richanghuodong" );
let cfg = cfgs[period];
let chd = this.nodReward.children;
let mat = gdata( this.data.config, "data_constant" ).prize_item.val[0];
// this.have = BC.getModel().getItemNumByBid( mat );
this.have = _data.num;
for (let i = 0; i < chd.length; i++) {
let nod = chd[i];
let ifg = cfg[ i + 1 + ( period - 1 )*14 ];
let item = nx.gui.find( nod, "item" );
let nodd = nx.gui.find( item, "award" );
nx.gui.setActive( nod, "focus", false );
setGray( nodd, 0 );
let cmp = nx.gui.getComponent( item, "award", "cmp.item.base" );
if( cmp ){
cmp.setData( ifg.items[0] );
}
}
if( nx.dt.arrNEmpty( _data.reward_list ) ){
for (let i = 0; i < _data.reward_list.length; i++) {
let award = _data.reward_list[i];
let nod = nx.gui.find( chd[ ( award.id - (period - 1) * 14 ) - 1 ] );
nx.gui.setActive( nod, "focus", true );
// nx.gui.setActive( nod, "focus", false );
if( nod ){
let item = nx.gui.find( nod, "item" );
let nodd = nx.gui.find( item, "award" );
setGray( nodd, 1 );
}
}
}
nx.tween.fadeOut( this.nodFocus, "", 0.01 );
nx.gui.setString( this.nodPeriod, "txt", nx.text.format( "TreasurePeriod", period ) );
nx.gui.setString( this.nodMat, "count/txt", nx.dt.shortCount( _data.num ) );
let tip1 = nx.gui.getComponent( this, "panel/op/charge/tip", "nx.vb.visible" );
if( tip1 ) {
tip1.setTarget( nx.mTip, this.mod.getTipKey( "rewarddd" ) );
}
// let time = Math.floor( Math.random() * this.nodReward.children.length );
// this.onDoing = false;
// // this.onDoAni( time, 0 );
},
// 播放輪轉動畫
onDoAni: function( _time, _result, _loop ){
this.loopCount = _loop >= 0 ? _loop : this.loopCount;
this.nodFocus.opacity = 156;
this.unscheduleAllCallbacks();
this.effect.load( "resDB/effects/E80043/action", ( _e ) => {
if( !_e ) {
this.effect.action( "action2", true );
} else {
this.effect.stop();
}
} );
this.scheduleOnce(() => {
this.index++;
//循环到最后一个值之后从0开始
if ( this.index >= this.nodReward.children.length ) {
this.index = 0;
}
if( _result > 0 ){
this.delayTime = 0.05;
this.onDoing = true;
}
//当前运行次数++
if ( this.loopCount >= this.nodReward.children.length * this.circleCount && _result > 0 ) {
//加速度,为最大时间间隔/空转之外需要运行的间隔(空转之外需要运行的间隔是一圈+抽奖的结果)
this.delayTime = 0.2;
}
this.loopCount++;
//总的运行次数 = 空转三圈 + 一圈缓冲 + 抽奖结果
this.count = this.nodReward.children.length * ( this.circleCount + 1 ) + _time;
//判断是不是运行完了
// console.log( this.loopCount + "當前的總數" + this.count + "ssss" + _result );
if ( this.loopCount >= this.count && _result > 0 ) {
//隐藏遮罩
this.nodFocus.position = this.nodReward.children[ _result - 1 ].position;
this.effect.load( "resDB/effects/E80043/action", ( _e ) => {
if( !_e ) {
this.effect.action( "action", true );
nx.audio.playSFX( "audios/effects/praycell" );
} else {
this.effect.stop();
}
} );
this.tween = cc.tween( this.nodFocus )
.delay( 1.5 )
.call( ()=>{
this.mod.reqGetTreasure( 1 );
// this.mod.freshTips();
this.onDoing = false;
} )
.start();
return;
} else {
//切换光环位置
this.nodFocus.position = this.nodReward.children[this.index].position;
//重新调用本方法(因为schedule不能动态修改运行间隔时间)
nx.audio.playSFX( "audios/effects/praycell" );
this.onDoAni( _time, _result, this.loopCount );
}
}, this.delayTime, 0); //执行次数为0,实际执行次数为1
},
onTouchTreasure: function(){
if( this.have == 0 ){
let tip = nx.text.getKey( "SummonTimesNotEnough" ) + "," + nx.text.getKey( "GotoCharge" );
nx.mbox( tip, [ "Cancle", "GotoCharge" ], ( _key, _box )=>{
_box.close();
if( _key == 'GotoCharge' ){
nx.bridge.createPanel( "WndPayment", { key: "recharge" } );
}
} );
return;
}
// 正在播動畫
if( this.onDoing ){
nx.tbox( "TreasureDoing" );
return;
}
this.mod.reqGetTreasure( 0, ( _ret, _data ) => {
if( !_ret ) {
nx.tbox( _data );
return;
}
// 本地道具-1
nx.gui.setString( this.nodMat, "count/txt", nx.dt.shortCount( this.have - 1 ) );
// 过程模拟
let num = -( this.nodReward.children.length );
nx.tween.fadeIn( this.nodFocus,"", 0.1 );
this.onDoAni( num/3, ( _data.reward_id - ( ( this.period - 1 ) * 14 ) ), 0 );
} );
},
onTouchHelp: function(){
let TC = TipsController.getInstance();
if( TC ) {
let txt = gdata( this.data.config, "data_rule" )[1];
TC.showTextPanel( txt.name, nx.text.getKey( txt.content ) );
}
},
});