From 8ef8fbe3cdd4ccd11fa0ec28b41788942bef88f0 Mon Sep 17 00:00:00 2001 From: Peter Osterlund Date: Sun, 14 Apr 2013 08:04:13 +0000 Subject: [PATCH] DroidFish: Show current time control in the extended title bar. --- DroidFish/src/org/petero/droidfish/DroidFish.java | 7 +++---- DroidFish/src/org/petero/droidfish/GUIInterface.java | 3 +++ .../petero/droidfish/gamelogic/DroidChessController.java | 7 ++++--- .../src/org/petero/droidfish/gamelogic/TimeControl.java | 8 ++++++++ 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/DroidFish/src/org/petero/droidfish/DroidFish.java b/DroidFish/src/org/petero/droidfish/DroidFish.java index 9a84e15..c5f543d 100644 --- a/DroidFish/src/org/petero/droidfish/DroidFish.java +++ b/DroidFish/src/org/petero/droidfish/DroidFish.java @@ -137,7 +137,6 @@ public class DroidFish extends Activity implements GUIInterface { // FIXME!!! Computer clock should stop if phone turned off (computer stops thinking if unplugged) // FIXME!!! Add support for all time controls defined by the PGN standard // FIXME!!! How to handle hour-glass time control? - // FIXME!!! What should happen if you change time controls in the middle of a game? // FIXME!!! Online play on FICS // FIXME!!! Add chess960 support @@ -152,7 +151,7 @@ public class DroidFish extends Activity implements GUIInterface { // FIXME!!! Better behavior if engine is terminated. How exactly? // FIXME!!! Handle PGN non-file intents with more than one game. - // FIXME!!! File load/save of FEN data + // FIXME!!! Save position to fen/epd file // FIXME!!! Strength setting for external engines // FIXME!!! Selection dialog for going into variation @@ -894,7 +893,7 @@ public class DroidFish extends Activity implements GUIInterface { int movesPerSession = getIntSetting("movesPerSession", 60); int timeIncrement = getIntSetting("timeIncrement", 0); ctrl.setTimeLimit(timeControl, movesPerSession, timeIncrement); - setSummaryTitle(); + updateTimeControlTitle(); boardGestures = settings.getBoolean("boardGestures", true); scrollSensitivity = Float.parseFloat(settings.getString("scrollSensitivity", "2")); @@ -1087,7 +1086,7 @@ public class DroidFish extends Activity implements GUIInterface { } /** Update center field in second header line. */ - private final void setSummaryTitle() { + public final void updateTimeControlTitle() { int[] tmpInfo = ctrl.getTimeLimit(); StringBuilder sb = new StringBuilder(); int tc = tmpInfo[0]; diff --git a/DroidFish/src/org/petero/droidfish/GUIInterface.java b/DroidFish/src/org/petero/droidfish/GUIInterface.java index ba27035..464a35d 100644 --- a/DroidFish/src/org/petero/droidfish/GUIInterface.java +++ b/DroidFish/src/org/petero/droidfish/GUIInterface.java @@ -83,6 +83,9 @@ public interface GUIInterface { /** Update title with the material difference. */ public void updateMaterialDifferenceTitle(Util.MaterialDiff diff); + /** Update title with time control information. */ + public void updateTimeControlTitle(); + /** Report a move made that is a candidate for GUI animation. */ public void setAnimMove(Position sourcePos, Move move, boolean forward); diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java index fa4eb0f..6ec7898 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/DroidChessController.java @@ -112,10 +112,10 @@ public class DroidChessController { game.timeController.setTimeControl(timeControl, movesPerSession, timeIncrement); } - /** - * @return Array containing time control, moves per session and time increment. - */ + /** @return Array containing time control, moves per session and time increment. */ public final int[] getTimeLimit() { + if (game != null) + return game.timeController.getTimeLimit(game.currPos().whiteMove); int[] ret = new int[3]; ret[0] = timeControl; ret[1] = movesPerSession; @@ -1036,6 +1036,7 @@ public class DroidChessController { updateRemainingTime(); updateMaterialDiffList(); + gui.updateTimeControlTitle(); } public final void updateMaterialDiffList() { diff --git a/DroidFish/src/org/petero/droidfish/gamelogic/TimeControl.java b/DroidFish/src/org/petero/droidfish/gamelogic/TimeControl.java index e745334..8266833 100644 --- a/DroidFish/src/org/petero/droidfish/gamelogic/TimeControl.java +++ b/DroidFish/src/org/petero/droidfish/gamelogic/TimeControl.java @@ -157,6 +157,14 @@ public class TimeControl { return getCurrentTC(whiteMove).second; } + /** @return Array containing time control, moves per session and time increment. */ + public int[] getTimeLimit(boolean whiteMove) { + ArrayList tc = whiteMove ? tcW : tcB; + int tcIdx = getCurrentTC(whiteMove).first; + TimeControlField t = tc.get(tcIdx); + return new int[]{(int)t.timeControl, t.movesPerSession, (int)t.increment}; + } + /** Return the current active time control index and number of moves to next time control. */ private Pair getCurrentTC(boolean whiteMove) { ArrayList tc = whiteMove ? tcW : tcB;