158 lines
3.9 KiB
JavaScript
158 lines
3.9 KiB
JavaScript
|
|
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 TaskMod = require( "task.mod" );
|
|
const TaskController = require( "task_controller" );
|
|
|
|
// 任务状态
|
|
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 );
|
|
|
|
// 任务监听
|
|
this.bindTask();
|
|
|
|
// 刷新
|
|
this.freshBase();
|
|
this.freshStatus();
|
|
|
|
},
|
|
|
|
// 任务监听
|
|
bindTask: function() {
|
|
|
|
if( this.mdata ) {
|
|
this.binder = this.mdata.bind( TaskEvent.UpdateSingleQuest, this.freshStatus.bind( this ) );
|
|
}
|
|
},
|
|
|
|
// 任务监听解除
|
|
unbindTask: function() {
|
|
|
|
if( this.mdata && this.binder ) {
|
|
this.mdata.unbind( this.binder );
|
|
this.binder = null;
|
|
}
|
|
|
|
},
|
|
|
|
// 刷新基本信息
|
|
freshBase: function() {
|
|
|
|
let desc = "", rewards = [];
|
|
if( this.mdata ) {
|
|
desc = this.mdata.getTaskContent();
|
|
rewards = this.mdata.config.commit_rewards;
|
|
}
|
|
|
|
// 描述
|
|
nx.gui.setString( this.nodName, "", nx.text.getKey( desc ) );
|
|
|
|
// 奖励信息
|
|
this.lstRewards.rebuild( rewards );
|
|
|
|
},
|
|
|
|
// 刷新任务状态
|
|
freshStatus: function() {
|
|
|
|
if( !this.mdata ) {
|
|
nx.gui.setActive( this.nodOps, "goto", false );
|
|
nx.gui.setActive( this.nodOps, "get", false );
|
|
nx.gui.setActive( this.nodOps, "done", false );
|
|
nx.gui.setActive( this.nodProg, "", false );
|
|
return;
|
|
}
|
|
|
|
// 操作更新
|
|
nx.gui.setActive( this.nodOps, "goto", this.mdata.finish == TST.un_finish );
|
|
nx.gui.setActive( this.nodOps, "get", this.mdata.finish == TST.finish );
|
|
nx.gui.setActive( this.nodOps, "done", this.mdata.finish == TST.completed );
|
|
|
|
// 进度更新
|
|
if( this.mdata.progress &&
|
|
this.mdata.finish != TST.completed ) {
|
|
nx.gui.setActive( this.nodProg, "", true );
|
|
let prog = this.mdata.progress[ 0 ];
|
|
let txt = cc.js.formatStr( "%s/%s", Utils.getMoneyString( prog.value ), Utils.getMoneyString( prog.target_val ) );
|
|
this.nodProg.progress = prog.value / prog.target_val;
|
|
nx.gui.setString( this.nodProg, "txt", txt );
|
|
}
|
|
|
|
},
|
|
|
|
// 点击获得
|
|
onTouchGet:function() {
|
|
|
|
if( !this.mdata ||
|
|
!this.mdata.config ||
|
|
this.mdata.finish != TST.finish ) {
|
|
return;
|
|
}
|
|
|
|
if( this.mdata.type == TaskConst.type.quest ) {
|
|
TaskMod.getInstance().requestSubmitTaskChange();
|
|
} else if( this.mdata.type == TaskConst.type.feat ) {
|
|
TaskController.getInstance().reqAchievementReward( this.mdata.id );
|
|
}
|
|
|
|
},
|
|
|
|
// 点击前往
|
|
onTouchGoto: function() {
|
|
|
|
if( !this.mdata ||
|
|
!this.mdata.config ||
|
|
this.mdata.finish != TST.un_finish ||
|
|
this.mdata.progress == null ) {
|
|
return;
|
|
}
|
|
for( var i in this.mdata.progress ) {
|
|
var v = this.mdata.progress[ i ];
|
|
if( v.finish == 0 ) {
|
|
nx.bridge.jumper.jump2Window( this.mdata.config.skip_id );
|
|
nx.bridge.closePanel( "WndTaskDaily" );
|
|
break;
|
|
}
|
|
}
|
|
|
|
},
|
|
|
|
});
|