UITrySkinPanel.ts 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { access } from "fs";
  2. import PlatUtils from "../../common-plugin/Scripts/PlatUtils";
  3. import { utils } from "../../common-plugin/Scripts/Utils";
  4. import { BannerLocation } from "../../common-plugin/Scripts/YZ_Constant";
  5. import { cocosz } from "../Framework/CocosZ";
  6. import { PanelName } from "../Framework/Constant";
  7. import UIPage from "../Framework/UIPage";
  8. import Ani from "../Game/ani";
  9. const { ccclass } = cc._decorator;
  10. @ccclass
  11. export default class UITrySkinPanel extends UIPage {
  12. private _mask: cc.Node = null;
  13. private _panel: cc.Node = null;
  14. private aniArr: cc.Node[] = [];
  15. private btnArr: cc.Node[] = [];
  16. skinArr: number[] = [];
  17. constructor() {
  18. super(PanelName.UITrySkinPanel);
  19. this.isValid() && this.onLoad();
  20. }
  21. protected onLoad() {
  22. this._panel = this._page.getChildByName("Panel");
  23. this._mask = this._page.getChildByName("Mask");
  24. this.aniArr[0] = this._panel.getChildByName("ani0");
  25. this.aniArr[1] = this._panel.getChildByName("ani1");
  26. this.aniArr[2] = this._panel.getChildByName("ani2");
  27. let btnNames: string[] = ["BtnVideo0", "BtnVideo1", "BtnVideo2", "BtnPass"];
  28. for (let i = 0; i < btnNames.length; i++) {
  29. let btn: cc.Node = cc.find(btnNames[i], this._panel);
  30. if (btn) {
  31. this.btnArr[i] = btn;
  32. btn.on(cc.Node.EventType.TOUCH_END, this._onBtnClickedHandler, this);
  33. }
  34. }
  35. }
  36. protected onOpen() {
  37. utils.SendEvent("页面-皮肤试用");
  38. // 暂停游戏逻辑
  39. cocosz.pauseCount++;
  40. // 未解锁的皮肤id数组
  41. let arr = cocosz.dataMgr.getRandomLockSkin();
  42. if (arr.length > 0) {
  43. // 随机3个皮肤
  44. for (let i = 0; i < 3; i++) {
  45. if (arr.length > 0) {
  46. let index = Math.floor(Math.random() * arr.length);
  47. let id = arr[index];
  48. arr.splice(index, 1);
  49. this.skinArr[i] = id;
  50. // 显示任务
  51. let aniTs = this.aniArr[i].getComponent(Ani);
  52. aniTs.setSkinById(id);
  53. aniTs.setWeaponById(cocosz.dataMgr.CurRange);
  54. this.aniArr[i].opacity = 0;
  55. cocosz.scheduleOnce(() => {
  56. if (this._page && this.aniArr[i]) {
  57. cc.tween(this.aniArr[i])
  58. .set({ y: 500, opacity: 255 })
  59. .to(0.4, { y: 50 }, { easing: "sineOut" })
  60. .start();
  61. }
  62. }, 0.3 * i)
  63. } else {
  64. // 皮肤不够隐藏
  65. this.aniArr[i].active = false;
  66. this.btnArr[i].active = false;
  67. }
  68. }
  69. } else {
  70. // 没有未解锁皮肤,自动隐藏
  71. cocosz.uiMgr.closePanel(PanelName.UITrySkinPanel);
  72. }
  73. }
  74. protected onClose(): void {
  75. cocosz.gameMgr.gameStart(cocosz.curLevel);
  76. }
  77. /**
  78. * 所有按钮点击事件
  79. * @param event
  80. * @param data
  81. */
  82. private async _onBtnClickedHandler(event: cc.Event, data: any) {
  83. //播放按钮点击音效
  84. await cocosz.audioMgr.playBtnEffect().catch();
  85. switch (event.target.name) {
  86. case "BtnVideo0":
  87. case "BtnVideo1":
  88. case "BtnVideo2": {
  89. utils.SendEvent("视频-弹窗角色试用-播放")
  90. cocosz.watchAD(() => {
  91. // 视频成功
  92. utils.SendEvent("视频-弹窗角色试用-成功")
  93. if (event.target.name == "BtnVideo0") {
  94. cocosz.gameMgr.gameCtr.curUseSkinId = this.skinArr[0];
  95. } else if (event.target.name == "BtnVideo1") {
  96. cocosz.gameMgr.gameCtr.curUseSkinId = this.skinArr[1];
  97. } else if (event.target.name == "BtnVideo2") {
  98. cocosz.gameMgr.gameCtr.curUseSkinId = this.skinArr[2];
  99. }
  100. cocosz.uiMgr.closePanel(PanelName.UITrySkinPanel);
  101. }, () => {
  102. // 视频失败
  103. utils.SendEvent("视频-弹窗角色试用-失败")
  104. cocosz.uiMgr.closePanel(PanelName.UITrySkinPanel);
  105. })
  106. break;
  107. }
  108. case "BtnPass": {
  109. cocosz.uiMgr.closePanel(PanelName.UITrySkinPanel);
  110. break;
  111. }
  112. }
  113. }
  114. }