mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-13 09:32:39 +01:00
DroidFish: When stopping analysis mode by pressing the toggle analysis button, restore the game mode from the last time the toggle analysis button was pressed.
This commit is contained in:
@@ -280,8 +280,15 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||||||
public int getName() { return R.string.toggle_analysis; }
|
public int getName() { return R.string.toggle_analysis; }
|
||||||
public int getIcon() { return R.raw.analyze; }
|
public int getIcon() { return R.raw.analyze; }
|
||||||
public boolean enabled() { return true; }
|
public boolean enabled() { return true; }
|
||||||
|
private int oldGameModeType = GameMode.EDIT_GAME;
|
||||||
public void run() {
|
public void run() {
|
||||||
int gameModeType = ctrl.analysisMode() ? GameMode.EDIT_GAME : GameMode.ANALYSIS;
|
int gameModeType;
|
||||||
|
if (ctrl.analysisMode()) {
|
||||||
|
gameModeType = oldGameModeType;
|
||||||
|
} else {
|
||||||
|
oldGameModeType = ctrl.getGameMode().getModeNr();
|
||||||
|
gameModeType = GameMode.ANALYSIS;
|
||||||
|
}
|
||||||
Editor editor = settings.edit();
|
Editor editor = settings.edit();
|
||||||
String gameModeStr = String.format("%d", gameModeType);
|
String gameModeStr = String.format("%d", gameModeType);
|
||||||
editor.putString("gameMode", gameModeStr);
|
editor.putString("gameMode", gameModeStr);
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
DroidFish - An Android chess program.
|
DroidFish - An Android chess program.
|
||||||
Copyright (C) 2011 Peter Österlund, peterosterlund2@gmail.com
|
Copyright (C) 2011-2012 Peter Österlund, peterosterlund2@gmail.com
|
||||||
|
|
||||||
This program is free software: you can redistribute it and/or modify
|
This program is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@@ -19,10 +19,7 @@
|
|||||||
package org.petero.droidfish;
|
package org.petero.droidfish;
|
||||||
|
|
||||||
public class GameMode {
|
public class GameMode {
|
||||||
private final boolean playerWhite;
|
private final int modeNr;
|
||||||
private final boolean playerBlack;
|
|
||||||
private final boolean analysisMode;
|
|
||||||
private final boolean clocksActive;
|
|
||||||
|
|
||||||
public static final int PLAYER_WHITE = 1;
|
public static final int PLAYER_WHITE = 1;
|
||||||
public static final int PLAYER_BLACK = 2;
|
public static final int PLAYER_BLACK = 2;
|
||||||
@@ -32,60 +29,59 @@ public class GameMode {
|
|||||||
public static final int EDIT_GAME = 6;
|
public static final int EDIT_GAME = 6;
|
||||||
|
|
||||||
public GameMode(int modeNr) {
|
public GameMode(int modeNr) {
|
||||||
|
this.modeNr = modeNr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getModeNr() {
|
||||||
|
return modeNr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Return true if white side is controlled by a human. */
|
||||||
|
public final boolean playerWhite() {
|
||||||
switch (modeNr) {
|
switch (modeNr) {
|
||||||
case PLAYER_WHITE: default:
|
case PLAYER_WHITE:
|
||||||
playerWhite = true;
|
|
||||||
playerBlack = false;
|
|
||||||
analysisMode = false;
|
|
||||||
clocksActive = true;
|
|
||||||
break;
|
|
||||||
case PLAYER_BLACK:
|
|
||||||
playerWhite = false;
|
|
||||||
playerBlack = true;
|
|
||||||
analysisMode = false;
|
|
||||||
clocksActive = true;
|
|
||||||
break;
|
|
||||||
case TWO_PLAYERS:
|
case TWO_PLAYERS:
|
||||||
playerWhite = true;
|
|
||||||
playerBlack = true;
|
|
||||||
analysisMode = false;
|
|
||||||
clocksActive = true;
|
|
||||||
break;
|
|
||||||
case ANALYSIS:
|
case ANALYSIS:
|
||||||
playerWhite = true;
|
|
||||||
playerBlack = true;
|
|
||||||
analysisMode = true;
|
|
||||||
clocksActive = false;
|
|
||||||
break;
|
|
||||||
case TWO_COMPUTERS:
|
|
||||||
playerWhite = false;
|
|
||||||
playerBlack = false;
|
|
||||||
analysisMode = false;
|
|
||||||
clocksActive = true;
|
|
||||||
break;
|
|
||||||
case EDIT_GAME:
|
case EDIT_GAME:
|
||||||
playerWhite = true;
|
return true;
|
||||||
playerBlack = true;
|
default:
|
||||||
analysisMode = false;
|
return false;
|
||||||
clocksActive = false;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean playerWhite() {
|
/** Return true if black side is controlled by a human. */
|
||||||
return playerWhite;
|
|
||||||
}
|
|
||||||
public final boolean playerBlack() {
|
public final boolean playerBlack() {
|
||||||
return playerBlack;
|
switch (modeNr) {
|
||||||
|
case PLAYER_BLACK:
|
||||||
|
case TWO_PLAYERS:
|
||||||
|
case ANALYSIS:
|
||||||
|
case EDIT_GAME:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean analysisMode() {
|
public final boolean analysisMode() {
|
||||||
return analysisMode;
|
return modeNr == ANALYSIS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return true if it is a humans turn to move. */
|
||||||
public final boolean humansTurn(boolean whiteMove) {
|
public final boolean humansTurn(boolean whiteMove) {
|
||||||
return (whiteMove ? playerWhite : playerBlack) || analysisMode;
|
return whiteMove ? playerWhite() : playerBlack();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Return true if the clocks are running. */
|
||||||
public final boolean clocksActive() {
|
public final boolean clocksActive() {
|
||||||
return clocksActive;
|
switch (modeNr) {
|
||||||
|
case PLAYER_WHITE:
|
||||||
|
case PLAYER_BLACK:
|
||||||
|
case TWO_PLAYERS:
|
||||||
|
case TWO_COMPUTERS:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -93,19 +89,11 @@ public class GameMode {
|
|||||||
if ((o == null) || (o.getClass() != this.getClass()))
|
if ((o == null) || (o.getClass() != this.getClass()))
|
||||||
return false;
|
return false;
|
||||||
GameMode other = (GameMode)o;
|
GameMode other = (GameMode)o;
|
||||||
if (playerWhite != other.playerWhite)
|
return modeNr == other.modeNr;
|
||||||
return false;
|
|
||||||
if (playerBlack != other.playerBlack)
|
|
||||||
return false;
|
|
||||||
if (analysisMode != other.analysisMode)
|
|
||||||
return false;
|
|
||||||
if (clocksActive != other.clocksActive)
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return 0;
|
return modeNr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,6 +131,10 @@ public class DroidChessController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GameMode getGameMode() {
|
||||||
|
return gameMode;
|
||||||
|
}
|
||||||
|
|
||||||
/** Return true if game mode is analysis. */
|
/** Return true if game mode is analysis. */
|
||||||
public final boolean analysisMode() {
|
public final boolean analysisMode() {
|
||||||
return gameMode.analysisMode();
|
return gameMode.analysisMode();
|
||||||
|
|||||||
Reference in New Issue
Block a user