PlayGamePassReward.ts 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import UserM, { GiftItemInfo } from "../../scripts/api/UserM";
  4. import { Tips } from "../../scripts/mgr/Tips";
  5. import GameM from "../../scripts/api/GameM";
  6. import { GoodsId } from "../../scripts/api/GoodsId";
  7. const { ccclass, property } = _decorator;
  8. @ccclass("PlayGamePassReward")
  9. export class PlayGamePassReward extends BaseUI {
  10. private data: GiftItemInfo;
  11. private gameId: number;
  12. private onClaimSuccess: () => void;
  13. async init(gameId: number, data: GiftItemInfo, onClaimSuccess: () => void) {
  14. this.data = data;
  15. this.gameId = gameId;
  16. this.onClaimSuccess = onClaimSuccess;
  17. this.setText("lbl_game_pass_reward", this.data.rewardMsg);
  18. this.FindNode("btn_game_pass_claim").active = this.data.canClaim > 0;
  19. }
  20. protected simpleOnBtnClick(name: string): void {
  21. switch (name) {
  22. case "btn_game_pass_claim":
  23. this.requestClaimGamePassGift();
  24. break;
  25. }
  26. }
  27. async requestClaimGamePassGift() {
  28. if (UserM.ins.getGamePassCount() <= 0) {
  29. Tips.show("Insufficient Game Pass");
  30. return;
  31. }
  32. let result = await GameM.ins.claimGamePassGift(
  33. this.gameId,
  34. this.data.giftId
  35. );
  36. if (result) {
  37. this.onClaimSuccess();
  38. }
  39. }
  40. }