FactroyMaker.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { _decorator, Component, Label, JsonAsset } from 'cc';
  2. import { ResourcesUtils } from '../../core/resourceManager/ResourcesUtils';
  3. import { Sound } from '../../core/sound/Sound';
  4. import { ConfigData } from '../../Data/ConfigData';
  5. import { g } from '../../Data/g';
  6. import { FactoryWindow } from './FactoryWindow';
  7. const { ccclass, property } = _decorator;
  8. @ccclass('FactroyMaker')
  9. export class FactroyMaker extends Component {
  10. @property({ type: Label, tooltip: "时间描述" }) timeLabel: Label;
  11. @property({ type: Label, tooltip: "次数描述" }) countLabel: Label;
  12. public countData: any;
  13. private productID: number;
  14. private window: FactoryWindow;
  15. private count = 0;
  16. public async setData(data: number, window: FactoryWindow) {
  17. this.productID = data;
  18. this.window = window;
  19. let config = ConfigData.configMap.get("product")[this.productID];
  20. this.timeLabel.string = "制作需要的时长:" + config["time"] / 60 + "分钟";
  21. this.count = config["reap"] - (this.countData ? (this.countData[this.productID] ? this.countData[this.productID] : 0) : 0);
  22. this.countLabel.string = "剩余次数:" + this.count + "次";
  23. }
  24. public onMakeButton(): void {
  25. if (this.count > 0 && g.gameData.getProductingList(this.window.buildID).length < g.gameData.getUnlock(this.window.buildID)) {
  26. this.count--;
  27. this.countLabel.string = "剩余次数:" + this.count + "次";
  28. this.window.make(this.productID);
  29. this.getComponent(Sound).play();
  30. }
  31. }
  32. }