Skip to content

Commit 1493372

Browse files
Merge pull request #5714 from kwvanderlinde/bugfix/5709-transfer-from-map
Fix token topology transfers and other issues with token bounds
2 parents e30553f + 587b38f commit 1493372

File tree

19 files changed

+110
-87
lines changed

19 files changed

+110
-87
lines changed

src/main/java/net/rptools/lib/image/ImageUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public static BufferedImage getScaledTokenImage(
148148
}
149149
}
150150
} else {
151-
Rectangle b = token.getBounds(grid.getZone());
151+
Rectangle b = token.getImageBounds(grid.getZone());
152152
try {
153153
return ImageUtil.scaleBufferedImage(
154154
img, (int) Math.ceil(b.width * zoom), (int) Math.ceil(b.height * zoom));

src/main/java/net/rptools/maptool/client/functions/TokenLocationFunctions.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private String tokenMoveMap(boolean fromCurrentMap, List<Object> args) throws Pa
241241
private TokenLocation getTokenLocation(boolean useDistancePerCell, Token token) {
242242
TokenLocation loc = new TokenLocation();
243243
if (useDistancePerCell) {
244-
Rectangle tokenBounds = token.getBounds(token.getZoneRenderer().getZone());
244+
Rectangle tokenBounds = token.getImageBounds(token.getZoneRenderer().getZone());
245245
loc.x = tokenBounds.x;
246246
loc.y = tokenBounds.y;
247247
} else {
@@ -337,10 +337,10 @@ public double getDistance(Token source, Token target, boolean units, String metr
337337
}
338338
} else {
339339
// take distance between center of the two tokens
340-
Rectangle sourceBounds = source.getBounds(zone);
340+
Rectangle sourceBounds = source.getImageBounds(zone);
341341
double sourceCenterX = sourceBounds.x + sourceBounds.width / 2.0;
342342
double sourceCenterY = sourceBounds.y + sourceBounds.height / 2.0;
343-
Rectangle targetBounds = target.getBounds(zone);
343+
Rectangle targetBounds = target.getImageBounds(zone);
344344
double targetCenterX = targetBounds.x + targetBounds.width / 2.0;
345345
double targetCenterY = targetBounds.y + targetBounds.height / 2.0;
346346

@@ -418,7 +418,7 @@ public double getDistance(
418418
}
419419

420420
// get the pixel coords for the center of the token
421-
Rectangle sourceBounds = source.getBounds(zone);
421+
Rectangle sourceBounds = source.getImageBounds(zone);
422422
double sourceCenterX = sourceBounds.x + sourceBounds.width / 2.0;
423423
double sourceCenterY = sourceBounds.y + sourceBounds.height / 2.0;
424424
double a = (int) (sourceCenterX - targetX);
@@ -452,7 +452,7 @@ public static boolean isTokenAtXY(Token token, Zone zone, Point[] points) {
452452
}
453453
}
454454
} else {
455-
Rectangle bounds = token.getBounds(zone);
455+
Rectangle bounds = token.getImageBounds(zone);
456456
for (Point point : points) {
457457
if (bounds.contains(point)) return true;
458458
}

src/main/java/net/rptools/maptool/client/functions/TokenMoveFunctions.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private List<Map<String, Integer>> crossedPoints(
267267
.getFootprint(grid)
268268
.getBounds(grid, grid.convert(new ZonePoint(entry.get("x"), entry.get("y"))));
269269
} else {
270-
originalArea = tokenInContext.getBounds(zone);
270+
originalArea = tokenInContext.getImageBounds(zone);
271271
}
272272
Rectangle2D oa = originalArea.getBounds2D();
273273
if (targetArea.contains(oa) || targetArea.intersects(oa)) {
@@ -300,7 +300,7 @@ private List<Map<String, Integer>> crossedToken(
300300
* if-else sequence...
301301
*/
302302
Grid grid = zone.getGrid();
303-
Rectangle targetArea = target.getBounds(zone);
303+
Rectangle targetArea = target.getImageBounds(zone);
304304

305305
if (pathPoints == null) {
306306
return returnPoints;
@@ -326,7 +326,7 @@ private List<Map<String, Integer>> crossedToken(
326326
Map<String, Integer> firstPoint = new HashMap<String, Integer>(),
327327
secondPoint = new HashMap<String, Integer>();
328328
for (Map<String, Integer> entry : pathPoints) {
329-
Rectangle tokenArea = tokenInContext.getBounds(zone);
329+
Rectangle tokenArea = tokenInContext.getImageBounds(zone);
330330
Point currentPoint = new Point(entry.get("x"), entry.get("y"));
331331
if (ctr > 0) {
332332
if (targetArea.intersectsLine(new Line2D.Double(previousPoint, currentPoint))

src/main/java/net/rptools/maptool/client/functions/TokenPropertyFunctions.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ public Object childEvaluate(
779779
Zone zone = zoneR.getZone();
780780

781781
// Get the pixel width or height of a given token
782-
Rectangle tokenBounds = token.getBounds(zone);
782+
Rectangle tokenBounds = token.getImageBounds(zone);
783783

784784
if (functionName.equalsIgnoreCase("getTokenWidth")) {
785785
return BigDecimal.valueOf(tokenBounds.width);
@@ -803,7 +803,7 @@ public Object childEvaluate(
803803
Zone zone = zoneR.getZone();
804804

805805
double magnitude = getBigDecimalFromParam(functionName, parameters, 0).doubleValue();
806-
Rectangle tokenBounds = token.getBounds(zone);
806+
Rectangle tokenBounds = token.getImageBounds(zone);
807807

808808
double oldWidth = tokenBounds.width;
809809
double oldHeight = tokenBounds.height;

src/main/java/net/rptools/maptool/client/functions/TokenSightFunctions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public Object childEvaluate(
110110
target
111111
.getFootprint(grid)
112112
.getBounds(grid, grid.convert(new ZonePoint(target.getX(), target.getY())));
113-
if (!target.isSnapToGrid()) bounds = target.getBounds(zone);
113+
if (!target.isSnapToGrid()) bounds = target.getImageBounds(zone);
114114

115115
int x = (int) bounds.getX();
116116
int y = (int) bounds.getY();

src/main/java/net/rptools/maptool/client/tool/PointerTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ private boolean validateMove(
19551955
}
19561956
}
19571957

1958-
Rectangle tokenSize = token.getBounds(zone);
1958+
Rectangle tokenSize = token.getFootprintBounds(zone);
19591959
Rectangle destination =
19601960
new Rectangle(
19611961
tokenSize.x + deltaX, tokenSize.y + deltaY, tokenSize.width, tokenSize.height);
@@ -1990,7 +1990,7 @@ private boolean validateMove_legacy(Set<GUID> tokenSet, ZonePoint leadTokenNewAn
19901990
int x = token.getX() + deltaX;
19911991
int y = token.getY() + deltaY;
19921992

1993-
Rectangle tokenSize = token.getBounds(zone);
1993+
Rectangle tokenSize = token.getFootprintBounds(zone);
19941994
/*
19951995
* Perhaps create a counter and count the number of times that the contains() check returns true? There are currently 9 rectangular areas checked by this code (note the "/3" in the two
19961996
* 'interval' variables) so checking for 5 or more would mean more than 55%+ of the destination was visible...

src/main/java/net/rptools/maptool/client/tool/StampTool.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ public void paintOverlay(ZoneRenderer renderer, Graphics2D g) {
999999
// Resize
10001000
if (!token.isSnapToScale()) {
10011001
double scale = renderer.getScale();
1002-
Rectangle footprintBounds = token.getBounds(renderer.getZone());
1002+
Rectangle footprintBounds = token.getFootprintBounds(renderer.getZone());
10031003

10041004
double scaledWidth = (footprintBounds.width * scale);
10051005
double scaledHeight = (footprintBounds.height * scale);
@@ -1194,7 +1194,7 @@ public void moveByKey(int dx, int dy, boolean micro) {
11941194
zp.x += snapOffsetX;
11951195
zp.y += snapOffsetY;
11961196
} else {
1197-
Rectangle tokenSize = tokenBeingDragged.getBounds(renderer.getZone());
1197+
Rectangle tokenSize = tokenBeingDragged.getFootprintBounds(renderer.getZone());
11981198
int x = tokenDragCurrent.x + (micro ? dx : (tokenSize.width * dx));
11991199
int y = tokenDragCurrent.y + (micro ? dy : (tokenSize.height * dy));
12001200
zp = new ZonePoint(x, y);

src/main/java/net/rptools/maptool/client/ui/exportdialog/ExportDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -923,7 +923,7 @@ public Rectangle zoneExtents(PlayerView view) {
923923
// Note: order doesn't matter, so don't need to go back-to-front.
924924
for (Token element :
925925
zone.getTokensForLayers(layer -> view.isGMView() || layer.isVisibleToPlayers())) {
926-
Rectangle drawnBounds = element.getBounds(zone);
926+
Rectangle drawnBounds = element.getImageBounds(zone);
927927
if (element.hasFacing()) {
928928
// Get the facing and do a quick fix to make the math easier: -90 is 'unrotated' for some
929929
// reason

src/main/java/net/rptools/maptool/client/ui/token/dialog/edit/TokenTopologyPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ protected void paintComponent(Graphics g) {
223223

224224
// Gather info
225225
BufferedImage image = ImageManager.getImage(token.getImageAssetId());
226-
java.awt.Rectangle tokenSize = token.getBounds(zone);
226+
java.awt.Rectangle tokenSize = token.getFootprintBounds(zone);
227227
Dimension originalImgSize = new Dimension(image.getWidth(), image.getHeight());
228228
Dimension imgSize = new Dimension(image.getWidth(), image.getHeight());
229229

src/main/java/net/rptools/maptool/client/ui/zone/FogUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ public static Point calculateVisionCenter(Token token, Zone zone) {
467467
.getFootprint(grid)
468468
.getBounds(grid, grid.convert(new ZonePoint(token.getX(), token.getY())));
469469
} else {
470-
bounds = token.getBounds(zone);
470+
bounds = token.getFootprintBounds(zone);
471471
}
472472

473473
x = bounds.x + bounds.width / 2;

0 commit comments

Comments
 (0)