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 { setOriginalSp, setSpriteFrame } from '@scripts/utils/ResHelper'; import { addBtnClick, removeBtnClick } from '@scripts/utils/UIHelper'; import { _decorator, Button, Component, Enum, instantiate, Label, Node, NodePool, Prefab, ProgressBar, Sprite, UIOpacity, UITransform } from 'cc'; const { ccclass, property } = _decorator; export enum RewardType { Daily = 'daily', Seasonal = 'seasonal' } @ccclass('RewardItem') export class RewardItem extends Component { @property(Node) private bg_unclaim: Node = null; @property(Node) private bg_claimed: Node = null; @property(Sprite) private task_icon: Sprite = null; @property(Label) private task_detail: Label = null; @property(ProgressBar) private progress: ProgressBar = null; @property(Label) private progress_label: Label = null; @property(Node) private rewards: Node = null; @property(Node) private btn_go: Node = null; @property(Node) private btn_claim: Node = null; @property(Node) private btn_claimed: Node = null; @property(Prefab) private prop_sc: Prefab = null; @property(Prefab) private prop_gc: Prefab = null; @property(Prefab) private prop_pass_xp: Prefab = null; private _data: any = {}; private _rewardType: RewardType; onLoad() { // 只绑定一次! addBtnClick(this.btn_go, this.handleBtnGoClick, this); addBtnClick(this.btn_claim, this.handleBtnClaimClick, this); addBtnClick(this.btn_claimed, this.handleBtnClaimedClick, this); } initItem(data: any = {}, rewardType: RewardType) { this._data = data; this._rewardType = rewardType; setSpriteFrame(this.bg_unclaim.getComponent(Sprite), 'textures/seasonPass/tasks/tasks_bg_claim_' + this._rewardType); setSpriteFrame(this.bg_claimed.getComponent(Sprite), 'textures/seasonPass/tasks/tasks_bg_claimed_' + this._rewardType); const { task_type, target_value, progress, reward, status } = this._data; const path_prefix = 'textures/seasonPass/tasks/detailIcon/'; let path = path_prefix; switch (task_type) { // 1 签到 // 2 完成指定数量的子游戏 // 3 子游戏游玩次数(需指定 game_id) // 4 子游戏游玩时长(需指定 game_id) // 5 获得 SC case 1: path += 'icon_check'; this.task_detail.string = `CHECK IN TODAY`; if (this._rewardType == RewardType.Seasonal) this.task_detail.string = `CHECK IN ${target_value} DAYS`; break; case 2: path += 'icon_game'; this.task_detail.string = `PLAY ${target_value} SUBGAMES`; break; case 3: path += 'icon_win'; this.task_detail.string = `WIN ${target_value} SUBGAMES`; break; case 4: path += 'icon_time'; this.task_detail.string = `PLAY ${target_value} MINS`; break; case 5: path += 'icon_sc'; this.task_detail.string = `OBTAIN SC`; break; } setOriginalSp(this.task_icon, path); this.progress.progress = progress / target_value; this.progress_label.string = `${progress}/${target_value}`; for (const [key, val] of Object.entries(reward)) { if (!this[`prop_${key}`] || val == 0) continue; const item = this.rewards.getChildByName(`prop_${key}`) ?? instantiate(this[`prop_${key}`]); item.parent = this.rewards; item.active = true; 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}`; } } this.btn_go.active = status == 0; this.btn_claim.active = status == 1; this.btn_claimed.active = status == 2; this.bg_unclaim.active = status != 2; this.bg_claimed.active = status == 2; } handleBtnGoClick() { const { task_type } = this._data; switch (task_type) { // 1 签到 // 2 完成指定数量的子游戏 // 3 子游戏游玩次数(需指定 game_id) // 4 子游戏游玩时长(需指定 game_id) // 5 获得 SC case 1: AppKernel.ui.open(UIViewID.CheckInView); // 监听签到变化 break; case 2: case 3: case 4: case 5: AppKernel.ui.close(UIViewID.SeasonPassView); break; } } async handleBtnClaimClick() { const { id: task_id, reward } = this._data; const res = await AppKernel.stores.seasonPassStore.reqSeasonPassTasksClaim(task_id); if (res) AppKernel.ui.open(UIViewID.RewardView, { reward }); } handleBtnClaimedClick() { } }