UIEffect.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. import { _decorator, Component, Node, SpriteFrame, Sprite, Vec3, v3, UITransform, Label, find, macro } from 'cc';
  2. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  3. import { WindowManager } from '../core/ui/window/WindowManager';
  4. import { Utils } from '../core/utils/Utils';
  5. import { g } from '../Data/g';
  6. import { platform } from '../Data/platform';
  7. import { FsUtils } from '../FsUtils/FsUtils';
  8. import { NoviceWindow } from '../Windows/NoviceWindow';
  9. import { Trajectory } from './Trajectory';
  10. const { ccclass, property } = _decorator;
  11. @ccclass('UIEffect')
  12. export class UIEffect extends Component {
  13. // @property({ tooltip: "飞行资源合集", type: [SpriteFrame] })
  14. public partics: Array<SpriteFrame> = [];
  15. // @property({ tooltip: "飞行目标点合集", type: [Node] })
  16. public endPoints: Array<Node> = [];
  17. // @property({ tooltip: "金币文本", type: Node })
  18. public moneyLabel: Node;
  19. // @property({ tooltip: "神石文本", type: Node })
  20. public diamondLabel: Node;
  21. start() {
  22. }
  23. public backNum = 0;//缓动动画回调次数
  24. public _window: Node;//新窗口node
  25. public async iniUItData() {
  26. let _diamondIcon = find("Canvas/UI/MainUI/顶部/用户数据组/神石信息/图标底/神石图标");
  27. let _goldIcon = find("Canvas/UI/MainUI/顶部/用户数据组/金币信息/图标底/金币图标");
  28. let _diamondLabel = find("Canvas/UI/MainUI/顶部/用户数据组/神石信息/文本/神石文本");
  29. let _goldLabel = find("Canvas/UI/MainUI/顶部/用户数据组/金币信息/文本/金币文本");
  30. let imgDiamond = await ResourcesUtils.load<SpriteFrame>("Images/Money/goldIcon/spriteFrame", SpriteFrame, this.node);
  31. let imgGold = await ResourcesUtils.load<SpriteFrame>("Images/Money/moneyIcon/spriteFrame", SpriteFrame, this.node);
  32. this.partics.push(imgDiamond);
  33. this.partics.push(imgGold);
  34. this.endPoints.push(_diamondIcon);
  35. this.endPoints.push(_goldIcon);
  36. this.moneyLabel = _goldLabel;
  37. this.diamondLabel = _diamondLabel;
  38. }
  39. /**
  40. * @param type (0:神石,1:金币)飞行资源类型
  41. * @param nodeNum 飞行数目
  42. * @param startPoint 起始点坐标
  43. * @param window 新窗口node
  44. */
  45. public async showEffect(type: number, nodeNum: number, startPoint: Vec3 = v3(0, 95, 0), window?: Node) {
  46. if (nodeNum <= 0) {
  47. let self = this;
  48. this.scheduleOnce(() => {
  49. WindowManager.close(self.node);
  50. })
  51. g.gameData.isPlayMoneyAnim = false;
  52. switch (type) {
  53. case 0:
  54. g.gameData.isPlayAddDiamondAnim = false;
  55. break;
  56. case 1:
  57. g.gameData.isPlayAddMoneyAnim = false;
  58. break;
  59. }
  60. return;
  61. }
  62. await this.iniUItData();
  63. this.tweenType = type;
  64. this.backNum = nodeNum;
  65. this._window = window;
  66. // this.node.active = true;
  67. for (let i = 0; i < nodeNum; i++) {
  68. let node = new Node();
  69. //附加图片显示组件
  70. node.addComponent(Sprite);
  71. node.getComponent(Sprite)!.spriteFrame = this.partics[type];
  72. node.addComponent(Trajectory);
  73. let trajectory = node.getComponent(Trajectory);
  74. trajectory.startPoint = startPoint;
  75. trajectory.ctrl1Point = new Vec3(Utils.random_both(300, -300), Utils.random_both(0, -500));
  76. trajectory.ctrl2Point = new Vec3(Utils.random_both(100, -100), Utils.random_both(300, -300));
  77. trajectory.endPoint = this.node.getComponent(UITransform).convertToNodeSpaceAR(this.endPoints[type].getWorldPosition());
  78. trajectory.backNode = this.node;
  79. node.position = startPoint;
  80. this.node.addChild(node);
  81. }
  82. }
  83. public backFun() {
  84. this.backNum--;
  85. switch (this.tweenType) {
  86. case 0:
  87. this.startDiamond += this.change_diamond;
  88. // this.diamondLabel.getComponent(Label).string = this.startDiamond + g.userData.diamond + "";
  89. this.diamondLabel.getComponent(Label).string = FsUtils.goldFormat(this.startDiamond + g.userData.diamond);
  90. break;
  91. case 1:
  92. this.startMoney += this.change_money;
  93. this.moneyLabel.getComponent(Label).string = FsUtils.moneyFormat(this.startMoney + g.userData.money);
  94. break;
  95. }
  96. if (this.backNum <= 0) {
  97. if (NoviceWindow.isNovicing) {
  98. NoviceWindow.isLastStep = true;
  99. }
  100. if (this._window) {
  101. this._window.active = true;
  102. }
  103. this.backNum = 0;
  104. // switch (this.tweenType) {
  105. // case 0:
  106. // g.userData.diamond += this.addAllDiamond;
  107. // g.gameData.isPlayAddDiamondAnim = false;
  108. // break;
  109. // case 1:
  110. // g.userData.money += this.addAllMoney;
  111. // g.gameData.isPlayAddMoneyAnim = false;
  112. // break;
  113. // }
  114. // g.gameData.isPlayMoneyAnim = false;
  115. WindowManager.close(this.node);
  116. }
  117. }
  118. public startMoney = 0;//初始金币
  119. public change_money = 0;//每次金币变化值
  120. public addAllMoney = 0;//金币变化总值
  121. public tweenType = 0;//变化货币类型
  122. public changeMoney(addMoney: number, times: number) {
  123. // g.userData.money = 19710000000;//测试
  124. // addMoney = 757990000;//测试
  125. this.startMoney = 0;
  126. this.addAllMoney = addMoney;
  127. this.change_money = Math.floor(addMoney / times);
  128. }
  129. public startDiamond = 0;//初始神石
  130. public change_diamond = 0;//每次神石变化值
  131. public addAllDiamond = 0;//神石变化总值
  132. public changeDiamond(addDiamond: number, times: number) {
  133. this.startDiamond = 0;
  134. this.addAllDiamond = addDiamond;
  135. this.change_diamond = Math.floor(addDiamond / times);
  136. }
  137. onDestroy() {
  138. if (NoviceWindow.isNovicing) {
  139. NoviceWindow.isLastStep = true;
  140. }
  141. switch (this.tweenType) {
  142. case 0:
  143. g.userData.diamond += this.addAllDiamond;
  144. platform.volcanicReport('addDiamond');
  145. g.gameData.isPlayAddDiamondAnim = false;
  146. break;
  147. case 1:
  148. g.userData.money += this.addAllMoney;
  149. g.gameData.isPlayAddMoneyAnim = false;
  150. break;
  151. }
  152. g.gameData.isPlayMoneyAnim = false;
  153. }
  154. }