BankQipaoTip.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /** 富翁银行气泡 */
  2. const { ccclass, property } = cc._decorator;
  3. @ccclass
  4. export default class BankQipaoTip extends cc.Component {
  5. @property(cc.Node)
  6. node_cunru: cc.Node = null;
  7. @property(cc.Node)
  8. node_tixian: cc.Node = null;
  9. @property(cc.Label)
  10. lab_money: cc.Label = null;
  11. @property(cc.Label)
  12. lab_dian: cc.Label = null;
  13. private itemP: cc.Prefab = null
  14. async onLoad() {
  15. this.node.opacity = 0;
  16. }
  17. onEnable() {
  18. this.node.opacity = 0;
  19. gData.safeDepositBoxData.updateQipao();
  20. }
  21. init(data = null) {
  22. this.node.opacity = 0;
  23. if (gData.safeDepositBoxData.currentRichBankCashTaskIndex > 0) {
  24. this.node.opacity = 255;
  25. this.node_tixian.active = true;
  26. this.node_cunru.active = false;
  27. let index = 0;
  28. this.schedule(() => {
  29. if (index == 0) {
  30. this.lab_dian.string = "。"
  31. index = 1
  32. } else if (index == 1) {
  33. this.lab_dian.string = "。。"
  34. index = 2
  35. } else if (index == 2) {
  36. this.lab_dian.string = "。。。"
  37. index = 0
  38. }
  39. }, 1);
  40. }
  41. else {
  42. if (data && data.length > 0) {
  43. this.node.opacity = 255;
  44. this.node_tixian.active = false;
  45. this.node_cunru.active = true;
  46. let money = 0
  47. for (let entry of data) {
  48. money += entry.amount
  49. }
  50. this.lab_money.string = (money * 0.01).toFixed(2) + "元";
  51. }
  52. else {
  53. this.node.opacity = 0;
  54. }
  55. }
  56. }
  57. async creatPacketAnim(type: number) {
  58. this.itemP = await mk.loader.load('module/safeDepositBox/prefabs/MoneySaveItem', cc.Prefab);
  59. let node = cc.instantiate(this.itemP)
  60. node.parent = cc.find("Canvas")
  61. node.scale = 1
  62. if (type == 1) {
  63. node.position = cc.find("Canvas").convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v3(-145, 337)))
  64. } else {
  65. node.position = cc.find("Canvas").convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v3(0, -324)))
  66. }
  67. let targetPos = cc.find("Canvas").convertToNodeSpaceAR(this.node.convertToWorldSpaceAR(cc.v3(0, -92)))
  68. node.runAction(cc.sequence(cc.spawn(cc.moveTo(1, cc.v2(targetPos)), cc.scaleTo(1, 0.4)), cc.callFunc(() => {
  69. node.destroy()
  70. })))
  71. }
  72. update() {
  73. if (gData.safeDepositBoxData.qipaoType != -1) {
  74. let type = gData.safeDepositBoxData.qipaoType;
  75. gData.safeDepositBoxData.qipaoType = -1;
  76. this.creatPacketAnim(type);
  77. }
  78. if (gData.safeDepositBoxData.freshQipao) {
  79. this.init(gData.safeDepositBoxData.cashRecordData);
  80. }
  81. }
  82. lateUpdate() {
  83. gData.safeDepositBoxData.freshQipao = false;
  84. }
  85. }