show invitee name where possible

When I've invited a Known Player, use that player's name in parens in
scoreboard and games list elem/summary until a remote device connects
(usually in response to an invitation) and provides an actual player
name. Makes it much easier to tell one pending game from another. And
doesn't really work (yet) where there's more than one remote player in
a game.
This commit is contained in:
Eric House 2021-05-30 13:31:33 -07:00
parent 6352958066
commit e667291da5
12 changed files with 102 additions and 9 deletions

View file

@ -1770,6 +1770,12 @@ public class BoardDelegate extends DelegateBase
} );
}
public String getInviteeName( int plyrNum )
{
return null == m_summary ? null
: m_summary.summarizePlayer( m_activity, m_rowid, plyrNum );
}
@Override
public void playerScoreHeld( int player )
{

View file

@ -633,6 +633,23 @@ public class DBUtils {
return result;
}
public String getKPName( Context context )
{
String result = null;
for ( int ii = 0; ii < m_means.size(); ++ii ) {
InviteMeans means = m_means.get(ii);
if ( means == InviteMeans.MQTT ) {
String player = XwJNI.kplr_nameForMqttDev( m_targets.get(ii) );
if ( null != player ) {
result = player;
break; // ordered newest-first, so we're done
}
}
}
return result;
}
void setRemotesRobots() { m_remotesRobots = true; }
boolean getRemotesRobots() { return m_remotesRobots; }
}

View file

@ -318,7 +318,7 @@ public class GameListItem extends LinearLayout
ExpiringLinearLayout tmp = (ExpiringLinearLayout)
LocUtils.inflate( m_context, R.layout.player_list_elem );
TextView tview = (TextView)tmp.findViewById( R.id.item_name );
tview.setText( summary.summarizePlayer( m_context, ii ) );
tview.setText( summary.summarizePlayer( m_context, m_rowid, ii ) );
tview = (TextView)tmp.findViewById( R.id.item_score );
tview.setText( String.format( "%d", summary.scores[ii] ) );
boolean thisHasTurn = summary.isNextToPlay( ii, isLocal );

View file

@ -398,14 +398,23 @@ public class GameSummary implements Serializable {
m_giFlags = new Integer( flags );
}
public String summarizePlayer( Context context, int indx )
public String summarizePlayer( Context context, long rowid, int indx )
{
String player = m_players[indx];
int formatID = 0;
if ( !isLocal(indx) ) {
boolean isMissing = 0 != ((1 << indx) & missingPlayers);
if ( isMissing ) {
player = LocUtils.getString( context, R.string.missing_player );
DBUtils.SentInvitesInfo si = DBUtils.getInvitesFor( context, rowid );
String kp = null;
if ( null != si ) {
kp = si.getKPName( context );
}
if ( null == kp ) {
player = LocUtils.getString( context, R.string.missing_player );
} else {
player = LocUtils.getString( context, R.string.invitee_fmt, kp );
}
} else {
formatID = R.string.str_nonlocal_name_fmt;
}

View file

@ -62,6 +62,7 @@ public interface UtilCtxt {
void remSelected();
void timerSelected( boolean inDuplicateMode, boolean canPause );
void informWordsBlocked( int nWords, String words, String dict );
String getInviteeName( int index );
void bonusSquareHeld( int bonus );
void playerScoreHeld( int player );

View file

@ -108,6 +108,13 @@ public class UtilCtxtImpl implements UtilCtxt {
subclassOverride( "informWordsBlocked" );
}
@Override
public String getInviteeName( int plyrNum )
{
subclassOverride( "getInviteeName" );
return null;
}
@Override
public void bonusSquareHeld( int bonus )
{

View file

@ -23,10 +23,16 @@
<!-- Used to format robot player names in the lists of players
found in each game listing -->
<string name="robot_name_fmt">%1$s (robot)</string>
<!-- When a "Known" player's been invited but hasn't yet
connected, display it's name here so user knows who to
expect. Displayed in the lists of players found in each game
listing.-->
<string name="invitee_fmt">(%1$s invited)</string>
<!-- Used as a substitute for the names of remote players when
they aren't available yet because the connection is not
complete. Displayed in the lists of players found in each
game listing. -->
complete (and when invitee_fmt above can't be used.)
Displayed in the lists of players found in each game
listing. -->
<string name="missing_player">(not here yet…)</string>
<!-- The display of each networked game includes one of three
states it can be in in the process of connecting to the

View file

@ -742,6 +742,27 @@ and_util_informWordsBlocked( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 nBadWords,
UTIL_CBK_TAIL();
}
static void
and_util_getInviteeName( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 plyrNum,
XP_UCHAR* buf, XP_U16* bufLen )
{
UTIL_CBK_HEADER( "getInviteeName", "(I)Ljava/lang/String;" );
jstring jresult = (*env)->CallObjectMethod( env, util->jutil, mid, plyrNum );
if ( NULL != jresult ) {
jsize len = (*env)->GetStringUTFLength( env, jresult );
if ( len < *bufLen ) {
const char* jchars = (*env)->GetStringUTFChars( env, jresult, NULL );
XP_STRCAT( buf, jchars );
(*env)->ReleaseStringUTFChars( env, jresult, jchars );
*bufLen = len;
} else {
*bufLen = 0;
}
deleteLocalRef( env, jresult );
}
UTIL_CBK_TAIL();
}
#ifdef XWFEATURE_DEVID
static const XP_UCHAR*
and_dutil_getDevID( XW_DUtilCtxt* duc, XWEnv xwe, DevIDType* typ )
@ -771,7 +792,7 @@ and_dutil_getDevID( XW_DUtilCtxt* duc, XWEnv xwe, DevIDType* typ )
*typ = (DevIDType)elems[0];
(*env)->ReleaseByteArrayElements( env, jbarr, elems, 0 );
}
deleteLocalRef( env, jbarr );
deleteLocalRefs( env, jbarr, jresult, DELETE_NO_REF );
DUTIL_CBK_TAIL();
return result;
}
@ -1023,6 +1044,7 @@ makeUtil( MPFORMAL JNIEnv* env,
SET_PROC(getDevUtilCtxt);
SET_PROC(informWordsBlocked);
SET_PROC(getInviteeName);
#undef SET_PROC
assertTableFull( vtable, sizeof(*vtable), "util" );

View file

@ -50,7 +50,7 @@ typedef enum {
typedef struct _DrawScoreInfo {
LastScoreCallback lsc;
void* lscClosure;
const XP_UCHAR* name;
XP_UCHAR name[64];
XP_U16 playerNum;
XP_S16 totalScore;
XP_S16 nTilesLeft; /* < 0 means don't use */

View file

@ -267,9 +267,16 @@ drawScoreBoard( BoardCtxt* board, XWEnv xwe )
dp->dsi.isRemote = !lp->isLocal;
XP_ASSERT( !isMissing || dp->dsi.isRemote );
if ( dp->dsi.isRemote && isMissing ) {
dp->dsi.name = dutil_getUserString( board->dutil, xwe, STR_PENDING_PLAYER );
XP_U16 len = VSIZE(dp->dsi.name);
util_getInviteeName( board->util, xwe, ii, dp->dsi.name, &len );
if ( !dp->dsi.name[0] || len == 0 ) {
const XP_UCHAR* tmp = dutil_getUserString( board->dutil, xwe,
STR_PENDING_PLAYER );
XP_STRCAT( dp->dsi.name, tmp );
}
} else {
dp->dsi.name = emptyStringIfNull( lp->name );
const XP_UCHAR* tmp = emptyStringIfNull( lp->name );
XP_STRCAT( dp->dsi.name, tmp );
}
dp->dsi.nTilesLeft = (nTilesInPool > 0)? -1:
model_getNumTilesTotal( model, ii );

View file

@ -179,6 +179,9 @@ typedef struct UtilVtable {
void (*m_util_informWordsBlocked)( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 nBadWords,
XWStreamCtxt* words, const XP_UCHAR* dictName );
void (*m_util_getInviteeName)( XW_UtilCtxt* uc, XWEnv xwe, XP_U16 plyrNum,
XP_UCHAR* buf, XP_U16* bufLen );
#ifdef XWFEATURE_SEARCHLIMIT
XP_Bool (*m_util_getTraySearchLimits)(XW_UtilCtxt* uc, XWEnv xwe,
XP_U16* min, XP_U16* max );
@ -317,6 +320,8 @@ struct XW_UtilCtxt {
#define util_informWordsBlocked(uc,e, c, w, d) \
(uc)->vtable->m_util_informWordsBlocked( (uc), (e), (c), (w), (d) )
#define util_getInviteeName(uc, xwe, plyrNum, buf, len ) \
(uc)->vtable->m_util_getInviteeName( (uc), (xwe), (plyrNum), (buf), (len) )
#ifdef XWFEATURE_SEARCHLIMIT
#define util_getTraySearchLimits(uc,e,min,max) \

View file

@ -288,6 +288,18 @@ linux_util_getDict( XW_UtilCtxt* uc, XWEnv xwe,
return result;
}
static void
linux_util_getInviteeName( XW_UtilCtxt* XP_UNUSED(uc), XWEnv XP_UNUSED(xwe),
XP_U16 index, XP_UCHAR* buf, XP_U16* bufLen )
{
int len = XP_SNPRINTF( buf, *bufLen-1, "(%d invited)", index );
if ( len < *bufLen ) {
*bufLen = len + 1;
} else {
*bufLen = 0;
}
}
static XW_DUtilCtxt*
linux_util_getDevUtilCtxt( XW_UtilCtxt* uc, XWEnv XP_UNUSED(xwe) )
{
@ -306,6 +318,7 @@ linux_util_vt_init( MPFORMAL XW_UtilCtxt* util )
util->vtable->m_util_makeEmptyDict = linux_util_makeEmptyDict;
util->vtable->m_util_getSquareBonus = linux_util_getSquareBonus;
util->vtable->m_util_getDict = linux_util_getDict;
util->vtable->m_util_getInviteeName = linux_util_getInviteeName;
util->vtable->m_util_getDevUtilCtxt = linux_util_getDevUtilCtxt;
}