import { AppKernel } from '@scripts/app/AppKernel'; import { UIViewID } from '@scripts/define/UIDefine'; import { UIView } from '@scripts/framework/ui/UIView'; import { formatMailTimeToMMDDYYYY, parseMailRewardStr } from '@scripts/utils/Helper'; import { setSpriteFrame } from '@scripts/utils/ResHelper'; import { addBtnClick, removeBtnClick } from '@scripts/utils/UIHelper'; import { _decorator, Button, Component, Enum, instantiate, Label, Node, NodePool, Prefab, ProgressBar, Sprite, SpriteFrame, tween, UIOpacity } from 'cc'; const { ccclass, property } = _decorator; @ccclass('NodeItem') export class NodeItem extends Component { @property(SpriteFrame) private img_bg_free_node: SpriteFrame = null; @property(SpriteFrame) private img_bg_dlx_node: SpriteFrame = null; @property(Node) private dlx: Node = null; @property(Node) private progress: Node = null; @property(Node) private free: Node = null; @property(Prefab) private prop_sc: Prefab = null; @property(Prefab) private prop_gc: Prefab = null; private _data: any = {}; onLoad() { addBtnClick(this.dlx, this.onDlxBtnClick, this); addBtnClick(this.free, this.onFreeBtnClick, this); } initItem(data: any = {}) { this._data = data; this.updateFree(); this.updateDeluxe(); this.updateProgress(); } updateFree() { const { node } = this._data; if (!node) return; const { free, unlocked } = node ?? {}; const { reward, claimed } = free ?? {}; const rewards = this.free.getChildByName('rewards'); const lock = this.free.getChildByName('lock'); const highlight = this.free.getChildByName('highlight'); const received = this.free.getChildByName('received'); const isEmpty = Object.values(reward).every(val => val == 0); this.free.active = !isEmpty; for (const [key, val] of Object.entries(reward)) { if (!this[`prop_${key}`] || val == 0) continue; const item = rewards.getChildByName(`prop_${key}`) ?? instantiate(this[`prop_${key}`]); item.parent = rewards; item.active = true; item.getComponent(Sprite).spriteFrame = this.img_bg_free_node; const num = item.getChildByName('num'); const label = num.getComponent(Label); if (key == "sc" || key == "gc") { label.string = `${(Number(val) / 100).toFixed(2)}`; } else { label.string = `${val}`; } } rewards.active = true; lock.active = unlocked == 0; highlight.active = claimed == 0 && unlocked == 1; received.active = claimed == 1; this.stopLightBlink(highlight); if (claimed == 0 && unlocked == 1) this.startLightBlink(highlight); } updateDeluxe() { const { node, is_deluxe } = this._data; if (!node) return; const { deluxe, unlocked } = node ?? {}; const { reward, claimed } = deluxe ?? {}; const rewards = this.dlx.getChildByName('rewards'); const lock = this.dlx.getChildByName('lock'); const highlight = this.dlx.getChildByName('highlight'); const received = this.dlx.getChildByName('received'); const isEmpty = Object.values(reward).every(val => val == 0); this.dlx.active = !isEmpty; for (const [key, val] of Object.entries(reward)) { if (!this[`prop_${key}`] || val == 0) continue; const item = rewards.getChildByName(`prop_${key}`) ?? instantiate(this[`prop_${key}`]); item.parent = rewards; item.active = true; item.getComponent(Sprite).spriteFrame = this.img_bg_dlx_node; const num = item.getChildByName('num'); const label = num.getComponent(Label); if (key == "sc" || key == "gc") { label.string = `${(Number(val) / 100).toFixed(2)}`; } else { label.string = `${val}`; } } rewards.active = true; lock.active = unlocked == 0 || is_deluxe == 0; highlight.active = claimed == 0 && unlocked == 1 && is_deluxe == 1; received.active = claimed == 1 && is_deluxe == 1; this.stopLightBlink(highlight); if (claimed == 0 && unlocked == 1 && is_deluxe == 1) this.startLightBlink(highlight); } updateProgress() { const { node, current_xp, is_deluxe } = this._data; if (!node) return; const { required_xp } = node ?? {}; const progressBar = this.progress.getComponent(ProgressBar); const label = this.progress.getChildByName('label').getComponent(Label); label.string = required_xp + "XP"; if (current_xp == required_xp) { progressBar.progress = 0.53; } else if (current_xp > required_xp) { progressBar.progress = 1; } else if (current_xp < required_xp) { progressBar.progress = 0; } else { } } private async onDlxBtnClick() { const { reward_id, reward } = this._data?.node?.deluxe ?? {}; const res = await AppKernel.stores.seasonPassStore.reqSeasonPassPrizeClaim(reward_id); if (res) AppKernel.ui.open(UIViewID.RewardView, { reward }); } private async onFreeBtnClick() { const { reward_id, reward } = this._data?.node?.free ?? {}; const res = await AppKernel.stores.seasonPassStore.reqSeasonPassPrizeClaim(reward_id); if (res) AppKernel.ui.open(UIViewID.RewardView, { reward }); } startLightBlink(lightNode: Node) { const uiOpacity = lightNode.getComponent(UIOpacity) || lightNode.addComponent(UIOpacity); // 先重置初始透明度 uiOpacity.opacity = 255; tween(uiOpacity) .to(0.6, { opacity: 0 }) .to(0.6, { opacity: 255 }) .union() .repeatForever() // 无限循环闪烁 .start(); } // 停止闪烁 stopLightBlink(lightNode: Node) { const uiOpacity = lightNode.getComponent(UIOpacity); if (!uiOpacity) return; tween(uiOpacity).stop(); uiOpacity.opacity = 255; // 恢复不透明 } }