消消方块阵换皮表情
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

132 lines
4.4 KiB

import { _decorator, Color, Component, Label, Node } from 'cc';
import { TargetTaskManager, TargetTaskType } from '../manager/TargetTaskManager';
import { SpriteLoad } from '../../mx/components/SpriteLoad';
import { GPath, GBundle } from '../game/ConfigRes';
import { ItemNumType, OtherDataType } from '../game/GameData';
import { GEvent } from '../../mx/module/event/GEvent';
const { ccclass, property } = _decorator;
@ccclass('taskTargetNode')
export class taskTargetNode extends Component {
@property({ type: Label })
desc: Label = null;
@property({ type: Label })
layNum: Label = null;
@property({ type: Node })
icon: Node = null;
@property({ type: Label })
iconNum: Label = null;
isCanReward = false
labColor = 'red'
protected onEnable(): void {
GEvent.Ins.on(GEvent.TargetTaskUpdate, this.refresReward, this);
// 切回主页 / 节点重新激活时补刷:隐藏期间可能已错过 TargetTaskUpdate
this.refreshTaskView();
}
protected onDisable(): void {
GEvent.Ins.off(GEvent.TargetTaskUpdate, this.refresReward, this);
}
protected onDestroy(): void {
GEvent.Ins.off(GEvent.TargetTaskUpdate, this.refresReward, this);
}
start() {
this.refreshTaskView();
}
/** 重新核算进度并刷新展示 */
private refreshTaskView(): void {
if (!this.node?.isValid) {
return;
}
gg.targetTaskManager.checkTask();
this.refresReward();
}
refresReward() {
if (!this.node?.isValid) {
return;
}
// 仍在主页树但父节点暂隐时也允许刷新文案;仅完全失效时跳过
console.log('refresReward')
let isHaveTask = gg.targetTaskManager.getIsNoTask()
if (isHaveTask) {
this.node.active = false
return
}
let config = gg.targetTaskManager.getCurTargetTaskConfig()
if (config) {
console.log('任务节点 config', config)
this.desc.string = gg.lang.get(config.desc)
let taregtNum = config.par2
let curNum = gg.targetTaskManager.getCurTargetTaskProgress()
if (curNum >= taregtNum) {
curNum = taregtNum
}
this.layNum.string = `(${curNum}/${taregtNum})`
let itemID = Number(config.rewards.split(',')[0])
let itemData = gg.data.table.getItemData(itemID)
this.icon.getComponent(SpriteLoad).setSprite(GPath.Item(itemData.icon), GBundle.Items);
this.iconNum.string = config.rewards.split(',')[1]
console.log('任务 taskTargetNode curNum', curNum, 'taregtNum', taregtNum)
if (curNum >= taregtNum) {
//
this.layNum.color = Color.GREEN
this.labColor = 'green'
this.isCanReward = true
this.node.find("任务内容框/canGet").active = true;
this.node.find("奖励框/canGet").active = true;
} else {
this.layNum.color = Color.RED
this.labColor = 'red'
this.isCanReward = false
this.node.find("任务内容框/canGet").active = false;
this.node.find("奖励框/canGet").active = false;
}
}
}
clickJumpGame(event) {
let config = gg.targetTaskManager.getCurTargetTaskConfig()
console.log('config', config)
console.log('this.isCanReward', this.isCanReward)
if (!config) {
return
}
if (this.isCanReward) {
//领取奖励并且接下一个任务
gg.targetTaskManager.finishTask()
//飞金币还是钻石
let itemID = Number(config.rewards.split(',')[0])
let addMoney = Number(config.rewards.split(',')[1])
GEvent.Ins.emit(GEvent.FlyMoney, itemID, event.target.worldPosition, addMoney, null, 10);
//检查下一个任务进度
gg.audio.playEffect({ name: "获得物品弹窗" });
} else {
// 跳转:延后一帧,避免与点击当帧 UI 隐藏/合批冲突
const jumpTo = config.jumpto;
this.scheduleOnce(() => {
if (!this.node?.isValid) {
return;
}
gg.game.gotoTaskJump(jumpTo);
}, 0);
}
}
}