const BridgeWindow = require( "bridge.window" ); const TaskController = require( "task.mod" ); const FxTogs = require( "nx.fx.togs" ); const FxSVC = require( "nx.fx.sv.expand" ); const TaskEvent = require( "task_event" ); cc.Class({ extends: BridgeWindow, properties: { togMenu: { default: null, type: FxTogs, }, togTaskMenu: { default: null, type: FxTogs, }, nodTaskList : { default: null, type: FxSVC, }, nodTaskContent : { default: null, type: cc.Node, }, nodTaskItem : { default: null, type: cc.Node, }, nodTaskItemDiff : { default: null, type: cc.Node, }, nodTaskPanelMain : { default: null, type: cc.Node, }, nodTaskPanelDiffer : { default: null, type: cc.Node, }, nodTask: { default: null, type: cc.Node }, }, onLoad: function(){ let TC = TaskController.getInstance(); let model = TC.getModel(); let allTask = model.getAllTaskInfo(); let tasks = allTask; nx.gui.hideAllChildren( this.togMenu.node, "" ); for( let i in tasks ) { let task = tasks[i]; // console.log( "任务相关" + JSON.stringify( task ) ); let showTasks = []; for (let t in task ) { let taskc = task[t]; taskc.forEach( _task =>{ if( _task.canshow ){ showTasks.push( _task ); } } ) nx.gui.setActive( this.togMenu.node, ( "item" + i ), showTasks.length > 0 ); } } this.bindGEvent( TaskEvent.UpdateTaskList, this.freshTask.bind( this ) ); this.togMenu.posTog = this.onTogMenu.bind( this ); }, // 重载:参数打开 onOpenConfigs: function( _params ) { // console.log( "參數相關----" + JSON.stringify( _params ) ); let goto = _params; if( goto && goto >= 0 ){ this.togMenu.togTo( goto ); this.onTogMenu( goto ); }else{ let chd = this.togMenu.node.children; for (let c = 0; c < chd.length; c++) { let nod = chd[c]; if( nod.active ){ this.togMenu.togTo( c ); this.onTogMenu( c ); break; } } } }, // 背包切换 onTogMenu: function( _index ) { let idx = parseInt( _index ); let type = 0; switch( ( idx ) ){ case 0 : { type = 10 }; break; case 1 : { type = 1 }; break; case 2 : { type = 9 }; break; case 3 : { type = 0 }; break; } this.selectTwo = idx; this.activeMenu( type ); }, // 背包切换 onTogMenuTask: function( _index ) { this.activeTask( _index ); }, freshTask: function( _data ){ let TC = TaskController.getInstance(); let model = TC.getModel(); let allTask = model.getAllTaskInfo(); let tasks = allTask; nx.gui.hideAllChildren( this.togMenu.node, "" ); for( let i in tasks ) { let task = tasks[i]; let showTasks = []; for (let t in task ) { let taskc = task[t]; taskc.forEach( _task =>{ if( _task.canshow ){ showTasks.push( _task ); } } ) nx.gui.setActive( this.togMenu.node, ( "item" + i ), showTasks.length > 0 ); } // console.log( "任务相关" + i ); } let chd = this.togMenu.node.children; if( this.selectTwo && chd[this.selectTwo].active ){ this.togMenu.togTo( this.selectTwo ); this.onTogMenu( this.selectTwo ); }else{ for (let c = 0; c < chd.length; c++) { let nod = chd[c]; if( nod.active ){ this.togMenu.togTo( c ); this.onTogMenu( c ); break; } } } // this.activeMenu( this.selectOne ); }, activeTask : function( _index ){ let show = 0; let shownext = 0; for (let i = 0; i < this.nodTaskContentc.children.length; i++) { let nod = this.nodTaskContentc.children[i]; if( i == _index ){ let child = nx.gui.find( nod, "on/content" ); child.children.forEach( _chd =>{ if( _chd.mdata.showfirst == 1 ){ this.onTouchTask( _chd ); show++; }else{ if( show == 0 ){ if( _chd.mdata.canshow ){ this.onTouchTask( _chd ); shownext ++; show++; } if( shownext == 0 ){ this.showTaskInfo( _chd ); } } } } ) } } }, // 激活菜单 activeMenu: function( _index ) { let TC = TaskController.getInstance(); if( TC ) { let model = TC.getModel(); let allTask = model.getAllTaskInfo(); this.nodTaskContentc = _index == 0 ? nx.gui.find( this.nodTaskPanelMain, "view/content" ) : nx.gui.find( this.nodTaskPanelDiffer, "view/content" ); this.togTaskMenu = this.nodTaskContentc.getComponent( "nx.fx.togs" ); this.togTaskMenu.posTog = this.onTogMenuTask.bind( this ); // this.togTaskMenu.togTo( 0 ); nx.gui.cleanAllChildren( this.nodTaskContentc ); let show = { mdata : { show : 0 } } this.selectOne = _index; this.freshLst( allTask[ _index + 1 ] ); this.scheduleOnce( ()=>{ this.showTaskInfo( show ); }, 0.2 ); } }, onTouchMenus: function(){ }, freshLst: function( _task ) { this.unscheduleAllCallbacks(); let self = this; let lst = []; let showss = []; let tweens = []; let nodParent = this.selectOne == 0 ? this.nodTaskPanelMain : this.nodTaskPanelDiffer ; for( let i in _task ) { let task = _task[ i ]; let showTasks = []; task.forEach( _task =>{ if( _task.canshow ){ showTasks.push( _task ); } } ) let data = { name: i, task: showTasks, } lst.push( data ); } let setChildren = function( _node ,_task, _t ){ let pnod = _node; let nods = nx.gui.find( _node, "on/content" ); // showss = []; _task.task.sort( ( a, b ) => { return b.finish - a.finish; } ) nx.gui.gocChildren( nods, "", _task.task.length ); // 设置 子任务相关显示 let hideall = 0; for (let i = 0; i < nods.children.length; i++) { let nod = nods.children[i]; let task = _task.task[i]; if( task ){ if( task.finish == 0 ){ hideall++; } nx.gui.setString( nod, "txt", nx.dt.strCut( task.desc, 30 ) ); nx.gui.setActive( nod, "on", task.show == 1 ); nx.gui.setActive( nod, "bg", true ); nx.gui.setString( nod, "lock/txt", task.desc ); task.showfirst = task.finish == 1 ? 1 : 0; nx.gui.setActive( nod, "tip", task.finish == 1 ); nod.mdata = task; nx.gui.setActive( nod, "lock", task.show == 0 ); if( task.show == 1 ){ if( i == 0 ){ showss.push( nod ); } // nx.gui.setActive( nod, "bg", false ); // nx.gui.setActive( nod, "on", true ); // self.showTaskInfo( nod ); // if( task.finish == 1 ){ // self.onTouchTask // } // showFirst = nx.dt.objClone( nod ); } } } }; let nods = []; for (let t = 0; t < lst.length; t++) { let task = lst[t]; if( task.task.length > 0 ){ let nod = this.selectOne == 0 ? cc.instantiate( this.nodTaskItem ) : cc.instantiate( this.nodTaskItemDiff ) ; nod.active = true; let cnt = nx.gui.find( nod, "on/content" ); nod.children.forEach( _nod =>{ nx.gui.setString( _nod, "type/name", task.name ); } ) setChildren( nod, task, t ); nods.push( nod ); } } nx.gui.setActive( nodParent, "empty", nx.dt.arrEmpty( nods ) ); let set = 0; tweens.push( this.nodTaskContentc ) ; for (let n = 0; n < nods.length; n++) { let nodd = nods[n]; nodd.setParent( this.nodTaskContentc ); set++; } nx.gui.setActive( this.nodTaskPanelMain, "", this.selectOne == 0 && set == nods.length ); nx.gui.setActive( this.nodTaskPanelDiffer, "", this.selectOne != 0 ); let cmp = nx.gui.getComponent( this.nodTaskContentc, "", "nx.fx.togs" ); if( cmp ){ cmp.rebuildTogs(); cmp._freshTogShow(); // for (let t = 0; t < tweens.length; t++) { // let tween = tweens[t]; // // nx.tween.fadeIn( tween, "", 0.3 ); // } // nx.tween.fadeIn( this.nodTaskContentc, "", 0.3 ); cmp.togTo( 0 ); // console.log( "刷新聚焦显示 " + show.length ); // self.onTouchTask( showFirst ); } // this.nodTaskContentc.children[0].onTouchTog this.scheduleOnce( ()=>{ for (let s = 0; s < showss.length; s++) { let nod = showss[s]; if( s == 0 ){ nx.gui.setActive( nod, "on", true ); self.onTouchTask( nod ); } } }, 0.1 ); }, showTaskInfo : function( _nod ){ let nod = nx.gui.find( this.nodTask, "info/view/content" ); let nodOp = nx.gui.find( this.nodTask, "ops" ); nx.gui.setActive( this.nodTask, "empty", false ); if( _nod.mdata.show == 1 ){ let task = _nod.mdata; nx.gui.setString( nod, "desc/txt", task.name ); nx.gui.setString( nod, "task/txt2", task.desc ); let awards = nx.gui.find( nod, "awards/rewards" ); // nx.gui.setActive( ) let cmp = awards.getComponent( "cmp.item.layout" ); // 任务子菜单 二级奖励显示 cmp.rebuild( task.commit_rewards ); this.nowTask = task; nx.gui.setActive( nodOp, "go", task.finish == 1 ); nx.gui.setActive( nodOp, "goto", task.finish == 0 && task.skip_id > 0 ); nx.gui.setActive( nod, "awards/finished", task.finish == 2 ); this.go = ()=>{ let id = task.skip_id; // 道具操作跳转 nx.bridge.jumper.jump2Window( id ); this.close(); } this.get = ()=>{ let TC = TaskController.getInstance(); if( TC ) { TC.requestSubmitTask( task.id ); } } nx.gui.setActive( nod, "desc", task.type == 1 ); // console.log( JSON.stringify( _nod.mdata ) + "任务显示信息" ); }else{ let cmp = nx.gui.getComponent( this.nodTaskContentc, "", "nx.fx.togs" ); if( cmp ){ cmp.rebuildTogs(); cmp._freshTogShow(); // for (let t = 0; t < tweens.length; t++) { // let tween = tweens[t]; // // nx.tween.fadeIn( tween, "", 0.3 ); // } // nx.tween.fadeIn( this.nodTaskContentc, "", 0.3 ); cmp.togTo( 0 ); // console.log( "刷新聚焦显示 " + show.length ); // self.onTouchTask( showFirst ); } } }, onTouchGoTo: function(){ nx.dt.fnInvoke( this.go ); }, onTouchGet: function(){ nx.dt.fnInvoke( this.get ); }, onFocusTask: function(){ }, onTouchTask: function( _nod ){ let nod = this.nodTaskContentc; for (let i = 0; i < nod.children.length; i++) { let item = nod.children[i]; let items = nx.gui.find( item, "on/content" ).children; items.forEach( _item =>{ nx.gui.setActive( _item, "on", false ); } ) } nx.gui.setActive( _nod, "on", true ); this.showTaskInfo( _nod ); }, });