internal void updateCellType(int x, int y) { TileFactory tf = TileFactory.Instance; //Cell selectedCell = model.scenario.getGameWorld().map.getCell(x, y); //selectedCell.tile = tf.getTile(model.TileTypeSelected); //model.notifyAll(); CellComponent cell = improvedModel.GetScenario().GetGameWorld().GetMap().GetCellAt(x, y); // Cell automatically removes old tile from overrided AddChild. cell.AddChild(tf.GetImprovedTile(improvedModel.TileTypeSelected)); // TODO: Change to new improvedModel here. }
internal void OnDragMapCell(CellComponent cell) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cell, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } }
/// <summary> /// Determines from the selection state if we are placing a resource, building, unit, or tile, and then places it based on /// the selection state. /// </summary> /// <param name="x"></param> /// <param name="y"></param> internal void OnClickMapCell(int x, int y) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; CellComponent cell = model.GetScenario().GetGameWorld().GetMap().GetCellAt(x, y); ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cell, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(UnitComponent)) { // Get instance of Unit Factory, produce unit, and place on map for the given player. } }
internal void OnClickMapCell(CellComponent cellComponent, float xPercent, float yPercent) { if (model.GetSelectionState().SelectionType == typeof(ZRTSModel.Tile)) { TileFactory tf = TileFactory.Instance; ZRTSModel.Tile tile = tf.GetImprovedTile(model.GetSelectionState().SelectedTileType); ChangeCellTileCommand command = new ChangeCellTileCommand(cellComponent, tile); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(UnitComponent)) { UnitFactory uf = UnitFactory.Instance; UnitComponent unit = uf.Create(model.GetSelectionState().SelectedUnitType); //unit.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddUnitCommand command = new AddUnitCommand(unit, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } else if (model.GetSelectionState().SelectionType == typeof(Building)) { BuildingFactory bf = BuildingFactory.Instance; Building building = bf.Build(model.GetSelectionState().SelectedBuildingType, true); //building.PointLocation = new PointF((float)cellComponent.X + xPercent, (float)cellComponent.Y + yPercent); PlayerComponent player = model.GetScenario().GetGameWorld().GetPlayerList().GetPlayerByName(model.GetSelectionState().SelectedPlayer); AddBuildingCommand command = new AddBuildingCommand(building, player, cellComponent); if (command.CanBeDone()) { model.GetCommandStack().ExecuteCommand(command); } } }