Skip to content

Commit

Permalink
Add winrate & blunder bar theme color
Browse files Browse the repository at this point in the history
  • Loading branch information
zsalch committed Oct 25, 2018
1 parent 843fc6f commit fa530d7
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 77 deletions.
64 changes: 51 additions & 13 deletions src/main/java/featurecat/lizzie/Config.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package featurecat.lizzie;

import featurecat.lizzie.theme.Theme;
import java.awt.Color;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand All @@ -14,14 +16,11 @@ public class Config {
public boolean showMoveNumber = false;
public boolean showWinrate = true;
public boolean largeWinrate = false;
public float winrateStrokeWidth = 3;
public boolean showWinrateBlunderBar = false;
public int minimumWinrateBlunderBarWidth = 3;
public boolean weightedDisplayBlunderBarHeight = false;
public boolean showBlunderBar = true;
public boolean weightedBlunderBarHeight = false;
public boolean dynamicWinrateGraphWidth = false;
public boolean showVariationGraph = true;
public boolean showComment = false;
public int commentFontSize = 0;
public boolean showComment = true;
public boolean showRawBoard = false;
public boolean showCaptured = true;
public boolean handicapInsteadOfWinrate = false;
Expand All @@ -43,6 +42,21 @@ public class Config {
private String configFilename = "config.txt";
private String persistFilename = "persist";

public Theme theme;
public float winrateStrokeWidth = 3;
public int minimumBlunderBarWidth = 3;
public int shadowSize = 100;
public String fontName = null;
public String uiFontName = null;
public String winrateFontName = null;
public int commentFontSize = 0;
public Color commentFontColor = null;
public Color commentBackgroundColor = null;
public Color winrateLineColor = null;
public Color winrateMissLineColor = null;
public Color blunderBarColor = null;
public boolean solidStoneIndicator = false;

private JSONObject loadAndMergeConfig(
JSONObject defaultCfg, String fileName, boolean needValidation) throws IOException {
File file = new File(fileName);
Expand Down Expand Up @@ -133,20 +147,18 @@ public Config() throws IOException {
leelazConfig = config.getJSONObject("leelaz");
uiConfig = config.getJSONObject("ui");

theme = new Theme(uiConfig);

showMoveNumber = uiConfig.getBoolean("show-move-number");
showStatus = uiConfig.getBoolean("show-status");
showBranch = uiConfig.getBoolean("show-leelaz-variation");
showWinrate = uiConfig.getBoolean("show-winrate");
largeWinrate = uiConfig.optBoolean("large-winrate", false);
winrateStrokeWidth = uiConfig.optFloat("winrate-stroke-width", 3);
showWinrateBlunderBar = uiConfig.optBoolean("show-winrate-blunder-bar", false);
minimumWinrateBlunderBarWidth = uiConfig.optInt("minimum-winrate-blunder-bar-width", 3);
weightedDisplayBlunderBarHeight =
uiConfig.optBoolean("weighted-display-blunder-bar-height", false);
showBlunderBar = uiConfig.optBoolean("show-blunder-bar", true);
weightedBlunderBarHeight = uiConfig.optBoolean("weighted-blunder-bar-height", false);
dynamicWinrateGraphWidth = uiConfig.optBoolean("dynamic-winrate-graph-width", false);
showVariationGraph = uiConfig.getBoolean("show-variation-graph");
showComment = uiConfig.optBoolean("show-comment", false);
commentFontSize = uiConfig.optInt("comment-font-size", 0);
showComment = uiConfig.optBoolean("show-comment", true);
showCaptured = uiConfig.getBoolean("show-captured");
showBestMoves = uiConfig.getBoolean("show-best-moves");
showNextMoves = uiConfig.getBoolean("show-next-moves");
Expand All @@ -155,6 +167,20 @@ public Config() throws IOException {
handicapInsteadOfWinrate = uiConfig.getBoolean("handicap-instead-of-winrate");
startMaximized = uiConfig.getBoolean("window-maximized");
showDynamicKomi = uiConfig.getBoolean("show-dynamic-komi");

winrateStrokeWidth = theme.winrateStrokeWidth();
minimumBlunderBarWidth = theme.minimumBlunderBarWidth();
shadowSize = theme.shadowSize();
fontName = theme.fontName();
uiFontName = theme.uiFontName();
winrateFontName = theme.winrateFontName();
commentFontSize = theme.commentFontSize();
commentFontColor = theme.commentFontColor();
commentBackgroundColor = theme.commentBackgroundColor();
winrateLineColor = theme.winrateLineColor();
winrateMissLineColor = theme.winrateMissLineColor();
blunderBarColor = theme.blunderBarColor();
solidStoneIndicator = theme.solidStoneIndicator();
}

// Modifies config by adding in values from default_config that are missing.
Expand Down Expand Up @@ -226,6 +252,10 @@ public boolean showLargeSubBoard() {
return showSubBoard && largeSubBoard;
}

public boolean showLargeWinrate() {
return showWinrate && largeWinrate;
}

/**
* Scans the current directory as well as the current PATH to find a reasonable default leelaz
* binary.
Expand Down Expand Up @@ -282,6 +312,14 @@ private JSONObject createDefaultConfig() {
ui.put("show-status", true);
ui.put("show-leelaz-variation", true);
ui.put("show-winrate", true);
ui.put("large-winrate", false);
ui.put("winrate-stroke-width", 3);
ui.put("show-blunder-bar", true);
ui.put("minimum-blunder-bar-width", 3);
ui.put("weighted-blunder-bar-height", false);
ui.put("dynamic-winrate-graph-width", false);
ui.put("show-comment", true);
ui.put("comment-font-size", 0);
ui.put("show-variation-graph", true);
ui.put("show-captured", true);
ui.put("show-best-moves", true);
Expand Down
62 changes: 26 additions & 36 deletions src/main/java/featurecat/lizzie/gui/BoardRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
import java.awt.font.TextAttribute;
import java.awt.geom.Point2D;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.imageio.ImageIO;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -73,8 +71,8 @@ public class BoardRenderer {
private int maxAlpha = 240;

public BoardRenderer(boolean isMainBoard) {
uiConfig = Lizzie.config.config.getJSONObject("ui");
uiPersist = Lizzie.config.persisted.getJSONObject("ui-persist");
uiConfig = Lizzie.config.uiConfig;
uiPersist = Lizzie.config.persisted;
try {
maxAlpha = uiPersist.getInt("max-alpha");
} catch (JSONException e) {
Expand Down Expand Up @@ -203,15 +201,15 @@ private void drawGoban(Graphics2D g0) {
g,
x + scaledMargin + squareLength * i,
y + scaledMargin / 2,
LizzieFrame.OpenSansRegularBase,
LizzieFrame.uiFont,
"" + alphabet.charAt(i),
stoneRadius * 4 / 5,
stoneRadius);
drawString(
g,
x + scaledMargin + squareLength * i,
y - scaledMargin / 2 + boardLength,
LizzieFrame.OpenSansRegularBase,
LizzieFrame.uiFont,
"" + alphabet.charAt(i),
stoneRadius * 4 / 5,
stoneRadius);
Expand All @@ -221,15 +219,15 @@ private void drawGoban(Graphics2D g0) {
g,
x + scaledMargin / 2,
y + scaledMargin + squareLength * i,
LizzieFrame.OpenSansRegularBase,
LizzieFrame.uiFont,
"" + (Board.BOARD_SIZE - i),
stoneRadius * 4 / 5,
stoneRadius);
drawString(
g,
x - scaledMargin / 2 + +boardLength,
y + scaledMargin + squareLength * i,
LizzieFrame.OpenSansRegularBase,
LizzieFrame.uiFont,
"" + (Board.BOARD_SIZE - i),
stoneRadius * 4 / 5,
stoneRadius);
Expand Down Expand Up @@ -449,7 +447,12 @@ private void drawMoveNumbers(Graphics2D g) {
boolean isWhite = board.getStones()[Board.getIndex(lastMove[0], lastMove[1])].isWhite();
g.setColor(isWhite ? Color.BLACK : Color.WHITE);

drawCircle(g, stoneX, stoneY, lastMoveMarkerRadius);
if (Lizzie.config.solidStoneIndicator) {
// Use a solid circle instead of
fillCircle(g, stoneX, stoneY, (int) (lastMoveMarkerRadius * 0.65));
} else {
drawCircle(g, stoneX, stoneY, lastMoveMarkerRadius);
}
} else if (lastMove == null && board.getData().moveNumber != 0 && !board.inScoreMode()) {
g.setColor(
board.getData().blackToPlay ? new Color(255, 255, 255, 150) : new Color(0, 0, 0, 150));
Expand All @@ -464,7 +467,7 @@ private void drawMoveNumbers(Graphics2D g) {
g,
x + boardLength / 2,
y + boardLength / 2,
LizzieFrame.OpenSansRegularBase,
LizzieFrame.uiFont,
"pass",
stoneRadius * 4,
stoneRadius * 6);
Expand Down Expand Up @@ -511,7 +514,7 @@ private void drawMoveNumbers(Graphics2D g) {
g,
stoneX,
stoneY,
LizzieFrame.OpenSansRegularBase,
LizzieFrame.uiFont,
moveNumberString,
(float) (stoneRadius * 1.4),
(int) (stoneRadius * 1.4));
Expand Down Expand Up @@ -627,7 +630,7 @@ private void drawLeelazSuggestions(Graphics2D g) {
g,
suggestionX,
suggestionY,
LizzieFrame.OpenSansSemiboldBase,
LizzieFrame.winrateFont,
Font.PLAIN,
text,
stoneRadius,
Expand All @@ -638,7 +641,7 @@ private void drawLeelazSuggestions(Graphics2D g) {
g,
suggestionX,
suggestionY + stoneRadius * 2 / 5,
LizzieFrame.OpenSansRegularBase,
LizzieFrame.uiFont,
getPlayoutsString(move.playouts),
(float) (stoneRadius * 0.8),
stoneRadius * 1.4);
Expand Down Expand Up @@ -674,12 +677,9 @@ private void drawNextMoves(Graphics2D g) {

private void drawWoodenBoard(Graphics2D g) {
if (uiConfig.getBoolean("fancy-board")) {
// fancy version
if (cachedBoardImage == null) {
try {
cachedBoardImage = ImageIO.read(getClass().getResourceAsStream("/assets/board.png"));
} catch (IOException e) {
e.printStackTrace();
}
cachedBoardImage = Lizzie.config.theme.board();
}

int shadowRadius = (int) (boardLength * MARGIN / 6);
Expand All @@ -703,6 +703,7 @@ private void drawWoodenBoard(Graphics2D g) {
g.setStroke(new BasicStroke(1));

} else {
// simple version
JSONArray boardColor = uiConfig.getJSONArray("board-color");
g.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_OFF);
g.setColor(new Color(boardColor.getInt(0), boardColor.getInt(1), boardColor.getInt(2)));
Expand Down Expand Up @@ -747,8 +748,8 @@ private void drawShadow(
Graphics2D g, int centerX, int centerY, boolean isGhost, float shadowStrength) {
if (!uiConfig.getBoolean("shadows-enabled")) return;

final int shadowSize = (int) (stoneRadius * 0.3 * uiConfig.getInt("shadow-size") / 100);
final int fartherShadowSize = (int) (stoneRadius * 0.17 * uiConfig.getInt("shadow-size") / 100);
final int shadowSize = (int) (stoneRadius * 0.3 * Lizzie.config.shadowSize / 100);
final int fartherShadowSize = (int) (stoneRadius * 0.17 * Lizzie.config.shadowSize / 100);

final Paint TOP_GRADIENT_PAINT;
final Paint LOWER_RIGHT_GRADIENT_PAINT;
Expand Down Expand Up @@ -840,18 +841,12 @@ private void drawStone(
}

/** Get scaled stone, if cached then return cached */
private BufferedImage getScaleStone(boolean isBlack, int size) {
public BufferedImage getScaleStone(boolean isBlack, int size) {
BufferedImage stone = isBlack ? cachedBlackStoneImage : cachedWhiteStoneImage;
if (stone == null) {
if (stone == null || stone.getWidth() != size || stone.getHeight() != size) {
stone = new BufferedImage(size, size, TYPE_INT_ARGB);
String imgPath = isBlack ? "/assets/black0.png" : "/assets/white0.png";
Image img = null;
try {
img = ImageIO.read(getClass().getResourceAsStream(imgPath));
} catch (IOException e) {
e.printStackTrace();
}
Graphics2D g2 = stone.createGraphics();
Image img = isBlack ? Lizzie.config.theme.blackStone() : Lizzie.config.theme.whiteStone();
g2.drawImage(img.getScaledInstance(size, size, java.awt.Image.SCALE_SMOOTH), 0, 0, null);
g2.dispose();
if (isBlack) {
Expand All @@ -865,12 +860,7 @@ private BufferedImage getScaleStone(boolean isBlack, int size) {

public BufferedImage getWallpaper() {
if (cachedWallpaperImage == null) {
try {
String wallpaperPath = "/assets/background.jpg";
cachedWallpaperImage = ImageIO.read(getClass().getResourceAsStream(wallpaperPath));
} catch (IOException e) {
e.printStackTrace();
}
cachedWallpaperImage = Lizzie.config.theme.background();
}
return cachedWallpaperImage;
}
Expand Down Expand Up @@ -970,7 +960,7 @@ private void drawString(
font = font.deriveFont((float) (font.getSize2D() * maximumFontWidth / fm.stringWidth(string)));
font = font.deriveFont(min(maximumFontHeight, font.getSize()));
g.setFont(font);

fm = g.getFontMetrics(font);
int height = fm.getAscent() - fm.getDescent();
int verticalOffset;
if (aboveOrBelow == -1) {
Expand Down
Loading

0 comments on commit fa530d7

Please sign in to comment.