| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import { v3 } from 'cc';
- import { _decorator, Component, Sprite, SpriteFrame, JsonAsset, Node, ProgressBar, EventHandler, Label } from 'cc';
- import { Http } from '../core/net/Http';
- import { ResourcesUtils } from '../core/resourceManager/ResourcesUtils';
- import { BitmapFont } from '../core/ui/BitmapFont';
- import { WindowManager } from '../core/ui/window/WindowManager';
- import { Utils } from '../core/utils/Utils';
- import { ConfigData } from '../Data/ConfigData';
- import { g } from '../Data/g';
- import { platform } from '../Data/platform';
- const { ccclass, property } = _decorator;
- @ccclass('FarmCountDown')
- export class FarmCountDown extends Component {
- @property({ type: EventHandler, tooltip: "成熟回调" }) onRiped: EventHandler;
- @property({ type: EventHandler, tooltip: "加速按钮回调" }) onSpeedButton: EventHandler;
- @property({ type: Node, tooltip: "常驻计时器组" }) normalGroup: Node;
- @property({ type: ProgressBar, tooltip: "常驻进度条" }) normalProgress: ProgressBar;
- @property({ type: BitmapFont, tooltip: "常驻计时" }) normalCount: BitmapFont;
- @property({ type: Node, tooltip: "可收获图标" }) ripedIcon: Node;
- @property({ type: Node, tooltip: "点击计时器组" }) selectGroup: Node;
- @property({ type: ProgressBar, tooltip: "点击进度条" }) selectProgress: ProgressBar;
- @property({ type: BitmapFont, tooltip: "点击计时" }) selectCount: BitmapFont;
- @property({ type: Sprite, tooltip: "作物图标" }) plantIcon: Sprite;
- @property({ type: Label, tooltip: "加速花费文本" }) castLabel: Label;
- @property({ tooltip: "网络请求对象", type: Http }) http: Http;
- private counting = false;
- /**成熟时间戳 */
- private ripeTime = 0;
- /**总时长 */
- private totleTime = 0;
- private buildID = 0;
- private isDataed = false;
- public async setData(configID: number, isShow = true) {
- if (!this.isDataed) {
- this.isDataed = true;
- this.buildID = configID;
- let producting = g.gameData.getProductingList(configID)[0];
- let config = ConfigData.configMap.get("product");
- let result = config[producting.productID];
- this.ripeTime = producting.ripeDate;
- this.totleTime = result["time"];
- this.normalGroup.active = true;
- this.counting = true;
- this.selectGroup.active = isShow;
- this.plantIcon.spriteFrame = await ResourcesUtils.load<SpriteFrame>("plant_icons/plantIcon_" + producting.productID + "/spriteFrame", SpriteFrame, this.node);
- }
- }
- update() {
- let now = Date.now();
- if (this.counting && now < this.ripeTime) {
- let timeString = Utils.formatCountDown(this.ripeTime - now);
- this.selectCount.string = this.normalCount.string = timeString;
- this.selectProgress.progress = 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("钻石不足");
- }
- public setCountActive(value: boolean): void {
- this.selectGroup.active = value;
- }
- private riped(): void {
- this.counting = false;
- this.normalGroup.active = false;
- this.selectGroup.active = false;
- this.ripedIcon.active = true;
- this.onRiped && this.onRiped.emit(null);
- }
- }
|