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

next: Add more keyboard shortcut #415

Merged
merged 5 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
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
17 changes: 15 additions & 2 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
public class Config {

public boolean showMoveNumber = false;
public int onlyLastMoveNumber = 0;
// 0: Do not show; -1: Show all move number; other: Show last move number
public int allowMoveNumber = -1;
public boolean newMoveNumberInBranch = true;
public boolean showWinrate = true;
public boolean largeWinrate = false;
Expand Down Expand Up @@ -148,6 +151,8 @@ public Config() throws IOException {
theme = new Theme(uiConfig);

showMoveNumber = uiConfig.getBoolean("show-move-number");
onlyLastMoveNumber = uiConfig.optInt("only-last-move-number");
allowMoveNumber = showMoveNumber ? (onlyLastMoveNumber > 0 ? onlyLastMoveNumber : -1) : 0;
newMoveNumberInBranch = uiConfig.optBoolean("new-move-number-in-branch", true);
showStatus = uiConfig.getBoolean("show-status");
showBranch = uiConfig.getBoolean("show-leelaz-variation");
Expand Down Expand Up @@ -214,7 +219,12 @@ public boolean mergeDefaults(JSONObject config, JSONObject defaultsConfig) {
}

public void toggleShowMoveNumber() {
this.showMoveNumber = !this.showMoveNumber;
if (this.onlyLastMoveNumber > 0) {
allowMoveNumber =
(allowMoveNumber == -1 ? onlyLastMoveNumber : (allowMoveNumber == 0 ? -1 : 0));
} else {
allowMoveNumber = (allowMoveNumber == 0 ? -1 : 0);
}
}

public void toggleNodeColorMode() {
Expand Down Expand Up @@ -348,6 +358,9 @@ private JSONObject createDefaultConfig() {
ui.put("window-maximized", false);
ui.put("show-dynamic-komi", true);
ui.put("min-playout-ratio-for-stats", 0.0);
ui.put("blunder-winrate-thresholds", "[-30,-20,-10,-5,5,10]");
ui.put("blunder-node-colors", "[[255,0,0],[0,255,0],[0,0,255],[255,255,0],[0,255,255],[255,0,255]]");
ui.put("comment-node-color", "[0,0,255,255]");

config.put("ui", ui);
return config;
Expand Down Expand Up @@ -394,4 +407,4 @@ private void writeConfig(JSONObject config, File file) throws IOException, JSONE
public void persist() throws IOException {
writeConfig(this.persisted, new File(persistFilename));
}
}
}
8 changes: 4 additions & 4 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ private void drawMoveNumbers(Graphics2D g) {
g.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
Board board = Lizzie.board;
Optional<int[]> lastMoveOpt = branchOpt.map(b -> b.data.lastMove).orElse(board.getLastMove());
if (!Lizzie.config.showMoveNumber && !branchOpt.isPresent()) {
if (Lizzie.config.allowMoveNumber == 0 && !branchOpt.isPresent()) {
if (lastMoveOpt.isPresent()) {
int[] lastMove = lastMoveOpt.get();

Expand Down Expand Up @@ -489,19 +489,19 @@ private void drawMoveNumbers(Graphics2D g) {

// Allow to display only last move number
int lastMoveNumber = branchOpt.map(b -> b.data.moveNumber).orElse(board.getData().moveNumber);
int onlyLastMoveNumber = Lizzie.config.uiConfig.optInt("only-last-move-number", 9999);

for (int i = 0; i < Board.boardSize; i++) {
for (int j = 0; j < Board.boardSize; j++) {
int stoneX = x + scaledMargin + squareLength * i;
int stoneY = y + scaledMargin + squareLength * j;
int here = Board.getIndex(i, j);

// Allow to display only last move number
if (lastMoveNumber - moveNumberList[Board.getIndex(i, j)] >= onlyLastMoveNumber) {
if (Lizzie.config.allowMoveNumber > -1
&& lastMoveNumber - moveNumberList[here] >= Lizzie.config.allowMoveNumber) {
continue;
}

int here = Board.getIndex(i, j);
Stone stoneHere = branchOpt.map(b -> b.data.stones[here]).orElse(board.getStones()[here]);

// don't write the move number if either: the move number is 0, or there will already be
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,20 @@ private void undoToChildOfPreviousWithVariation() {
if (!Lizzie.board.undoToChildOfPreviousWithVariation()) Lizzie.board.previousMove();
}

private void undoToFirstParentWithVariations() {
if (Lizzie.board.undoToChildOfPreviousWithVariation()) {
Lizzie.board.previousMove();
}
}

private void goCommentNode(boolean moveForward) {
if (moveForward) {
redo(Lizzie.board.getHistory().getCurrentHistoryNode().goToNextNodeWithComment());
} else {
undo(Lizzie.board.getHistory().getCurrentHistoryNode().goToPreviousNodeWithComment());
}
}

private void redo() {
redo(1);
}
Expand Down Expand Up @@ -157,13 +171,17 @@ public void keyPressed(KeyEvent e) {
case VK_LEFT:
if (e.isShiftDown()) {
moveBranchUp();
} else if (controlIsPressed(e)) {
undoToFirstParentWithVariations();
} else {
previousBranch();
}
break;

case VK_UP:
if (e.isShiftDown()) {
if (controlIsPressed(e) && e.isShiftDown()) {
goCommentNode(false);
} else if (e.isShiftDown()) {
undoToChildOfPreviousWithVariation();
} else if (controlIsPressed(e)) {
undo(10);
Expand All @@ -181,7 +199,9 @@ public void keyPressed(KeyEvent e) {
break;

case VK_DOWN:
if (controlIsPressed(e)) {
if (controlIsPressed(e) && e.isShiftDown()) {
goCommentNode(true);
} else if (controlIsPressed(e)) {
redo(10);
} else {
redo();
Expand Down Expand Up @@ -254,7 +274,11 @@ public void keyPressed(KeyEvent e) {
break;

case VK_HOME:
while (Lizzie.board.previousMove()) ;
if (controlIsPressed(e)) {
Lizzie.board.clear();
} else {
while (Lizzie.board.previousMove()) ;
}
break;

case VK_END:
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/featurecat/lizzie/rules/BoardHistoryNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,42 @@ public boolean isMainTrunk() {
}
return true;
}

/**
* Go to the next node with the comment.
*
* @return the move count to the next node with comment, 0 otherwise
*/
public int goToNextNodeWithComment() {
BoardHistoryNode node = this;
int moves = 0;
while (node.next().isPresent()) {
moves++;
BoardHistoryNode next = node.next().get();
if (!next.getData().comment.isEmpty()) {
break;
}
node = next;
}
return moves;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The int returned here is never used, same comment for the next method.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It return value will be used by the function goCommentNode in the Input.java

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, then you might wan't to add a one line javadoc @returns ... :)

}

/**
* Go to the previous node with the comment.
*
* @return the move count to the previous node with comment, 0 otherwise
*/
public int goToPreviousNodeWithComment() {
BoardHistoryNode node = this;
int moves = 0;
while (node.previous().isPresent()) {
moves++;
BoardHistoryNode previous = node.previous().get();
if (!previous.getData().comment.isEmpty()) {
break;
}
node = previous;
}
return moves;
}
}