From bd70a1dd7d551614b4761cc9814ffb73638c92bf Mon Sep 17 00:00:00 2001 From: Eric House Date: Mon, 9 Jul 2012 21:44:29 -0700 Subject: [PATCH] improve text in remaining tiles dialog, and always show the tiles for all trays rather than excluding those in current player's tray. --- .../XWords4/jni/LocalizedStrIncludes.h | 4 +- .../android/XWords4/res/values/strings.xml | 7 ++++ .../org/eehouse/android/xw4/jni/UtilCtxt.java | 3 ++ .../eehouse/android/xw4/jni/UtilCtxtImpl.java | 7 ++++ xwords4/common/server.c | 42 ++++++++++++++----- xwords4/linux/LocalizedStrIncludes.h | 2 + xwords4/linux/linuxutl.c | 5 +++ 7 files changed, 58 insertions(+), 12 deletions(-) diff --git a/xwords4/android/XWords4/jni/LocalizedStrIncludes.h b/xwords4/android/XWords4/jni/LocalizedStrIncludes.h index 7dd9819fd..a4f86f4b5 100644 --- a/xwords4/android/XWords4/jni/LocalizedStrIncludes.h +++ b/xwords4/android/XWords4/jni/LocalizedStrIncludes.h @@ -26,6 +26,8 @@ # define STR_COMMIT_CONFIRM 20 # define STR_BONUS_ALL 21 # define STRD_TURN_SCORE 22 +# define STRD_REMAINS_HEADER 23 +# define STRD_REMAINS_EXPL 24 -# define N_AND_USER_STRINGS 22 +# define N_AND_USER_STRINGS 24 #endif diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index ffcfb0ce6..7d1841c7e 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -769,6 +769,13 @@ one turn is substituted for %d.--> Score for turn: %d\n + + %d tiles left in pool. + + %d tiles left in pool and all + tray[s]:\n + Are you sure you want to undo the diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java index e168726d5..dfae6d311 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxt.java @@ -82,6 +82,9 @@ public interface UtilCtxt { static final int STR_COMMIT_CONFIRM = 20; static final int STR_BONUS_ALL = 21; static final int STRD_TURN_SCORE = 22; + static final int STRD_REMAINS_HEADER = 23; + static final int STRD_REMAINS_EXPL = 24; + String getUserString( int stringCode ); static final int QUERY_COMMIT_TURN = 0; diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java index 6ca2c09c2..63762ccf1 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/UtilCtxtImpl.java @@ -175,6 +175,13 @@ public class UtilCtxtImpl implements UtilCtxt { case UtilCtxt.STRD_TURN_SCORE: id = R.string.strd_turn_score; break; + case UtilCtxt.STRD_REMAINS_HEADER: + id = R.string.strd_remains_header; + break; + case UtilCtxt.STRD_REMAINS_EXPL: + id = R.string.strd_remains_expl; + break; + default: DbgUtils.logf( "no such stringCode: %d", stringCode ); } diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 551db8135..e6e3aa809 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -2788,45 +2788,65 @@ server_formatDictCounts( ServerCtxt* server, XWStreamCtxt* stream, */ void server_formatRemainingTiles( ServerCtxt* server, XWStreamCtxt* stream, - XP_S16 player ) + XP_S16 XP_UNUSED(player) ) { PoolContext* pool = server->pool; if ( !!pool ) { - DictionaryCtxt* dict; + XP_UCHAR buf[48]; + DictionaryCtxt* dict = model_getDictionary( server->vol.model ); Tile tile; - XP_U16 nChars; + XP_U16 nChars = dict_numTileFaces( dict ); + XP_U16 offset; XP_U16 counts[MAX_UNIQUE_TILES+1]; /* 1 for the blank */ + XP_U16 nLeft = pool_getNTilesLeft( pool ); + XP_UCHAR cntsBuf[512]; XP_ASSERT( !!server->vol.model ); + const XP_UCHAR* fmt = util_getUserString( server->vol.util, + STRD_REMAINS_HEADER ); + XP_SNPRINTF( buf, sizeof(buf), fmt, nLeft ); + stream_catString( stream, buf ); + stream_catString( stream, "\n\n" ); + XP_MEMSET( counts, 0, sizeof(counts) ); - model_countAllTrayTiles( server->vol.model, counts, player ); + model_countAllTrayTiles( server->vol.model, counts, -1 ); - dict = model_getDictionary( server->vol.model ); - nChars = dict_numTileFaces( dict ); - - for ( tile = 0; ; ) { + for ( cntsBuf[0] = '\0', offset = 0, tile = 0; + offset < sizeof(cntsBuf); ) { XP_U16 count = pool_getNTilesLeftFor( pool, tile ) + counts[tile]; XP_Bool hasCount = count > 0; + nLeft += counts[tile]; if ( hasCount ) { const XP_UCHAR* face = dict_getTileString( dict, tile ); for ( ; ; ) { - stream_catString( stream, face ); + offset += XP_SNPRINTF( &cntsBuf[offset], + sizeof(cntsBuf) - offset, "%s", + face ); if ( --count == 0 ) { break; } - stream_catString( stream, "." ); + offset += XP_SNPRINTF( &cntsBuf[offset], + sizeof(cntsBuf) - offset, "." ); } } if ( ++tile >= nChars ) { break; } else if ( hasCount ) { - stream_catString( stream, (void*)" " ); + offset += XP_SNPRINTF( &cntsBuf[offset], + sizeof(cntsBuf) - offset, " " ); } + XP_ASSERT( offset < sizeof(cntsBuf) ); } + + fmt = util_getUserString( server->vol.util, STRD_REMAINS_EXPL ); + XP_SNPRINTF( buf, sizeof(buf), fmt, nLeft ); + stream_catString( stream, buf ); + + stream_catString( stream, cntsBuf ); } } /* server_formatRemainingTiles */ diff --git a/xwords4/linux/LocalizedStrIncludes.h b/xwords4/linux/LocalizedStrIncludes.h index 92674c648..66637efbe 100644 --- a/xwords4/linux/LocalizedStrIncludes.h +++ b/xwords4/linux/LocalizedStrIncludes.h @@ -55,6 +55,8 @@ enum { STR_REMOTE, STRS_VALUES_HEADER, + STRD_REMAINS_HEADER, + STRD_REMAINS_EXPL, STR_LAST }; diff --git a/xwords4/linux/linuxutl.c b/xwords4/linux/linuxutl.c index 3f98accc2..1b4f9e51c 100644 --- a/xwords4/linux/linuxutl.c +++ b/xwords4/linux/linuxutl.c @@ -331,6 +331,11 @@ linux_util_getUserString( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 code ) case STRS_VALUES_HEADER: return (XP_UCHAR*)"%s counts/values:\n"; + case STRD_REMAINS_HEADER: + return (XP_UCHAR*)"%d tiles left in pool."; + case STRD_REMAINS_EXPL: + return (XP_UCHAR*)"%d tiles left in pool and all tray[s]:\n"; + default: return (XP_UCHAR*)"unknown code to linux_util_getUserString"; }