YzLoginPanel.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import CompatibleTool from "./CompatibleTool";
  2. import PlatUtils from "./PlatUtils";
  3. import { utils } from "./Utils";
  4. import YZ_Constant, { BannerLocation } from "./YZ_Constant";
  5. import YZ_LocalStorage from "./YZ_LocalStorage";
  6. const { ccclass, property } = cc._decorator;
  7. @ccclass
  8. export default class YzLoginPanel extends cc.Component {
  9. ratio: number = 1;
  10. okBtn: cc.Node = null;
  11. successFunc: Function = null;
  12. failFunc: Function = null;
  13. onLoad() {
  14. if (utils.otherConfig && utils.otherConfig.group) {
  15. this.node.group = utils.otherConfig.group;
  16. }
  17. let panel = cc.find("Panel", this.node);
  18. this.okBtn = cc.find("OKBtn", panel);
  19. if (cc.winSize.height < cc.winSize.width) {
  20. // 横屏游戏
  21. this.ratio = cc.winSize.width / 1920 * 0.75;
  22. } else {
  23. this.ratio = cc.winSize.width / 1080;
  24. }
  25. cc.find("Panel", this.node).scale = this.ratio;
  26. }
  27. protected onDestroy(): void {
  28. cc.game.targetOff(this);
  29. }
  30. onOKClickListener() {
  31. this.okBtn.getComponent(cc.Button).interactable = false;
  32. let successFunc = () => {
  33. utils.showLog("登录成功!");
  34. this.successFunc && this.successFunc();
  35. this.node.destroy();
  36. }
  37. let failFunc = (result: any) => {
  38. this.failFunc && this.failFunc();
  39. this.okBtn.getComponent(cc.Button).interactable = true;
  40. // utils.showMsg("登录失败,请重试");
  41. }
  42. cc.game.targetOff(this);
  43. cc.game.on(YZ_Constant.ST_LOGIN_SUCCESS, successFunc, this);
  44. cc.game.on(YZ_Constant.ST_LOGIN_FAIL, failFunc, this);
  45. utils.login(null, null);
  46. }
  47. onCloseClickListener() {
  48. utils.GameExit();
  49. }
  50. // update (dt) {}
  51. }