diff --git a/src/main/java/featurecat/lizzie/Config.java b/src/main/java/featurecat/lizzie/Config.java index 71f1315fa..9ccb39b3d 100644 --- a/src/main/java/featurecat/lizzie/Config.java +++ b/src/main/java/featurecat/lizzie/Config.java @@ -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; @@ -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); showCaptured = uiConfig.getBoolean("show-captured"); showBestMoves = uiConfig.getBoolean("show-best-moves"); showNextMoves = uiConfig.getBoolean("show-next-moves"); @@ -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; } diff --git a/src/main/java/featurecat/lizzie/gui/Input.java b/src/main/java/featurecat/lizzie/gui/Input.java index c0862a4fd..b7f765cd0 100644 --- a/src/main/java/featurecat/lizzie/gui/Input.java +++ b/src/main/java/featurecat/lizzie/gui/Input.java @@ -288,6 +288,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(); @@ -370,6 +374,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) { diff --git a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java index 8f2dfbb34..526b2bfeb 100644 --- a/src/main/java/featurecat/lizzie/gui/LizzieFrame.java +++ b/src/main/java/featurecat/lizzie/gui/LizzieFrame.java @@ -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; @@ -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"), @@ -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 { @@ -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); @@ -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 { @@ -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(); @@ -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; + } } diff --git a/src/main/java/featurecat/lizzie/rules/BoardHistoryList.java b/src/main/java/featurecat/lizzie/rules/BoardHistoryList.java index 044ec0f02..643079036 100644 --- a/src/main/java/featurecat/lizzie/rules/BoardHistoryList.java +++ b/src/main/java/featurecat/lizzie/rules/BoardHistoryList.java @@ -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 * diff --git a/src/main/resources/l10n/DisplayStrings.properties b/src/main/resources/l10n/DisplayStrings.properties index 05deb875a..c8cf8079e 100644 --- a/src/main/resources/l10n/DisplayStrings.properties +++ b/src/main/resources/l10n/DisplayStrings.properties @@ -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 diff --git a/src/main/resources/l10n/DisplayStrings_RO.properties b/src/main/resources/l10n/DisplayStrings_RO.properties index 07b385516..d01b4059a 100644 --- a/src/main/resources/l10n/DisplayStrings_RO.properties +++ b/src/main/resources/l10n/DisplayStrings_RO.properties @@ -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 diff --git a/src/main/resources/l10n/DisplayStrings_zh_CN.properties b/src/main/resources/l10n/DisplayStrings_zh_CN.properties index 95d9c079d..2309ac564 100644 --- a/src/main/resources/l10n/DisplayStrings_zh_CN.properties +++ b/src/main/resources/l10n/DisplayStrings_zh_CN.properties @@ -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