From 2d2f3e23fdc481eea7e683f246a619f2ab5855c5 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 2 Sep 2011 18:36:03 -0700 Subject: [PATCH] change signature of util_playerScoreHeld(): pass player num rather than formatted text. Client code can use new model_getPlayersLastScore() or whatever else it wants to build text to show the user. --- xwords4/android/XWords4/jni/utilwrapper.c | 8 +++----- .../org/eehouse/android/xw4/BoardActivity.java | 10 ++++++---- .../org/eehouse/android/xw4/jni/UtilCtxt.java | 17 +++++++---------- .../eehouse/android/xw4/jni/UtilCtxtImpl.java | 8 +------- xwords4/common/board.c | 10 +++++----- xwords4/common/util.h | 7 +++---- xwords4/linux/gtkmain.c | 14 +++++++++++--- 7 files changed, 36 insertions(+), 38 deletions(-) diff --git a/xwords4/android/XWords4/jni/utilwrapper.c b/xwords4/android/XWords4/jni/utilwrapper.c index 8c1cd0979..396e78122 100644 --- a/xwords4/android/XWords4/jni/utilwrapper.c +++ b/xwords4/android/XWords4/jni/utilwrapper.c @@ -399,12 +399,10 @@ and_util_bonusSquareHeld( XW_UtilCtxt* uc, XWBonusType bonus ) } static void -and_util_playerScoreHeld( XW_UtilCtxt* uc, const XP_UCHAR* txt ) +and_util_playerScoreHeld( XW_UtilCtxt* uc, XP_U16 player ) { - UTIL_CBK_HEADER( "playerScoreHeld", "(Ljava/lang/String;)V" ); - jstring jmsg = (*env)->NewStringUTF( env, txt ); - (*env)->CallVoidMethod( env, util->jutil, mid, jmsg ); - (*env)->DeleteLocalRef( env, jmsg ); + UTIL_CBK_HEADER( "playerScoreHeld", "(I)V" ); + (*env)->CallVoidMethod( env, util->jutil, mid, player ); UTIL_CBK_TAIL(); } #endif diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java index cecf834e3..69ad65acb 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -930,8 +930,13 @@ public class BoardActivity extends XWActivity } @Override - public void playerScoreHeld( final String text ) + public void playerScoreHeld( int player ) { + String expl = XwJNI.model_getPlayersLastScore( m_jniGamePtr, + player ); + String name = m_gi.players[player].name; + final String text = expl.length() > 0 ? + String.format( "%s\n%s", name, expl ) : name; post( new Runnable() { public void run() { Toast.makeText( BoardActivity.this, text, @@ -1072,9 +1077,6 @@ public class BoardActivity extends XWActivity case UtilCtxt.ERR_NO_PEEK_ROBOT_TILES: resid = R.string.str_no_peek_robot_tiles; break; - case UtilCtxt.ERR_CANT_TRADE_MID_MOVE: - resid = R.string.str_cant_trade_mid_move; - break; case UtilCtxt.ERR_NO_EMPTY_TRADE: resid = R.string.str_no_empty_trade; break; 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 514c5d3b5..b890bb5a7 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 @@ -48,7 +48,7 @@ public interface UtilCtxt { void setIsServer( boolean isServer ); void bonusSquareHeld( int bonus ); - void playerScoreHeld( String text ); + void playerScoreHeld( int player ); static final int STRD_ROBOT_TRADED = 1; static final int STR_ROBOT_MOVED = 2; @@ -70,10 +70,8 @@ public interface UtilCtxt { static final int STRD_TRADED = 18; static final int STR_LOSTTURN = 19; static final int STR_COMMIT_CONFIRM = 20; - static final int STR_LOCAL_NAME = 21; - static final int STR_NONLOCAL_NAME = 22; - static final int STR_BONUS_ALL = 23; - static final int STRD_TURN_SCORE = 24; + static final int STR_BONUS_ALL = 21; + static final int STRD_TURN_SCORE = 22; String getUserString( int stringCode ); static final int QUERY_COMMIT_TURN = 0; @@ -97,11 +95,10 @@ public interface UtilCtxt { static final int ERR_REG_UNEXPECTED_USER = 10; static final int ERR_REG_SERVER_SANS_REMOTE = 11; static final int STR_NEED_BT_HOST_ADDR = 12; - static final int ERR_CANT_TRADE_MID_MOVE = 13; - static final int ERR_NO_EMPTY_TRADE = 14; - static final int ERR_CANT_UNDO_TILEASSIGN = 15; - static final int ERR_CANT_HINT_WHILE_DISABLED = 16; - static final int ERR_RELAY_BASE = 17; + static final int ERR_NO_EMPTY_TRADE = 13; + static final int ERR_CANT_UNDO_TILEASSIGN = 14; + static final int ERR_CANT_HINT_WHILE_DISABLED = 15; + static final int ERR_RELAY_BASE = 16; void userError( int id ); void notifyGameOver(); 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 969384d4d..3654e082f 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 @@ -87,7 +87,7 @@ public class UtilCtxtImpl implements UtilCtxt { { } - public void playerScoreHeld( String text ) + public void playerScoreHeld( int player ) { } @@ -155,12 +155,6 @@ public class UtilCtxtImpl implements UtilCtxt { case UtilCtxt.STR_COMMIT_CONFIRM: id = R.string.str_commit_confirm; break; - case UtilCtxt.STR_LOCAL_NAME: - id = R.string.str_local_name; - break; - case UtilCtxt.STR_NONLOCAL_NAME: - id = R.string.str_nonlocal_name; - break; case UtilCtxt.STR_BONUS_ALL: id = R.string.str_bonus_all; break; diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 5d7a2c61d..440a77679 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -945,7 +945,9 @@ timerFiredForPen( BoardCtxt* board ) { XP_Bool draw = XP_FALSE; const XP_UCHAR* text = (XP_UCHAR*)NULL; +#ifdef XWFEATURE_MINIWIN XP_UCHAR buf[80]; +#endif if ( board->penDownObject == OBJ_BOARD ) { if ( !dragDropInProgress( board ) || !dragDropHasMoved( board ) ) { @@ -974,7 +976,6 @@ timerFiredForPen( BoardCtxt* board ) board->penTimerFired = XP_TRUE; } } else if ( board->penDownObject == OBJ_SCORE ) { - LocalPlayer* lp; XP_S16 scoreIndex = figureScoreRectTapped( board, board->penDownX, board->penDownY ); /* I've seen this assert fire on simulator. No log is kept so I can't @@ -982,11 +983,11 @@ timerFiredForPen( BoardCtxt* board ) /* XP_ASSERT( player >= 0 ); */ if ( scoreIndex > CURSOR_LOC_REM ) { XP_U16 player = scoreIndex - 1; +#ifdef XWFEATURE_MINIWIN const XP_UCHAR* format; XP_UCHAR scoreExpl[48]; XP_U16 explLen; - - lp = &board->gi->players[player]; + LocalPlayer* lp = &board->gi->players[player]; format = util_getUserString( board->util, lp->isLocal? STR_LOCAL_NAME: STR_NONLOCAL_NAME ); XP_SNPRINTF( buf, sizeof(buf), format, emptyStringIfNull(lp->name) ); @@ -998,10 +999,9 @@ timerFiredForPen( BoardCtxt* board ) XP_ASSERT( XP_STRLEN(buf) + explLen < sizeof(buf) ); XP_STRCAT( buf, scoreExpl ); } -#ifdef XWFEATURE_MINIWIN text = buf; #else - util_playerScoreHeld( board->util, buf ); + util_playerScoreHeld( board->util, player ); #endif } diff --git a/xwords4/common/util.h b/xwords4/common/util.h index 9c5064a0f..00b6cf0c6 100644 --- a/xwords4/common/util.h +++ b/xwords4/common/util.h @@ -52,7 +52,6 @@ typedef enum { ERR_REG_SERVER_SANS_REMOTE, STR_NEED_BT_HOST_ADDR, #endif - ERR_CANT_TRADE_MID_MOVE, ERR_NO_EMPTY_TRADE, /* ERR_CANT_ENGINE_MID_MOVE, */ /* ERR_NOT_YOUR_TURN_TO_TRADE, */ @@ -160,7 +159,7 @@ typedef struct UtilVtable { #ifndef XWFEATURE_MINIWIN void (*m_util_bonusSquareHeld)( XW_UtilCtxt* uc, XWBonusType bonus ); - void (*m_util_playerScoreHeld)( XW_UtilCtxt* uc, const XP_UCHAR* txt ); + void (*m_util_playerScoreHeld)( XW_UtilCtxt* uc, XP_U16 player ); #endif #ifndef XWFEATURE_STANDALONE_ONLY @@ -266,8 +265,8 @@ struct XW_UtilCtxt { #ifndef XWFEATURE_MINIWIN # define util_bonusSquareHeld( uc, b ) \ (uc)->vtable->m_util_bonusSquareHeld( (uc), (b) ) -# define util_playerScoreHeld( uc, txt ) \ - (uc)->vtable->m_util_playerScoreHeld( (uc), (txt) ) +# define util_playerScoreHeld( uc, player ) \ + (uc)->vtable->m_util_playerScoreHeld( (uc), (player) ) #endif #ifndef XWFEATURE_STANDALONE_ONLY diff --git a/xwords4/linux/gtkmain.c b/xwords4/linux/gtkmain.c index 4d18df942..d3abe3258 100644 --- a/xwords4/linux/gtkmain.c +++ b/xwords4/linux/gtkmain.c @@ -1703,11 +1703,19 @@ gtk_util_bonusSquareHeld( XW_UtilCtxt* uc, XWBonusType bonus ) } static void -gtk_util_playerScoreHeld( XW_UtilCtxt* uc, const XP_UCHAR* txt ) +gtk_util_playerScoreHeld( XW_UtilCtxt* uc, XP_U16 player ) { LOG_FUNC(); - XP_USE( uc ); - XP_USE( txt ); + + GtkAppGlobals* globals = (GtkAppGlobals*)uc->closure; + + XP_UCHAR scoreExpl[48]; + XP_U16 explLen = sizeof(scoreExpl); + + if ( model_getPlayersLastScore( globals->cGlobals.game.model, + player, scoreExpl, &explLen ) ) { + XP_LOGF( "got: %s", scoreExpl ); + } } #endif