Skip to content

Commit

Permalink
make showing dynamic komi optional
Browse files Browse the repository at this point in the history
  • Loading branch information
kuba97531 committed Jul 21, 2018
1 parent c0707b2 commit da5357c
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class Config {
public boolean showRawBoard = false;
public boolean showCaptured = true;
public boolean handicapInsteadOfWinrate = false;
public boolean showDynamicKomi = true;

public boolean showStatus = true;
public boolean showBranch = true;
Expand Down Expand Up @@ -146,6 +147,7 @@ public Config() throws IOException {
largeSubBoard = uiConfig.getBoolean("large-subboard");
handicapInsteadOfWinrate = uiConfig.getBoolean("handicap-instead-of-winrate");
startMaximized = uiConfig.getBoolean("window-maximized");
showDynamicKomi = uiConfig.getBoolean("show-dynamic-komi");
}

// Modifies config by adding in values from default_config that are missing.
Expand Down Expand Up @@ -269,6 +271,7 @@ private JSONObject createDefaultConfig() {
ui.put("board-size", 19);
ui.put("window-size", new JSONArray("[1024, 768]"));
ui.put("window-maximized", false);
ui.put("show-dynamic-komi", true);

config.put("ui", ui);
return config;
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/featurecat/lizzie/gui/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ private boolean controlIsPressed(KeyEvent e) {
return e.isControlDown() || (mac && e.isMetaDown());
}

private void toggleShowDynamicKomi() {
Lizzie.config.showDynamicKomi = !Lizzie.config.showDynamicKomi;
}

@Override
public void keyPressed(KeyEvent e) {

Expand Down Expand Up @@ -358,6 +362,10 @@ public void keyPressed(KeyEvent e) {
}
break;

case VK_D:
toggleShowDynamicKomi();
break;

default:
shouldDisableAnalysis = false;
}
Expand Down
22 changes: 15 additions & 7 deletions src/main/java/featurecat/lizzie/gui/LizzieFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
Expand Down Expand Up @@ -399,7 +400,7 @@ public void paint(Graphics g0) {
ponderingX, ponderingY, ponderingSize);
}

if (Lizzie.leelaz.getDynamicKomi() != null) {
if (Lizzie.config.showDynamicKomi && Lizzie.leelaz.getDynamicKomi() != null) {
drawPonderingState(g, resourceBundle.getString("LizzieFrame.display.dynamic-komi"), dynamicKomiLabelX, dynamicKomiLabelY, dynamicKomiSize);
drawPonderingState(g, Lizzie.leelaz.getDynamicKomi(), dynamicKomiX, dynamicKomiY, dynamicKomiSize);
}
Expand Down Expand Up @@ -531,17 +532,22 @@ void drawControls() {
// redraw background
createBackground();

List<String> commandsToShow = new ArrayList<>(Arrays.asList(commands));
if (Lizzie.leelaz.getDynamicKomi() != null) {
commandsToShow.add(resourceBundle.getString("LizzieFrame.commands.keyD"));
}

Graphics2D g = cachedImage.createGraphics();

int maxSize = Math.min(getWidth(), getHeight());
Font font = new Font(systemDefaultFontName, Font.PLAIN, (int) (maxSize * 0.034));
g.setFont(font);
FontMetrics metrics = g.getFontMetrics(font);
int maxCommandWidth = Arrays.asList(commands).stream().reduce(0, (Integer i, String command) -> Math.max(i, metrics.stringWidth(command)), (Integer a, Integer b) -> Math.max(a, b));
int maxCommandWidth = commandsToShow.stream().reduce(0, (Integer i, String command) -> Math.max(i, metrics.stringWidth(command)), (Integer a, Integer b) -> Math.max(a, b));
int lineHeight = (int) (font.getSize() * 1.15);

int boxWidth = Util.clamp((int) (maxCommandWidth * 1.4), 0, getWidth());
int boxHeight = Util.clamp(commands.length * lineHeight, 0, getHeight());
int boxHeight = Util.clamp(commandsToShow.size() * lineHeight, 0, getHeight());

int commandsX = Util.clamp(getWidth() / 2 - boxWidth / 2, 0, getWidth());
int commandsY = Util.clamp(getHeight() / 2 - boxHeight / 2, 0, getHeight());
Expand All @@ -567,10 +573,12 @@ void drawControls() {
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

g.setColor(Color.WHITE);
for (int i = 0; i < commands.length; i++) {
String[] split = commands[i].split("\\|");
g.drawString(split[0], verticalLineX - metrics.stringWidth(split[0]) - strokeRadius * 4, font.getSize() + (commandsY + i * lineHeight));
g.drawString(split[1], verticalLineX + strokeRadius * 4, font.getSize() + (commandsY + i * lineHeight));
int lineOffset = commandsY;
for (String command : commandsToShow) {
String[] split = command.split("\\|");
g.drawString(split[0], verticalLineX - metrics.stringWidth(split[0]) - strokeRadius * 4, font.getSize() + lineOffset);
g.drawString(split[1], verticalLineX + strokeRadius * 4, font.getSize() + lineOffset);
lineOffset += lineHeight;
}

refreshBackground();
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/l10n/DisplayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ LizzieFrame.commands.keyAltC=ctrl-c|copy SGF to clipboard
LizzieFrame.commands.keyAltV=ctrl-v|paste SGF from clipboard
LizzieFrame.commands.keyC=c|toggle coordinates
LizzieFrame.commands.keyControl=ctrl|undo/redo 10 moves
LizzieFrame.commands.keyD=d|show/hide dynamic komi
LizzieFrame.commands.keyDownArrow=down arrow|redo
LizzieFrame.commands.keyEnd=end|go to end
LizzieFrame.commands.keyEnter=enter|force Leela Zero move
Expand Down Expand Up @@ -51,4 +52,4 @@ LizzieFrame.display.loading=Leela Zero is loading...
LizzieFrame.display.download-latest-network-prompt=Download the latest network file? This may take some time.
LizzieFrame.display.leelaz-missing=Did not find Leela Zero, update config.txt or download from Leela Zero homepage
LizzieFrame.display.network-missing=Did not find network/weights.\nUpdate config.txt (network-file) or download from Leela Zero homepage
LizzieFrame.display.dynamic-komi=dyn. komi:
LizzieFrame.display.dynamic-komi=dyn. komi:
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 @@ -6,6 +6,7 @@
LizzieFrame.commands.keyAltC=ctrl-c|\u62F7\u8D1DSGF\u5230\u526A\u8D34\u677F
LizzieFrame.commands.keyAltV=ctrl-v|\u4ECE\u526A\u8D34\u677F\u7C98\u8D34SGF\u5C40\u9762
LizzieFrame.commands.keyC=c|\u663E\u793A/\u9690\u85CF\u5750\u6807
LizzieFrame.commands.keyD=d|show/hide dynamic komi
LizzieFrame.commands.keyControl=ctrl|\u5411\u524D/\u5411\u540E10\u6B65
LizzieFrame.commands.keyDownArrow=\u4E0B\u65B9\u5411\u952E|\u5411\u540E\u4E00\u6B65
LizzieFrame.commands.keyEnd=end|\u8DF3\u5230\u68CB\u8C31\u672B\u5C3E
Expand Down

0 comments on commit da5357c

Please sign in to comment.