Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two issues from moving token when "Snap Token While Dragging" is off #704

Merged
merged 2 commits into from
Sep 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions src/main/java/net/rptools/maptool/client/ui/zone/ZoneRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ public void commitMoveSelectionSet(GUID keyTokenId) {
BigDecimal tmc = null;
moveTimer.stop("setup");

int offsetX, offsetY;

moveTimer.start("eachtoken");
for (GUID tokenGUID : selectionSet) {
Token token = zone.getToken(tokenGUID);
Expand All @@ -497,16 +499,34 @@ public void commitMoveSelectionSet(GUID keyTokenId) {
tokenCell = zone.getGrid().convert(new ZonePoint(token.getX(), token.getY()));
else tokenCell = new ZonePoint(token.getX(), token.getY());

int cellOffX = originPoint.x - tokenCell.x;
int cellOffY = originPoint.y - tokenCell.y;
int cellOffX, cellOffY;
if (token.isSnapToGrid() == keyToken.isSnapToGrid()) {
cellOffX = originPoint.x - tokenCell.x;
cellOffY = originPoint.y - tokenCell.y;
} else cellOffX = cellOffY = 0; // not used unless both are of same SnapToGrid

if (token.isSnapToGrid()
&& (!AppPreferences.getTokensSnapWhileDragging() || !keyToken.isSnapToGrid())) {
// convert to Cellpoint and back to ensure token ends up at correct X and Y
CellPoint cellEnd =
zone.getGrid()
.convert(
new ZonePoint(
token.getX() + set.getOffsetX(), token.getY() + set.getOffsetY()));
ZonePoint pointEnd = cellEnd.convertToZonePoint(zone.getGrid());
offsetX = pointEnd.x - token.getX();
offsetY = pointEnd.y - token.getY();
} else {
offsetX = set.getOffsetX();
offsetY = set.getOffsetY();
}

/*
* Lee: the problem now is to keep the precise coordinate computations for unsnapped tokens following a snapped key token. The derived path in the following section contains rounded
* down values because the integer cell values were passed. If these were double in nature, the precision would be kept, but that would be too difficult to change at this stage...
*/

token.applyMove(
set, path, set.getOffsetX(), set.getOffsetY(), keyToken, cellOffX, cellOffY);
token.applyMove(set, path, offsetX, offsetY, keyToken, cellOffX, cellOffY);

// Lee: setting originPoint to landing point
token.setOriginPoint(new ZonePoint(token.getX(), token.getY()));
Expand Down