/****************************************************************** * * 成就项 * ******************************************************************/ const SVCItem = require( "nx.fx.sv.expand.item" ); const ItemLayout = require( "cmp.item.layout" ); const TaskConst = require( "task_const" ); const TaskEvent = require( "task_event" ); const TaskController = require( "task.mod" ); // 任务状态 const TST = TaskConst.task_status; cc.Class( { extends: SVCItem, properties: { nodName: { default: null, type: cc.Label }, nodProg: { default: null, type: cc.ProgressBar }, lstRewards: { default: null, type: ItemLayout }, nodOps: { default: null, type: cc.Node }, }, // 数据重置 rebind: function( _idx, _data, _key ) { // 任务监听解除 this.unbindTask(); this._super( _idx, _data, _key ); if( nx.dt.objEmpty( _data ) ) { return; } // 任务绑定 this.task = _data ? _data.task : null; if( this.task ) { if( this.task.finish == TST.un_finish || this.task.finish == TST.finish ) { this.binder = this.task.bind( TaskEvent.UpdateSingleQuest, this.freshStatus.bind( this ) ); } } // 刷新 this.freshBase(); this.freshStatus(); }, // 任务监听解除 unbindTask: function() { if( this.task && this.binder ) { this.task.unbind( this.binder ); this.binder = null; } }, // 刷新基本信息 freshBase: function() { // 描述 nx.gui.setString( this.nodName, "", nx.text.getKey( this.mdata.desc ) ); // 点数 nx.gui.setString( this, "point/txt", this.mdata.ach_point ); // 奖励 this.lstRewards.rebuild( this.mdata.commit_rewards ); }, // 刷新状态 freshStatus: function() { // 置空 let self = this; let empty = function() { nx.gui.hideAllChildren( self.nodOps, "" ); self.nodProg.progress = 0; nx.gui.setString( self.nodProg, "txt", "0/0" ); }; // 空不处理 if( !this.task ) { empty(); return; } // 操作更新 nx.gui.setActive( this.nodOps, "goto", false ); nx.gui.setActive( this.nodOps, "get", this.task.finish == TST.finish ); nx.gui.setActive( this.nodOps, "done", this.task.finish == TST.completed ); // 进度更新 if( this.task.finish == TST.finish || this.task.finish == TST.completed ) { this.nodProg.progress = 1; nx.gui.setString( this.nodProg, "txt", "100%" ); } else { let prog = this.task.progress[ 0 ]; this.nodProg.progress = prog.value / prog.target_val; let txt = cc.js.formatStr( "%s/%s", Utils.getMoneyString( prog.value ), Utils.getMoneyString( prog.target_val ) ); nx.gui.setString( this.nodProg, "txt", txt ); } }, // 点击获得 onTouchGet: function() { if( !this.mdata ) { return; } let TM = TaskController.getInstance(); TM.reqAchievementReward( this.mdata.id, ( _ret, _data ) => { if( !_ret ) { nx.tbox( _data ); return; } } ); }, // 点击前往 onTouchGoto: function() { // TODO... }, } );