From 758205e5a538940f9928ede6cc29595661e75368 Mon Sep 17 00:00:00 2001 From: CyB3RC0nN0R Date: Wed, 24 Jul 2019 19:07:22 +0200 Subject: [PATCH] Fixed engine menu reloading on engine addition --- src/dev/kske/chess/board/Board.java | 2 -- src/dev/kske/chess/ui/EngineUtil.java | 3 ++- src/dev/kske/chess/ui/MenuBar.java | 9 +++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/dev/kske/chess/board/Board.java b/src/dev/kske/chess/board/Board.java index b8da2ba..9b654e4 100644 --- a/src/dev/kske/chess/board/Board.java +++ b/src/dev/kske/chess/board/Board.java @@ -103,8 +103,6 @@ public class Board implements Cloneable { Piece piece = getPos(move); Piece capturePiece = getDest(move); - // TODO: reset halfmove clock - switch (move.type) { case PAWN_PROMOTION: setPos(move, null); diff --git a/src/dev/kske/chess/ui/EngineUtil.java b/src/dev/kske/chess/ui/EngineUtil.java index b56c416..3a97228 100644 --- a/src/dev/kske/chess/ui/EngineUtil.java +++ b/src/dev/kske/chess/ui/EngineUtil.java @@ -30,7 +30,7 @@ public class EngineUtil { private EngineUtil() {} - public static void addEngine(String enginePath) { + public static void addEngine(String enginePath, Runnable followup) { try { EngineInfo info = new EngineInfo(enginePath); UCIHandle handle = new UCIHandle(enginePath); @@ -51,6 +51,7 @@ public class EngineUtil { engineInfos.add(info); handle.quit(); saveEngineInfos(); + followup.run(); } }); handle.start(); diff --git a/src/dev/kske/chess/ui/MenuBar.java b/src/dev/kske/chess/ui/MenuBar.java index 62100a9..aad87f7 100644 --- a/src/dev/kske/chess/ui/MenuBar.java +++ b/src/dev/kske/chess/ui/MenuBar.java @@ -81,8 +81,13 @@ public class MenuBar extends JMenuBar { "Engine selection", JOptionPane.QUESTION_MESSAGE); if (enginePath != null) { - EngineUtil.addEngine(enginePath); - // TODO: Rebuilt the engine menu + EngineUtil.addEngine(enginePath, () -> { + EngineInfo info = EngineUtil.getEngineInfos() + .get(EngineUtil.getEngineInfos().size() - 1); + JMenuItem engineMenuItem = new JMenuItem(info.name); + engineMenuItem.addActionListener((evt2) -> startGame(Game.createUCI(boardPane, info.path))); + engineMenu.add(engineMenuItem); + }); } }); engineMenu.add(addEngineMenuItem);