BallUIShop.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import {
  2. _decorator,
  3. Component,
  4. instantiate,
  5. Layout,
  6. Node,
  7. ScrollView,
  8. } from "cc";
  9. import BaseUI from "../base/BaseUI";
  10. import { ModuleDef } from "../../scripts/ModuleDef";
  11. import { GameUILayers } from "../../scripts/GameUILayers";
  12. import { Lobby } from "./Lobby";
  13. import { CommonTabsTitle } from "../ui_base/CommonTabsTitle";
  14. import { ShopItem } from "../ui_items/ShopItem";
  15. import UIUtils from "../base/UIUtils";
  16. const { ccclass, property } = _decorator;
  17. @ccclass("BallUIShop")
  18. export class BallUIShop extends BaseUI {
  19. static show() {
  20. tgx.UIMgr.inst.show(ModuleDef.BALL, "ui_lobby/ui_shop", GameUILayers.POPUP);
  21. }
  22. protected onDestroy(): void {
  23. Lobby.ins.enter();
  24. }
  25. private _tabs: CommonTabsTitle;
  26. protected onLoad(): void {
  27. super.onLoad();
  28. let self = this;
  29. this._ScrollView = this.FindAs("ScrollView", ScrollView);
  30. this._tpl = this.FindNode("ShopItem");
  31. this._tpl.active = false;
  32. this._tabs = this.getComponentInChildren(CommonTabsTitle);
  33. this._tabs.init(["MENU1", "MENU2"], {
  34. onTabClick(index) {
  35. self.tabSelect(index);
  36. },
  37. });
  38. }
  39. private _ScrollView: ScrollView;
  40. private _tpl: Node;
  41. async refreshUI() {
  42. this._ScrollView.content.removeAllChildren();
  43. for (let i = 0; i < 20; i++) {
  44. let item = instantiate(this._tpl);
  45. // item.setPosition(0, 0, 0);
  46. this._ScrollView.content.addChild(item);
  47. let comp = item.getComponent(ShopItem);
  48. comp.init(i);
  49. }
  50. UIUtils.AnimateLayoutItems(this._ScrollView.content, {
  51. duration: 0.4,
  52. delayInterval: 100,
  53. });
  54. }
  55. private tabSelect(tab: number) {
  56. this._tabs.setSelect(tab);
  57. this.refreshUI();
  58. }
  59. protected start(): void {
  60. this.tabSelect(0);
  61. }
  62. }