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

309 lines
8.7 KiB
JavaScript

/******************************************************************
* Copyright(C) 2019 - 2020 Nx Studio
*
* STEP-UP 打开页
*
******************************************************************/
const BridgeComponent = require( "bridge.component" );
const FxSVC = require( "nx.fx.sv.expand" );
const STModel = require( "act.stepup.mod" );
const SummonDefine = require( "summon.define" );
const MALL = require( "mall_controller" );
const MallConst = require( "mall_const" );
const StepWnd = require( "cmp.act.stepup" );
const StepMax = 25;
const StepLoop = 5;
const STST = SummonDefine.StepUpStage;
cc.Class( {
extends: BridgeComponent,
properties: {
cmpRoot: { default: null, type: StepWnd },
nodBG: { default: null, type: cc.Node },
nodTarget: { default: null, type: cc.Node },
nodRaw: { default: null, type: cc.Node },
taskList: { default: null, type: FxSVC },
nodDate: { default: null, type: cc.Node },
nodRewards: { default: null, type: cc.Node },
},
// 显示
onEnable: function() {
this.configs = STModel.getInstance().getConfig();
// 重建奖励
this.buildRewards();
// 背景图
let path = cc.path.join( "resDB/bigs", this.configs.cfgs.bg || "bg002" );
nx.gui.setSpriteFrame( this.nodBG, "", path );
// 目标名
path = cc.path.join( "resDB/acts/steps", this.configs.cfgs.res_paths, nx.getLocLanguage() + "_role" );
nx.gui.setSpriteFrame( this.nodTarget, "img", path );
// 相关常量
nx.gui.setString( this.nodRewards, "rounds/info/max", StepMax );
// 活动时间
let est = STModel.getInstance().data.end_time;
nx.gui.setString( this.nodDate, "txt", nx.bridge.time.cdSimple( est ) );
// 事件绑定
this.bindGEvent( SummonDefine.StepUpFresh, this.onFreshData.bind( this ) );
this.onFreshData();
},
// 关闭
onDisable: function() {
// 监听事件释放
this.unbindGEvents();
},
// 重建奖励
buildRewards: function() {
// 单设
let single = function( _rd, _node, _info ) {
let icon = nx.gui.getComponent( _node, "", "cmp.item.base" );
if( icon ) {
icon.setData( _info.reward[ 0 ] );
}
nx.gui.setActive( _node, "got", false );
nx.gui.setActive( _node, "get", false );
};
// 奖励
let rewards = this.configs.rewards;
let root = nx.gui.find( this.nodRewards, "items" );
for( let k in rewards ) {
let item = nx.gui.find( root, "item" + k );
single( k, item, rewards[ k ] );
}
},
// 刷新奖励
freshRewards: function() {
// 当前轮次
let data = STModel.getInstance().getData();
let steps = ( ( data.turns * StepLoop ) + data.step ) - 1;
nx.gui.setString( this.nodRewards, "rounds/info/cur", steps );
// 奖励信息
let keys = [ 5, 10, 15, 20, 25 ];
let boxes = nx.gui.find( this.nodRewards, "progs/bar" );
let items = nx.gui.find( this.nodRewards, "items" );
for( let i = 0; i < keys.length; ++i ) {
let k = keys[ i ];
let item = nx.gui.find( items, "item" + k );
let box = nx.gui.find( boxes, "box" + k );
// 未达到
if( k > steps ) {
nx.gui.setActive( item, "get", false );
nx.gui.setActive( item, "got", false );
nx.gui.setColor( box, "tips/txt", cc.Color.WHITE );
continue;
}
let got = nx.dt.arrMember( data.get_reward, null, ( _m ) => {
return _m && _m.turn == k;
} );
nx.gui.setActive( item, "get", !got );
nx.gui.setActive( item, "got", got );
nx.gui.setColor( box, "tips/txt", new cc.color( "#01FFE3" ) );
}
// 进度模拟
let flags = nx.gui.find( this.nodRewards, "progs/flags" );
for( let i = 0; i < flags.children.length; ++i ) {
let dot = flags.children[ i ];
dot.active = ( i < steps );
}
},
// 更新
freshTasks: function() {
let data = STModel.getInstance().getData();
let steps = ( data.turns * StepLoop ) + data.step;
// 重建
let turn = Math.min( data.turns, 4 );
if( nx.dt.arrEmpty( this.steps ) ||
( data.step % StepLoop ) == 1 ) {
this.steps = nx.dt.objClone( this.configs.steps );
for( let i = 0; i < this.steps.length; ++i ) {
this.steps[ i ].step = ( turn * StepLoop ) + i + 1;
}
this.taskList.rebuild( this.steps );
}
let chds = this.taskList.bindSCV.content.children;
for( let i = 0; i < chds.length; ++i ) {
let node = chds[ i ];
if( node && node.svItem ) {
node.svItem.setCurrentStep( steps );
}
}
if( ( data.step % StepLoop ) == 1 ) {
let scv = nx.gui.getComponent( this.taskList, "", cc.ScrollView );
if( scv ) {
this.scheduleOnce( () => {
scv.scrollToTop( 0.5 );
}, 0.1 );
}
}
},
// 数据更新
onFreshData: function( _data ) {
// 召唤次数
let data = STModel.getInstance().getData();
// 活动日期
nx.gui.setActive( this.nodDate, "txt", data.state <= STST.Open );
nx.gui.setActive( this.nodDate, "done", data.state > STST.Open );
// 刷新奖励
this.freshRewards();
// 刷新任务步骤&&显示排行榜
nx.gui.setActive( this, "panel/steps/task", data.state == STST.Open );
nx.gui.setActive( this, "panel/steps/rank", data.state == STST.Complete );
if( data.state == STST.Open ) {
this.freshTasks();
}
},
// 点击获得
onTouchGet: function( _btn ) {
let args = _btn ? _btn.params : {};
if( nx.dt.objEmpty( args ) ) {
return;
}
// 道具不足
if( !args.enough ) {
nx.tbox( "SummonItemNotEnough" );
this.onTouchGift();
return;
}
let data = STModel.getInstance().getData();
if( args.bid == 3 && data.gold_times == 0 ) {
let des = this.configs.diamond_times.desc + nx.text.getKey( "StepUpStepUpTimeNoEnough" );
nx.tbox( des );
return;
}
// 召唤
STModel.getInstance().reqSummon( args.type, ( _ret, _data ) => {
// 失败
if( !_ret ) {
nx.tbox( _data );
this.onTouchGift();
return;
}
// 判空
if( nx.dt.arrEmpty( _data.partner_bids ) ) {
nx.warn( "$Summon:空召唤跳过!" );
return;
}
// 动画
nx.bridge.summonAnimation.doStart();
nx.bridge.summonAnimation.setResult( _data );
} );
},
// 轮次奖励
onTouchTurnReward: function( _key ) {
let turn = parseInt( _key );
if( !nx.dt.numPositive( turn, false ) ) {
return;
}
// 轮次奖励
STModel.getInstance().reqTurnReward( turn, ( _ret, _data ) => {
// 失败
if( !_ret ) {
nx.tbox( _data );
return;
}
console.log( _data );
} );
},
// 积分商城
onTouchScoreShop: function() {
MALL.getInstance().openMallPanel( true, [ MallConst.MallType.SummonShop, 54 ] );
nx.bridge.closePanel( "WndActStepUp" );
},
// 点击助力奖励
onTouchGift: function() {
if( this.cmpRoot && this.cmpRoot.actRoot &&
this.configs && this.configs.cfgs ) {
this.cmpRoot.actRoot.jumpToMenu( this.configs.cfgs.shop_camp_id );
}
},
// 排行榜
onTouchOpenRank: function() {
nx.bridge.createPanel( "WndActStepUpRank" );
},
// 点击规则
onTouchRule: function() {
let data = STModel.getInstance().getData();
if( nx.dt.objEmpty( data ) ) {
return;
}
const DATA = game.configs.step_up_recruit_data;
const camp = DATA.data_desc[ "1" ];
let params = {
desc: camp.desc,
rates: [],
};
const pros = DATA.data_probability[ "10001" ];
for( let i in pros ) {
let t = pros[ i ];
params.rates.push( [
t.name,
t.probability,
] );
}
nx.bridge.createPanel( "WndSummonRateShow", params );
},
} );