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); } } }
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. } }