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 #862 (insufficient x-shift in variation tree) #864

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
49 changes: 14 additions & 35 deletions src/main/java/featurecat/lizzie/gui/VariationTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public class VariationTree {
private BoardHistoryNode curMove;
private Rectangle area;
private Point clickPoint;
private int curMoveLane = 0;

public VariationTree() {
laneUsageList = new ArrayList<Integer>();
Expand Down Expand Up @@ -69,6 +70,8 @@ public Optional<BoardHistoryNode> drawTree(

// At this point, lane contains the lane we should use (the main branch is in lane 0)

if (startNode == curMove) curMoveLane = lane;

BoardHistoryNode cur = startNode;
int curposx = posx + lane * XSPACING;
int dotoffset = DOT_DIAM / 2;
Expand Down Expand Up @@ -156,6 +159,7 @@ public Optional<BoardHistoryNode> drawTree(
if (cur.isEndDummay()) {
continue;
}
if (cur == curMove) curMoveLane = lane;
if (calc) {
if (inNode(curposx + dotoffset, posy + dotoffset)) {
return Optional.of(cur);
Expand Down Expand Up @@ -233,6 +237,16 @@ public Optional<BoardHistoryNode> draw(
if (width <= 0 || height <= 0) {
return Optional.empty(); // we don't have enough space
}
area.setBounds(posx, posy, width, height);

// Get the lane of the current node by a dummy drawing.
if (!calc) {
int DUMMY = Integer.MIN_VALUE / 2;
clickPoint.setLocation(DUMMY, DUMMY);
curMoveLane = 0;
draw(g, posx, posy, width, height, true); // set curMoveLane as a side effect
}
int lane = curMoveLane;

// Use dense tree for saving space if large-subboard
YSPACING = (Lizzie.config.showLargeSubBoard() ? 20 : 30);
Expand All @@ -241,7 +255,6 @@ public Optional<BoardHistoryNode> draw(
int strokeRadius = Lizzie.config.showBorder ? 2 : 0;
if (!calc) {
// Draw background
area.setBounds(posx, posy, width, height);
g.setColor(new Color(0, 0, 0, 60));
g.fillRect(posx, posy, width, height);

Expand Down Expand Up @@ -272,7 +285,6 @@ public Optional<BoardHistoryNode> draw(
node = node.previous().get();
curposy -= YSPACING;
}
int lane = getCurLane(node, curMove, curposy, posy + height, 0, true);
int startx = posx + xoffset;
if (((lane + 1) * XSPACING + xoffset + DOT_DIAM + strokeRadius - width) > 0) {
startx = startx - ((lane + 1) * XSPACING + xoffset + DOT_DIAM + strokeRadius - width);
Expand Down Expand Up @@ -306,37 +318,4 @@ public void onClicked(int x, int y) {
node.ifPresent(n -> Lizzie.board.moveToAnyPosition(n));
}
}

private int getCurLane(
BoardHistoryNode start,
BoardHistoryNode curMove,
int curposy,
int maxy,
int laneCount,
boolean isMain) {
BoardHistoryNode next = start;
int nexty = curposy;
while (next.next().isPresent() && nexty + YSPACING < maxy) {
nexty += YSPACING;
next = next.next().get();
}
while (next.previous().isPresent() && (isMain || next != start)) {
next = next.previous().get();
for (int i = 1; i < next.numberOfChildren(); i++) {
laneCount++;
if (next.findIndexOfNode(curMove, true) == i) {
return laneCount;
}
Optional<BoardHistoryNode> variation = next.getVariation(i);
if (variation.isPresent()) {
int subLane = getCurLane(variation.get(), curMove, nexty, maxy, laneCount, false);
if (subLane > 0) {
return subLane;
}
}
}
nexty -= YSPACING;
}
return 0;
}
}