| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- import { AppKernel } from '@scripts/app/AppKernel';
- import { IGameInfo } from '@scripts/store/gameStore/data';
- import { setSpriteFrame } from '@scripts/utils/ResHelper';
- import { addBtnClick, removeBtnClick, setAlpha } from '@scripts/utils/UIHelper';
- import { _decorator, Button, Color, Component, Label, Node, Size, Sprite } from 'cc';
- const { ccclass, property } = _decorator;
- @ccclass('GameItem')
- export class GameItem extends Component {
- @property(Sprite)
- gameIcon: Sprite;
- @property(Node)
- btnFavo: Node;
- @property(Sprite)
- favoFlag: Sprite;
- @property(Label)
- lblGameName: Label;
- private _data: IGameInfo;
- private _dataIdx: number;
- protected onLoad(): void {
- addBtnClick(this.node, this.onClick, this);
- addBtnClick(this.btnFavo, this.onBtnFavoClick, this);
- }
- public updateItem(data: IGameInfo, index: number) {
- this._data = data;
- this._dataIdx = index;
- if (!this.node.active) this.node.active = true;
- if (this.lblGameName) this.lblGameName.string = data.gameName;
- setAlpha(this.favoFlag, data.isFavorite);
- setSpriteFrame(this.gameIcon, "https://cdn.usgamestatic.com/24680/game/lw/bankersbreachcollisionways@1x.webp");
- }
- private onClick() {
- AppKernel.appLobby.openGame(this._data);
- // AppKernel.appLobby.openGame(this._gameConfig.id);
- }
- private async onBtnFavoClick() {
- const gameStore = AppKernel.stores.gameStore;
- if (gameStore.favoriting) return;
- const index = this._dataIdx;
- const data = this._data;
- const isFavorite = data.isFavorite;
- const game = isFavorite ? await gameStore.reqFavoRemove(data.gameID)
- : await gameStore.reqFavoAdd(data.gameID);
- if (!!game && this._dataIdx === index) {
- this.updateItem(game, index);
- }
- }
- }
|