guoqing.zhu 53c34a90dd updat
2022-06-04 13:41:18 +08:00

161 lines
3.9 KiB
JavaScript

var NetManage = require("NetManage");
const { task } = require("../../game/gameConfig");
cc.Class({
extends: cc.Component,
properties: {
nd_uprewards: {
default: [],
type: cc.Node,
},
tableView: {
default: null,
type: cc.Node,
},
pr_progress: {
default: null,
type: cc.ProgressBar,
},
lb_huoyue: {
default: null,
type: cc.Label,
},
tg_btns: {
default: null,
type: cc.ToggleContainer,
},
nd_dailyTask: {
default: null,
type: cc.Node,
},
nd_wantedTask: {
default: null,
type: cc.Node,
},
pb_singleWanted: {
default: null,
type: cc.Prefab,
},
nd_wantedNode: {
default: null,
type: cc.Node,
},
nd_content: {
default: null,
type: cc.Node,
},
},
// LIFE-CYCLE CALLBACKS:
onLoad() {
cc.Notifier.on('missionList', this, this.initdata.bind(this));
// wanted mission
cc.Notifier.on("ReFreshMission", this, () => {
this.initWantedMission();
});
cc.Notifier.on("FinishOne", this, () => {
this.initWantedMission();
});
},
onDestroy() {
cc.Notifier.off("missionList", this);
},
initdata(v) {
// daily mission
this.lb_huoyue.string = v.current_active_value;
this.pr_progress.progress = v.current_active_value / v.max_active_value;
for (var i = 0; i < v.mission_list1.length; i++) {
var nd_hasget = this.nd_uprewards[i].getChildByName("getReward");
var nd_canget = this.nd_uprewards[i].getChildByName("Available");
var icon = this.nd_uprewards[i].getChildByName("icon")
nd_hasget.active = false;
nd_canget.active = false;
this.nd_uprewards[i].getChildByName("num").getComponent(cc.Label).string =
v.mission_list1[i].target;
var state = v.mission_list1[i].state;
if (state == 0) {
nd_canget.active = true;
} else if (state == 1) {
nd_hasget.active = true;
}
this.nd_uprewards[i].mission_id = v.mission_list1[i].mission_id;
this.nd_uprewards[i].state = state;
}
v.mission_list2.sort((a, b) => {
var aa = 0;
if (a.state == 1) {
aa = 2;
}
if (a.state == 2) {
aa = 1;
}
var bb = 0;
if (b.state == 1) {
bb = 2;
}
if (b.state == 2) {
bb = 1;
}
return aa - bb;
});
this.tableView
.getComponent("tableView")
.initTableView(v.mission_list2.length, {
array: v.mission_list2,
target: this,
});
},
onclose() {
this.node.destroy();
},
onclickhuoyue(v1, v2) {
var cfg = this.nd_uprewards[Number(v2)];
var state = cfg.state;
if (state == 0) {
NetManage.commitMission(cfg.mission_id, () => {
NetManage.missionList(1);
});
} else if (state == 2) {
cc.uiHelper.showTips("Not full of activity");
}
},
onChangeTog(event, customEventData) {
if (customEventData == 0) {
this.nd_dailyTask.active = true;
this.nd_wantedTask.active = false;
} else if (customEventData == 1) {
this.nd_dailyTask.active = false;
this.nd_wantedTask.active = true;
this.initWantedMission();
}
},
initWantedMission() {
NetManage.missionList(3, (data) => {
this.wantedMission = data;
this.nd_wantedNode.destroyAllChildren();
var list = this.wantedMission.mission_list1;
list.forEach((mission) => {
var data = task[mission.mission_id];
const missionNode = cc.instantiate(this.pb_singleWanted);
const singleMiSc = missionNode.getComponent("singleWanted");
this.nd_wantedNode.addChild(missionNode);
singleMiSc.title.string = data.name;
singleMiSc.init(data, mission);
});
});
},
});