HomeView.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, instantiate, Label, Node, ScrollView, size, Size } from 'cc';
  2. import { AppKernel } from '@scripts/app/AppKernel';
  3. import { UIView } from '@scripts/framework/ui/UIView';
  4. import { UIViewID } from '@scripts/define/UIDefine';
  5. import { GameItem } from './GameItem';
  6. import { addBtnClick } from '@scripts/utils/UIHelper';
  7. import { IGameInfo } from '@scripts/store/gameStore/data';
  8. import LoopList from '@scripts/components/loopList/LoopList';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('HomeView')
  11. export class HomeView extends UIView {
  12. readonly viewId = UIViewID.HomeView;
  13. @property(Node)
  14. gameRoot: Node;
  15. @property(Node)
  16. btnMail: Node;
  17. @property(Node)
  18. btnStore: Node;
  19. @property(Node)
  20. gamePrefab: Node;
  21. @property(ScrollView)
  22. gameScroll: ScrollView;
  23. @property(Node)
  24. gameRender: Node;
  25. protected onCreate(): void | Promise<void> {
  26. // AppKernel.events.on('login:success', this.updateView, this);
  27. addBtnClick(this.btnMail, this.onBtnMailClick, this);
  28. addBtnClick(this.btnStore, this.onBtnStoreClick, this);
  29. }
  30. protected onOpen(_params: unknown): void | Promise<void> {
  31. this.updateView();
  32. }
  33. private updateView() {
  34. const mainStore = AppKernel.stores.mainStore;
  35. // this.gameRoot.destroyAllChildren();
  36. const gameStore = AppKernel.stores.gameStore;
  37. const gameList = gameStore.getGameList();
  38. // gameList.map(game => this.initGameItem(game));
  39. LoopList.ins<IGameInfo>("HomeGameList").init(this.gameScroll, this.gameRender, 20);
  40. LoopList.ins<IGameInfo>("HomeGameList").initData(gameList, this.gamePrefab, size(115, 140))
  41. }
  42. private async initGameItem(game: IGameInfo) {
  43. const gameNode = instantiate(this.gamePrefab).getComponent(GameItem);
  44. gameNode.node.setParent(this.gameRoot);
  45. gameNode.node.active = true;
  46. }
  47. private onBtnMailClick() {
  48. AppKernel.ui.open(UIViewID.MailView);
  49. }
  50. private onBtnStoreClick() {
  51. AppKernel.ui.open(UIViewID.StoreView);
  52. }
  53. }