131 lines
3.3 KiB
JavaScript
131 lines
3.3 KiB
JavaScript
"use strict";
|
|
cc._RF.push(module, 'bc83aVfESRJpYMAGIQLxaX7', 'cmp.achievement.item');
|
|
// Scripts/mod/home/achievement/cmp.achievement.item.js
|
|
|
|
"use strict";
|
|
|
|
/******************************************************************
|
|
*
|
|
* 成就项
|
|
*
|
|
******************************************************************/
|
|
|
|
var SVCItem = require("nx.fx.sv.expand.item");
|
|
var ItemLayout = require("cmp.item.layout");
|
|
var TaskConst = require("task_const");
|
|
var TaskEvent = require("task_event");
|
|
var TaskController = require("task.mod");
|
|
|
|
// 任务状态
|
|
var 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 rebind(_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 unbindTask() {
|
|
if (this.task && this.binder) {
|
|
this.task.unbind(this.binder);
|
|
this.binder = null;
|
|
}
|
|
},
|
|
// 刷新基本信息
|
|
freshBase: function freshBase() {
|
|
// 描述
|
|
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 freshStatus() {
|
|
// 置空
|
|
var self = this;
|
|
var empty = function empty() {
|
|
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 {
|
|
var prog = this.task.progress[0];
|
|
this.nodProg.progress = prog.value / prog.target_val;
|
|
var txt = cc.js.formatStr("%s/%s", Utils.getMoneyString(prog.value), Utils.getMoneyString(prog.target_val));
|
|
nx.gui.setString(this.nodProg, "txt", txt);
|
|
}
|
|
},
|
|
// 点击获得
|
|
onTouchGet: function onTouchGet() {
|
|
if (!this.mdata) {
|
|
return;
|
|
}
|
|
var TM = TaskController.getInstance();
|
|
TM.reqAchievementReward(this.mdata.id, function (_ret, _data) {
|
|
if (!_ret) {
|
|
nx.tbox(_data);
|
|
return;
|
|
}
|
|
});
|
|
},
|
|
// 点击前往
|
|
onTouchGoto: function onTouchGoto() {
|
|
// TODO...
|
|
}
|
|
});
|
|
|
|
cc._RF.pop(); |