FactoryPlus.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import { _decorator, Component, Node, Label, JsonAsset } from 'cc';
  2. import { Http } from '../../core/net/Http';
  3. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  4. import { WindowManager } from '../../core/ui/window/WindowManager';
  5. import { ConfigData } from '../../Data/ConfigData';
  6. import { g } from '../../Data/g';
  7. import { platform } from '../../Data/platform';
  8. const { ccclass, property } = _decorator;
  9. @ccclass('FactoryPlus')
  10. export class FactoryPlus extends Component {
  11. @property({ type: Node, tooltip: "钻石组" }) diamondNode: Node;
  12. @property({ type: Label, tooltip: "花费文本" }) castLabel: Label;
  13. @property({ tooltip: "配置ID" }) configID: number = 0;
  14. @property({ tooltip: "网络请求对象", type: Http }) http: Http;
  15. private windowConfigID: number = 0;
  16. private canActive = false;
  17. async start() {
  18. let config = ConfigData.configMap.get("make");
  19. this.castLabel.string = config[this.configID]["diamond"] + "";
  20. this.diamondNode.active = false;
  21. }
  22. update() {
  23. if (this.windowConfigID != 0) {
  24. let unLockCount = g.gameData.getUnlock(this.windowConfigID);
  25. if (this.configID < unLockCount) {
  26. this.node.active = false;
  27. } else if (this.configID == unLockCount) {
  28. this.diamondNode.active = true;
  29. this.canActive = true;
  30. } else if (this.configID > unLockCount) {
  31. this.diamondNode.active = true;
  32. this.canActive = false;
  33. }
  34. }
  35. }
  36. public setData(buildID: number): void {
  37. this.windowConfigID = buildID;
  38. }
  39. public async onActiveButton() {
  40. if (this.canActive) {
  41. if (g.userData.diamond >= parseInt(this.castLabel.string)) {
  42. let result = await this.http.send("/api/product/extendProductOrder", { buildID: this.windowConfigID });
  43. if (result.code == 0) {
  44. platform.reportThinking("diamond_decrease", JSON.stringify({ previous_number: g.userData.diamond, decrease_number: result.data, current_number: g.userData.diamond - result.data, reasons: "extendProductOrder" }));
  45. g.userData.diamond -= result.diamond;
  46. g.gameData.setUnlock(this.windowConfigID, g.gameData.getUnlock(this.windowConfigID) + 1);
  47. return;
  48. }
  49. }
  50. WindowManager.showTips("钻石不足");
  51. }
  52. }
  53. }