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

647 lines
21 KiB
JavaScript

const BridgeWindow = require( "bridge.window" );
const NxSpine = require( "nx.fx.spine" );
const Mod = require( "act.dailytreasure.mod" );
const ItemBase = require( "cmp.item.base" );
const themeMod = require( "acts.mod" );
const FxTogs = require( "nx.fx.togs" );
const BackPackController = require( "backpack_controller" );
const FID = require( "bridge.function.ids" );
const TipsController = require( "tips_controller" );
const ActPopup = require( "act.popup.base" );
const NormalLen = 56;
const TotalLen = 156;
cc.Class({
extends: ActPopup,
properties: {
nodMenu : { default: null, type : FxTogs },
nodShow : { default: null, type: cc.Node },
nodTask : { default: null, type: cc.Node },
spRole: { default: null, type: NxSpine },
sppRole: { default: null, type: NxSpine },
nodRewards : { default: null, type: cc.Node },
nodRewardsR : { default: null, type: cc.Node },
nodRight : { default: null, type: cc.Node },
nodProg: { default: null, type: cc.Node },
nodTimes : { default: null, type: cc.Node },
nodEndTimes : { default: null, type: cc.Node },
nodJump : { default: null, type: cc.Toggle },
nodMat : { default: null, type: cc.Node },
// E90901
},
// 初始化
onOpenConfigs: function( _params ) {
this._super( _params );
this.mod = Mod.getInstance();
// 无效
if( !this.mod ) {
this.delayClose();
return;
}
this.spRole.load( "resDB/models/H30102/H30102", ( _e ) => {
if( !_e ) {
this.spRole.action( "stand2", true );
} else {
this.spRole.stop();
}
} );
this.sppRole.load( "resDB/models/H30019/show", ( _e ) => {
if( !_e ) {
this.sppRole.action( "action1", true );
} else {
this.sppRole.stop();
}
} );
// this.periods_num = gdata( this.mod.data.config, "data_const" ).periods_num ;
// Tog监听
let period = this.mod.vget( "dailySPrayTask" );
let rewards = gdata( this.mod.data.config, "data_reach_reward" )[period.period] ;
this.cfg = gdata( this.mod.data.config, "data_base_info" )[period.period] ;
this.tasks = gdata( this.mod.data.config, "data_day_task_list" )[period.period];
let mat = this.cfg.loss_item_once[0][0];
this.nodMenu.posTog = this.onTogMenu.bind( this );
this.nodMenu.togTo( 1 );
this.onTogMenu( 1 );
let mcmp = nx.gui.getComponent( this.nodMat, "", "bridge.binder.item.icon.count" );
if( mcmp ){
mcmp.setID( mat );
}
let reachs = [];
for (let i in rewards ) {
let reward = rewards[i];
reachs.push( reward );
}
this.reaches = reachs;
let time = new Date();
let showtime = this.mod.data.end_time - ( time / 1000 );
nx.gui.setCdTxt( this.nodEndTimes, "time", showtime );
this.showRewards = reachs;
let chd = this.nodRewards.children;
for (let r = 0; r < reachs.length; r++) {
let reach = reachs[r];
let nod = chd[r];
if( nod ){
let cmp = nx.gui.getComponent( nod, "box", "cmp.common.itemlayout" );
if( cmp ){
cmp.rebuild( reach.reward );
}
nx.gui.find( nod, "can/get" ).zIndex = reach.id;
nx.gui.setActive( nod, "can", false );
nx.gui.setString( nod, "point", reach.num );
nx.gui.setActive( nod, "boxopen", false );
}
}
this.onShowRewards();
// 活动监听
this.mod.vbind( this, [
[ "dailyStarPrayData", this.freshInfo.bind( this ) ],
] );
this.mod.reqBaseData();
// this.setTask();
},
onEnable: function(){
},
// 销毁
onDestroy: function() {
// 活动监听解除
if( this.mod ) {
this.mod.vunbind( this );
}
delete this.mod;
this._super();
},
/** {"free_end_time":0,"draw_times":0,"gold_times":20,"luck_num":0,"ids":[],"log_info":[]}*/
freshInfo: function( _data ){
if( _data ){
let luck_num = _data.luck_num;
let free_time = _data.free_end_time;
let left = this.diamond_times - _data.gold_times;
this.leftDia = left ;
// this.records = _data.log_info;
// nx.gui.setString( this.nodTimes, "txt", _data.draw_times );
nx.gui.setString( this.nodEndTimes, "times/num", left );
nx.gui.setString( this.nodEndTimes, "times/all", this.diamond_times );
this.nodJump.isChecked = _data.is_skip == 1;
this.skip = _data.is_skip == 1;
this.setProg( luck_num );
let time = new Date();
let showtime = free_time - ( time / 1000 );
let nodd = nx.gui.find( this.nodRight, "ops/once/time" );
nx.gui.setCdTxt( nodd, "ttime", showtime );
this.dealOp();
this.dealReachRewards( _data.ids );
this.index = -1; //当前光环在哪个奖品上
// 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; //前面循环的圈数(效果圈,只为效果,和奖品无关)
}
},
onShowRewards: function(){
let period = this.mod.vget( "dailySPrayTask" );
let rewards = gdata( this.mod.data.config, "data_reward_info" )[period.period] ;
let chd = this.nodRewardsR.children;
for (let i in rewards ) {
let reward = rewards[i];
let id = reward.point;
let nod = chd[id - 1];
// { bid, num }
let shows = {
bid : reward.item_id,
num : reward.num,
info : reward.id,
}
let cmp = nx.gui.getComponent( nod, "item", ItemBase );
if( cmp ){
cmp.setData( shows );
}
let level = 0;
switch( reward.level_name ){
case "A" : { level = 2 };break;
case "B" : { level = 3 };break;
case "S" : { level = 4 };break;
}
let ico = "prefab/acts/starskyprayer/ui/starskyprayer_0" + level;
nx.gui.setSpriteFrame( nod, "icor", ico );
nx.gui.setActive( nod, "focus", false );
}
},
setProg: function( _num ){
// 右上角 幸運值 相關顯示
let lucknod = nx.gui.find( this.nodTimes, "times/num" );
nx.gui.setString( lucknod, "", _num );
let showval = 0;
switch( _num ){
case 200 : showval = 300 ; break;
}
let bar = nx.gui.getComponent( this.nodProg, "", cc.ProgressBar );
if( bar ){
bar.progress = _num / ( bar.totalLength - 100 );
}
},
dealReachRewards : function( _reds ){
// ids":[{"id":7,"status":0},{"id":6,"status":0},{"id":5,"status":0},{"id":4,"status":0},{"id":3,"status":0},{"id":2,"status":0},{"id":1,"status":2}]
let ids = _reds;
if( _reds ){
let chd = this.nodRewards.children;
for ( let i = 0; i < ids.length; i++ ) {
let dataa = ids[i];
let nod = chd[ dataa.id - 1 ];
nx.gui.setActive( nod, "can", dataa.status == 1 );
nx.gui.setActive( nod, "boxopen", dataa.status == 2 );
// nx.gui.setActive( nod, "box", dataa.status == 1 || dataa.status == 0 );
nx.gui.setActive( nod, "box", true );
}
}
},
// 處理 操作以及材料顯示
dealOp: function(){
if( !this.cfg ){
return;
}
this.useItemF = false;
this.useItemT = false;
let mat = this.cfg.loss_item_once[0][0];
let needmatf = this.cfg.loss_item_once[0][1];
let needmatt = this.cfg.loss_item_ten[0][1];
let model = BackPackController.getInstance().getModel();
let have = model.getItemNumByBid( mat );
this.havemat = have;
this.needMatT = needmatt;
this.needMatF = needmatf;
this.name = gitemdata( mat );
let once = nx.gui.find( this.nodRight, "ops/once" );
let ten = nx.gui.find( this.nodRight, "ops/ten" );
nx.gui.setActive( once, "mat", true );
nx.gui.setActive( once, "time", false );
// 当拥有的材料数量不小于10个时
if( have >= needmatt ){
nx.bridge.setIconS( once, "mat/icon", mat );
nx.bridge.setIconS( ten, "mat/icon", mat );
nx.gui.setString( once, "mat/neednum", "X" + needmatf );
nx.gui.setString( ten, "mat/neednum", "X" + needmatt );
this.useItemF = true;
this.useItemT = true;
// dealUseDia();
}else{
// 当材料可以 1抽
if( have >= needmatf ){
nx.bridge.setIconS( once, "mat/icon", mat );
nx.bridge.setIconS( ten, "mat/icon", mat );
nx.gui.setString( once, "mat/neednum", "X" + needmatf );
nx.gui.setString( ten, "mat/neednum", "X" + needmatt );
this.useItemF = true;
this.useItemT = false;
}else{
nx.bridge.setIconS( once, "mat/icon", mat );
nx.bridge.setIconS( ten, "mat/icon", mat );
nx.gui.setString( once, "mat/neednum", "X" + needmatf );
nx.gui.setString( ten, "mat/neednum", "X" + needmatt );
this.useItemF = false;
this.useItemT = false;
}
}
},
// 打開 記錄
onTouchRecord: function(){
this.mod.reqStarPrayRecord( ( _ret, _data )=>{
if( !_ret ){
return;
}
nx.bridge.createPanel( "WndActStarSkyPrayRecords", _data );
} )
},
//
onTouchShop: function(){
let shopInfo = gdata( this.mod.data.config, "data_shop_info" ) ;
nx.bridge.createPanel( "WndActStarSkyPrayShop", shopInfo );
},
// 播放輪轉動畫
onDoAni: function( _time, _result, _loop, _usetype ){
let result = _result[0];
if( this.tween ){
this.tween.stop();
}
let period = this.mod.vget( "dailySPrayTask" );
let ggid = period.period;
this.loopCount = _loop >= 0 ? _loop : this.loopCount;
this.usetype = _usetype;
// this.nodFocus.opacity = 156;
let num = 0;
for (let i = 0; i < this.nodRewardsR.children.length; i++) {
let nod = this.nodRewardsR.children[i];
let cmp = nx.gui.getComponent( nod, "item", ItemBase );
if( cmp ){
if( cmp.mdata.info == result.id ){
// nx.gui.setActive( nod, "focus", true );
num = i;
}
}
}
let all = num + 3 * this.nodRewardsR.children.length;
this.unscheduleAllCallbacks();
let self = this;
this.scheduleOnce(() => {
this.index++;
//循环到最后一个值之后从0开始
if ( this.index >= this.nodRewardsR.children.length ) {
this.index = 0;
}
if( this.loopCount > 0 ){
this.delayTime = 0.05;
this.onDoing = true;
}
//当前运行次数++
if ( this.loopCount >= this.nodRewardsR.children.length * this.circleCount && _result > 0 ) {
//加速度,为最大时间间隔/空转之外需要运行的间隔(空转之外需要运行的间隔是一圈+抽奖的结果)
this.delayTime = 0.20;
}
this.loopCount++;
if( this.loopCount > all ){
this.loopCount = all ;
}
//总的运行次数 = 空转三圈 + 一圈缓冲 + 抽奖结果
this.count = this.nodRewardsR.children.length * ( this.circleCount + 1 ) + _time;
//判断是不是运行完了
if ( this.loopCount >= all && result.id > 0 ) {
for (let i = 0; i < this.nodRewardsR.children.length; i++) {
let nod = this.nodRewardsR.children[i];
let cmp = nx.gui.getComponent( nod, "item", ItemBase );
if( cmp ){
if( cmp.mdata.info == result.id ){
nx.gui.setActive( nod, "focus", true );
nx.audio.playSFX( "audios/effects/praycell" );
nod = nod;
}else{
nx.gui.setActive( nod, "focus", false );
}
}
// nx.gui.setActive( nod, "focus", false );
}
//隐藏遮罩
this.tween = cc.tween( this.node )
// .delay( 0.3 )
// .call( ()=>{
// } )
.delay( 0.5 )
.call( ()=>{
let nowresult = _result.shift();
if( !nowresult || nx.dt.arrEmpty( _result ) ){
let dataa = {
group_id : ggid,
type : self.usetype,
id : 0
}
self.mod.reqGetStarPrayRewardData( dataa );
self.onDoing = false;
for (let i = 0; i < this.nodRewardsR.children.length; i++) {
let nod = this.nodRewardsR.children[i];
let cmp = nx.gui.getComponent( nod, "item", ItemBase );
if( cmp ){
nx.gui.setActive( nod, "focus", false );
}
}
return;
}
for (let i = 0; i < this.nodRewardsR.children.length; i++) {
let nod = this.nodRewardsR.children[i];
let cmp = nx.gui.getComponent( nod, "item", ItemBase );
if( cmp ){
nx.gui.setActive( nod, "focus", false );
}
}
this.onDoAni( _time, _result, 0, self.usetype );
this.onDoing = false;
} )
.start();
return;
} else {
//切换光环位置
for (let i = 0; i < this.nodRewardsR.children.length; i++) {
let nod = this.nodRewardsR.children[i];
nx.gui.setActive( nod, "focus", false );
}
nx.gui.setActive( this.nodRewardsR.children[this.index], "focus", true );
//重新调用本方法(因为schedule不能动态修改运行间隔时间)
nx.audio.playSFX( "audios/effects/praycell" );
this.onDoAni( _time, _result, this.loopCount, self.usetype );
}
}, this.delayTime, 0 ); //执行次数为0,实际执行次数为1
},
onTouchPray: function( _idx ){
let self = this;
let times = parseInt( _idx );
let period = this.mod.vget( "dailySPrayTask" );
let ggid = period.period;
// if( this.havemat > )
// if( this.useFree )
if( times == 1 )
{
if( this.havemat < this.needMatF ){
let name = this.name ? this.name.name : "";
let str = nx.text.format( "ActDailyTreasureBuyTip", name );
nx.mbox( str, [ 'cancel', 'Goto' ], ( _key, _box ) => {
_box.close();
if( _key == "Goto" ) {
self.nodMenu.togTo( 0 );
self.onTogMenu( 0 );
}
} );
// nx.tbox( "PrayDiaTimesLimit" );
return;
}else{
}
}else{
if( this.havemat < this.needMatT ){
let name = this.name ? this.name.name : "";
let str = nx.text.format( "ActDailyTreasureBuyTip", name );
nx.mbox( str, [ 'cancel', 'Goto' ], ( _key, _box ) => {
_box.close();
if( _key == "Goto" ) {
self.nodMenu.togTo( 0 );
self.onTogMenu( 0 );
}
} );
// nx.tbox( "PrayDiaTimesLimit" );
return;
}
}
let str = nx.text.format( "elfin_hatch_unlock_6", nx.text.getKey( "Dia" ) );
let usetype = 0;
// 正在播動畫
if( this.onDoing ){
nx.tbox( "DailyDiaDoing" );
return;
}
this.unscheduleAllCallbacks();
if( times == 1 ){
if( this.useItemF ){
usetype = 4;
}
}else{
if( this.useItemT ){
usetype = 4;
}
}
let dataa = {
group_id : ggid,
times : times,
}
this.mod.reqGetStarPray( dataa, ( _ret, _data ) => {
// console.log( "當前的返回相關" + JSON.stringify( _data ) );
if( !_ret ) {
nx.tbox( _data );
return;
}
// {"flag":1,"msg":"","item_id":[{"id":102}]}
// 本地道具-1
// nx.gui.setString( this.nodMat, "count/txt", nx.dt.shortCount( this.have - 1 ) );
// 过程模拟
let num = -( this.nodRewardsR.children.length );
// nx.tween.fadeIn( this.nodFocus,"", 0.1 );
let self = this;
this.finalResult = _data.item_id;
if( this.skip || times == 10 ){
let dataa = {
group_id : ggid,
type : usetype,
id : 0
}
self.onDoing = false;
self.mod.reqGetStarPrayRewardData( dataa );
return;
}
// this.schedule( dealPlay, _data.item_id.length, cc.macro.REPEAT_FOREVER );
this.onDoAni( num/3, _data.item_id, 0, usetype );
// dealPlay();
} );
},
onTouchGetReach: function( _btn ){
this.mod.reqGetStarReachReward( _btn.zIndex );
},
onTouchJump: function(){
let jump = this.nodJump.isChecked;
// this.mod.reqGetStarReachReward( _btn.zIndex );
this.mod.reqSetStatus( jump );
},
onTouchHelp: function(){
let explain = gdata( this.mod.data.config, "data_explain" )[1];
let prob = gdata( this.mod.data.config, "data_prob_info" );
let probs = [];
for (let i in prob ) {
let pro = prob[i];
probs.push( pro );
}
let ruleinfo = {
desc : explain.desc,
prob : probs,
mod : this.mod
}
nx.bridge.createPanel( "WndActStarSkyPrayRule", ruleinfo );
},
onTogMenu: function( _idx ){
let id = parseInt( _idx );
nx.gui.setActive( this.nodShow, "", id == 1 );
nx.gui.setActive( this.nodTask, "", id == 0 );
let mat = this.cfg.loss_item_once[0][0];
let model = BackPackController.getInstance().getModel();
this.havemat = model.getItemNumByBid( mat );
if( id == 1 ){
this.mod.reqBaseInfo();
}else{
this.mod.reqBaseData();
let time = new Date();
let showtime = this.mod.data.end_time - ( time / 1000 );
nx.gui.setCdTxt( this.nodEndTimes, "time", showtime );
}
},
setTask: function(){
let cmp = nx.gui.getComponent( this.nodTask, "", "act.dailytreasure.task" );
if( cmp ){
cmp.setCfg( this.tasks );
}
},
});