| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- import { FactoryCountDown } from "./FactoryCountDown";
- const { ccclass, property } = cc._decorator;
- export enum FactroyState {
- Lock,
- Producting,
- Free
- }
- @ccclass
- export class MapIcon extends cc.Component {
- @property({ tooltip: "点击是否缩放动画" }) touchAmition: boolean = true;
- @property({ type: cc.Animation, tooltip: "点击动画" }) animation: cc.Animation = null;
- @property({ type: cc.Node, tooltip: "建筑状态组" }) stateGroup: cc.Node = null;
- @property({ type: cc.Node, tooltip: "完成品展示节点" }) showGroup: cc.Node = null;
- @property({ tooltip: "配置ID" }) configID: number = 0;
- @property({ type: FactoryCountDown, tooltip: "计时装置" }) countDown: FactoryCountDown = null;
- private _state = FactroyState.Lock;
- private hasActive = false;
- private havrestList: { id: number, node: Node }[] = [];
- start() {
- // if (gData.gameData.hasBuildData(this.configID)) {
- // this.activeFactroy();
- // }
- }
- update() {
- // if (this._state == FactroyState.Lock && gData.gameData.hasBuildData(this.configID)) {
- // this.activeFactroy();
- // }
- // let producting = gData.gameData.getProductingList(this.configID);
- // if (producting.length > 0) {
- // this.setState(FactroyState.Producting);
- // } else {
- // this.setState(FactroyState.Free);
- // }
- }
- public activeFactroy(): void {
- this.hasActive = true;
- }
- public async inPolygon() {
- // (this.touchAmition && this.animation) && this.animation.play();
- // var sound = this.getComponent(Sound);
- // sound && sound.play();
- // if (this._state != FactroyState.Lock) {
- // if (this.havrestList.length == 0) {
- // this.getComponent(OpenWindow).open(this.configID, this.countDown);
- // } else {
- // WindowManager.open("Prefabs/HarvestWindow", WindowOpenMode.CloseAndCover, this.configID, this.onHarvest.bind(this));
- // }
- // } else {
- // let lvl = ConfigData.configMap.get("build")[this.configID]["lvl"];
- // WindowManager.showTips(`${lvl}级解锁`);
- // }
- }
- /**生产完成回调 */
- public async onProductComplete(id: number) {
- // if (this.showGroup) {
- // let prefab = await ResourcesUtils.load<Prefab>("Prefabs/ProductShow", null, this.node);
- // let item = instantiate(prefab);
- // item.getComponent(ProductShow).id = id;
- // item.setParent(this.showGroup);
- // let x = Utils.random_both(-this.showGroup.getComponent(UITransform).width / 2, this.showGroup.getComponent(UITransform).width / 2);
- // let y = Utils.random_both(-this.showGroup.getComponent(UITransform).height / 2, this.showGroup.getComponent(UITransform).height / 2);
- // item.setPosition(v3(x, y, 0));
- // this.havrestList.push({ id: id, node: item });
- // }
- }
- public clean(): void {
- this.showGroup.removeAllChildren();
- this.havrestList = [];
- }
- private onHarvest(mult: number): void {
- // this.havrestList.shift().node.destroy();
- }
- private setState(value: FactroyState): void {
- if (this.hasActive) {
- if (this._state != value) {
- this._state = value;
- if (this._state == FactroyState.Producting) {
- this.stateGroup && (this.stateGroup.active = true);
- } else {
- this.stateGroup && (this.stateGroup.active = false);
- }
- }
- }
- }
- }
|