diff --git a/xwords4/android/XWords4/jni/anddict.c b/xwords4/android/XWords4/jni/anddict.c index d36b9f383..4f8500919 100644 --- a/xwords4/android/XWords4/jni/anddict.c +++ b/xwords4/android/XWords4/jni/anddict.c @@ -425,7 +425,6 @@ void makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts, jobjectArray jdicts, jobjectArray jnames, jstring jlang ) { - LOG_FUNC(); int ii; jsize len = (*env)->GetArrayLength( env, jdicts ); XP_ASSERT( len == (*env)->GetArrayLength( env, jnames ) ); @@ -442,7 +441,6 @@ makeDicts( MPFORMAL JNIEnv *env, JNIUtilCtxt* jniutil, PlayerDicts* dicts, } dicts->dicts[ii] = dict; } - LOG_RETURN_VOID(); } DictionaryCtxt* diff --git a/xwords4/common/dictnry.c b/xwords4/common/dictnry.c index 353a1fc18..1f7538b27 100644 --- a/xwords4/common/dictnry.c +++ b/xwords4/common/dictnry.c @@ -390,6 +390,28 @@ dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream ) } /* dict_loadFromStream */ #endif +#ifdef TEXT_MODEL +/* Return the strlen of the longest face, e.g. 1 for English and Italian; + 2 for Spanish; 3 for Catalan */ +XP_U16 +dict_getMaxWidth( const DictionaryCtxt* dict ) +{ + XP_U16 result = 0; + Tile tile; + XP_U16 nFaces = dict_numTileFaces( dict ); + + for ( tile = 0; tile < nFaces; ++tile ) { + const XP_UCHAR* face = dict_getTileString( dict, tile ); + XP_U16 len = XP_STRLEN( face ); + if ( len > result ) { + result = len; + } + } + return result; +} +#endif + + const XP_UCHAR* dict_getName( const DictionaryCtxt* dict ) { diff --git a/xwords4/common/dictnry.h b/xwords4/common/dictnry.h index af1ab8ba4..7064d8c7e 100644 --- a/xwords4/common/dictnry.h +++ b/xwords4/common/dictnry.h @@ -160,6 +160,12 @@ XP_U32 dict_getWordCount( const DictionaryCtxt* dict ); void dict_writeToStream( const DictionaryCtxt* ctxt, XWStreamCtxt* stream ); void dict_loadFromStream( DictionaryCtxt* dict, XWStreamCtxt* stream ); +#ifdef TEXT_MODEL +/* Return the strlen of the longest face, e.g. 1 for English and Italian; + 2 for Spanish; 3 for Catalan */ +XP_U16 dict_getMaxWidth( const DictionaryCtxt* dict ); +#endif + /* These methods get "overridden" by subclasses. That is, they must be implemented by each platform. */ diff --git a/xwords4/common/model.c b/xwords4/common/model.c index 0b23f4bb5..a6a946922 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -172,6 +172,47 @@ model_writeToStream( ModelCtxt* model, XWStreamCtxt* stream ) #endif } /* model_writeToStream */ +#ifdef TEXT_MODEL +void +model_writeToTextStream( const ModelCtxt* model, XWStreamCtxt* stream ) +{ + const DictionaryCtxt* dict = model_getDictionary( model ); + int width = dict_getMaxWidth( dict ); + XP_UCHAR empty[4] = {0}; + XP_U16 ii; + XP_U16 col, row; + + for ( ii = 0; ii < width; ++ii ) { + empty[ii] = '.'; + } + + for ( row = 0; row < model->nRows; ++row ) { + XP_UCHAR buf[256]; + XP_U16 len = 0; + for ( col = 0; col < model->nCols; ++col ) { + XP_Bool isBlank; + Tile tile; + if ( model_getTile( model, col, row, XP_FALSE, -1, &tile, + &isBlank, NULL, NULL ) ) { + const XP_UCHAR* face = dict_getTileString( dict, tile ); + XP_UCHAR lower[1+XP_STRLEN(face)]; + XP_STRNCPY( lower, face, sizeof(lower) ); + if ( isBlank ) { + XP_LOWERSTR( lower ); + } + len += snprintf( &buf[len], sizeof(buf) - len, "%*s", + width, lower ); + } else { + len += snprintf( &buf[len], sizeof(buf) - len, "%s", empty ); + } + } + buf[len++] = '\n'; + buf[len] = '\0'; + stream_catString( stream, buf ); + } +} +#endif + void model_init( ModelCtxt* model, XP_U16 nCols, XP_U16 nRows ) { diff --git a/xwords4/common/model.h b/xwords4/common/model.h index 1c39629ed..e0ec0d495 100644 --- a/xwords4/common/model.h +++ b/xwords4/common/model.h @@ -109,6 +109,10 @@ ModelCtxt* model_makeFromStream( MPFORMAL XWStreamCtxt* stream, void model_writeToStream( ModelCtxt* model, XWStreamCtxt* stream ); +#ifdef TEXT_MODEL +void model_writeToTextStream( const ModelCtxt* model, XWStreamCtxt* stream ); +#endif + void model_init( ModelCtxt* model, XP_U16 nCols, XP_U16 nRows ); void model_destroy( ModelCtxt* model ); void model_setNPlayers( ModelCtxt* model, XP_U16 numPlayers ); diff --git a/xwords4/common/nwgamest.c b/xwords4/common/nwgamest.c index 5e1d9bad6..0c8413fe1 100644 --- a/xwords4/common/nwgamest.c +++ b/xwords4/common/nwgamest.c @@ -110,7 +110,7 @@ newg_load( NewGameCtx* ngc, const CurGameInfo* gi ) XP_S16 ii, jj; DeviceRole role; XP_Bool localOnly; - XP_Bool shown[MAX_NUM_PLAYERS] = { XP_FALSE, XP_FALSE, XP_FALSE, XP_FALSE}; + XP_Bool shown[MAX_NUM_PLAYERS] = { XP_FALSE }; ngc->juggleEnabled = TRI_ENAB_NONE; ngc->settingsEnabled = TRI_ENAB_NONE; diff --git a/xwords4/linux/Makefile b/xwords4/linux/Makefile index b33886edd..228050428 100644 --- a/xwords4/linux/Makefile +++ b/xwords4/linux/Makefile @@ -87,6 +87,7 @@ DEFINES += -DFEATURE_TRAY_EDIT DEFINES += -DXWFEATURE_CROSSHAIRS DEFINES += -DXWFEATURE_CHAT DEFINES += -DDISABLE_TILE_SEL +DEFINES += -DTEXT_MODEL ifdef CURSES_CELL_HT DEFINES += -DCURSES_CELL_HT=$(CURSES_CELL_HT) diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index 3285b5e2e..803fbf858 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -740,6 +740,23 @@ game_history( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals ) catGameHistory( &globals->cGlobals ); } /* game_history */ +#ifdef TEXT_MODEL +static void +dump_board( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals ) +{ + if ( !!globals->cGlobals.game.model ) { + XWStreamCtxt* stream = + mem_stream_make( MEMPOOL + globals->cGlobals.params->vtMgr, + globals, + CHANNEL_NONE, + catOnClose ); + model_writeToTextStream( globals->cGlobals.game.model, stream ); + stream_destroy( stream ); + } +} +#endif + static void final_scores( GtkWidget* XP_UNUSED(widget), GtkAppGlobals* globals ) { @@ -953,6 +970,10 @@ makeMenus( GtkAppGlobals* globals, int XP_UNUSED(argc), GTK_SIGNAL_FUNC(tile_values), globals ); (void)createAddItem( fileMenu, "Game history", GTK_SIGNAL_FUNC(game_history), globals ); +#ifdef TEXT_MODEL + (void)createAddItem( fileMenu, "Dump board", + GTK_SIGNAL_FUNC(dump_board), globals ); +#endif (void)createAddItem( fileMenu, "Final scores", GTK_SIGNAL_FUNC(final_scores), globals ); diff --git a/xwords4/linux/linuxmain.c b/xwords4/linux/linuxmain.c index b0df336f7..9fbe9c944 100644 --- a/xwords4/linux/linuxmain.c +++ b/xwords4/linux/linuxmain.c @@ -316,8 +316,7 @@ typedef struct _CmdInfoRec { static CmdInfoRec CmdInfoRecs[] = { { CMD_SKIP_GAMEOVER, false, "skip-final", "skip final scores display" } - ,{ CMD_SHOW_OTHERSCORES, false, "no-show-other", - "do not show robot and remote scores" } + ,{ CMD_SHOW_OTHERSCORES, false, "show-other", "show robot/remote scores" } ,{ CMD_HOSTIP, true, "hostip", "remote host ip address (for direct connect)" } ,{ CMD_DICT, true, "game-dict", "dictionary name for game" } ,{ CMD_PLAYERDICT, true, "player-dict", "dictionary name for player (in sequence)" } @@ -957,7 +956,7 @@ main( int argc, char** argv ) mainParams.skipCommitConfirm = XP_TRUE; mainParams.showColors = XP_TRUE; mainParams.allowPeek = XP_TRUE; - mainParams.showRobotScores = XP_TRUE; + mainParams.showRobotScores = XP_FALSE; /* serverName = mainParams.info.clientInfo.serverName = "localhost"; */ @@ -981,7 +980,7 @@ main( int argc, char** argv ) mainParams.skipGameOver = XP_TRUE; break; case CMD_SHOW_OTHERSCORES: - mainParams.showRobotScores = XP_FALSE; + mainParams.showRobotScores = XP_TRUE; break; #ifdef XWFEATURE_RELAY case CMD_ROOMNAME: diff --git a/xwords4/linux/linuxutl.c b/xwords4/linux/linuxutl.c index ed98ad461..cf72e12a8 100644 --- a/xwords4/linux/linuxutl.c +++ b/xwords4/linux/linuxutl.c @@ -24,6 +24,7 @@ #include #include #include +#include /* BAD: use glib to support utf8 */ #include "linuxutl.h" #include "main.h" @@ -409,3 +410,15 @@ linux_getErrString( UtilErrID id, XP_Bool* silent ) return (XP_UCHAR*)message; } /* linux_getErrString */ + +#ifdef TEXT_MODEL +/* This is broken for UTF-8, even Spanish */ +void +linux_lowerstr( XP_UCHAR* str ) +{ + while ( *str ) { + *str = tolower( *str ); + ++str; + } +} +#endif diff --git a/xwords4/linux/xptypes.h b/xwords4/linux/xptypes.h index 645d05a5e..075120e11 100644 --- a/xwords4/linux/xptypes.h +++ b/xwords4/linux/xptypes.h @@ -104,6 +104,8 @@ void linux_freep( void** ptrp ); #define XP_STRNCMP(s1,s2,len) strncmp((s1),(s2),(len)) #define XP_STRNCPY(s1,s2,len) strncpy((s1),(s2),(len)) #define XP_STRCMP(s1,s2) strcmp((s1),(s2)) +void linux_lowerstr( XP_UCHAR* str ); +#define XP_LOWERSTR(str) linux_lowerstr(str) #define XP_RANDOM() random() #define XP_SNPRINTF snprintf