/****************************************************************** * * 任务主界面 * ******************************************************************/ const BridgeWindow = require( "bridge.window" ); const FxTogs = require( "nx.fx.togs" ); const TaskController = require( "task.mod" ); const TaskEvent = require( "task_event" ); cc.Class( { extends: BridgeWindow, properties: { togMenu: { default: null, type: FxTogs, }, togMenuTask: { default: null, type: FxTogs, }, togMenuTaskInfo: { default: null, type: FxTogs, }, nodEmpty: { default: null, type: cc.Node }, nodTask: { default: null, type: cc.Node }, nodOp: { default: null, type: cc.Node } }, onLoad: function() { this.bindGEvent( TaskEvent.UpdateTaskList, this.freshTask.bind( this ) ); // Tog监听 this.togMenu.posTog = this.onTogMenu.bind( this ); this.togMenu.togTo( 0 ); this.activeMenu( 0 ); this.togMenuTask.posTog = this.onTogMenuTask.bind( this ); this.togMenuTaskInfo.posTog = this.onTogMenuTaskInfo.bind( this ); }, // 重载:参数打开 onOpenConfigs: function( _params ) { }, onEnable: function() { // 视图监听 this.vbind( [ [ "TaskInfo", this.onTaskShow.bind( this ) ] ] ); }, onDisable: function(){ this.vunbind(); }, freshTask: function() { // {"id":10001,"name":"指挥官在梦境中遇到了神秘女子,增长了见闻","lev":1,"type":1,"group":0,"group_desc":"第1章","desc":"角色升到10级","progress":[{"cli_label":"evt_levup","target":0,"target_val":10,"param":[],"value":10,"finish":1}],"extra":[],"commit_rewards":[],"res":"","finish":2,"show":1} this.activeMenu( this.selectOne ); this.activeMenuTask( this.selectTwo ); }, freshLst: function( _task ) { let lst = []; for( let i in _task ) { let task = _task[ i ]; let data = { name: i, task: task, } lst.push( data ); } // console.log( JSON.stringify( lst ) + "当前的任务数据" + JSON.stringify( _task ) ); nx.gui.gocChildren( this.togMenuTask, "", lst.length ); let num = 0; let ccount = 0; let hideall = 0; let chd = this.togMenuTask.node.children; for( let i = 0; i < lst.length; i++ ) { let task = lst[ i ]; // 设置相关 任务章节名称 nx.gui.setString( chd[ i ], "on/type/name", task.name ); nx.gui.setString( chd[ i ], "off/type/name", task.name ); nx.gui.setString( chd[ i ], "lock/type/name", task.name ); let nod = nx.gui.find( chd[ i ], "on/content" ); task.task.sort( ( a, b )=>{ return b.finish - a.finish; } ) nx.gui.gocChildren( nod, "", task.task.length ); let chds = nod.children; let connt = 0 for( let j = 0; j < chds.length; j++ ) { let inod = chds[ j ]; let data = task.task[ j ]; // let dess = task.task[0].group_desc; let cmp = inod.getComponent( "cmp.main.task.item" ); if( data ) { if( cmp ) { cmp.setData( data, j ); } // 判定是否需要显示所有的任务都完成的状态 if( data.finish == 2 && data.type == 2 ) { num++; } // 判定是否需要显示任务 // if( !data.canshow && ( data.type == 2 || data.type == 1 ) &&( data.group_desc && dess && dess == data.group_desc ) ) { // // console.log( JSON.stringify( data ) + "当前任务是否可以显示--->>>>" + data.canshow ); // // connt++; // } } } ccount = connt; nx.gui.setActive( chd[ i ], "on/type/done", num >= task.task.length ); nx.gui.setActive( chd[ i ], "off/type/done", num >= task.task.length ); nx.gui.setActive( chd[ i ], "on", ccount < task.task.length ); nx.gui.setActive( chd[ i ], "off", ccount < task.task.length ); nx.gui.setActive( chd[ i ], "", ccount < task.task.length ); if( ccount >= task.task.length ){ hideall++; } this.canshow = ccount < task.task.length; // console.log( nx.gui.find( chd[ i ] ).active + "支线任务显示状态" + ccount + nx.gui.find( chd[ i ], "on" ).active ); nx.gui.setActive( chd[ i ], "lock", ccount >= task.task.length ); } nx.gui.setActive( this.nodEmpty, "", hideall >= lst.length ); // 任务相关 子菜单一级 // this.taskLst.rebuild( lst ); // 引导辅助 if( nx.bridge.plot && nx.bridge.plot.isDoing() ) { this.scheduleOnce( () => { this.positionTask1_6(); }, 0.3 ); } this.scheduleOnce( () => { let cmp = this.togMenuTask.getComponent( FxTogs ); if( cmp ) { cmp.rebuildTogs(); cmp._freshTogShow(); // this.togMenuTask.togTo(0); this.togMenuTask.togTo( 0 ); this.activeMenuTask( 0 ); } }, 0.1 ); }, // 重载:关闭前 onPreClosed: function() { }, // 激活菜单 activeMenu: function( _index ) { let TC = TaskController.getInstance(); if( TC ) { let model = TC.getModel(); let allTask = model.getAllTaskInfo(); // console.log( "所有的任务信息主线支线" + JSON.stringify( allTask ) ); this.freshLst( allTask[ _index + 1 ] ); this.selectOne = _index; } }, // 激活菜单 activeMenuTask: function( _index ) { // console.log( "当前点击的任务类型" + _index ); let nod = this.togMenuTask; let nowSelectNode = nod.node.children[ _index ]; let cmp = nx.gui.find( nowSelectNode, "on/content" ).children[ 0 ].getComponent( "cmp.main.task.item" ); // console.log( "当前的数据" + JSON.stringify( cmp.mdata ) ); this.selectTwo = _index; if( cmp ) { cmp.onTouchfocus(); } }, // 激活菜单 activeMenuTaskInfo: function( _index ) { // console.log( "当前点击的任务具体" + _index ); }, // 背包切换 onTogMenu: function( _index ) { this.activeMenu( parseInt( _index ) ); }, // 任务类型切换 onTogMenuTask: function( _index ) { this.activeMenuTask( parseInt( _index ) ); }, // 任务类型切换 onTogMenuTaskInfo: function( _index ) { this.activeMenuTaskInfo( parseInt( _index ) ); }, onTaskShow: function( _task ) { if( _task ) { if( _task.canshow ){ nx.gui.setString( this.nodTask, "desc/txt", _task.name ); nx.gui.setString( this.nodTask, "task/txt2", _task.desc ); let awards = nx.gui.find( this.nodTask, "awards/rewards" ); // nx.gui.setActive( ) let cmp = awards.getComponent( "cmp.item.layout" ); // 任务子菜单 二级奖励显示 cmp.rebuild( _task.commit_rewards ); this.nowTask = _task; nx.gui.setActive( this.nodOp, "go", _task.finish == 1 ); nx.gui.setActive( this.nodOp, "goto", _task.finish == 0 && _task.skip_id > 0 ); nx.gui.setActive( this.nodTask, "awards/finished", _task.finish == 2 ); nx.gui.setActive( this.nodTask, "desc", _task.type == 1 ); } nx.gui.setActive( this.nodOp.parent, "empty", !_task.canshow ); } }, onTouchGet: function() { let TC = TaskController.getInstance(); if( TC ) { TC.requestSubmitTask( this.nowTask.id ); } }, onTouchGoto: function() { // console.log( "当前的任务信息" + JSON.stringify( this.nowTask ) ); let id = this.nowTask.skip_id; // 道具操作跳转 nx.bridge.jumper.jump2Window( id ); this.close(); }, // ============================================ // 引导辅助 // ============================================ // 任务1-6定位 positionTask1_6: function() { nx.wyl = this; let node = null; // 总的任务节点 let chd = this.togMenuTask.node.children; for( let i = 0; i < chd.length; i++ ) { let nod = nx.gui.find( chd[ i ], "on/content" ); let chds = nod.children; for( let j = 0; j < chds.length; j++ ) { let inod = chds[ j ]; let cmp = inod.getComponent( "cmp.main.task.item" ); if( cmp && cmp.mdata ) { if( cmp.mdata.id == 10002 ) { this.select = j; node = inod; break; } } } } if( !node ) { nx.error( "$ParterPage:定位任务1-6失败!" ); let nod = nx.gui.find( chd[ 0 ], "on/content" ); node = nod.children[ 1 ]; if( !node ) { this.select = 1; return; } } let cell = nx.gui.find( this, "panel/plot1-6" ); let pos = node.convertToWorldSpaceAR( cc.Vec2.ZERO ); cell.position = cell.parent.convertToNodeSpaceAR( pos ); cell.width = node.width; cell.height = node.height; }, // 点击切换到1-6任务 onTouchTogTask1_6: function() { let nod = this.togMenuTask; let nowSelectNode = nod.node.children[ 0 ]; let cmp = nx.gui.find( nowSelectNode, "on/content" ).children[ this.select ].getComponent( "cmp.main.task.item" ); if( cmp ) { cmp.onTouchfocus(); } }, } );