import { FarmState } from '../../game/data/GameData'; import { FarmIcon } from './FarmIcon'; const { ccclass } = cc._decorator; @ccclass export class FarmSystem { public farms: Array = []; private _currSelectFarm: FarmIcon = null; public plantWindowIsOpening = false; /** 种植冷却 */ public plantIsRequesting = false; public set currSelectFarm(farm: FarmIcon) { if (this._currSelectFarm) { this._currSelectFarm.selectFarm(false); } this._currSelectFarm = farm; if (this._currSelectFarm) { let icon = this._currSelectFarm; icon.selectFarm(true); } } public get currSelectFarm(): FarmIcon { return this._currSelectFarm; } public addFram(fram: FarmIcon) { this.farms[fram.sortID] = fram; } public plant(id: number): void { this.currSelectFarm && this.currSelectFarm.plant(id); } public selectNextFarm(): FarmIcon | null { let nextFarm = this.getCanPlantFarm(); if (nextFarm) { this.currSelectFarm = nextFarm; } else { //暂时注释 // WindowManager.close(); } return nextFarm; } /**获取可种植农田 */ private getCanPlantFarm(): FarmIcon | null { for (let i = 0; i < this.farms.length; i++) { if (this.farms[i] != this.currSelectFarm && this.farms[i].state == FarmState.Empty) { return this.farms[i]; } } return null; } /**触摸事件的同级传递 */ public next(node: FarmIcon, e): void { let index = this.farms.indexOf(node); if (index % 3 < 2) { this.farms[index + 1].node.emit(cc.Node.EventType.TOUCH_END, e); } } public novice_plant(): void { let frame = this.farms[0]; frame.novice_plant(); } public novice_clean(): void { let frame = this.farms[0]; frame.novice_clean(); } }