123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- const Api = require('../net/Api');
- cc.Class({
- extends: cc.Component,
- properties: {
- questNode: cc.Node,
- questFrames: {
- tooltip: '任务图标',
- default: [],
- type: [cc.SpriteFrame],
- },
- questBtns: [cc.Node],
- starNode: {
- tooltip: '星星节点',
- default: [],
- type: [cc.Node]
- },
- giftFrames: {
- tooltip: '奖励图片素材',
- default: [],
- type: [cc.SpriteFrame]
- },
- starFrames: {
- tooltip: '星星图片素材',
- default: [],
- type: [cc.SpriteFrame]
- },
- progressLabel: {
- tooltip: '奖励数量',
- default: null,
- type: cc.Label
- },
- progressBar: cc.ProgressBar,
- questTitle: {
- tooltip: '任务标题',
- default: null,
- type: cc.Label
- },
- qusetMsg: {
- tooltip: '任务说明',
- default: null,
- type: cc.Label
- }
- },
- onLoad () {
- this.giftMap = ['diamond', 'coin', 'ticket']
- },
- start () {
- },
- init (parent, tasks, sn, questIndex) {
- this.parent = parent
- this.quest = parent.quest
- this.tasks = tasks
- this.questIndex = questIndex
- sn = this.sn = parseInt(sn)
-
- this.questNode.getComponent('cc.Sprite').spriteFrame = this.questFrames[this.questIndex]
-
- this._setTaskItem(sn)
- },
-
- _setTaskItem (sn) {
- let task = this.task = this.tasks.find(n => {
- if(sn == 0) {
- return n.sn == 1
- } else {
- return n.sn == sn
- }
- })
- if(sn == 5 && task.status == 2) {
- this._setMaxItem()
- } else {
- let level = sn == 0 ? 0 : sn - 1
- let nameLevelMap = ['I', 'II', 'III', 'IV', 'V']
- let giftType
- let giftCount
-
- this.giftMap.forEach(n => {
- if(task[n] > 0) {
- giftType = n
- giftCount = task[n]
- }
- })
-
-
- this.questTitle.string = `${task.name}(${nameLevelMap[level]})`
-
-
- this.qusetMsg.string = task.msg.replace('${num}', task.totalAimValue)
-
-
- this._setStarLevel(level)
-
-
- let aimValue = task.aimValue > task.totalAimValue ? task.totalAimValue : task.aimValue
- this._setProgress(aimValue, task.totalAimValue)
-
-
- this._setGiftBtn(task.status, giftType, giftCount)
- }
- },
- _setMaxItem () {
- let task = this.tasks[4]
-
- this.questTitle.string = `${task.name}(V)`
-
-
- this.qusetMsg.string = task.msg.replace('${num}', task.totalAimValue)
-
- this._setStarLevel(5)
-
- let aimValue = task.aimValue > task.totalAimValue ? task.totalAimValue : task.aimValue
- this._setProgress(aimValue, task.totalAimValue)
-
- this._setGiftBtn(2)
- },
-
- handleGiftBtn () {
- Api.httpPost({
- url: "/task/gain.do",
- data: {
- taskId: this.task.taskId,
- sn: this.task.sn
- },
- success: (res) => {
-
- this.quest.updateUserInfo(this.task.coin, this.task.diamond, this.task.ticket)
-
- this.quest.showActGift({
- ticket: this.task.ticket,
- diamond: this.task.diamond,
- coin: this.task.coin
- })
-
- if(this.sn < 5) {
- this.sn += 1
- this._setTaskItem(this.sn)
- } else {
- this._setMaxItem()
- }
- },
- fail: () => {
-
- }
- })
- },
-
- _setGiftBtn (status, giftType, giftCount) {
- this.questBtns.forEach(n => {
- n.active = false
- })
-
- let btn
-
- switch (status) {
- case 0:
- btn = this.questBtns[1]
- break;
- case 1:
- btn = this.questBtns[0]
- break;
- case 2:
- btn = this.questBtns[2]
- break;
- default:
- break;
- }
- btn.active = true
-
- if(status != 2) {
- let countNode = cc.find('/count_label', btn)
- let spriteNode = cc.find('/sprite', btn)
- let giftSprite
- this.giftMap.forEach((value, index) => {
- if(value == giftType) {
- giftSprite = this.giftFrames[index]
- }
- })
-
-
- countNode.getComponent('cc.Label').string = `${giftCount}`
- spriteNode.getComponent('cc.Sprite').spriteFrame = giftSprite
- }
- },
-
- _setProgress (current, total) {
- let _progress = (current / total).toFixed(1)
- console.log(_progress);
- this.progressBar.progress = _progress
- this.progressLabel.string = `${current} / ${total}`
- },
-
- _setStarLevel (level) {
- this.starNode.forEach((node, index) => {
- if(index < level) {
- node.getComponent('cc.Sprite').spriteFrame = this.starFrames[1]
- } else {
- node.getComponent('cc.Sprite').spriteFrame = this.starFrames[0]
- }
- })
- }
- });
|