| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import { _decorator, instantiate, Label, Node } from 'cc';
- import { AppKernel } from '@scripts/app/AppKernel';
- import { IGameInfo } from '@scripts/store/pageSlice/data';
- import { UIView } from '@scripts/framework/ui/UIView';
- import { UIViewID } from '@scripts/define/UIDefine';
- import { GameItem } from './GameItem';
- const { ccclass, property } = _decorator;
- @ccclass('HomeView')
- export class HomeView extends UIView {
- readonly viewId = UIViewID.HomeView;
- @property(Label)
- lblNickName: Label;
- @property(GameItem)
- gamePrefab: GameItem;
- @property(Node)
- gameRoot: Node;
- protected onCreate(): void | Promise<void> {
- AppKernel.events.on('login:success', this.updateView, this);
- }
- protected onOpen(_params: unknown): void | Promise<void> {
- this.updateView();
- }
- private updateView() {
- const mainStore = AppKernel.stores.mainStore;
- this.lblNickName.string = mainStore.userInfo?.NickName || "";
- const pageStore = AppKernel.stores.pageStore;
- const gameList = pageStore.gameList || [];
- if (gameList.length > 0) {
- const index = 0;//Math.floor(Math.random() * gameList.length);
- this.initGameItem(gameList[index]);
- }
- }
- private async initGameItem(game: IGameInfo) {
- const gameNode = instantiate(this.gamePrefab.node).getComponent(GameItem);
- gameNode.node.setParent(this.gameRoot);
- gameNode.node.active = true;
- gameNode.initView(game);
- }
- }
|