BadgeDetailLayer.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { _decorator, Component, Node } from "cc";
  2. import { Hall } from "../hall/Hall";
  3. import BaseUI from "../../scripts/base/BaseUI";
  4. import WalletM from "../../scripts/api/WalletM";
  5. import UserM from "../../scripts/api/UserM";
  6. import { instantiate } from "cc";
  7. import { ScrollView } from "cc";
  8. import AB from "../../scripts/base/AB";
  9. import { Prefab } from "cc";
  10. import { BadgeItem } from "../item/BadgeItem";
  11. const { ccclass, property } = _decorator;
  12. @ccclass("BadgeDetailLayer")
  13. export class BadgeDetailLayer extends BaseUI {
  14. static TYPE_RANK = 1;
  15. static TYPE_GAME_PASS = 2;
  16. static async show(type: number) {
  17. let layer = await Hall.ins.showLayer("prefab/layer/BadgeDetailLayer");
  18. layer.getComponent(BadgeDetailLayer).init(type);
  19. }
  20. private scrollView: ScrollView = null;
  21. protected onLoad(): void {
  22. super.onLoad();
  23. this.scrollView = this.FindAs("ScrollView", ScrollView);
  24. }
  25. private _type: number = 0;
  26. async init(type: number) {
  27. this._type = type;
  28. let tpl: Prefab = await AB.ins.loadPrefab("prefab/item/BadgeItem");
  29. let list = await UserM.ins.getBadgeList();
  30. if (!list || !list.badgeList || list.badgeList.length == 0) {
  31. this.FindNode("NoData").active = true;
  32. return;
  33. }
  34. this.FindNode("NoData").active = false;
  35. for (let i = 0; i < list.badgeList.length; i++) {
  36. let item = list.badgeList[i];
  37. let itemNode = instantiate(tpl);
  38. itemNode.getComponent(BadgeItem).init(item);
  39. this.scrollView.content.addChild(itemNode);
  40. }
  41. }
  42. }