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

402 lines
11 KiB
JavaScript

/******************************************************************
*
* 七日特训
*
******************************************************************/
const ActPopup = require( "act.popup.base" );
const FxSVC = require( "nx.fx.sv.expand" );
const NxTog = require( "nx.fx.togs" );
const ActEvt = require( "action_event" );
const TipsController = require( "tips_controller" );
const ActTrainingMod = require("act.training7.mod");
const PathTool = require("pathtool");
const NxSpine = require("nx.fx.spine");
const FID = require( "bridge.function.ids" );
const themeMod = require( "acts.mod" );
cc.Class( {
extends: ActPopup,
properties: {
roleSp:{
default:null,
type:NxSpine
},
//倒计时
endClock: {
default: null,
type: cc.Node
},
//最终大奖
bestItem: {
default: null,
type: cc.Node
},
itemList: {
default: null,
type: cc.Node
},
fabGift: {
default: null,
type: cc.Node
},
//縂點數
totalScore:{
default:null,
type:cc.Label
},
//分數記錄
score: {
default: null,
type: cc.Node
},
//激活點數
activeSc: {
default: null,
type: cc.Node
},
//點數進度條
scoreBar: {
default: null,
type: cc.ProgressBar
},
DayTogs: {
default: null,
type: cc.Node
},
togGroup:{
default:null,
type:cc.ToggleContainer
},
TaskTogs: {
default: null,
type: NxTog
},
taskList:{
default:null,
type:FxSVC
},
shopNd:{
default:null,
type:cc.Node
},
shopList:{
default:null,
type:cc.Node
},
shopItem:{
default:null,
type:cc.Node
}
},
// 初始化
onLoad: function( ) {
this.mod = ActTrainingMod.getInstance();
this.upstar_data = game.configs.holiday_upstars_data;
this.items = {};
this.buyItems = {};
this.currentDay = 1;
this.initCurrentDay = 1;
this.selectDay = 1;
this.task_type = 0;
this.TaskTogs.posTog = this.onTogTask.bind( this );
},
onOpenConfigs(_params){
this._super( _params );
this.bindInitEvt();
this.TaskTogs.togTo( 0 );
this.bindChain();
this.mod.sender13601();
this.setRoleEft();
},
setRoleEft(){
let role = gdata( this.mod.data.config, "data_constant" ).models_id.desc;
let res_path = PathTool.getSpinePath( role,"show",false);
this.roleSp.load(res_path,(_e)=>{
if(_e){
this.roleSp.stop();
}else{
this.roleSp.action("action1",true);
}
});
},
bindChain(){
let nds = this.DayTogs.children;
for(let i=0;i<nds.length;i++){
let dot = nx.gui.getComponent( nds[i], "tip", "nx.vb.visible" );
if(dot){
if(this.mod.tipKeys()[i]){
let key = this.mod.getTipKey(this.mod.tipKeys()[i]);
dot.setTarget( nx.mTip, key );
}
}
}
},
bindInitEvt(){
//初始化更新
this.bindGEvent( ActEvt.UPDATE_SEVENT_GOAL, this.upSevenGoals.bind( this ) );
//领取奖励
this.bindGEvent( ActEvt.UPDATE_SEVENT_GET, this.getTargetGoal.bind( this ) );
},
onPreClosed(){
//清除旧的
nx.bridge.NodeChidrenDestroy(this.itemList);
if( this.finalGift ) {
this.finalGift.destroy();
}
nx.bridge.NodeChidrenDestroy(this.shopList);
this.finalGift = null;
this.items = {};
this.buyItems = {};
},
close: function() {
this._super();
//判断下是不是要回到openserver
let needShow = cc.sys.localStorage.getItem("needBackOpenServerAct");
if(needShow == 1)
{
//cc.sys.localStorage.removeItem("needBackOpenServerAct")
nx.bridge.createPanel("WndOpenServer");
}
},
onTogDay( _e,_index ){
let day = Number(_index);
if(this.selectDay == day)return;
if(day > this.currentDay){
this.togGroup.toggleItems[(this.selectDay - 1)].isChecked = true;
return nx.tbox("lab_action_seven_goal_window_tip1");
}
this.selectDay = day;
this.upDaysTask();
},
onTogTask( _index ) {
if(this.task_type == _index)return;
this.task_type = _index;
this.upDaysTask();
},
upSevenGoals( data ) {
this.currentDay = data.cur_day;
this.initCurrentDay = data.cur_day;
// this.selectDay = data.cur_day;
nx.gui.setCdTxt( this.endClock, "", data.end_time );
//处理点数奖励
this.upRewardGifts();
//更新点数
this.upScores( data.num );
//更新任務
this.upDaysTask();
//設置解鎖狀態
this.upClockDayBtns();
},
getTargetGoal(data) {
//先排序
let index = 1;
if(data.type == 1){
let limit_list = this.mod.getSevenGoalWelfareList(this.selectDay);
for(let i in limit_list){
if(limit_list[i].goal_id = data.id){
index = i;
break;
}
}
this.mod.updataGoalWelfareList(data.day_type, index, data.status);
this.addScore(data.day_type,data.type,data.id);
}else if(data.type == 2){
let task_list = this.mod.getServerGrowListData(this.selectDay - 1);
for(let j in task_list){
if(task_list[j].goal_id = data.id){
index = j;
break;
}
}
this.mod.updataGrowListData(data.day_type-1, index, data.status);
this.addScore(data.day_type,data.type,data.id);
}else if(data.type == 4){//商店不需要积分
let half_list = this.mod.getHalfGiftList(data.day_type);
index = 1;
for(var i in half_list){
if(half_list[i].day == data.id){
index = i;
break;
}
}
this.mod.updataHalfListData(data.day_type, index, data.status);
}else if(data.type == 5){
this.upRewardGifts();
}
//重新刷新
this.upDaysTask();
},
addScore(day,type,id){
if(!day || !type || !id){
return;
}
let data_list = null;
let goal_data = {};
if(type == 2){
data_list = this.mod.getWalfareGrowUpData(day - 1);
}else{
data_list = this.mod.getWalfareData(day);
}
for(let i in data_list){
if(id == data_list[i].goal_id){
goal_data = data_list[i];
break;
}
}
//刷新分数
let last_score = Number(this.totalScore.string);
this.upScores(last_score + goal_data.award2);
},
upRewardGifts() {
let all_target = this.mod.getBoxRewardData();
for( let i = 0; i < 6; i++ ) {
let data = all_target[ i ];
if( data ) {
let item = this.items[ i ];
if( !item ) {
item = cc.instantiate( this.fabGift );
item.parent = this.itemList;
item.y = 0;
item.scale = 0.8;
this.items[ i ] = item;
}
let cmp = nx.gui.getComponent( item, "", "cmp.item.base" );
if( cmp ) {
cmp.setGoal( data );
cmp.setData( data.award[ 0 ] );
}
}
}
let SevData = all_target[ 6 ];
if( !nx.dt.objEmpty( SevData ) ) {
if( !this.finalGift ) {
this.finalGift = cc.instantiate( this.fabGift );
this.finalGift.parent = this.bestItem;
this.finalGift.x = 0;
this.finalGift.y = 0;
}
let bestCmp = nx.gui.getComponent( this.finalGift, "", "cmp.item.base" );
if( bestCmp ) {
bestCmp.setGoal( SevData );
bestCmp.setData( SevData.award[ 0 ] );
}
}
},
upScores( score ) {
this.totalScore.string = score;
let all_target = this.mod.getBoxRewardData();
// if( nx.dt.objEmpty( all_target ) ){
// return;
// }
for( let i = 0; i < all_target.length; i++ ) {
let nd = nx.gui.find( this.score, String( i + 1 ) );
if( nd ) {
let data = all_target[ i ];
if(!nx.dt.objEmpty(data)){
nx.gui.setString( nd, "exp", data.goal );
if( score >= data.goal ) {
nx.gui.setActive( this.activeSc, String( i + 1 ),true );
}
}
}
}
if( all_target[ 6 ] ){
//總進度
let max_target = all_target[ 6 ].goal;
this.scoreBar.progress = score / max_target;
}
},
upDaysTask(){
this.taskList.node.active = false;
this.shopNd.active = false;
if(this.task_type < 2){//任務列表
this.taskList.node.active = true;
if(this.task_type == 0){//基礎任務
let task_list = this.mod.getServerGrowListData(this.selectDay - 1);
this.mod.sortItemList(task_list);
this.taskList.svcKey = "data_growthtarget";
this.taskList.rebuild(task_list);
}else{//限時任務
let limit_list = this.mod.getSevenGoalWelfareList(this.selectDay);
this.mod.sortItemList(limit_list);
this.taskList.svcKey = "data_welfarecollection";
this.taskList.rebuild(limit_list);
}
}else{//商店
this.shopNd.active = true;
let half_list = this.mod.getWelfareHalfData(this.selectDay);
this.updateShopBuy(half_list);
}
},
upClockDayBtns(){
let cdn = this.DayTogs.children;
for(let i=0;i<cdn.length;i++){
let tog = cdn[i];
if(this.currentDay >= (i+1)){
let off = nx.gui.find(tog,"off");
nx.gui.setActive(off,"lock",false);
}
}
},
updateShopBuy(datas){
for(let i in datas){
let data = datas[i];
let item = this.buyItems[i];
if(!item){
item = cc.instantiate(this.shopItem);
item.parent = this.shopList;
item.y = 0;
this.buyItems[i] = item;
}
let cmp = nx.gui.getComponent(item,"","cmp.act.training7.buy");
cmp.setData(data);
}
},
// 规则说明
onTouchTip: function() {
let TC = TipsController.getInstance();
if( TC ) {
let txt = game.configs.day_goals_data.data_drama_explain[1];
TC.showTextPanel( "tip", txt.desc );
}
},
} );