GameItem.ts 927 B

123456789101112131415161718192021222324252627282930313233
  1. import { AppKernel } from '@scripts/app/AppKernel';
  2. import { IGameInfo } from '@scripts/store/pageSlice/data';
  3. import { addBtnClick, removeBtnClick } from '@scripts/utils/UIHelper';
  4. import { _decorator, Component, Node, Sprite } from 'cc';
  5. const { ccclass, property } = _decorator;
  6. @ccclass('GameItem')
  7. export class GameItem extends Component {
  8. @property(Sprite)
  9. gameIcon: Sprite;
  10. private _gameConfig: IGameInfo;
  11. protected onLoad(): void {
  12. addBtnClick(this.node, this.onClick, this);
  13. }
  14. protected onDestroy(): void {
  15. removeBtnClick(this.node, this.onClick, this);
  16. }
  17. public async initView(game: IGameInfo) {
  18. this._gameConfig = game;
  19. const resLoader = AppKernel.resources;
  20. this.gameIcon.spriteFrame = await resLoader.loadRemoteSp(game.img);
  21. }
  22. private onClick() {
  23. AppKernel.services.lobbyService.openGame(this._gameConfig.id);
  24. }
  25. }