GetDiamond.ts 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import { _decorator, Component, Node, Label, tween, v3, find, EventHandler } from 'cc';
  2. import { OpenWindow } from '../core/ui/window/OpenWindow';
  3. import { Window } from '../core/ui/window/Window';
  4. import { WindowManager } from '../core/ui/window/WindowManager';
  5. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  6. import { g } from '../Data/g';
  7. import { UIEffect } from '../Main/UIEffect';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('GetDiamond')
  10. export class GetDiamond extends Component {
  11. @property({ tooltip: "旋转光效节点", type: Node })
  12. public turnLightBox: Node;
  13. @property({ tooltip: "贡献icon", type: Node })
  14. public diamondIcon: Node;
  15. @property({ tooltip: "贡献值txt", type: Node })
  16. public diamondTxt: Node;
  17. @property({ tooltip: "领取按钮", type: Node }) private getBtn: Node;
  18. @property({ tooltip: "更多领取按钮", type: Node }) private getMoreBtn: Node;
  19. public newWindowType: number = -1;//新窗口类型
  20. public newWindowData: any;//新窗口参数
  21. public addDiamond: number = 0;//新获得神石数值
  22. public closeBackFun: EventHandler;
  23. start() {
  24. g.gameData.isPlayAddDiamondAnim = true;
  25. }
  26. /**
  27. * @zn 初始化界面信息
  28. * @param data 0:神石值,1:所需打开新窗口类型(-1:无新窗口打开,0:金币窗口,1:合成红包奖励),2:新窗口参数(无新窗口不用填写),3:窗口关闭回调(无回调可不填)
  29. */
  30. public setData(data: any[]) {
  31. this.diamondTxt.getComponent(Label).string = "神石:" + data[0];
  32. this.addDiamond = data[0];
  33. this.newWindowType = data[1];//红包类型
  34. this.newWindowData = this.newWindowType == 0 ? data[2] : null;
  35. if (data[3]) {
  36. this.closeBackFun = data[3];
  37. }
  38. if (this.newWindowType == 1) {
  39. this.getBtn.active = false;
  40. } else {
  41. this.getMoreBtn.active = false;
  42. }
  43. }
  44. /**
  45. * 领取神石
  46. */
  47. public async getDiamond() {
  48. //通知货币变化 货币飞行动画
  49. let times = this.addDiamond > 10 ? 10 : this.addDiamond;
  50. let _window = await WindowManager.open("Prefabs/Windows/货币飞行控制器", WindowOpenMode.NotCloseAndAdd);
  51. switch (this.newWindowType) {
  52. case 0://打开金币领取窗口
  53. await this.getComponent(OpenWindow).open(this.newWindowData);
  54. g.gameData.isPlayMoneyAnim = true;
  55. break;
  56. case 1://打开金币领取窗口
  57. this.getComponent(Window).close();
  58. WindowManager.open('Prefabs/Each/EachWindow', WindowOpenMode.NotCloseAndAdd);
  59. break;
  60. default://直接关闭窗口
  61. this.getComponent(Window).close();
  62. break;
  63. }
  64. _window.getComponent(UIEffect).changeDiamond(this.addDiamond, times);
  65. _window.getComponent(UIEffect).showEffect(0, times);
  66. this.closeBackFun && this.closeBackFun.emit([]);
  67. }
  68. }