//sel poly now keeps the previous selection, converting its outline into a polygon if necessary.

This loses some blocks, if anyone cares
Dieser Commit ist enthalten in:
TomyLobo 2011-12-27 12:07:11 +01:00
Ursprung 76fd63d64b
Commit 7d503fdc5c
4 geänderte Dateien mit 45 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -616,7 +616,7 @@ public class SelectionCommands {
selector = new ExtendingCuboidRegionSelector(oldSelector); selector = new ExtendingCuboidRegionSelector(oldSelector);
player.print("Cuboid: left click for a starting point, right click to extend"); player.print("Cuboid: left click for a starting point, right click to extend");
} else if (typeName.equalsIgnoreCase("poly")) { } else if (typeName.equalsIgnoreCase("poly")) {
selector = new Polygonal2DRegionSelector(world); selector = new Polygonal2DRegionSelector(oldSelector);
player.print("2D polygon selector: Left/right click to add a point."); player.print("2D polygon selector: Left/right click to add a point.");
} else { } else {
player.printError("Only 'cuboid', 'extend' and 'poly' are accepted."); player.printError("Only 'cuboid', 'extend' and 'poly' are accepted.");

Datei anzeigen

@ -39,17 +39,17 @@ public class CuboidRegionSelector implements RegionSelector, CUIPointBasedRegion
protected BlockVector pos1; protected BlockVector pos1;
protected BlockVector pos2; protected BlockVector pos2;
protected CuboidRegion region; protected CuboidRegion region;
public CuboidRegionSelector(LocalWorld world) { public CuboidRegionSelector(LocalWorld world) {
region = new CuboidRegion(world, new Vector(), new Vector()); region = new CuboidRegion(world, new Vector(), new Vector());
} }
public CuboidRegionSelector() { public CuboidRegionSelector() {
this((LocalWorld)null); this((LocalWorld) null);
} }
public CuboidRegionSelector(RegionSelector oldSelector) { public CuboidRegionSelector(RegionSelector oldSelector) {
region = new CuboidRegion(oldSelector.getIncompleteRegion().getWorld(), new Vector(), new Vector()); this(oldSelector.getIncompleteRegion().getWorld());
if (oldSelector instanceof CuboidRegionSelector) { if (oldSelector instanceof CuboidRegionSelector) {
final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector; final CuboidRegionSelector cuboidRegionSelector = (CuboidRegionSelector) oldSelector;

Datei anzeigen

@ -50,7 +50,7 @@ public class Polygonal2DRegion implements Region {
* Construct the region * Construct the region
*/ */
public Polygonal2DRegion() { public Polygonal2DRegion() {
this(null); this((LocalWorld) null);
} }
/** /**
@ -84,6 +84,11 @@ public class Polygonal2DRegion implements Region {
recalculate(); recalculate();
} }
public Polygonal2DRegion(Polygonal2DRegion region) {
this(region.world, region.points, region.minY, region.maxY);
hasY = region.hasY;
}
/** /**
* Get the list of points. * Get the list of points.
* *

Datei anzeigen

@ -19,6 +19,7 @@
package com.sk89q.worldedit.regions; package com.sk89q.worldedit.regions;
import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import com.sk89q.worldedit.BlockVector; import com.sk89q.worldedit.BlockVector;
@ -41,11 +42,44 @@ import com.sk89q.worldedit.cui.SelectionShapeEvent;
public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedRegion { public class Polygonal2DRegionSelector implements RegionSelector, CUIPointBasedRegion {
protected BlockVector pos1; protected BlockVector pos1;
protected Polygonal2DRegion region; protected Polygonal2DRegion region;
public Polygonal2DRegionSelector(LocalWorld world) { public Polygonal2DRegionSelector(LocalWorld world) {
region = new Polygonal2DRegion(world); region = new Polygonal2DRegion(world);
} }
public Polygonal2DRegionSelector(RegionSelector oldSelector) {
this(oldSelector.getIncompleteRegion().getWorld());
if (oldSelector instanceof Polygonal2DRegionSelector) {
final Polygonal2DRegionSelector polygonal2DRegionSelector = (Polygonal2DRegionSelector) oldSelector;
pos1 = polygonal2DRegionSelector.pos1;
region = new Polygonal2DRegion(polygonal2DRegionSelector.region);
} else {
final Region oldRegion;
try {
oldRegion = oldSelector.getRegion();
} catch (IncompleteRegionException e) {
return;
}
BlockVector min = oldRegion.getMinimumPoint().toBlockVector();
BlockVector max = oldRegion.getMaximumPoint().toBlockVector();
int minY = min.getBlockY();
int maxY = max.getBlockY();
List<BlockVector2D> points = new ArrayList<BlockVector2D>(4);
points.add(new BlockVector2D(min.getX(), min.getZ()));
points.add(new BlockVector2D(min.getX(), max.getZ()));
points.add(new BlockVector2D(max.getX(), max.getZ()));
points.add(new BlockVector2D(max.getX(), min.getZ()));
pos1 = min;
region = new Polygonal2DRegion(oldRegion.getWorld(), points, minY, maxY);
}
}
public boolean selectPrimary(Vector pos) { public boolean selectPrimary(Vector pos) {
if (pos.equals(pos1)) { if (pos.equals(pos1)) {
return false; return false;