| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- 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: "生虫回调" }) onSick: 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.Sprite, tooltip: "常驻进度条" }) normalProgress: cc.Sprite = null;
- @property({ type: BitmapFontC, tooltip: "常驻计时" }) normalCount: BitmapFontC = null;
- @property({ type: cc.Node, tooltip: "可收获图标" }) ripedIcon: cc.Node = null;
- @property({ type: cc.Node, tooltip: "生病图标" }) sickIcon: cc.Node = null;
- @property({ type: cc.Sprite, tooltip: "生病图标" }) clockIcon: cc.Sprite = null;
- private counting = false;
- /**成熟时间戳 */
- private ripeTime = 0;
- /**总时长 */
- private totleTime = 0;
- private isDataed = false;
- private isRipeInit = 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.sickIcon.active = false;
- this.counting = true;
- this.normalCount.string = '';
- this.normalProgress.fillRange = 0;
- if (this.clockIcon) {
- let plantPath = 'game/coregame/texture/factory_icons/factory_';
- this.clockIcon.spriteFrame = await mk.loader.load(plantPath + producting.picture, cc.SpriteFrame);
- }
- }
- }
- 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.fillRange = 1 - ((this.ripeTime - now) / (this.totleTime * 1000));
- } else if (this.counting && now > this.ripeTime) {
- if (!this.isRipeInit) {
- this.isRipeInit = true;
- this.riped();
- }
- }
- }
- public cleanRiped(): void {
- this.isRipeInit = false;
- this.isDataed = false;
- this.ripedIcon.active = false;
- this.sickIcon.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("钻石不足");
- }
- /** 设置显示
- * @param state 0 生虫 1 成熟
- */
- async setState(state) {
- this.normalProgress.fillRange = 0;
- this.normalCount.string = '';
- this.normalGroup.active = false;
- if (state == 0) {
- this.sickIcon.active = true;
- this.ripedIcon.active = false;
- }
- else if (state == 1) {
- this.sickIcon.active = false;
- this.ripedIcon.active = true;
- }
- }
- public riped(): void {
- this.counting = false;
- this.normalGroup.active = false;
- if (Math.random() < 0.2) {
- this.sickIcon.active = true;
- this.onSick && this.onSick.emit(null);
- }
- else {
- this.ripedIcon.active = true;
- this.onRiped && this.onRiped.emit(null);
- }
- }
- }
|