RedBagProgressNode.ts 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { utils } from "./Utils";
  2. import { BannerLocation, SubLocation } from "./YZ_Constant";
  3. import PlatUtils from "./PlatUtils";
  4. import CompatibleTool from "./CompatibleTool";
  5. const { ccclass, property } = cc._decorator;
  6. @ccclass
  7. export default class RedBagProgressNode extends cc.Component {
  8. progressLbl: cc.Label = null;
  9. progressBar: cc.ProgressBar = null;
  10. tripNode: cc.Node = null;
  11. tripProgressLbl: cc.Label = null;
  12. _location: any = "default";
  13. onLoad() {
  14. this.progressLbl = this.node.getComponentInChildren(cc.Label)
  15. this.progressBar = this.node.getComponentInChildren(cc.ProgressBar);
  16. this.tripNode = cc.find("Mask/tripNode", this.node);
  17. this.tripNode.opacity = 0;
  18. this.tripProgressLbl = this.tripNode.getComponentInChildren(cc.Label);
  19. }
  20. public init(data?: any) {
  21. if (data) {
  22. if (data.location) {
  23. this._location = data.location;
  24. }
  25. }
  26. cc.log("wid s==========" + utils.yzRedBagInfo.totalProgress + " pro =" + utils.yzRedBagInfo.progress);
  27. this.progressBar.progress = utils.yzRedBagInfo.progress / utils.yzRedBagInfo.totalProgress;
  28. this.progressLbl.string = `${utils.yzRedBagInfo.progress}/${utils.yzRedBagInfo.totalProgress}`
  29. this.tripProgressLbl.string = `通过${utils.yzRedBagInfo.totalProgress}关即可领取红包`
  30. if (utils.yzRedBagInfo.progress >= utils.yzRedBagInfo.totalProgress) {
  31. cc.find("Mask/Icon/pro_cghb", this.node).active = false;
  32. cc.find("Mask/Icon/pro_full", this.node).active = true;
  33. cc.find("Mask/Icon/pro_full", this.node).stopAllActions();
  34. cc.find("Mask/Icon/pro_full", this.node).runAction(cc.repeatForever(cc.sequence(cc.scaleTo(0.5, 1.2), cc.scaleTo(0.5, 1))));
  35. } else {
  36. cc.find("Mask/Icon/pro_cghb", this.node).active = true;
  37. cc.find("Mask/Icon/pro_full", this.node).active = false;
  38. cc.find("Mask/Icon/pro_full", this.node).stopAllActions();
  39. }
  40. setTimeout(() => {
  41. if (this.tripNode && cc.isValid(this.tripNode)) {
  42. this.tripNode.runAction(cc.sequence(cc.fadeIn(0.3), cc.callFunc(() => {
  43. if (this.tripNode && cc.isValid(this.tripNode)) {
  44. this.tripNode.runAction(cc.sequence(cc.delayTime(5), cc.fadeOut(0.3)));
  45. }
  46. })))
  47. }
  48. }, 3000);
  49. }
  50. onEnable() {
  51. this.init();
  52. utils.SendEvent(`红包进度挂件-${this._location}-展示成功`);
  53. cc.game.on("YZ_RED_BAG_PROGRESS_CHANGE", () => {
  54. this.init();
  55. }, this);
  56. }
  57. showOpenRedBagPanel() {
  58. utils.SendEvent(`红包进度挂件-${this._location}-点击上报`);
  59. if (utils.yzRedBagInfo.progress >= utils.yzRedBagInfo.totalProgress) {
  60. utils.showOpenRedBagPanel({ showType: 2 });
  61. } else {
  62. utils.showMsg("再挑战" + (utils.yzRedBagInfo.totalProgress - utils.yzRedBagInfo.progress) + "关即可领取现金红包");
  63. }
  64. }
  65. onDisable() {
  66. this.unscheduleAllCallbacks();
  67. this.node.targetOff(this);
  68. cc.game.targetOff(this);
  69. }
  70. // _postData(appid: string) {
  71. // utils.postData(appid);
  72. // }
  73. }