DroidFish: Preliminary support for figurine chess notation. From Leo Mayer, with some small changes by me.

This commit is contained in:
Peter Osterlund
2012-08-27 18:14:10 +00:00
parent feb5fabb22
commit 37610d8297
8 changed files with 74 additions and 11 deletions

View File

@@ -134,7 +134,7 @@ public class ChessBoard extends View {
if (isInEditMode())
return;
Typeface chessFont = Typeface.createFromAsset(getContext().getAssets(), "ChessCases.ttf");
Typeface chessFont = Typeface.createFromAsset(getContext().getAssets(), "fonts/ChessCases.ttf");
whitePiecePaint.setTypeface(chessFont);
blackPiecePaint.setTypeface(chessFont);

View File

@@ -129,7 +129,6 @@ public class DroidFish extends Activity implements GUIInterface {
// FIXME!!! Remove invalid playerActions in PGN import (should be done in verifyChildren)
// FIXME!!! Implement bookmark mechanism for positions in pgn files
// FIXME!!! Add support for "Chess Leipzig" font
// FIXME!!! Implement figurine notation
// 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
@@ -205,6 +204,11 @@ public class DroidFish extends Activity implements GUIInterface {
private WakeLock wakeLock = null;
private boolean useWakeLock = false;
// private Typeface figNotation;
private Typeface defaultMoveListTypeFace;
private Typeface defaultThinkingListTypeFace;
/** Defines all configurable button actions. */
private ActionFactory actionFactory = new ActionFactory() {
private HashMap<String, UIAction> actions;
@@ -353,7 +357,7 @@ public class DroidFish extends Activity implements GUIInterface {
custom3ButtonActions = new ButtonActions("custom3", CUSTOM3_BUTTON_DIALOG,
R.string.select_action);
TextIO.setPieceNames(getString(R.string.piece_names));
setPieceNames(PGNOptions.PT_LOCAL);
initUI(true);
gameTextListener = new PgnScreenText(pgnOptions);
@@ -389,6 +393,15 @@ public class DroidFish extends Activity implements GUIInterface {
}
}
private final void setPieceNames(int pieceType) {
if (pieceType == PGNOptions.PT_FIGURINE) {
// Unicode code points for chess pieces
TextIO.setPieceNames("\u2659 \u2658 \u2657 \u2656 \u2655 \u2654");
} else {
TextIO.setPieceNames(getString(R.string.piece_names));
}
}
/** Create directory structure on SD card. */
private void createDirectories() {
File extDir = Environment.getExternalStorageDirectory();
@@ -499,7 +512,9 @@ public class DroidFish extends Activity implements GUIInterface {
status = (TextView)findViewById(R.id.status);
moveListScroll = (ScrollView)findViewById(R.id.scrollView);
moveList = (TextView)findViewById(R.id.moveList);
defaultMoveListTypeFace = moveList.getTypeface();
thinking = (TextView)findViewById(R.id.thinking);
defaultThinkingListTypeFace = thinking.getTypeface();
status.setFocusable(false);
moveListScroll.setFocusable(false);
moveList.setFocusable(false);
@@ -770,6 +785,7 @@ public class DroidFish extends Activity implements GUIInterface {
setWakeLock(useWakeLock);
int fontSize = getIntSetting("fontSize", 12);
// figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf");
status.setTextSize(fontSize);
moveList.setTextSize(fontSize);
thinking.setTextSize(fontSize);
@@ -825,7 +841,28 @@ public class DroidFish extends Activity implements GUIInterface {
cb.setColors();
gameTextListener.clear();
setPieceNames(pgnOptions.view.pieceType);
ctrl.prefsChanged(oldViewPieceType != pgnOptions.view.pieceType);
// update the typeset in case of a change anyway, cause it could occur
// as well in rotation
setFigurineNotation(pgnOptions.view.pieceType == PGNOptions.PT_FIGURINE, fontSize);
}
/**
* Change the Pieces into figurine or regular (i.e. letters) display
*/
private void setFigurineNotation(boolean displayAsFigures, int fontSize) {
/* if (displayAsFigures) {
// increase the font cause it has different kerning and looks small
float increaseFontSize = fontSize * 1.1f;
moveList.setTypeface(figNotation);
moveList.setTextSize(increaseFontSize);
thinking.setTypeface(figNotation);
thinking.setTextSize(increaseFontSize);
} else { */
moveList.setTypeface(defaultMoveListTypeFace);
thinking.setTypeface(defaultThinkingListTypeFace);
// }
}
private void updateButtons() {

View File

@@ -20,8 +20,13 @@ package org.petero.droidfish;
/** Settings controlling PGN import/export */
public class PGNOptions {
public static final int PT_ENGLISH = 0; // Piece type english letters
public static final int PT_LOCAL = 1; // Piece type local language letters
/** Pieces displayed as english letters. */
public static final int PT_ENGLISH = 0;
/** Pieces displayed as local language letters. */
public static final int PT_LOCAL = 1;
/** Piece displayed in figurine notation, by using the english piece-names
* and a special font. */
public static final int PT_FIGURINE = 2;
public static class Viewer {
public boolean variations;

View File

@@ -587,7 +587,14 @@ public class DroidChessController {
/** Return true if localized piece names should be used. */
private final boolean localPt() {
return pgnOptions.view.pieceType == PGNOptions.PT_LOCAL;
switch (pgnOptions.view.pieceType) {
case PGNOptions.PT_ENGLISH:
return false;
case PGNOptions.PT_LOCAL:
case PGNOptions.PT_FIGURINE:
default:
return true;
}
}
/** Engine search information receiver. */

View File

@@ -1188,12 +1188,12 @@ public class GameTree {
}
}
String str;
if (options.exp.pieceType == PGNOptions.PT_LOCAL) {
str = moveStrLocal;
} else {
if (options.exp.pieceType == PGNOptions.PT_ENGLISH) {
str = moveStr;
if (options.exp.pgnPromotions && (move != null) && (move.promoteTo != Piece.EMPTY))
str = TextIO.pgnPromotion(str);
} else {
str = moveStrLocal;
}
out.processToken(this, PgnToken.SYMBOL, str);
needMoveNr = false;