GetGoldWin.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import { _decorator, Component, Node, Prefab, instantiate, UITransform, Label, find, v3, EventHandler } from 'cc';
  2. import { Http } from '../core/net/Http';
  3. import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
  4. import { Window } from '../core/ui/window/Window';
  5. import { g } from '../Data/g';
  6. import { RotatingLightAnim } from '../SpecialEffects/RotatingLightAnim';
  7. import { StarAnim } from '../SpecialEffects/StarAnim';
  8. import { FsUtils } from "../FsUtils/FsUtils";
  9. import { UIEffect } from '../Main/UIEffect';
  10. import { WindowManager } from '../core/ui/window/WindowManager';
  11. import { WindowOpenMode } from '../core/ui/window/WindowOpenMode';
  12. import { LoginWaitWin } from './LoginWaitWin';
  13. const { ccclass, property } = _decorator;
  14. @ccclass('GetGoldWin')
  15. export class GetGoldWin extends Component {
  16. @property({ tooltip: "旋转光效节点", type: Node })
  17. public turnLightNode: Node;
  18. @property({ tooltip: "旋转光效预制体路径" })
  19. public lightEfficiency = "";
  20. @property({ tooltip: "星星特效节点", type: Node })
  21. public starNode: Node;
  22. @property({ tooltip: "星星特效预制体路径" })
  23. public starEfficiency = "";
  24. @property({ tooltip: "领取金币按键", type: Node })
  25. public getMoneyBtn: Node;
  26. @property({ tooltip: "金币金额", type: Node })
  27. public moneyTxt: Node;
  28. @property({ tooltip: "http服务", type: Http })
  29. public http: Http;
  30. @property({ tooltip: "内容框", type: Node }) public Group: Node;
  31. public titleArray = ["获得金币", "离线收益", "恭喜获得", "获得金币"];
  32. public httpString = ["/api/wealth/OpenFlyBox", "/api/wealth/GetOffMoney"];
  33. public type = 0;
  34. public getGoldBack: EventHandler;
  35. public toGetMoney: number = 0;//领取金币金额
  36. start() {
  37. g.gameData.isPlayAddMoneyAnim = true;
  38. g.gameData.isPlayVideo = false;
  39. }
  40. /**
  41. * 设置界面信息
  42. * @param data 0:金币金额
  43. * 1:类型(0:飞行宝箱,1:离线,2:金币不足,3:轮盘抽奖金币)
  44. * 2:窗口关闭回调方法
  45. */
  46. public setData(data: any[]) {
  47. this.type = data[1];
  48. this.moneyTxt.getComponent(Label).string = FsUtils.moneyFormat(data[0]);
  49. this.toGetMoney = data[0];
  50. if (data[2]) {
  51. this.getGoldBack = data[2];
  52. }
  53. }
  54. public async addStar() {
  55. for (let i = 0; i < 20; i++) {
  56. let prefabsData = await ResourcesUtils.load<Prefab>(this.starEfficiency, null, this.node);
  57. var starNode = instantiate(prefabsData);
  58. starNode.parent = this.starNode;
  59. let starAnim = starNode.getComponent(StarAnim);
  60. let wrapMode = Math.random() < 0.5 ? 38 : 2;
  61. let startTime = Math.random() * 3;
  62. let _size = this.starNode.getComponent(UITransform).contentSize;
  63. let tempWidth = Math.random() * _size.width;
  64. let temp_x = tempWidth > _size.width / 2 ?
  65. -(tempWidth - (_size.width / 2)) : tempWidth;
  66. let tempHeight = Math.random() * _size.height;
  67. let temp_y = tempHeight > _size.height / 2 ?
  68. -(tempHeight - (_size.height / 2)) : tempHeight;
  69. starAnim.setData(wrapMode, startTime, temp_x, temp_y, Math.random() * 1.3, "star1");
  70. }
  71. }
  72. public isSend = false;
  73. public async close() {
  74. if (g.gameData.isPlayVideo) {
  75. return;
  76. }
  77. g.gameData.isPlayVideo = true;
  78. if (this.type != 3 && this.type != 2) {
  79. //#region 打开加载等待界面
  80. let _window = await WindowManager.open("Prefabs/Windows/加载等待窗口", WindowOpenMode.NotCloseAndCover);
  81. //#endregion
  82. let data = await this.http.send(this.httpString[this.type]);//领取金币
  83. _window.getComponent(LoginWaitWin).close();//关闭加载等待界面
  84. switch (data.code) {
  85. case 0:
  86. if (this.type == 0) {
  87. g.gameData.flyBoxIntervalTime = 1000 * 60 * 4;//宝箱领取成功,出现时间间隔改为四分钟
  88. g.gameData.flyBoxTimes = data.data.times;//宝箱领取成功,出现次数更新
  89. }
  90. this.toGetMoney = data.data.addMoney;
  91. break;
  92. default:
  93. if (data.code) {
  94. WindowManager.showTips(g.CodeMsg[data.code]);
  95. } else {
  96. WindowManager.showTips("获取金币消息错误");
  97. }
  98. this.getComponent(Window).close();
  99. return;
  100. }
  101. }
  102. let times = this.toGetMoney > 0 ? this.toGetMoney : 1;
  103. times = times > 10 ? 10 : times;
  104. let _window = await WindowManager.open("Prefabs/Windows/货币飞行控制器", WindowOpenMode.NotCloseAndAdd);
  105. _window.getComponent(UIEffect).changeMoney(this.toGetMoney, times);
  106. _window.getComponent(UIEffect).showEffect(1, times);
  107. this.getGoldBack && this.getGoldBack.emit([]);//领取完奖励回调
  108. this.getComponent(Window).close();
  109. }
  110. update() {
  111. if (g.gameData.isPlayMoneyAnim == this.Group.active) {
  112. this.Group.active = !g.gameData.isPlayMoneyAnim;
  113. this.Group.active && this.addStar();
  114. }
  115. }
  116. onDestroy() {
  117. g.gameData.isPlayVideo = false;
  118. }
  119. }