mirror of
https://github.com/peterosterlund2/droidfish.git
synced 2025-12-14 01:42:40 +01:00
DroidFish: Show material diff in edit board mode. From Leo Mayer.
This commit is contained in:
@@ -3,21 +3,65 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_gravity="center_vertical">
|
||||||
<view
|
<view
|
||||||
class="org.petero.droidfish.activities.ChessBoardEdit"
|
|
||||||
android:id="@+id/eb_chessboard"
|
android:id="@+id/eb_chessboard"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent"/>
|
android:layout_height="fill_parent"
|
||||||
|
class="org.petero.droidfish.activities.ChessBoardEdit"/>
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="fill_parent">
|
android:layout_height="fill_parent"
|
||||||
<include
|
android:orientation="vertical"
|
||||||
|
android:paddingLeft="2dp" >
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/first_title_line"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
layout="@layout/title">
|
android:layout_gravity="center_vertical"
|
||||||
</include>
|
android:background="@android:drawable/title_bar"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:tag="title" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/white_clock"
|
||||||
|
style="?android:attr/windowTitleStyle"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
android:gravity="left"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:scrollHorizontally="false"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:tag="title" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title_text"
|
||||||
|
style="?android:attr/windowTitleStyle"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:tag="title"
|
||||||
|
android:text="@string/app_name" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/black_clock"
|
||||||
|
style="?android:attr/windowTitleStyle"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
android:gravity="right"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:scrollHorizontally="true"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:tag="title" />
|
||||||
|
</LinearLayout>
|
||||||
<TextView
|
<TextView
|
||||||
android:text=""
|
android:text=""
|
||||||
android:id="@+id/eb_status"
|
android:id="@+id/eb_status"
|
||||||
@@ -45,12 +89,69 @@
|
|||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
<Button
|
<Button
|
||||||
android:text="@string/cancel"
|
|
||||||
android:id="@+id/eb_cancel"
|
android:id="@+id/eb_cancel"
|
||||||
android:layout_width="0dip"
|
android:layout_width="0dip"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_weight="1">
|
android:layout_weight="1"
|
||||||
</Button>
|
android:text="@string/cancel" />
|
||||||
|
</LinearLayout>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/footer"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="bottom"
|
||||||
|
android:orientation="horizontal" >
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/second_title_line"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@android:drawable/title_bar"
|
||||||
|
android:gravity="bottom"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:tag="title" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/white_pieces"
|
||||||
|
style="?android:attr/windowTitleStyle"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
android:gravity="left|center_vertical"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:tag="title"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title_text_summary"
|
||||||
|
style="?android:attr/windowTitleStyle"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center|center_vertical"
|
||||||
|
android:tag="title"
|
||||||
|
android:visibility="visible" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/black_pieces"
|
||||||
|
style="?android:attr/windowTitleStyle"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ellipsize="marquee"
|
||||||
|
android:focusable="true"
|
||||||
|
android:focusableInTouchMode="true"
|
||||||
|
android:gravity="left|center_vertical"
|
||||||
|
android:marqueeRepeatLimit="marquee_forever"
|
||||||
|
android:scrollHorizontally="true"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:tag="title"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
android:orientation="vertical" >
|
android:orientation="vertical" >
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/first_title_line"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public final class Util {
|
|||||||
public static MaterialDiff getMaterialDiff(Position pos) {
|
public static MaterialDiff getMaterialDiff(Position pos) {
|
||||||
StringBuilder whiteString = new StringBuilder();
|
StringBuilder whiteString = new StringBuilder();
|
||||||
StringBuilder blackString = new StringBuilder();
|
StringBuilder blackString = new StringBuilder();
|
||||||
for (int p = Piece.WPAWN; p >= Piece.WQUEEN; p--) {
|
for (int p = Piece.WPAWN; p >= Piece.WKING; p--) {
|
||||||
int diff = pos.nPieces(p) - pos.nPieces(Piece.swapColor(p));
|
int diff = pos.nPieces(p) - pos.nPieces(Piece.swapColor(p));
|
||||||
while (diff < 0) {
|
while (diff < 0) {
|
||||||
whiteString.append(Piece.toUniCode(Piece.swapColor(p)));
|
whiteString.append(Piece.toUniCode(Piece.swapColor(p)));
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import org.petero.droidfish.ChessBoard;
|
|||||||
import org.petero.droidfish.R;
|
import org.petero.droidfish.R;
|
||||||
import org.petero.droidfish.ChessBoard.SquareDecoration;
|
import org.petero.droidfish.ChessBoard.SquareDecoration;
|
||||||
import org.petero.droidfish.Util;
|
import org.petero.droidfish.Util;
|
||||||
|
import org.petero.droidfish.Util.MaterialDiff;
|
||||||
import org.petero.droidfish.gamelogic.ChessParseError;
|
import org.petero.droidfish.gamelogic.ChessParseError;
|
||||||
import org.petero.droidfish.gamelogic.Move;
|
import org.petero.droidfish.gamelogic.Move;
|
||||||
import org.petero.droidfish.gamelogic.Pair;
|
import org.petero.droidfish.gamelogic.Pair;
|
||||||
@@ -39,6 +40,7 @@ import android.content.DialogInterface;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Typeface;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
@@ -63,15 +65,20 @@ public class EditBoard extends Activity {
|
|||||||
private Button okButton;
|
private Button okButton;
|
||||||
private Button cancelButton;
|
private Button cancelButton;
|
||||||
private TextView whiteTitleText, blackTitleText, engineTitleText;
|
private TextView whiteTitleText, blackTitleText, engineTitleText;
|
||||||
private View secondTitleLine;
|
|
||||||
|
|
||||||
boolean egtbHints;
|
boolean egtbHints;
|
||||||
|
private TextView whiteFigText;
|
||||||
|
private TextView blackFigText;
|
||||||
|
private TextView summaryTitleText;
|
||||||
|
private Typeface figNotation;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
||||||
|
|
||||||
|
figNotation = Typeface.createFromAsset(getAssets(), "fonts/DroidFishChessNotationDark.otf");
|
||||||
|
|
||||||
initUI();
|
initUI();
|
||||||
|
|
||||||
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
@@ -84,6 +91,7 @@ public class EditBoard extends Activity {
|
|||||||
try {
|
try {
|
||||||
pos = TextIO.readFEN(i.getAction());
|
pos = TextIO.readFEN(i.getAction());
|
||||||
cb.setPosition(pos);
|
cb.setPosition(pos);
|
||||||
|
checkValidAndUpdateMaterialDiff();
|
||||||
} catch (ChessParseError e) {
|
} catch (ChessParseError e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,6 +109,7 @@ public class EditBoard extends Activity {
|
|||||||
setSelection(oldCB.selectedSquare);
|
setSelection(oldCB.selectedSquare);
|
||||||
cb.userSelectedSquare = oldCB.userSelectedSquare;
|
cb.userSelectedSquare = oldCB.userSelectedSquare;
|
||||||
status.setText(statusStr);
|
status.setText(statusStr);
|
||||||
|
checkValidAndUpdateMaterialDiff();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void initUI() {
|
private final void initUI() {
|
||||||
@@ -116,8 +125,16 @@ public class EditBoard extends Activity {
|
|||||||
blackTitleText.setVisibility(View.GONE);
|
blackTitleText.setVisibility(View.GONE);
|
||||||
engineTitleText = (TextView)findViewById(R.id.title_text);
|
engineTitleText = (TextView)findViewById(R.id.title_text);
|
||||||
engineTitleText.setVisibility(View.GONE);
|
engineTitleText.setVisibility(View.GONE);
|
||||||
secondTitleLine = findViewById(R.id.second_title_line);
|
whiteFigText = (TextView) findViewById(R.id.white_pieces);
|
||||||
secondTitleLine.setVisibility(View.GONE);
|
whiteFigText.setTypeface(figNotation);
|
||||||
|
whiteFigText.setSelected(true);
|
||||||
|
whiteFigText.setTextColor(whiteTitleText.getTextColors());
|
||||||
|
blackFigText = (TextView) findViewById(R.id.black_pieces);
|
||||||
|
blackFigText.setTypeface(figNotation);
|
||||||
|
blackFigText.setSelected(true);
|
||||||
|
blackFigText.setTextColor(blackTitleText.getTextColors());
|
||||||
|
summaryTitleText = (TextView) findViewById(R.id.title_text_summary);
|
||||||
|
summaryTitleText.setVisibility(View.GONE);
|
||||||
|
|
||||||
okButton.setOnClickListener(new OnClickListener() {
|
okButton.setOnClickListener(new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
@@ -243,7 +260,7 @@ public class EditBoard extends Activity {
|
|||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
else
|
else
|
||||||
setSelection(m.from);
|
setSelection(m.from);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -256,7 +273,7 @@ public class EditBoard extends Activity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final void sendBackResult() {
|
private final void sendBackResult() {
|
||||||
if (checkValid()) {
|
if (checkValidAndUpdateMaterialDiff()) {
|
||||||
setPosFields();
|
setPosFields();
|
||||||
String fen = TextIO.toFEN(cb.pos);
|
String fen = TextIO.toFEN(cb.pos);
|
||||||
setResult(RESULT_OK, (new Intent()).setAction(fen));
|
setResult(RESULT_OK, (new Intent()).setAction(fen));
|
||||||
@@ -287,9 +304,13 @@ public class EditBoard extends Activity {
|
|||||||
cb.pos.setEpSquare(epSquare);
|
cb.pos.setEpSquare(epSquare);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Test if a position is valid. */
|
/** Test if a position is valid and update material diff display. */
|
||||||
private final boolean checkValid() {
|
private final boolean checkValidAndUpdateMaterialDiff() {
|
||||||
try {
|
try {
|
||||||
|
MaterialDiff md = Util.getMaterialDiff(cb.pos);
|
||||||
|
whiteFigText.setText(md.white);
|
||||||
|
blackFigText.setText(md.black);
|
||||||
|
|
||||||
String fen = TextIO.toFEN(cb.pos);
|
String fen = TextIO.toFEN(cb.pos);
|
||||||
TextIO.readFEN(fen);
|
TextIO.readFEN(fen);
|
||||||
status.setText("");
|
status.setText("");
|
||||||
@@ -332,13 +353,13 @@ public class EditBoard extends Activity {
|
|||||||
case 0: // Edit side to move
|
case 0: // Edit side to move
|
||||||
showDialog(SIDE_DIALOG);
|
showDialog(SIDE_DIALOG);
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
break;
|
break;
|
||||||
case 1: { // Clear board
|
case 1: { // Clear board
|
||||||
Position pos = new Position();
|
Position pos = new Position();
|
||||||
cb.setPosition(pos);
|
cb.setPosition(pos);
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: { // Set initial position
|
case 2: { // Set initial position
|
||||||
@@ -346,7 +367,7 @@ public class EditBoard extends Activity {
|
|||||||
Position pos = TextIO.readFEN(TextIO.startPosFEN);
|
Position pos = TextIO.readFEN(TextIO.startPosFEN);
|
||||||
cb.setPosition(pos);
|
cb.setPosition(pos);
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
} catch (ChessParseError e) {
|
} catch (ChessParseError e) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -355,19 +376,19 @@ public class EditBoard extends Activity {
|
|||||||
removeDialog(CASTLE_DIALOG);
|
removeDialog(CASTLE_DIALOG);
|
||||||
showDialog(CASTLE_DIALOG);
|
showDialog(CASTLE_DIALOG);
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
break;
|
break;
|
||||||
case 4: // Edit en passant file
|
case 4: // Edit en passant file
|
||||||
removeDialog(EP_DIALOG);
|
removeDialog(EP_DIALOG);
|
||||||
showDialog(EP_DIALOG);
|
showDialog(EP_DIALOG);
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
break;
|
break;
|
||||||
case 5: // Edit move counters
|
case 5: // Edit move counters
|
||||||
removeDialog(MOVCNT_DIALOG);
|
removeDialog(MOVCNT_DIALOG);
|
||||||
showDialog(MOVCNT_DIALOG);
|
showDialog(MOVCNT_DIALOG);
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
break;
|
break;
|
||||||
case 6: { // Copy position
|
case 6: { // Copy position
|
||||||
setPosFields();
|
setPosFields();
|
||||||
@@ -390,7 +411,7 @@ public class EditBoard extends Activity {
|
|||||||
Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
|
Toast.makeText(getApplicationContext(), getParseErrString(e), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
setSelection(-1);
|
setSelection(-1);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -408,11 +429,11 @@ public class EditBoard extends Activity {
|
|||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
if (id == 0) { // white to move
|
if (id == 0) { // white to move
|
||||||
cb.pos.setWhiteMove(true);
|
cb.pos.setWhiteMove(true);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
} else {
|
} else {
|
||||||
cb.pos.setWhiteMove(false);
|
cb.pos.setWhiteMove(false);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
dialog.cancel();
|
dialog.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -452,7 +473,7 @@ public class EditBoard extends Activity {
|
|||||||
if (h8Castle) castleMask |= 1 << Position.H8_CASTLE;
|
if (h8Castle) castleMask |= 1 << Position.H8_CASTLE;
|
||||||
pos.setCastleMask(castleMask);
|
pos.setCastleMask(castleMask);
|
||||||
cb.setPosition(pos);
|
cb.setPosition(pos);
|
||||||
checkValid();
|
checkValidAndUpdateMaterialDiff();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AlertDialog alert = builder.create();
|
AlertDialog alert = builder.create();
|
||||||
|
|||||||
Reference in New Issue
Block a user