123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413 |
- /** @format */
- import {UI} from '../enums/UI'
- import {BaseUI} from './BaseUI'
- import {Data, Mgr} from '../GameControl'
- import {ccUtils} from '../utils/ccUtils'
- import {label, list, node, observer, render} from '../mobx/observer'
- import {msgCmd} from '../proto/msg_cmd'
- import {ITaskConfig, TaskConfig} from '../config/TaskConfig'
- import {CONDITION_FUNC, GOODS, LANGUAGE_TYPE, STATE, TASK_TYPE} from '../enums/Enum'
- import {i18nLabel} from '../uiutils/i18nLabel'
- import List from '../uiutils/List'
- import {questActiveAwardRsp, questGetDataRsp} from '../proto/game'
- import {idNum, quest} from '../proto/typedef'
- import {ActiverewardConfig, IActiverewardConfig} from '../config/ActiverewardConfig'
- import {EliteInfoConfig} from '../config/EliteInfoConfig'
- import {StageInfoConfig} from '../config/StageInfoConfig'
- import {FunctionsConfig} from '../config/FunctionsConfig'
- import {IRewardNty} from '../interface/UIInterface'
- const {ccclass, property} = cc._decorator
- interface task {
- taskCfg: ITaskConfig
- quest: quest
- reward: idNum[]
- }
- interface taskList {
- type: number //类型
- level: number //等级
- award: number //领取奖励 0/20/40/60/80/100
- activationNum: number
- tasks: task[]
- }
- enum Touch_UI {
- adventureMainUI = 23,
- adventureEliteUI,
- challengeUI,
- }
- @ccclass
- @observer
- export class TaskUI extends BaseUI {
- //任务奖励节点列表
- rewards: cc.Node[]
- @list('task_list')
- taskPageList: List
- @list('achievement_list')
- achievementList: List
- //宝箱
- @node('activation/activation_progress/chest_box')
- chestBox: cc.Node
- //包含活跃值、宝箱和进度条的总类节点
- @node('activation')
- activationNode: cc.Node
- @node('task_list')
- tasklistNode: cc.Node
- @node('achievement_list')
- achievementListNode: cc.Node
- @node('taskType_list')
- typeNode: cc.Node
- bubble_box: cc.Node
- bubble_arrow: cc.Node
- //所有任务列表
- taskAllData: Map<TASK_TYPE, taskList> = new Map()
- hasActiveReward: boolean = false
- checkBubbleShow: boolean = false
- activeRewardsData: IActiverewardConfig[] = [] //活跃度奖励数据
- selTaskType: TASK_TYPE = TASK_TYPE.daily
- selTaskItemIndex: number = 0
- selRewardIdNum: idNum[]
- isTaskRewards: boolean = true
- activeRewardsNum: number = 2
- activeDailyIndex: number = 0
- activeWeekIndex: number = 0
- chestActivationData: number[] = [20, 40, 60, 80, 100]
- onShow(args, fromUI?: number) {
- cc.find('trans', this.node).on(cc.Node.EventType.TOUCH_END, this.cancelBubbleBox, this)
- cc.find('trans', this.node)['_touchListener'].swallowTouches = false
- Mgr.net.add(msgCmd.cmd_quest_get_data_rsp, this, this.onQuestRsp)
- //从右到左显示货币
- Mgr.ui.show(UI.CurrencyUI, [GOODS.coin, GOODS.diamond, GOODS.fatigue])
- //活跃宝箱获取奖励
- Mgr.net.add(msgCmd.cmd_quest_active_award_rsp, this, this.getRewardRsp)
- //任务获取奖励
- Mgr.net.add(msgCmd.cmd_quest_get_award_rsp, this, this.getRewardRsp)
- Mgr.net.send(msgCmd.cmd_quest_get_data)
- //强制初始化
- this.selTaskType = TASK_TYPE.daily
- this.typeNode.children[0].getComponent(cc.Toggle).isChecked = true
- }
- onHide(): any {
- Mgr.event.removeAll(this)
- }
- //分拣任务类型 daily:日常 weekly:周常 achievement:成就
- classifyTasks(task: taskList, level: number, award: number, quests: quest[]) {
- task.level = level
- task.award = award
- for (let i = 0; i < quests.length; i++) {
- task.tasks.push({
- quest: quests[i],
- taskCfg: TaskConfig[quests[i].id],
- reward: Mgr.goods.getIdNumByCfgArr(TaskConfig[quests[i].id].reward),
- })
- }
- return task
- }
- //初始化任务列表数据
- initTaskAllListData(data: questGetDataRsp) {
- for (let i = TASK_TYPE.daily; i <= TASK_TYPE.achievement; i++) {
- let taskList: taskList = {
- type: 0,
- award: 0,
- level: 0,
- activationNum: 0,
- tasks: [],
- },
- activationNum = 0
- taskList.type = i
- switch (taskList.type) {
- case TASK_TYPE.daily:
- taskList = this.classifyTasks(taskList, data.dlv, data.daward, data.daily)
- activationNum = Data.user.goods.get(GOODS.activation)
- taskList.activationNum = activationNum == undefined ? 0 : activationNum
- break
- case TASK_TYPE.weekly:
- taskList = this.classifyTasks(taskList, data.wlv, data.waward, data.weekly)
- activationNum = Data.user.goods.get(GOODS.weeklyIntegral)
- taskList.activationNum = activationNum == undefined ? 0 : activationNum
- break
- case TASK_TYPE.achievement:
- taskList = this.classifyTasks(taskList, 0, 0, data.achievement)
- break
- }
- this.taskAllData.set(i, taskList)
- //排列任务顺序 id升序 可领取任务置前,已领取任务置后
- let list = this.taskAllData.get(i)
- let readyTasks: task[] = list.tasks.filter(task => task.quest.state === STATE.ready)
- let completedTasks: task[] = list.tasks.filter(task => task.quest.state === STATE.done)
- list.tasks = list.tasks.filter(task => task.quest.state !== STATE.ready && task.quest.state !== STATE.done)
- list.tasks.sort((a, b) => a.quest.id - b.quest.id)
- readyTasks.sort((a, b) => a.quest.id - b.quest.id)
- completedTasks.sort((a, b) => a.quest.id - b.quest.id)
- readyTasks.forEach(task => list.tasks.unshift(task))
- completedTasks.forEach(task => list.tasks.push(task))
- }
- }
- initUi() {
- this.handleGetAwardRemainTime()
- //初始化宝箱
- this.initChestBox()
- //根据任务日常/周常初始化全部活跃奖励
- this.activeRewardsData = []
- let list = this.selTaskType == TASK_TYPE.achievement ? this.achievementList : this.taskPageList,
- level = this.taskAllData.get(this.selTaskType).level
- for (let item in ActiverewardConfig) {
- if (ActiverewardConfig[item].type == this.selTaskType) {
- if (level >= ActiverewardConfig[item].interval[0] && level <= ActiverewardConfig[item].interval[1]) {
- this.activeRewardsData.push(ActiverewardConfig[item])
- }
- }
- }
- //查看左侧页签红点状态
- for (let type = TASK_TYPE.daily; type <= TASK_TYPE.achievement; type++) {
- //查看是否有可领取任务
- let node = this.typeNode.children[type - 1],
- tasks = this.taskAllData.get(type).tasks,
- checkGet = tasks.some(task => task.quest.state == STATE.ready)
- //对已领取的宝箱置灰
- //红点显示:
- //成就页面有可领取任务,其他需同时满足任务领取&宝箱领取
- if (type == TASK_TYPE.achievement) {
- cc.find('red_dots', node).active = checkGet
- } else {
- //是否存在可领取活跃奖励
- let curActiveIndex = type == TASK_TYPE.daily ? this.activeDailyIndex : this.activeWeekIndex
- let hasActiveReward =
- Math.floor(this.taskAllData.get(type).activationNum / 20) - 1 >= curActiveIndex &&
- curActiveIndex < this.chestActivationData.length
- cc.find('red_dots', node).active = checkGet || hasActiveReward
- if (type == this.selTaskType) this.hasActiveReward = hasActiveReward
- }
- }
- //默认跳转至列表第一个位置
- list.scrollTo(0)
- list.numItems = this.taskAllData.get(this.selTaskType).tasks.length
- if (this.selTaskType != TASK_TYPE.achievement) {
- let node = cc.find('activation_progress/progress_bottom', this.activationNode)
- //周常 周积分 110004 日常 活跃度 110003
- //初始化进度条
- let progress = this.taskAllData.get(this.selTaskType).activationNum
- //初始化活跃值
- let activateBox = cc.find('activate_box', this.activationNode)
- ccUtils.setLabel(progress.toString(), activateBox, 'num')
- ccUtils.initProgressBar(node, progress, 100)
- }
- //根据activation节点可见日常、周常、成就列表
- this.activationNode.active = !(this.selTaskType == TASK_TYPE.achievement)
- this.tasklistNode.active = !(this.selTaskType == TASK_TYPE.achievement)
- this.achievementListNode.active = this.selTaskType == TASK_TYPE.achievement
- }
- //初始化任务单例奖励列表
- initRewards(parent: cc.Node) {
- let children = parent.children,
- idNum: idNum[] = []
- for (let i = 0; i < children.length; i++) {
- let data: idNum = null
- //任务列表奖励初始化
- if (this.isTaskRewards) {
- data = this.taskAllData.get(this.selTaskType).tasks[this.selTaskItemIndex].reward[i]
- cc.find('select_1', children[i]).active =
- this.taskAllData.get(this.selTaskType).tasks[this.selTaskItemIndex].quest.state == STATE.done
- } else {
- //宝箱bubble奖励初始化
- data = this.selRewardIdNum[i]
- }
- idNum.push({id: data.id, num: data.num})
- }
- Mgr.goods.initGoods(
- idNum,
- children.map(goodsParent => cc.find('goods', goodsParent)),
- this,
- )
- }
- //初始化活跃宝箱
- initChestBox() {
- let item = cc.find('chest_item', this.chestBox)
- ccUtils.instantChildren(item, this.chestActivationData.length, this.chestBox)
- for (let i = 0; i < this.chestActivationData.length; i++) {
- let node = this.chestBox.children[i]
- node['index'] = i
- let activation = this.taskAllData.get(this.selTaskType).activationNum
- let icon = cc.find('chest_icon', node)
- let hasReward = cc.find('hasReward', node)
- let canGet = Math.floor(activation / 20) - 1 >= i
- ccUtils.setLabel(this.chestActivationData[i].toString(), node, 'label')
- //对已领取的宝箱置灰
- let hasGet: boolean = this.chestActivationData[i] <= this.taskAllData.get(this.selTaskType).award
- ccUtils.setSpriteGray(hasGet, icon)
- cc.find('active', node).active = canGet
- hasReward.active = canGet && !hasGet
- icon.active = !hasReward.active
- }
- let getCurActive = (type: TASK_TYPE) => {
- let curActive: number = 0
- for (let i = 0; i < this.chestActivationData.length; i++) {
- let activeChest: boolean = this.chestActivationData[i] <= this.taskAllData.get(type).award
- if (activeChest) curActive = i + 1
- }
- return curActive
- }
- this.activeDailyIndex = getCurActive(TASK_TYPE.daily)
- this.activeWeekIndex = getCurActive(TASK_TYPE.weekly)
- }
- //初始化任务列表
- initTaskItem(node: cc.Node, index: number) {
- //任务在任务列表中的下标
- this.selTaskItemIndex = index
- let data = this.taskAllData.get(this.selTaskType).tasks[index]
- //生成任务描述
- let label = cc.find('task_decs', node).getComponent(i18nLabel)
- ccUtils.setLabel(data.taskCfg.des, node, 'task_decs')
- //label 参数 #0/#1
- //单独为成就写入param
- if (this.selTaskType == TASK_TYPE.achievement) {
- let param = data.taskCfg.parameter,
- cfg = null
- switch (data.taskCfg.touch) {
- case Touch_UI.adventureMainUI:
- cfg = StageInfoConfig[param]
- label.init(data.taskCfg.des, [`${Mgr.i18n.getLabel(cfg.name, [])}-${cfg.des}`])
- break
- case Touch_UI.adventureEliteUI:
- cfg = EliteInfoConfig[param]
- label.init(data.taskCfg.des, [`${Mgr.i18n.getLabel(cfg.name, [])}-${cfg.ID % 10}`])
- break
- default:
- label.init(data.taskCfg.des, [data.taskCfg.parameter.toString()])
- break
- }
- }
- //生成奖励列表
- this.isTaskRewards = true
- let rewardItem = cc.find('rewards/reward_item', node)
- ccUtils.instantChildren(rewardItem, data.reward.length, rewardItem.parent)
- this.initRewards(rewardItem.parent)
- //获取完成进度
- //mark -1需要记录 -0不需要记录
- let progressNode = cc.find('progress_bottom', node)
- let progress =
- data.taskCfg.mark == 0 ? (data.quest.state == STATE.undo ? STATE.undo : STATE.ready) : data.quest.progress
- let needSum = data.taskCfg.mark == 0 ? 1 : data.taskCfg.parameter
- ccUtils.initProgressBar(progressNode, progress, needSum, 'progress_label')
- //初始化跳转按钮
- let state = data.quest.state
- let go_btn = cc.find('go_btn', node),
- clain_btn = cc.find('clain_btn', node),
- com_label = cc.find('com_label', node)
- go_btn.active = state == STATE.undo
- clain_btn.active = state == STATE.ready
- com_label.active = state == STATE.done
- if (go_btn.active || clain_btn.active) {
- if (state == STATE.ready) {
- clain_btn['id'] = data.taskCfg.ID
- } else {
- go_btn['jump'] = data.taskCfg.jump
- }
- }
- //针对不同完成状态显示高亮与普通任务背景
- cc.find('complete', node).active = state == STATE.ready
- //对已领取奖励任务进行node置灰
- cc.find('gray', node).active = state == STATE.done
- }
- //网络事件=======================================
- onQuestRsp(data: questGetDataRsp) {
- this.initTaskAllListData(data)
- this.initUi()
- }
- getRewardRsp(data: questActiveAwardRsp, reward: IRewardNty) {
- Mgr.ui.showReward(reward)
- Mgr.net.send(msgCmd.cmd_quest_get_data)
- }
- //触发事件=======================================
- @render
- //处理任务领取剩余时间
- handleGetAwardRemainTime() {
- let time = Data.main.serverTime,
- lb = cc.find('remain_time/layout/info', this.activationNode),
- endOfDay = this.selTaskType == TASK_TYPE.weekly ? Date.getWeekTime(time, 0) : Date.getDayTime(time),
- remain = Math.floor(endOfDay - time) < 60 ? 60 : Math.floor(endOfDay - time)
- if (remain == 0) {
- Mgr.net.send(msgCmd.cmd_quest_get_data)
- } else {
- ccUtils.setLabel(`${Mgr.i18n.getTimeLabel(remain)}`, lb)
- }
- }
- // 点击事件=======================================
- onTypeClick(event, data) {
- if (this.selTaskType == parseInt(data)) {
- return
- }
- this.selTaskType = parseInt(data)
- this.initUi()
- }
- onClainClick(event) {
- Mgr.net.send(msgCmd.cmd_quest_get_award, {id: event.target.id})
- }
- onGoClick(event) {
- Mgr.global.tryJumpMod(event.target['jump'])
- }
- //活跃宝箱点击事件
- //按钮可交互时 存在两种状态
- //1. 存在可领取奖励 点击一次性领取全部奖励,并刷新页面
- //2. 无领取奖励 点击宝箱上方显示奖励气泡(气泡默认隐藏)
- onChestClick(event) {
- let parent = event.currentTarget.parent,
- index = parent['index']
- if (this.hasActiveReward) {
- Mgr.net.send(msgCmd.cmd_quest_active_award, {type: this.selTaskType})
- } else {
- this.checkBubbleShow = !this.checkBubbleShow
- if (this.bubble_box == null) {
- this.bubble_box = cc.find('bubble_box', parent)
- this.bubble_arrow = cc.find('arrow', parent)
- }
- this.bubble_box.active = this.checkBubbleShow
- this.bubble_arrow.active = this.checkBubbleShow
- this.isTaskRewards = false
- if (this.bubble_box.active) {
- this.selRewardIdNum = Mgr.goods.getIdNumByCfgArr(this.activeRewardsData[index].reward)
- let rewardItem = cc.find('reward_item', this.bubble_box)
- ccUtils.instantChildren(rewardItem, this.selRewardIdNum.length, this.bubble_box)
- this.initRewards(this.bubble_box)
- }
- if (!this.checkBubbleShow) {
- this.bubble_box = null
- }
- }
- }
- cancelBubbleBox() {
- if (this.bubble_box != null) {
- this.bubble_box.active = false
- this.bubble_arrow.active = false
- this.checkBubbleShow = false
- this.bubble_box = null
- }
- }
- }
|