| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- 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, UIOpacity } 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;
- switch (task_type) {
- // 1 签到
- // 2 完成指定数量的子游戏
- // 3 子游戏游玩次数(需指定 game_id)
- // 4 子游戏游玩时长(需指定 game_id)
- // 5 获得 SC
- case 1:
- setSpriteFrame(this.task_icon, 'textures/seasonPass/tasks/detailIcon/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:
- setSpriteFrame(this.task_icon, 'textures/seasonPass/tasks/detailIcon/icon_game');
- this.task_detail.string = `PLAY ${target_value} SUBGAMES`;
- break;
- case 3:
- setSpriteFrame(this.task_icon, 'textures/seasonPass/tasks/detailIcon/icon_win');
- this.task_detail.string = `WIN ${target_value} SUBGAMES`;
- break;
- case 4:
- setSpriteFrame(this.task_icon, 'textures/seasonPass/tasks/detailIcon/icon_time');
- this.task_detail.string = `PLAY ${target_value} MINS`;
- break;
- case 5:
- setSpriteFrame(this.task_icon, 'textures/seasonPass/tasks/detailIcon/icon_sc');
- this.task_detail.string = `OBTAIN SC`;
- break;
- }
- 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() {
- }
- }
|