import { _decorator, instantiate, Label, Node, ScrollView, size, Size } from 'cc'; import { AppKernel } from '@scripts/app/AppKernel'; import { UIView } from '@scripts/framework/ui/UIView'; import { UIViewID } from '@scripts/define/UIDefine'; import { GameItem } from './GameItem'; import { addBtnClick } from '@scripts/utils/UIHelper'; import { IGameInfo } from '@scripts/store/gameStore/data'; import LoopList from '@scripts/components/loopList/LoopList'; const { ccclass, property } = _decorator; @ccclass('HomeView') export class HomeView extends UIView { readonly viewId = UIViewID.HomeView; @property(Node) gameRoot: Node; @property(Node) btnMail: Node; @property(Node) btnStore: Node; @property(Node) gamePrefab: Node; @property(ScrollView) gameScroll: ScrollView; @property(Node) gameRender: Node; protected onCreate(): void | Promise { // AppKernel.events.on('login:success', this.updateView, this); addBtnClick(this.btnMail, this.onBtnMailClick, this); addBtnClick(this.btnStore, this.onBtnStoreClick, this); } protected onOpen(_params: unknown): void | Promise { this.updateView(); } private updateView() { const mainStore = AppKernel.stores.mainStore; // this.gameRoot.destroyAllChildren(); const gameStore = AppKernel.stores.gameStore; const gameList = gameStore.getGameList(); // gameList.map(game => this.initGameItem(game)); LoopList.ins("HomeGameList").init(this.gameScroll, this.gameRender, 20); LoopList.ins("HomeGameList").initData(gameList, this.gamePrefab, size(115, 140)) } private async initGameItem(game: IGameInfo) { const gameNode = instantiate(this.gamePrefab).getComponent(GameItem); gameNode.node.setParent(this.gameRoot); gameNode.node.active = true; } private onBtnMailClick() { AppKernel.ui.open(UIViewID.MailView); } private onBtnStoreClick() { AppKernel.ui.open(UIViewID.StoreView); } }