Skip to content

Commit

Permalink
Merge #650
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/main/java/featurecat/lizzie/gui/BoardRenderer.java
  • Loading branch information
Hiraoka committed Sep 28, 2020
2 parents f400bf5 + 614774a commit 8ba7fe6
Show file tree
Hide file tree
Showing 17 changed files with 377 additions and 29 deletions.
2 changes: 2 additions & 0 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public class Config {
public String gtpConsoleStyle = "";
private final String defaultGtpConsoleStyle =
"body {background:#000000; color:#d0d0d0; font-family:Consolas, Menlo, Monaco, 'Ubuntu Mono', monospace; margin:4px;} .command {color:#ffffff;font-weight:bold;} .winrate {color:#ffffff;font-weight:bold;} .coord {color:#ffffff;font-weight:bold;}";
public boolean notRefreshVariation = false;

private JSONObject loadAndMergeConfig(
JSONObject defaultCfg, String fileName, boolean needValidation) throws IOException {
Expand Down Expand Up @@ -220,6 +221,7 @@ public Config() throws IOException {
appendWinrateToComment = uiConfig.optBoolean("append-winrate-to-comment");
holdBestMovesToSgf = uiConfig.optBoolean("hold-bestmoves-to-sgf", true);
showBestMovesByHold = uiConfig.optBoolean("show-bestmoves-by-hold", true);
notRefreshVariation = uiConfig.optBoolean("not-refresh-variation", false);
showCoordinates = uiConfig.optBoolean("show-coordinates");
replayBranchIntervalSeconds = uiConfig.optDouble("replay-branch-interval-seconds", 1.0);
colorByWinrateInsteadOfVisits = uiConfig.optBoolean("color-by-winrate-instead-of-visits");
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/featurecat/lizzie/gui/BasicInfoPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;

/** The window used to display the game. */
Expand Down Expand Up @@ -67,6 +69,20 @@ protected void paintComponent(Graphics g0) {
// cleanup
bsGraphics.dispose();
// bs.show();
addMouseMotionListener(
new MouseMotionListener() {
@Override
public void mouseMoved(MouseEvent e) {
if (Lizzie.config.showSubBoard) {
Lizzie.frame.clearIsMouseOverSub();
}
}

@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
});
}

private void drawCaptured(Graphics2D g, int posX, int posY, int width, int height) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/featurecat/lizzie/gui/BoardPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,15 @@ public void mouseExited(MouseEvent e) {
onMouseExited(e.getX(), e.getY());
}
});

addMouseMotionListener(
new MouseMotionListener() {
@Override
public void mouseMoved(MouseEvent e) {
onMouseMoved(e.getX(), e.getY());
if (Lizzie.config.showSubBoard) {
Lizzie.frame.clearIsMouseOverSub();
}
}

@Override
Expand Down
90 changes: 88 additions & 2 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public class BoardRenderer {

private int maxAlpha = 240;

private boolean isMouseOverSub = false;
private boolean clickedSub = false;
private int bestmoveIndexSub = 0;
private List<String> variation;
private String mouseOverCoords = "";

// Computed in drawLeelazSuggestionsBackground and stored for
// display in drawLeelazSuggestionsForeground
private class TextData {
Expand Down Expand Up @@ -130,6 +136,7 @@ public void draw(Graphics2D g) {

// Stopwatch timer = new Stopwatch();
drawGoban(g);
if (!isMainBoard) drawSubBoardStatus(g);
if (Lizzie.config.showNameInBoard && isMainBoard) drawName(g);
// timer.lap("background");
drawStones();
Expand Down Expand Up @@ -338,6 +345,42 @@ private void drawGoban(Graphics2D g0) {
cachedY = y;
}

private void drawSubBoardStatus(Graphics2D g) {
// TODO Auto-generated method stub
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
g.setColor(Color.BLACK);
if (isMouseOverSub) {
g.fillRect(
x + boardWidth - stoneRadius * 7 / 2,
y + boardHeight - scaledMarginHeight * 9 / 10,
scaledMarginHeight * 3 / 10,
scaledMarginHeight * 8 / 10);
g.fillRect(
x + boardWidth + scaledMarginHeight * 5 / 10 - stoneRadius * 7 / 2,
y + boardHeight - scaledMarginHeight * 9 / 10,
scaledMarginHeight * 3 / 10,
scaledMarginHeight * 8 / 10);
} else {
int[] xPoints = {
x + boardWidth - stoneRadius * 7 / 2,
x + boardWidth - stoneRadius * 7 / 2,
x + boardWidth - stoneRadius * 5 / 2
};
int[] yPoints = {
y + boardHeight - 1,
y + boardHeight - scaledMarginHeight + 1,
y + boardHeight - scaledMarginHeight / 2
};
g.fillPolygon(xPoints, yPoints, 3);
}
g.setFont(new Font(Lizzie.config.uiFontName, Font.BOLD, stoneRadius * 3 / 2));
g.drawString(
"" + (this.bestmoveIndexSub + 1),
x + boardWidth - stoneRadius * 9 / 5,
y + boardHeight - stoneRadius / 10);
}

private void drawName(Graphics2D g0) {
if (Lizzie.board == null) {
return;
Expand Down Expand Up @@ -532,6 +575,7 @@ private void drawScore(Graphics2D go) {

/** Draw the 'ghost stones' which show a variationOpt Leelaz is thinking about */
private void drawBranch() {
boolean isShowingBranch = showingBranch;
showingBranch = false;
branchStonesImage = new BufferedImage(boardWidth, boardHeight, TYPE_INT_ARGB);
branchStonesShadowImage = new BufferedImage(boardWidth, boardHeight, TYPE_INT_ARGB);
Expand Down Expand Up @@ -570,8 +614,21 @@ private void drawBranch() {
|| (isMainBoard && Lizzie.frame.isShowingPolicy)) {
return;
}
List<String> variation = suggestedMove.get().variation;
if (isMainBoard) {
if (!Lizzie.config.notRefreshVariation
|| (!isShowingBranch || !mouseOverCoords.equals(suggestedMove.get().coordinate)))
variation = suggestedMove.get().variation;
} else {
if (!isMouseOverSub || clickedSub) {
if (clickedSub) {
clickedSub = false;
setDisplayedBranchLength(SHOW_NORMAL_BOARD);
}
variation = suggestedMove.get().variation;
}
}
Branch branch = new Branch(Lizzie.board, variation, displayedBranchLength);
if (isMainBoard) mouseOverCoords = suggestedMove.get().coordinate;
branchOpt = Optional.of(branch);
variationOpt = Optional.of(variation);
showingBranch = true;
Expand Down Expand Up @@ -610,7 +667,11 @@ public Optional<MoveData> mouseOveredMove() {
}

private Optional<MoveData> getBestMove() {
return bestMoves.isEmpty() ? Optional.empty() : Optional.of(bestMoves.get(0));
if (!bestMoves.isEmpty()) {
if (bestMoves.size() < this.bestmoveIndexSub + 1) bestmoveIndexSub = bestMoves.size() - 1;
return Optional.of(bestMoves.get(bestmoveIndexSub));
}
return Optional.empty();
}

/** Render the shadows and stones in correct background-foreground order */
Expand Down Expand Up @@ -1699,6 +1760,9 @@ public boolean incrementDisplayedBranchLength(int n) {
default:
// force nonnegative
displayedBranchLength = max(0, displayedBranchLength + n);
if (variation != null) {
displayedBranchLength = min(displayedBranchLength, variation.size() + 1);
} else displayedBranchLength = 0;
return true;
}
}
Expand Down Expand Up @@ -1917,4 +1981,26 @@ private void drawPolicy(Graphics2D g) {
}
}
}

public boolean getIsMouseOverSub() {
return isMouseOverSub;
}

public void setIsMouseOverSub(boolean status) {
isMouseOverSub = status;
}

public void setClickedSub(boolean status) {
clickedSub = status;
}

public void increaseBestmoveIndexSub(int n) {
if (bestmoveIndexSub + n >= 0) bestmoveIndexSub = bestmoveIndexSub + n;
}

public void clearBeforeMove() {
setDisplayedBranchLength(SHOW_NORMAL_BOARD);
clickedSub = false;
bestmoveIndexSub = 0;
}
}
14 changes: 14 additions & 0 deletions src/main/java/featurecat/lizzie/gui/CommentPane.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@ public void mouseClicked(MouseEvent e) {
scrollPane.setViewportView(commentPane);
setVisible(false);

commentPane.addMouseMotionListener(
new MouseMotionListener() {
@Override
public void mouseMoved(MouseEvent e) {
if (Lizzie.config.showSubBoard) {
Lizzie.frame.clearIsMouseOverSub();
}
}

@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub
}
});
// mouseMotionAdapter = new MouseMotionAdapter() {
// @Override
// public void mouseDragged(MouseEvent e) {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/featurecat/lizzie/gui/ConfigDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public class ConfigDialog extends JDialog {
public JCheckBox chkHoldBestMovesToSgf;
public JCheckBox chkShowBestMovesByHold;
public JCheckBox chkColorByWinrateInsteadOfVisits;
public JCheckBox chkNotRefreshVariation;
public JSlider sldBoardPositionProportion;
public JTextField txtLimitBestMoveNum;
public JTextField txtLimitBranchLength;
Expand Down Expand Up @@ -1098,6 +1099,14 @@ protected DocumentFilter getDocumentFilter() {
chkShowBestMovesByHold.setBounds(536, 278, 57, 23);
uiTab.add(chkShowBestMovesByHold);

JLabel lblNotRefreshVaritions =
new JLabel(resourceBundle.getString("LizzieConfig.title.notRefreshVariation"));
lblNotRefreshVaritions.setBounds(372, 308, 187, 16);
uiTab.add(lblNotRefreshVaritions);
chkNotRefreshVariation = new JCheckBox("");
chkNotRefreshVariation.setBounds(536, 305, 57, 23);
uiTab.add(chkNotRefreshVariation);

JLabel lblColorByWinrateInsteadOfVisits =
new JLabel(resourceBundle.getString("LizzieConfig.title.colorByWinrateInsteadOfVisits"));
lblColorByWinrateInsteadOfVisits.setBounds(6, 308, 163, 16);
Expand Down Expand Up @@ -1202,6 +1211,7 @@ protected DocumentFilter getDocumentFilter() {
chkAppendWinrateToComment.setSelected(Lizzie.config.appendWinrateToComment);
chkHoldBestMovesToSgf.setSelected(Lizzie.config.holdBestMovesToSgf);
chkShowBestMovesByHold.setSelected(Lizzie.config.showBestMovesByHold);
chkNotRefreshVariation.setSelected(Lizzie.config.notRefreshVariation);
chkColorByWinrateInsteadOfVisits.setSelected(Lizzie.config.colorByWinrateInsteadOfVisits);
sldBoardPositionProportion.setValue(Lizzie.config.boardPositionProportion);
txtLimitBestMoveNum.setText(String.valueOf(Lizzie.config.limitBestMoveNum));
Expand Down Expand Up @@ -2530,6 +2540,8 @@ private void saveConfig() {
Lizzie.config.uiConfig.putOpt("hold-bestmoves-to-sgf", Lizzie.config.holdBestMovesToSgf);
Lizzie.config.showBestMovesByHold = chkShowBestMovesByHold.isSelected();
Lizzie.config.uiConfig.putOpt("show-bestmoves-by-hold", Lizzie.config.showBestMovesByHold);
Lizzie.config.notRefreshVariation = chkNotRefreshVariation.isSelected();
Lizzie.config.uiConfig.putOpt("not-refresh-variation", Lizzie.config.notRefreshVariation);
Lizzie.config.colorByWinrateInsteadOfVisits = chkColorByWinrateInsteadOfVisits.isSelected();
Lizzie.config.uiConfig.putOpt(
"color-by-winrate-instead-of-visits", Lizzie.config.colorByWinrateInsteadOfVisits);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public void mouseClicked(MouseEvent e) {}
@Override
public void mousePressed(MouseEvent e) {
Lizzie.frame.toolBar.setTxtUnfocus();
if (Lizzie.frame.subBoardOnClick(e)) return;
if (e.getButton() == MouseEvent.BUTTON1) { // left click
if (e.getClickCount() == 2) { // TODO: Maybe need to delay check
Lizzie.frame.onDoubleClicked(e.getX(), e.getY());
Expand Down Expand Up @@ -564,6 +565,9 @@ public void mouseWheelMoved(MouseWheelEvent e) {
if (Lizzie.frame.processCommentMouseWheelMoved(e)) {
return;
}
if (Lizzie.frame.processSubBoardMouseWheelMoved(e)) {
return;
}
if (e.getWhen() - wheelWhen > 0) {
wheelWhen = e.getWhen();
if (Lizzie.board.inAnalysisMode()) Lizzie.board.toggleAnalysis();
Expand Down
Loading

0 comments on commit 8ba7fe6

Please sign in to comment.