| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- import { _decorator, Component, Node, Label, JsonAsset } from 'cc';
- import { Http } from '../../core/net/Http';
- import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
- import { WindowManager } from '../../core/ui/window/WindowManager';
- import { ConfigData } from '../../Data/ConfigData';
- import { g } from '../../Data/g';
- import { platform } from '../../Data/platform';
- const { ccclass, property } = _decorator;
- @ccclass('FactoryPlus')
- export class FactoryPlus extends Component {
- @property({ type: Node, tooltip: "钻石组" }) diamondNode: Node;
- @property({ type: Label, tooltip: "花费文本" }) castLabel: Label;
- @property({ tooltip: "配置ID" }) configID: number = 0;
- @property({ tooltip: "网络请求对象", type: Http }) http: Http;
- private windowConfigID: number = 0;
- private canActive = false;
- async start() {
- let config = ConfigData.configMap.get("make");
- this.castLabel.string = config[this.configID]["diamond"] + "";
- this.diamondNode.active = false;
- }
- update() {
- if (this.windowConfigID != 0) {
- let unLockCount = g.gameData.getUnlock(this.windowConfigID);
- if (this.configID < unLockCount) {
- this.node.active = false;
- } else if (this.configID == unLockCount) {
- this.diamondNode.active = true;
- this.canActive = true;
- } else if (this.configID > unLockCount) {
- this.diamondNode.active = true;
- this.canActive = false;
- }
- }
- }
- public setData(buildID: number): void {
- this.windowConfigID = buildID;
- }
- public async onActiveButton() {
- if (this.canActive) {
- if (g.userData.diamond >= parseInt(this.castLabel.string)) {
- let result = await this.http.send("/api/product/extendProductOrder", { buildID: this.windowConfigID });
- 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: "extendProductOrder" }));
- g.userData.diamond -= result.diamond;
- g.gameData.setUnlock(this.windowConfigID, g.gameData.getUnlock(this.windowConfigID) + 1);
- return;
- }
- }
- WindowManager.showTips("钻石不足");
- }
- }
- }
|