179 lines
4.2 KiB
JavaScript
179 lines
4.2 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));
|
|
cc.Notifier.on(
|
|
'hasSendMission',
|
|
this,
|
|
this.initWantedMission.bind(this)
|
|
);
|
|
// wanted mission
|
|
|
|
cc.Notifier.on(
|
|
'ReFreshMission',
|
|
this,
|
|
this.initWantedMission.bind(this)
|
|
);
|
|
|
|
cc.Notifier.on('FinishOne', this, this.initWantedMission.bind(this));
|
|
},
|
|
onDestroy() {
|
|
cc.Notifier.off('missionList', this);
|
|
cc.Notifier.off('ReFreshMission', this);
|
|
cc.Notifier.off('FinishOne', this);
|
|
},
|
|
|
|
initdata(v) {
|
|
// daily mission
|
|
|
|
this.lb_huoyue.string = v.current_active_value;
|
|
this.pr_progress.progress = v.current_active_value / 70;
|
|
|
|
if (v.current_active_value >= 10 && v.current_active_value < 30) {
|
|
var node0 = this.nd_uprewards[0].getChildByName('Available');
|
|
if (node0) node0.active = true;
|
|
} else if (
|
|
v.current_active_value >= 30 &&
|
|
v.current_active_value < 50
|
|
) {
|
|
var node0 = this.nd_uprewards[0].getChildByName('Available');
|
|
if (node0) node0.active = true;
|
|
var node1 = this.nd_uprewards[1].getChildByName('Available');
|
|
if (node1) node1.active = true;
|
|
} else if (v.current_active_value >= 50) {
|
|
var node0 = this.nd_uprewards[0].getChildByName('Available');
|
|
if (node0) node0.active = true;
|
|
var node1 = this.nd_uprewards[1].getChildByName('Available');
|
|
if (node1) node1.active = true;
|
|
var node2 = this.nd_uprewards[2].getChildByName('Available');
|
|
if (node2) node2.active = true;
|
|
}
|
|
|
|
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();
|
|
cc.Notifier.emit('refreshBaseInfo');
|
|
},
|
|
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;
|
|
NetManage.missionList(1, (data) => {
|
|
this.nd_wantedNode.destroyAllChildren();
|
|
this.initdata(data);
|
|
});
|
|
} else if (customEventData == 1) {
|
|
this.nd_dailyTask.active = false;
|
|
this.nd_wantedTask.active = true;
|
|
this.initWantedMission();
|
|
}
|
|
},
|
|
|
|
initWantedMission() {
|
|
var canvas = cc.find('Canvas');
|
|
var taskNode = canvas.getComponentInChildren('UITask');
|
|
var wantNode = taskNode.getComponent('UITask').nd_wantedNode;
|
|
var prefab = taskNode.getComponent('UITask').pb_singleWanted;
|
|
NetManage.missionList(3, (data) => {
|
|
this.wantedMission = data;
|
|
wantNode.destroyAllChildren();
|
|
var list = this.wantedMission.mission_list1;
|
|
list.forEach((mission) => {
|
|
var data = task[mission.mission_id];
|
|
const missionNode = cc.instantiate(prefab);
|
|
const singleMiSc = missionNode.getComponent('singleWanted');
|
|
wantNode.addChild(missionNode);
|
|
singleMiSc.title.string = data.name;
|
|
singleMiSc.init(data, mission);
|
|
});
|
|
});
|
|
},
|
|
});
|