123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- import { _decorator, Component, Node } from "cc";
- import { Hall } from "../hall/Hall";
- import { ScrollView } from "cc";
- import BaseUI from "../../scripts/base/BaseUI";
- import UIUtils from "../../scripts/base/UIUtils";
- import AB from "../../scripts/base/AB";
- import { Prefab } from "cc";
- import { instantiate } from "cc";
- import { UITransform } from "cc";
- import { Sprite } from "cc";
- import { GoodInfo } from "../../scripts/api/UserM";
- import { TapClose } from "../../scripts/base/TapClose";
- import { RewardItem } from "../item/RewardItem";
- import { GoodsId } from "../../scripts/api/GoodsId";
- import { FlyContainer } from "../hall/FlyContainer";
- import { isValid } from "cc";
- const { ccclass, property } = _decorator;
- export interface OnCloseCallback {
- (): void;
- }
- @ccclass("RewardLayer")
- export class RewardLayer extends BaseUI {
- static mock() {
- if (1 > 1) {
- RewardLayer.show([
- {
- id: 1,
- count: 100,
- },
- ]);
- return;
- }
- RewardLayer.show([
- {
- id: 1,
- count: 100,
- },
- {
- id: 2,
- count: 600,
- },
- {
- id: 4,
- count: 300,
- },
- {
- id: 1,
- count: 100,
- },
- {
- id: 1,
- count: 100,
- },
- {
- id: 1,
- count: 100,
- },
- {
- id: 2,
- count: 200,
- },
- {
- id: 1,
- count: 300,
- },
- {
- id: 1,
- count: 300,
- },
- {
- id: 1,
- count: 100,
- },
- ]);
- }
- static async show(items: GoodInfo[], onClose: OnCloseCallback = null) {
- let layer = await Hall.ins.showLayer("prefab/layer/RewardLayer");
- layer.getComponent(RewardLayer).init(items, onClose);
- }
- protected onLoad(): void {
- super.onLoad();
- }
- private items: GoodInfo[] = [];
- private onClose: OnCloseCallback;
- init(items: GoodInfo[], onClose: OnCloseCallback) {
- this.items = items;
- this.onClose = onClose;
- let bgTr = this.FindAs("bg", UITransform);
- if (items.length == 1) {
- bgTr.node.getComponent(Sprite).enabled = false;
- }
- this.FindNode("lbl_nothing").active = false;
- if (!items || items.length == 0) {
- this.FindNode("lbl_nothing").active = true;
- return;
- }
- this.ui();
- }
-
- protected closePage(): void {
- this.onClose?.();
- try {
- this.getComponentsInChildren(RewardItem).forEach((item) => {
- let good = item.getItem();
- FlyContainer.ins.onReward(item.node, good);
- });
-
- this.node.destroy();
- } catch (error) {
- console.log("error", error);
- }
- super.closePage();
- }
- async ui() {
- this.canClose = false;
- let tap = this.node.getComponentInChildren(TapClose);
- tap.node.active = false;
- let tpl: Prefab = await AB.ins.loadPrefab("prefab/item/RewardItem");
- let animTime = 200;
- for (let i = 0; i < this.items.length; i++) {
- let item = this.items[i];
- let itemNode = instantiate(tpl);
- itemNode.active = false;
- itemNode.setPosition(0, 0, 0);
- itemNode.parent = this.FindNode("slot" + (i + 1));
- let delay = 200 + i * 200;
- animTime = delay;
- itemNode.getComponent(RewardItem).init(delay, item);
- }
- let self = this;
- setTimeout(() => {
- self.canClose = true;
- if (isValid(self.node)) {
- tap.node.active = true;
- }
- }, this.items.length * 200 + 2000);
- }
- }
|