public void RemoveBuilding(BuildingModel building) { if (_buildings.Remove(building)) { _selectables.Remove(building); NotifyCollectionModification("Buildings", building, CollectionModification.Remove); } }
private void OnBuildingConstructionStart(GameView sender, Type buildingType) { // This means there is an unfinished placement going. // It will be terminated. if (_buildingPlacement != null) { var controller = AppRoot.Instance.GetController(_buildingPlacement.BaseName); controller.DestroyModel(_buildingPlacement); //BuildingController.Instance.DestroyModel(_buildingPlacement); _buildingPlacement = null; } BuildingModel model = null; // Going for a pretty non-generic path. Sorry, but have to finish this. if (buildingType == typeof(BarracksModel)) { model = EntityFactory.CreateBarracks(sender); } else if (buildingType == typeof(PowerPlantModel)) { model = EntityFactory.CreatePowerPlant(sender); } else if (buildingType == typeof(CommandCenterModel)) { model = EntityFactory.CreateCommandCenter(sender); } else if (buildingType == typeof(SupplyCenterModel)) { model = EntityFactory.CreateSupplyCenter(sender); } else if (buildingType == typeof(HouseModel)) { model = EntityFactory.CreateHouse(sender); } if (model != null) { _buildingPlacement = model; model.CoordX = -100; sender.BoardHoverRegistered += OnBoardHoverRegistered; } }
private void OnBoardClickRegistered(GameView sender, int coordX, int coordY, UnityEngine.EventSystems.PointerEventData.InputButton btn) { var model = (GameModel)this._viewToModel[sender]; if (btn == PointerEventData.InputButton.Left) { // There is an undergoing placement. // This will not select units. if (_buildingPlacement != null) { var available = !GridManager.Instance.CheckOverlap(coordX, coordY, _buildingPlacement.Width, _buildingPlacement.Height, GridLayers.Buildings | GridLayers.Units); if (available) { model.AddBuilding(_buildingPlacement); _buildingPlacement.Placed = true; _buildingPlacement = null; sender.BoardHoverRegistered -= OnBoardHoverRegistered; } } else { bool hit = false; foreach (var selectable in model.Selectables) { // Check given coords with Rectangles of selectables. if (selectable.CheckOverlap(coordX, coordY)) { hit = true; if (_currentSelection != null) { _currentSelection.OnDeSelection(); } selectable.OnSelection(); _currentSelection = selectable; model.SelectedEntity = selectable; break; } } if (_currentSelection != null && !hit) { _currentSelection.OnDeSelection(); _currentSelection = null; model.SelectedEntity = null; } } } else if (btn == PointerEventData.InputButton.Right) { if (_currentSelection != null) { // Too tired to think something anything near engineering at this point. // Just getting things done. // We have only to entities that get right click commands. if (_currentSelection is SoldierModel) { SoldierModel soldier = (SoldierModel)_currentSelection; var path = GridManager.Instance.FindPath(soldier.CoordX, soldier.CoordY, coordX, coordY); if (path != null) { soldier.Path = path; } else { Debug.LogError("Could not find a path."); } } else if (_currentSelection is ProductionBuildingModel) { if (!GridManager.Instance.CheckOverlap(coordX, coordY, 1, 1, GridLayers.Buildings)) { ((ProductionBuildingModel)_currentSelection).RallyPoint = new Vector2(coordX, coordY); } } } } }
public void AddBuilding(BuildingModel building) { _buildings.Add(building); _selectables.Add(building); NotifyCollectionModification("Buildings", building, CollectionModification.Add); }
protected virtual void BuildingsAdd(object model, BuildingModel building) { GridManager.Instance.UpdateMap(building.CoordX, building.CoordY, building.Width, building.Height, GridLayers.Buildings); }