mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-02-26 22:33:53 +01:00
DroidFish: When "quick move input" is enabled and the user taps on a piece that has no valid moves, display a toast that explains that the piece can not be moved. Idea from Leo Mayer.
This commit is contained in:
parent
b66acc006f
commit
21fa9d1522
|
@ -146,6 +146,7 @@ you are not actively using the program.\
|
|||
<string name="resign_black">Game over, black resigns!</string>
|
||||
<string name="book">Book:</string>
|
||||
<string name="invalid_move">Invalid move</string>
|
||||
<string name="piece_can_not_be_moved">Piece can not be moved</string>
|
||||
<string name="preferences">Preferences</string>
|
||||
<string name="load_game_title">Edit File / Load Game</string>
|
||||
<string name="save_game_title">Edit File / Save Game</string>
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.petero.droidfish.gamelogic.MoveGen;
|
|||
import org.petero.droidfish.gamelogic.Pair;
|
||||
import org.petero.droidfish.gamelogic.Piece;
|
||||
import org.petero.droidfish.gamelogic.Position;
|
||||
import org.petero.droidfish.gamelogic.TextIO;
|
||||
import org.petero.droidfish.gamelogic.UndoInfo;
|
||||
|
||||
import android.content.Context;
|
||||
|
@ -40,8 +41,10 @@ import android.os.Handler;
|
|||
import android.util.AttributeSet;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class ChessBoard extends View {
|
||||
private PGNOptions pgnOptions = null;
|
||||
public Position pos;
|
||||
|
||||
public int selectedSquare;
|
||||
|
@ -87,6 +90,10 @@ public class ChessBoard extends View {
|
|||
private Paint decorationPaint;
|
||||
private ArrayList<Paint> moveMarkPaint;
|
||||
|
||||
public void setPgnOptions(PGNOptions pgnOptions) {
|
||||
this.pgnOptions = pgnOptions;
|
||||
}
|
||||
|
||||
public ChessBoard(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
pos = new Position();
|
||||
|
@ -635,6 +642,16 @@ public class ChessBoard extends View {
|
|||
userSelectedSquare = false;
|
||||
return matchingMove;
|
||||
}
|
||||
if (!anyMatch && (sq >= 0)) {
|
||||
int p = pos.getPiece(sq);
|
||||
if (myColor(p)) {
|
||||
String msg = getContext().getString(R.string.piece_can_not_be_moved);
|
||||
boolean localized = (pgnOptions != null) &&
|
||||
(pgnOptions.view.pieceType != PGNOptions.PT_ENGLISH);
|
||||
msg += ": " + TextIO.pieceAndSquareToString(localized, p, sq);
|
||||
Toast.makeText(getContext(), msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
setSelection(anyMatch ? sq : -1);
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -525,6 +525,7 @@ public class DroidFish extends Activity implements GUIInterface {
|
|||
cb.setFocusable(true);
|
||||
cb.requestFocus();
|
||||
cb.setClickable(true);
|
||||
cb.setPgnOptions(pgnOptions);
|
||||
|
||||
final GestureDetector gd = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
|
||||
private float scrollX = 0;
|
||||
|
|
|
@ -728,6 +728,17 @@ public class TextIO {
|
|||
return ret.toString();
|
||||
}
|
||||
|
||||
/** Convert a piece and a square to a string, such as Nf3. */
|
||||
public final static String pieceAndSquareToString(boolean localized, int p, int sq) {
|
||||
String ret;
|
||||
if ((p == Piece.WPAWN) || (p == Piece.BPAWN))
|
||||
ret = localized ? pieceNames[0] : "P";
|
||||
else
|
||||
ret = localized ? pieceToCharLocalized(p) : pieceToChar(p);
|
||||
ret += squareToString(sq);
|
||||
return ret;
|
||||
}
|
||||
|
||||
private final static String pieceToChar(int p) {
|
||||
switch (p) {
|
||||
case Piece.WQUEEN: case Piece.BQUEEN: return "Q";
|
||||
|
|
Loading…
Reference in New Issue
Block a user