complete getUsername() impl to call into prefs for user choice

This commit is contained in:
Eric House 2022-10-14 10:37:06 -07:00
parent 848ae6f0f6
commit 41d9d4a254
2 changed files with 6 additions and 11 deletions

View file

@ -246,12 +246,12 @@ public class DUtilCtxt {
// PENDING use prefs for this
public String getUsername( int posn, boolean isLocal, boolean isRobot )
{
Log.d( TAG, "getUsername(posn=%d; isLocal=%b, isRobot=%b)",
posn, isLocal, isRobot );
String fmt = isLocal ? "Lcl" : "Rmt";
fmt += isRobot ? "Rbt" : "Hum";
fmt += " %d";
return String.format( fmt, posn + 1 );
String result = isRobot
? CommonPrefs.getDefaultRobotName( m_context )
: CommonPrefs.getDefaultPlayerName( m_context, posn );
Log.d( TAG, "getUsername(posn=%d; isLocal=%b, isRobot=%b) => %s",
posn, isLocal, isRobot, result );
return result;
}
// A pause can come in when a game's open or when it's not. If it's open,

View file

@ -857,7 +857,6 @@ and_dutil_getUsername( XW_DUtilCtxt* duc, XWEnv xwe, XP_U16 num,
XP_Bool isLocal, XP_Bool isRobot,
XP_UCHAR* buf, XP_U16* lenp )
{
LOG_FUNC();
DUTIL_CBK_HEADER( "getUsername", "(IZZ)Ljava/lang/String;" );
jstring jresult = (*env)->CallObjectMethod( env, dutil->jdutil, mid,
@ -865,15 +864,11 @@ and_dutil_getUsername( XW_DUtilCtxt* duc, XWEnv xwe, XP_U16 num,
jsize len = (*env)->GetStringUTFLength( env, jresult );
if ( len < *lenp ) {
const char* jchars = (*env)->GetStringUTFChars( env, jresult, NULL );
XP_LOGFF( "len(\"%s\"): %d", jchars, len );
*lenp = XP_SNPRINTF( buf, len+1, "%s", jchars );
XP_LOGFF( "snprintf wrote: '%s'", buf );
// *lenp = len;
(*env)->ReleaseStringUTFChars( env, jresult, jchars );
deleteLocalRef( env, jresult );
}
DUTIL_CBK_TAIL();
LOG_RETURNF( "%s", buf );
}
static void