BindGameLayer.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, Node } from "cc";
  2. import BaseUI from "../../scripts/base/BaseUI";
  3. import { Hall } from "../hall/Hall";
  4. import {
  5. BindGameInputLayer,
  6. BindGameInputLayerListener,
  7. } from "./BindGameInputLayer";
  8. import { Tips } from "../../scripts/mgr/Tips";
  9. import { BindGameM } from "../../scripts/api/BindGameM";
  10. import UserM from "../../scripts/api/UserM";
  11. import GameM from "../../scripts/api/GameM";
  12. const { ccclass, property } = _decorator;
  13. @ccclass("BindGameLayer")
  14. export class BindGameLayer
  15. extends BaseUI
  16. implements BindGameInputLayerListener
  17. {
  18. static async show() {
  19. let layer = await Hall.ins.showLayer("prefab/layer/BindGameLayer");
  20. layer.getComponent(BindGameLayer).init();
  21. }
  22. protected onLoad(): void {
  23. super.onLoad();
  24. this.FindNode("BindGameItem").active = false;
  25. }
  26. private async init() {
  27. await UserM.ins.refreshInfo();
  28. let isPvzLinked: boolean = await UserM.ins.getPvzLinked();
  29. this.setText(
  30. "lbl_link_pvz_state",
  31. "Link Status: " + (isPvzLinked ? "✅" : "❌")
  32. );
  33. if (isPvzLinked) {
  34. let pvz_user_name = UserM.ins.data.gameList.find(
  35. (item) => item.gameId == 1
  36. )?.gameUser?.userName;
  37. if (pvz_user_name != null && pvz_user_name.length > 0) {
  38. this.setText("lbl_link_pvz_user_name", "@" + pvz_user_name);
  39. }
  40. }
  41. }
  42. OnInput(gameId: number, input: string): void {
  43. this.startBindGame(gameId, input);
  44. }
  45. async startBindGame(gameId: number, input: string) {
  46. let result = await GameM.ins.bindGame(gameId, input);
  47. if (result != null) {
  48. this.init();
  49. // Tips.show("Waiting for binding...");
  50. // this.setText("lbl_code_banana", input);
  51. }
  52. }
  53. protected simpleOnBtnClick(name: string): void {
  54. switch (name) {
  55. case "btn_bind_game_pvz":
  56. // Tips.show("Coming soon");
  57. let gameId = 1;
  58. BindGameInputLayer.show(gameId, this);
  59. break;
  60. }
  61. }
  62. }