123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- import { _decorator, Component, Node } from "cc";
- import BaseUI from "../../scripts/base/BaseUI";
- import UIUtils from "../../scripts/base/UIUtils";
- import { Vec3 } from "cc";
- import { GoodInfo } from "../../scripts/api/UserM";
- import { GoodsId } from "../../scripts/api/GoodsId";
- import ConfigM from "../../scripts/api/ConfigM";
- import { isValid } from "cc";
- const { ccclass, property } = _decorator;
- export interface OnItemClick {
- (item: GoodInfo): void;
- }
- @ccclass("RewardItem")
- export class RewardItem extends BaseUI {
- private onItemClick: OnItemClick = null;
- private item: GoodInfo = null;
- public getItem(): GoodInfo {
- return this.item;
- }
- init(delay: number, item: GoodInfo, onItemClick: OnItemClick = null) {
- let self = this;
- self.onItemClick = onItemClick;
- self.item = item;
- this.setText("lbl_count", "x" + item.count);
- let parent = this.FindNode("icon_layout");
- parent.children.forEach((child) => {
- child.active = false;
- });
- switch (item.id) {
- case GoodsId.POG:
- case GoodsId.POG_10:
- parent.getChildByName("icon_pog").active = true;
- // itemName = "POG";
- break;
- case GoodsId.GEM:
- case GoodsId.DIAMOND_10:
- parent.getChildByName("icon_gem").active = true;
- break;
- case GoodsId.GAME_PASS_SHARD:
- parent.getChildByName("icon_puzzle").active = true;
- break;
- case GoodsId.GAME_PASS:
- parent.getChildByName("game_pass").active = true;
- break;
- case GoodsId.POG_CRITICAL_CARD:
- parent.getChildByName("icon_crit").active = true;
- break;
- case GoodsId.FREE_ITEM_BOX:
- case GoodsId.ITEM_BOX:
- parent.getChildByName("icon_item_box").active = true;
- break;
- case GoodsId.FREE_POG_BOX:
- case GoodsId.POG_BOX:
- parent.getChildByName("icon_pog_box").active = true;
- break;
- case GoodsId.AIR:
- parent.getChildByName("icon_nothing").active = true;
- this.FindNode("lbl_count").active = false;
- break;
- case GoodsId.TOG:
- parent.getChildByName("icon_tog").active = true;
- break;
- case GoodsId.ES_TOG:
- parent.getChildByName("icon_estog").active = true;
- break;
- case GoodsId.FAMILY_BOX:
- parent.getChildByName("icon_family_box").active = true;
- break;
- }
- let configItemName = ConfigM.ins.getGoodName(item.id);
- this.setText("lbl_name", configItemName);
- if (delay <= 0) {
- self.node.active = true;
- } else {
- this.anim(delay, item);
- }
- }
- anim(delay: number, item: GoodInfo) {
- let time = delay;
- let self = this;
- self.node.setPosition(0, -700, 0);
- self.node.scale = new Vec3(0.5, 0.5, 0.5);
- setTimeout(() => {
- if (isValid(self.node)) {
- self.node.active = true;
- UIUtils.AnimBezierMoveAndScale(this.node, new Vec3(0, 0, 0), 1, 0.5);
- }
- }, time);
- }
- protected simpleOnBtnClick(name: string): void {
- if (this.onItemClick) {
- this.onItemClick(this.item);
- }
- }
- }
|