MapIcon.ts 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. import { FactoryCountDown } from "./FactoryCountDown";
  2. const { ccclass, property } = cc._decorator;
  3. export enum FactroyState {
  4. Lock,
  5. Producting,
  6. Free
  7. }
  8. @ccclass
  9. export class MapIcon extends cc.Component {
  10. @property({ tooltip: "点击是否缩放动画" }) touchAmition: boolean = true;
  11. @property({ type: cc.Animation, tooltip: "点击动画" }) animation: cc.Animation = null;
  12. @property({ type: cc.Node, tooltip: "建筑状态组" }) stateGroup: cc.Node = null;
  13. @property({ type: cc.Node, tooltip: "完成品展示节点" }) showGroup: cc.Node = null;
  14. @property({ tooltip: "配置ID" }) configID: number = 0;
  15. @property({ type: FactoryCountDown, tooltip: "计时装置" }) countDown: FactoryCountDown = null;
  16. private _state = FactroyState.Lock;
  17. private hasActive = false;
  18. private havrestList: { id: number, node: Node }[] = [];
  19. start() {
  20. // if (gData.gameData.hasBuildData(this.configID)) {
  21. // this.activeFactroy();
  22. // }
  23. }
  24. update() {
  25. // if (this._state == FactroyState.Lock && gData.gameData.hasBuildData(this.configID)) {
  26. // this.activeFactroy();
  27. // }
  28. // let producting = gData.gameData.getProductingList(this.configID);
  29. // if (producting.length > 0) {
  30. // this.setState(FactroyState.Producting);
  31. // } else {
  32. // this.setState(FactroyState.Free);
  33. // }
  34. }
  35. public activeFactroy(): void {
  36. this.hasActive = true;
  37. }
  38. public async inPolygon() {
  39. // (this.touchAmition && this.animation) && this.animation.play();
  40. // var sound = this.getComponent(Sound);
  41. // sound && sound.play();
  42. // if (this._state != FactroyState.Lock) {
  43. // if (this.havrestList.length == 0) {
  44. // this.getComponent(OpenWindow).open(this.configID, this.countDown);
  45. // } else {
  46. // WindowManager.open("Prefabs/HarvestWindow", WindowOpenMode.CloseAndCover, this.configID, this.onHarvest.bind(this));
  47. // }
  48. // } else {
  49. // let lvl = ConfigData.configMap.get("build")[this.configID]["lvl"];
  50. // WindowManager.showTips(`${lvl}级解锁`);
  51. // }
  52. }
  53. /**生产完成回调 */
  54. public async onProductComplete(id: number) {
  55. // if (this.showGroup) {
  56. // let prefab = await ResourcesUtils.load<Prefab>("Prefabs/ProductShow", null, this.node);
  57. // let item = instantiate(prefab);
  58. // item.getComponent(ProductShow).id = id;
  59. // item.setParent(this.showGroup);
  60. // let x = Utils.random_both(-this.showGroup.getComponent(UITransform).width / 2, this.showGroup.getComponent(UITransform).width / 2);
  61. // let y = Utils.random_both(-this.showGroup.getComponent(UITransform).height / 2, this.showGroup.getComponent(UITransform).height / 2);
  62. // item.setPosition(v3(x, y, 0));
  63. // this.havrestList.push({ id: id, node: item });
  64. // }
  65. }
  66. public clean(): void {
  67. this.showGroup.removeAllChildren();
  68. this.havrestList = [];
  69. }
  70. private onHarvest(mult: number): void {
  71. // this.havrestList.shift().node.destroy();
  72. }
  73. private setState(value: FactroyState): void {
  74. if (this.hasActive) {
  75. if (this._state != value) {
  76. this._state = value;
  77. if (this._state == FactroyState.Producting) {
  78. this.stateGroup && (this.stateGroup.active = true);
  79. } else {
  80. this.stateGroup && (this.stateGroup.active = false);
  81. }
  82. }
  83. }
  84. }
  85. }