| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- import { BitmapFontC } from "../../game/component/BitmapFontC";
- import Util from "../util/Util";
- const { ccclass, property } = cc._decorator;
- @ccclass
- export class FarmCountDown extends cc.Component {
- @property({ type: cc.Component.EventHandler, tooltip: "成熟回调" }) onRiped: cc.Component.EventHandler = null;
- @property({ type: cc.Component.EventHandler, tooltip: "加速按钮回调" }) onSpeedButton: cc.Component.EventHandler = null;
- @property({ type: cc.Node, tooltip: "常驻计时器组" }) normalGroup: cc.Node = null;
- @property({ type: cc.ProgressBar, tooltip: "常驻进度条" }) normalProgress: cc.ProgressBar = null;
- @property({ type: BitmapFontC, tooltip: "常驻计时" }) normalCount: BitmapFontC = null;
- @property({ type: cc.Node, tooltip: "可收获图标" }) ripedIcon: cc.Node = null;
- private counting = false;
- /**成熟时间戳 */
- private ripeTime = 0;
- /**总时长 */
- private totleTime = 0;
- private isDataed = false;
- public async setData(data) {
- if (!this.isDataed) {
- this.isDataed = true;
- let producting = gData.gameData.getProductMap(data.productID);
- this.ripeTime = data.growSpan;
- this.totleTime = producting.time;
- this.normalGroup.active = true;
- this.counting = true;
- this.normalCount.string = '';
- this.normalProgress.progress = 0;
- }
- }
- update() {
- let now = Date.now();
- if (this.counting && now < this.ripeTime) {
- let timeString = Util.ParseTime2Format(Math.floor((this.ripeTime - now) * 0.001), 'm:s');
- this.normalCount.string = timeString;
- this.normalProgress.progress = 1 - ((this.ripeTime - now) / (this.totleTime * 1000));
- } else if (this.counting && now > this.ripeTime) {
- this.riped();
- }
- }
- public cleanRiped(): void {
- this.isDataed = false;
- this.ripedIcon.active = false;
- }
- public async onSpeed() {
- //通信 暂时注释
- // if (g.userData.diamond >= 25) {
- // let result = await this.http.send("/api/product/quickProduct", { buildID: this.buildID });
- // if (result.code == 0) {
- // platform.reportThinking("diamond_decrease", JSON.stringify({ previous_number: g.userData.diamond, decrease_number: result.data, current_number: g.userData.diamond - result.data, reasons: "speed" }));
- // g.userData.diamond -= result.data;
- // this.riped();
- // this.selectGroup.active = false;
- // this.onSpeedButton && this.onSpeedButton.emit(null);
- // return;
- // }
- // }
- // WindowManager.showTips("钻石不足");
- }
- private riped(): void {
- this.counting = false;
- this.normalGroup.active = false;
- this.ripedIcon.active = true;
- this.onRiped && this.onRiped.emit(null);
- }
- }
|