mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-18 22:26:30 +01:00
handle final scores menuitem: add server_endGame to jni and new
dialog/mechanism to call back and forth between threads to query and end game on positive response.
This commit is contained in:
parent
142492ad85
commit
cf9c952fc2
5 changed files with 58 additions and 1 deletions
|
@ -910,3 +910,14 @@ Java_org_eehouse_android_xw4_jni_XwJNI_comms_1resendAll
|
||||||
(void)comms_resendAll( state->game.comms );
|
(void)comms_resendAll( state->game.comms );
|
||||||
XWJNI_END();
|
XWJNI_END();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
Java_org_eehouse_android_xw4_jni_XwJNI_server_1endGame
|
||||||
|
( JNIEnv* env, jclass C, jint gamePtr )
|
||||||
|
{
|
||||||
|
XWJNI_START();
|
||||||
|
XP_ASSERT( !!state->game.server );
|
||||||
|
server_endGame( state->game.server );
|
||||||
|
XWJNI_END();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -227,6 +227,9 @@
|
||||||
<string name="badwords_lost"> Turn lost.</string>
|
<string name="badwords_lost"> Turn lost.</string>
|
||||||
<string name="badwords_title">Illegal word[s]</string>
|
<string name="badwords_title">Illegal word[s]</string>
|
||||||
|
|
||||||
|
<string name="ids_endnow">Are you sure you want to end the game now?</string>
|
||||||
|
|
||||||
|
|
||||||
<!-- These do not require localization -->
|
<!-- These do not require localization -->
|
||||||
<string name="key_color_tiles">key_color_tiles</string>
|
<string name="key_color_tiles">key_color_tiles</string>
|
||||||
<string name="key_show_arrow">key_show_arrow</string>
|
<string name="key_show_arrow">key_show_arrow</string>
|
||||||
|
|
|
@ -36,6 +36,7 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
private static final int DLG_BADWORDS = 2;
|
private static final int DLG_BADWORDS = 2;
|
||||||
private static final int QUERY_REQUEST_BLK = 3;
|
private static final int QUERY_REQUEST_BLK = 3;
|
||||||
private static final int PICK_TILE_REQUEST_BLK = 4;
|
private static final int PICK_TILE_REQUEST_BLK = 4;
|
||||||
|
private static final int QUERY_ENDGAME = 5;
|
||||||
|
|
||||||
private BoardView m_view;
|
private BoardView m_view;
|
||||||
private int m_jniGamePtr;
|
private int m_jniGamePtr;
|
||||||
|
@ -136,6 +137,26 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
dialog = ab.create();
|
dialog = ab.create();
|
||||||
dialog.setOnDismissListener( makeODL() );
|
dialog.setOnDismissListener( makeODL() );
|
||||||
break;
|
break;
|
||||||
|
case QUERY_ENDGAME:
|
||||||
|
dialog = new AlertDialog.Builder( this )
|
||||||
|
.setTitle( R.string.query_title )
|
||||||
|
.setMessage( R.string.ids_endnow )
|
||||||
|
.setPositiveButton( R.string.button_yes,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick( DialogInterface dlg,
|
||||||
|
int item ) {
|
||||||
|
m_jniThread.handle(JNICmd.CMD_ENDGAME);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setNegativeButton( R.string.button_no,
|
||||||
|
new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick( DialogInterface dlg,
|
||||||
|
int item ) {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return dialog;
|
return dialog;
|
||||||
} // onCreateDialog
|
} // onCreateDialog
|
||||||
|
@ -231,6 +252,9 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
m_dlgTitle = msg.arg1;
|
m_dlgTitle = msg.arg1;
|
||||||
showDialog( DLG_OKONLY );
|
showDialog( DLG_OKONLY );
|
||||||
break;
|
break;
|
||||||
|
case JNIThread.QUERY_ENDGAME:
|
||||||
|
showDialog( QUERY_ENDGAME );
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
@ -343,7 +367,8 @@ public class BoardActivity extends Activity implements UtilCtxt {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.board_menu_game_final:
|
case R.id.board_menu_game_final:
|
||||||
Utils.notImpl(this);
|
m_jniThread.handle( JNIThread.JNICmd.CMD_FINAL,
|
||||||
|
R.string.history_title );
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case R.id.board_menu_game_resend:
|
case R.id.board_menu_game_resend:
|
||||||
|
|
|
@ -41,12 +41,15 @@ public class JNIThread extends Thread {
|
||||||
CMD_REMAINING,
|
CMD_REMAINING,
|
||||||
CMD_RESEND,
|
CMD_RESEND,
|
||||||
CMD_HISTORY,
|
CMD_HISTORY,
|
||||||
|
CMD_FINAL,
|
||||||
|
CMD_ENDGAME,
|
||||||
CMD_POST_OVER,
|
CMD_POST_OVER,
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final int RUNNING = 1;
|
public static final int RUNNING = 1;
|
||||||
public static final int DRAW = 2;
|
public static final int DRAW = 2;
|
||||||
public static final int DIALOG = 3;
|
public static final int DIALOG = 3;
|
||||||
|
public static final int QUERY_ENDGAME = 4;
|
||||||
|
|
||||||
private boolean m_stopped = false;
|
private boolean m_stopped = false;
|
||||||
private int m_jniGamePtr;
|
private int m_jniGamePtr;
|
||||||
|
@ -303,6 +306,20 @@ public class JNIThread extends Thread {
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case CMD_FINAL:
|
||||||
|
if ( XwJNI.server_getGameIsOver( m_jniGamePtr ) ) {
|
||||||
|
String msg = XwJNI.server_writeFinalScores( m_jniGamePtr );
|
||||||
|
sendForDialog( R.string.query_title, msg );
|
||||||
|
} else {
|
||||||
|
Message.obtain( m_handler, QUERY_ENDGAME ).sendToTarget();
|
||||||
|
draw = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CMD_ENDGAME:
|
||||||
|
XwJNI.server_endGame( m_jniGamePtr );
|
||||||
|
break;
|
||||||
|
|
||||||
case CMD_POST_OVER:
|
case CMD_POST_OVER:
|
||||||
sendForDialog( ((Integer)args[0]).intValue(),
|
sendForDialog( ((Integer)args[0]).intValue(),
|
||||||
XwJNI.server_writeFinalScores( m_jniGamePtr ) );
|
XwJNI.server_writeFinalScores( m_jniGamePtr ) );
|
||||||
|
|
|
@ -123,6 +123,7 @@ public class XwJNI {
|
||||||
public static native boolean server_getGameIsOver( int gamePtr );
|
public static native boolean server_getGameIsOver( int gamePtr );
|
||||||
public static native String server_writeFinalScores( int gamePtr );
|
public static native String server_writeFinalScores( int gamePtr );
|
||||||
public static native void server_initClientConnection( int gamePtr );
|
public static native void server_initClientConnection( int gamePtr );
|
||||||
|
public static native void server_endGame( int gamePtr );
|
||||||
|
|
||||||
// Comms
|
// Comms
|
||||||
public static native void comms_start( int gamePtr );
|
public static native void comms_start( int gamePtr );
|
||||||
|
|
Loading…
Reference in a new issue