zhuguoqing ff550d5d6a init
2022-05-22 10:32:02 +08:00

170 lines
4.4 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,
},
spine_hero: {
default: null,
type: sp.Skeleton,
},
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);
},
//任务状态 0:可领取 1:已领取 2:未完成(不可领取)
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");
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,
});
// console.log(this.nd_content.childernCount);
// cc.loader.loadRes("spine/heropic/pic_hero" + cc.playerData.getshowhero(), sp.SkeletonData, function(err, sp) {
// this.spine_hero.skeletonData = sp;
// this.spine_hero._updateSkeletonData();
// this.spine_hero.setAnimation(0, "animation", true);
// }.bind(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);
});
});
},
});