FarmCountDown.ts 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { BitmapFontC } from "../../game/component/BitmapFontC";
  2. import Util from "../util/Util";
  3. const { ccclass, property } = cc._decorator;
  4. @ccclass
  5. export class FarmCountDown extends cc.Component {
  6. @property({ type: cc.Component.EventHandler, tooltip: "成熟回调" }) onRiped: cc.Component.EventHandler = null;
  7. @property({ type: cc.Component.EventHandler, tooltip: "加速按钮回调" }) onSpeedButton: cc.Component.EventHandler = null;
  8. @property({ type: cc.Node, tooltip: "常驻计时器组" }) normalGroup: cc.Node = null;
  9. @property({ type: cc.ProgressBar, tooltip: "常驻进度条" }) normalProgress: cc.ProgressBar = null;
  10. @property({ type: BitmapFontC, tooltip: "常驻计时" }) normalCount: BitmapFontC = null;
  11. @property({ type: cc.Node, tooltip: "可收获图标" }) ripedIcon: cc.Node = null;
  12. private counting = false;
  13. /**成熟时间戳 */
  14. private ripeTime = 0;
  15. /**总时长 */
  16. private totleTime = 0;
  17. private isDataed = false;
  18. public async setData(data) {
  19. if (!this.isDataed) {
  20. this.isDataed = true;
  21. let producting = gData.gameData.getProductMap(data.productID);
  22. this.ripeTime = data.growSpan;
  23. this.totleTime = producting.time;
  24. this.normalGroup.active = true;
  25. this.counting = true;
  26. this.normalCount.string = '';
  27. this.normalProgress.progress = 0;
  28. }
  29. }
  30. update() {
  31. let now = Date.now();
  32. if (this.counting && now < this.ripeTime) {
  33. let timeString = Util.ParseTime2Format(Math.floor((this.ripeTime - now) * 0.001), 'm:s');
  34. this.normalCount.string = timeString;
  35. this.normalProgress.progress = 1 - ((this.ripeTime - now) / (this.totleTime * 1000));
  36. } else if (this.counting && now > this.ripeTime) {
  37. this.riped();
  38. }
  39. }
  40. public cleanRiped(): void {
  41. this.isDataed = false;
  42. this.ripedIcon.active = false;
  43. }
  44. public async onSpeed() {
  45. //通信 暂时注释
  46. // if (g.userData.diamond >= 25) {
  47. // let result = await this.http.send("/api/product/quickProduct", { buildID: this.buildID });
  48. // if (result.code == 0) {
  49. // platform.reportThinking("diamond_decrease", JSON.stringify({ previous_number: g.userData.diamond, decrease_number: result.data, current_number: g.userData.diamond - result.data, reasons: "speed" }));
  50. // g.userData.diamond -= result.data;
  51. // this.riped();
  52. // this.selectGroup.active = false;
  53. // this.onSpeedButton && this.onSpeedButton.emit(null);
  54. // return;
  55. // }
  56. // }
  57. // WindowManager.showTips("钻石不足");
  58. }
  59. private riped(): void {
  60. this.counting = false;
  61. this.normalGroup.active = false;
  62. this.ripedIcon.active = true;
  63. this.onRiped && this.onRiped.emit(null);
  64. }
  65. }