| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 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';
- import { addBtnClick } from '@scripts/utils/UIHelper';
- 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;
- @property(Node)
- btnMail: Node;
- protected onCreate(): void | Promise<void> {
- AppKernel.events.on('login:success', this.updateView, this);
- addBtnClick(this.btnMail, this.onBtnMailClick, 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);
- }
- private onBtnMailClick() {
- AppKernel.ui.open(UIViewID.MailView);
- }
- }
|