BadgeDetailLayer.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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 all = await UserM.ins.getBadgeList();
  30. let list = [];
  31. for (let i = 0; i < all.badgeList.length; i++) {
  32. if (all.badgeList[i].type == type) {
  33. list.push(all.badgeList[i]);
  34. }
  35. }
  36. list = list.filter((item) => item.id != 0);
  37. if (list.length == 0) {
  38. this.FindNode("NoData").active = true;
  39. return;
  40. }
  41. this.FindNode("NoData").active = false;
  42. for (let i = 0; i < list.length; i++) {
  43. let item = list[i];
  44. let itemNode = instantiate(tpl);
  45. itemNode.getComponent(BadgeItem).init(item);
  46. this.scrollView.content.addChild(itemNode);
  47. }
  48. }
  49. }