GetWindow.ts 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { _decorator, Component, Node, Label, Sprite, SpriteFrame, find } from 'cc';
  2. import { ADHelper } from '../../ADHelper';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { Utils } from '../../core/utils/Utils';
  5. import { g } from '../../Data/g';
  6. import { NoviceWindow } from '../Novice/NoviceWindow';
  7. import { UIEffect } from '../UIEffect';
  8. import { GetType } from './GetType';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('GetWindow')
  11. export class GetWindow extends Component {
  12. @property({ type: Label, tooltip: "数量文本" }) countLabel: Label;
  13. @property({ type: Sprite, tooltip: "icon图标" }) icon: Sprite;
  14. private imageMap = [
  15. { big: "Images/Turntable/red/spriteFrame", small: "Images/Turntable/red_small/spriteFrame" },
  16. { big: "Images/Turntable/diamond/spriteFrame", small: "Images/Turntable/diamond_small/spriteFrame" },
  17. { big: "Images/Turntable/star/spriteFrame", small: "Images/Turntable/star_small/spriteFrame" }
  18. ]
  19. private data: { count: number, type: GetType, needBezierEffect: boolean, particCount: number }[] = [];
  20. private effectNode: Node;
  21. start() {
  22. if (!NoviceWindow.isNovicing) {
  23. this.getComponent(ADHelper).show();
  24. }
  25. }
  26. public async onParams(data: { count: number, type: GetType, needBezierEffect: boolean, particCount: number }[] = [{
  27. count: 1500,
  28. type: GetType.RedBag,
  29. needBezierEffect: true,
  30. particCount: 11
  31. }], effectNode?: Node) {
  32. this.countLabel.string = "x" + data[0].count;
  33. this.data = data.concat();
  34. this.effectNode = effectNode;
  35. this.icon.spriteFrame = await ResourcesUtils.load<SpriteFrame>(this.imageMap[this.data[0].type].big, SpriteFrame, this.node);
  36. }
  37. onDestroy() {
  38. for (let i = 0; i < this.data.length; i++) {
  39. if (this.data[i].needBezierEffect) {
  40. find("Canvas/UI").getComponent(UIEffect).showBezierRedBagEffect(this.data[i].type, this.effectNode, this.data[i].particCount);
  41. }
  42. switch (this.data[i].type) {
  43. case GetType.RedBag:
  44. g.userData.bonus += this.data[i].count;
  45. break;
  46. case GetType.Diamond:
  47. g.userData.diamond += this.data[i].count;
  48. break;
  49. case GetType.exp:
  50. g.userData.lv += this.data[i].count;
  51. break;
  52. }
  53. }
  54. }
  55. }