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: Support display the comment of the SGF file #365

Merged
merged 3 commits into from
Oct 5, 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
7 changes: 7 additions & 0 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class Config {
public boolean showMoveNumber = false;
public boolean showWinrate = true;
public boolean showVariationGraph = true;
public boolean showComment = false;
public int commentFontSize = 0;
public boolean showRawBoard = false;
public boolean showCaptured = true;
public boolean handicapInsteadOfWinrate = false;
Expand Down Expand Up @@ -132,6 +134,8 @@ public Config() throws IOException {
showBranch = uiConfig.getBoolean("show-leelaz-variation");
showWinrate = uiConfig.getBoolean("show-winrate");
showVariationGraph = uiConfig.getBoolean("show-variation-graph");
showComment = uiConfig.optBoolean("show-comment", false);
commentFontSize = uiConfig.optInt("comment-font-size", 0);
OlivierBlanvillain marked this conversation as resolved.
Show resolved Hide resolved
showCaptured = uiConfig.getBoolean("show-captured");
showBestMoves = uiConfig.getBoolean("show-best-moves");
showNextMoves = uiConfig.getBoolean("show-next-moves");
Expand Down Expand Up @@ -179,6 +183,9 @@ public void toggleShowWinrate() {
public void toggleShowVariationGraph() {
this.showVariationGraph = !this.showVariationGraph;
}
public void toggleShowComment() {
this.showComment = !this.showComment;
}
public void toggleShowBestMoves() {
this.showBestMoves = !this.showBestMoves;
}
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,10 @@ public void keyPressed(KeyEvent e) {
Lizzie.config.toggleShowVariationGraph();
break;

case VK_T:
Lizzie.config.toggleShowComment();
break;

case VK_C:
if (controlIsPressed(e)) {
Lizzie.frame.copySgf();
Expand Down Expand Up @@ -399,6 +403,9 @@ public void keyReleased(KeyEvent e) {

@Override
public void mouseWheelMoved(MouseWheelEvent e) {
if (Lizzie.frame.processCommentMouseWheelMoved(e)) {
return;
}
if (Lizzie.board.inAnalysisMode())
Lizzie.board.toggleAnalysis();
if (e.getWheelRotation() > 0) {
Expand Down
101 changes: 100 additions & 1 deletion src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;

import java.awt.event.MouseWheelEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.image.BufferStrategy;
Expand Down Expand Up @@ -68,6 +69,7 @@ public class LizzieFrame extends JFrame {
resourceBundle.getString("LizzieFrame.commands.keyV"),
resourceBundle.getString("LizzieFrame.commands.keyW"),
resourceBundle.getString("LizzieFrame.commands.keyG"),
resourceBundle.getString("LizzieFrame.commands.keyT"),
resourceBundle.getString("LizzieFrame.commands.keyHome"),
resourceBundle.getString("LizzieFrame.commands.keyEnd"),
resourceBundle.getString("LizzieFrame.commands.keyControl"),
Expand Down Expand Up @@ -95,6 +97,13 @@ public class LizzieFrame extends JFrame {

private long lastAutosaveTime = System.currentTimeMillis();

// Display Comment
private JScrollPane scrollPane = null;
private JTextPane commentPane = null;
private BufferedImage commentImage = null;
private String cachedComment = null;
private Rectangle commentRect = null;

static {
// load fonts
try {
Expand Down Expand Up @@ -125,6 +134,17 @@ public LizzieFrame() {
setExtendedState(Frame.MAXIMIZED_BOTH); // start maximized
}

// Comment Pane
commentPane = new JTextPane();
commentPane.setEditable(false);
commentPane.setMargin(new Insets(5, 5, 5, 5));
commentPane.setBackground(new Color(0, 0, 0, 200));
commentPane.setForeground(Color.WHITE);
scrollPane = new JScrollPane();
scrollPane.setViewportView(commentPane);
scrollPane.setBorder(null);
scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

setVisible(true);

createBufferStrategy(2);
Expand Down Expand Up @@ -414,7 +434,17 @@ public void paint(Graphics g0) {

if (Lizzie.config.showVariationGraph) {
drawVariationTreeContainer(backgroundG, vx, vy, vw, vh);
variationTree.draw(g, treex, treey, treew, treeh);
int cHeight = 0;
if (Lizzie.config.showComment) {
// Draw the Comment of the Sgf
cHeight = drawComment(g, vx, vy, vw, vh, false);
}
variationTree.draw(g, treex, treey, treew, treeh - cHeight);
} else {
if (Lizzie.config.showComment) {
// Draw the Comment of the Sgf
drawComment(g, vx, topInset, vw, vh - topInset + vy, true);
}
}
if (Lizzie.config.showSubBoard) {
try {
Expand Down Expand Up @@ -867,6 +897,44 @@ public void onMouseDragged(int x, int y) {
}
}

/**
* Process Comment Mouse Wheel Moved
*
* @return true when the scroll event was processed by this method
*/
public boolean processCommentMouseWheelMoved(MouseWheelEvent e) {
if (Lizzie.config.showComment && commentRect != null && commentRect.contains(e.getX(), e.getY())) {
scrollPane.dispatchEvent(e);
createCommentImage(true, 0, 0);
getGraphics().drawImage(commentImage, commentRect.x, commentRect.y, commentRect.width, commentRect.height, null);
return true;
} else {
return false;
}
}

/**
* Create comment cached image
*
* @param forceRefresh
* @param w
* @param h
*/
public void createCommentImage(boolean forceRefresh, int w, int h) {
if (forceRefresh || commentImage == null || scrollPane.getWidth() != w || scrollPane.getHeight() != h) {
if (w > 0 && h > 0) {
scrollPane.setSize(w, h);
}
commentImage = new BufferedImage(scrollPane.getWidth(), scrollPane.getHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics2D g2 = commentImage.createGraphics();
scrollPane.doLayout();
scrollPane.addNotify();
scrollPane.validate();
scrollPane.printAll(g2);
g2.dispose();
}
}

private void autosaveMaybe() {
int interval = Lizzie.config.config.getJSONObject("ui").getInt("autosave-interval-seconds") * 1000;
long currentTime = System.currentTimeMillis();
Expand Down Expand Up @@ -945,4 +1013,35 @@ public void pasteSgf() {
public void increaseMaxAlpha(int k) {
boardRenderer.increaseMaxAlpha(k);
}

/**
* Draw the Comment of the Sgf file
*
* @param g
* @param x
* @param y
* @param w
* @param h
* @param full
* @return
*/
private int drawComment(Graphics2D g, int x, int y, int w, int h, boolean full) {
String comment = (Lizzie.board.getHistory().getData() != null && Lizzie.board.getHistory().getData().comment != null) ? Lizzie.board.getHistory().getData().comment : "";
int cHeight = full ? h : (int)(h*0.5);
int fontSize = (int)(Math.min(getWidth(), getHeight()) * 0.0294);
if (Lizzie.config.commentFontSize > 0) {
fontSize = Lizzie.config.commentFontSize;
} else if (fontSize < 16) {
fontSize = 16;
}
Font font = new Font(systemDefaultFontName, Font.PLAIN, fontSize);
commentPane.setFont(font);
commentPane.setText(comment);
commentPane.setSize(w, cHeight);
createCommentImage(comment != null && !comment.equals(this.cachedComment), w, cHeight);
commentRect = new Rectangle(x, y + (h - cHeight), scrollPane.getWidth(), scrollPane.getHeight());
g.drawImage(commentImage, commentRect.x, commentRect.y, commentRect.width, commentRect.height, null);
cachedComment = comment;
return cHeight;
}
}
14 changes: 0 additions & 14 deletions src/main/java/featurecat/lizzie/rules/BoardHistoryList.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,6 @@ public BoardData next() {
return head.getData();
}

/**
* moves the pointer to the right, returns the node stored there
*
* @return the next node, null if there is no next node
*/
public BoardHistoryNode nextNode() {
if (head.next() == null)
return null;
else
head = head.next();

return head;
}

/**
* moves the pointer to the variation number idx, returns the data stored there
*
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/DisplayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ LizzieFrame.commands.keyEnd=end|go to end
LizzieFrame.commands.keyEnter=enter|force Leela Zero move
LizzieFrame.commands.keyF=f|toggle next move display
LizzieFrame.commands.keyG=g|toggle variation graph
LizzieFrame.commands.keyT=t|toggle comment display
LizzieFrame.commands.keyHome=home|go to start
LizzieFrame.commands.keyI=i|edit game info
LizzieFrame.commands.keyA=a|run automatic analysis of game
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/DisplayStrings_RO.properties
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ LizzieFrame.commands.keyEnd=end|mergi la sfârșit
LizzieFrame.commands.keyEnter=enter|forțează mutarea lui Leela Zero
LizzieFrame.commands.keyF=f|afișează/ascunde următoarea mutare
LizzieFrame.commands.keyG=g|afișează/ascunde graficul cu variante
LizzieFrame.commands.keyT=t|afișează/ascunde comentariul
LizzieFrame.commands.keyHome=home|mergi la început
LizzieFrame.commands.keyI=i|editează informațiile jocului
LizzieFrame.commands.keyA=a|rulează analiza automată a jocului
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/l10n/DisplayStrings_zh_CN.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LizzieFrame.commands.keyEnd=end|\u8DF3\u5230\u68CB\u8C31\u672B\u5C3E
LizzieFrame.commands.keyEnter=enter|\u8BA9Leela Zero\u843D\u5B50
LizzieFrame.commands.keyF=f|\u663E\u793A/\u9690\u85CF\u4E0B\u4E00\u624B
LizzieFrame.commands.keyG=g|\u663E\u793A/\u9690\u85CF\u5206\u652F\u56FE
LizzieFrame.commands.keyT=t|\u663E\u793A/\u9690\u85CF\u8BC4\u8BBA
LizzieFrame.commands.keyHome=home|\u8DF3\u8F6C\u5230\u68CB\u8C31\u5F00\u5934
LizzieFrame.commands.keyI=i|\u7F16\u8F91\u68CB\u5C40\u4FE1\u606F
LizzieFrame.commands.keyA=a|\u8FD0\u884C\u7B80\u5355\u7684\u81EA\u52A8\u5168\u76D8\u5206\u6790
Expand Down