show new client-formatted turn summary in notification; remove old

common-formatting code.
This commit is contained in:
Eric House 2014-08-26 21:37:33 -07:00
parent 2d08848715
commit 88248131da
19 changed files with 542 additions and 606 deletions

File diff suppressed because it is too large Load diff

View file

@ -19,17 +19,13 @@
# define STR_PHONY_REJECTED 13
# define STRD_CUMULATIVE_SCORE 14
# define STRS_NEW_TILES 15
# define STR_PASSED 16
# define STRSD_SUMMARYSCORED 17
# define STRD_TRADED 18
# define STR_LOSTTURN 19
# 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 STR_RESIGNED 25
# define STR_WINNER 26
# define STR_COMMIT_CONFIRM 16
# define STR_BONUS_ALL 17
# define STRD_TURN_SCORE 18
# define STRD_REMAINS_HEADER 19
# define STRD_REMAINS_EXPL 20
# define STR_RESIGNED 21
# define STR_WINNER 22
# define N_AND_USER_STRINGS 26
# define N_AND_USER_STRINGS 22
#endif

View file

@ -202,16 +202,6 @@ setJGI( JNIEnv* env, jobject jgi, const CurGameInfo* gi )
}
} /* setJGI */
static void
setLMI( JNIEnv* env, jobject jlmi, const LastMoveInfo* lmi )
{
setInt( env, jlmi, "score", lmi->score );
setInt( env, jlmi, "nTiles", lmi->nTiles );
setInt( env, jlmi, "moveType", lmi->moveType );
setString( env, jlmi, "name", lmi->name );
setString( env, jlmi, "word", lmi->word );
}
#ifdef COMMON_LAYOUT
static const SetInfo bd_ints[] = {
ARR_MEMBER( BoardDims, left )
@ -1143,24 +1133,24 @@ Java_org_eehouse_android_xw4_jni_XwJNI_model_1getNumTilesInTray
return result;
}
JNIEXPORT jstring JNICALL
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_model_1getPlayersLastScore
( JNIEnv* env, jclass C, jint gamePtr, jint player, jobject jlmi )
{
jstring result = NULL;
XWJNI_START();
XP_ASSERT( !!state->game.model );
XP_UCHAR buf[64] = {0};
XP_U16 buflen = sizeof(buf);
LastMoveInfo lmi;
if ( !model_getPlayersLastScore( state->game.model, player, &lmi,
buf, &buflen ) ) {
buf[0] = '\0';
XP_Bool valid = model_getPlayersLastScore( state->game.model,
player, &lmi );
setBool( env, jlmi, "isValid", valid );
if ( valid ) {
setInt( env, jlmi, "score", lmi.score );
setInt( env, jlmi, "nTiles", lmi.nTiles );
setInt( env, jlmi, "moveType", lmi.moveType );
setString( env, jlmi, "name", lmi.name );
setString( env, jlmi, "word", lmi.word );
}
setLMI( env, jlmi, &lmi );
result = (*env)->NewStringUTF( env, buf );
XWJNI_END();
return result;
}
JNIEXPORT jstring JNICALL

View file

@ -709,20 +709,6 @@
phonies is set to lose turn when word used not in wordlist
-->
<string name="str_phony_rejected">Illegal word in move; turn lost!</string>
<!-- Used in formatting exchange move summaries: passed means the
user skipped his turn, or made a move involving 0 tiles for 0
points -->
<string name="str_passed">Passed</string>
<!-- formats tiles and score together, and probably doesn't need
translation unless the colon ':' needs to be replaced -->
<string name="strsd_summaryscored_fmt">%1$s:%2$d</string>
<!-- Used in formatting reports of trades (exchanges of tiles).
Number of tiles traded is substituted for %1$d-->
<string name="strd_traded_fmt">Exchanged %1$d tiles</string>
<!-- Used in formatting history and move reports; means user
skipped a turn because of an attempted illegal move/play of a
phony -->
<string name="str_lostturn">Lost turn</string>
<!-- Beginning of the message presented to a user when asking him
to confirm committing the current turn-->
<string name="str_commit_confirm">Commit the current move?\n</string>
@ -2281,4 +2267,9 @@
<!-- Used when prev player's name can't be looked up -->
<string name="prev_player">Your opponent</string>
<!-- formatting for last move summary in notifications -->
<string name="lmi_pass_fmt">%1$s passed</string>
<string name="lmi_move_fmt">%1$s played %2$s for %3$d points</string>
<string name="lmi_trade_fmt">%1$s traded %2$d tiles</string>
<string name="lmi_phony_fmt">%1$s lost a turn</string>
</resources>

View file

@ -602,20 +602,6 @@
phonies is set to lose turn when word used not in wordlist
-->
<string name="str_phony_rejected">Lagelli drow ni evom; nrut !tsol</string>
<!-- Used in formatting exchange move summaries: passed means the
user skipped his turn, or made a move involving 0 tiles for 0
points -->
<string name="str_passed">Dessap</string>
<!-- formats tiles and score together, and probably doesn't need
translation unless the colon ':' needs to be replaced -->
<string name="strsd_summaryscored_fmt">%1$s:%2$d</string>
<!-- Used in formatting reports of trades (exchanges of tiles).
Number of tiles traded is substituted for %1$d-->
<string name="strd_traded_fmt">Degnahcxe %1$d selit</string>
<!-- Used in formatting history and move reports; means user
skipped a turn because of an attempted illegal move/play of a
phony -->
<string name="str_lostturn">Tsol nrut</string>
<!-- Beginning of the message presented to a user when asking him
to confirm committing the current turn-->
<string name="str_commit_confirm">Timmoc eht tnerruc ?evom\n</string>
@ -1951,4 +1937,9 @@
<string name="nag_warn_last_fmt">Tsal gninraw: %1$s</string>
<!-- Used when prev player's name can't be looked up -->
<string name="prev_player">Ruoy tnenoppo</string>
<!-- formatting for last move summary in notifications -->
<string name="lmi_pass_fmt">%1$s dessap</string>
<string name="lmi_move_fmt">%1$s deyalp %2$s rof %3$d stniop</string>
<string name="lmi_trade_fmt">%1$s dedart %2$d selit</string>
<string name="lmi_phony_fmt">%1$s tsol a nrut</string>
</resources>

View file

@ -602,20 +602,6 @@
phonies is set to lose turn when word used not in wordlist
-->
<string name="str_phony_rejected">ILLEGAL WORD IN MOVE; TURN LOST!</string>
<!-- Used in formatting exchange move summaries: passed means the
user skipped his turn, or made a move involving 0 tiles for 0
points -->
<string name="str_passed">PASSED</string>
<!-- formats tiles and score together, and probably doesn't need
translation unless the colon ':' needs to be replaced -->
<string name="strsd_summaryscored_fmt">%1$s:%2$d</string>
<!-- Used in formatting reports of trades (exchanges of tiles).
Number of tiles traded is substituted for %1$d-->
<string name="strd_traded_fmt">EXCHANGED %1$d TILES</string>
<!-- Used in formatting history and move reports; means user
skipped a turn because of an attempted illegal move/play of a
phony -->
<string name="str_lostturn">LOST TURN</string>
<!-- Beginning of the message presented to a user when asking him
to confirm committing the current turn-->
<string name="str_commit_confirm">COMMIT THE CURRENT MOVE?\n</string>
@ -1951,4 +1937,9 @@
<string name="nag_warn_last_fmt">LAST WARNING: %1$s</string>
<!-- Used when prev player's name can't be looked up -->
<string name="prev_player">YOUR OPPONENT</string>
<!-- formatting for last move summary in notifications -->
<string name="lmi_pass_fmt">%1$s PASSED</string>
<string name="lmi_move_fmt">%1$s PLAYED %2$s FOR %3$d POINTS</string>
<string name="lmi_trade_fmt">%1$s TRADED %2$d TILES</string>
<string name="lmi_phony_fmt">%1$s LOST A TURN</string>
</resources>

View file

@ -1416,14 +1416,12 @@ public class BoardDelegate extends DelegateBase
public void playerScoreHeld( int player )
{
LastMoveInfo lmi = new LastMoveInfo();
String expl = XwJNI.model_getPlayersLastScore( m_jniGamePtr,
player, lmi );
expl = lmi.format( m_activity );
if ( expl.length() == 0 ) {
XwJNI.model_getPlayersLastScore( m_jniGamePtr, player, lmi );
String expl = lmi.format( m_activity );
if ( null == expl || 0 == expl.length() ) {
expl = getString( R.string.no_moves_made );
}
String name = m_gi.players[player].name;
final String text = String.format( "%s\n%s", name, expl );
final String text = expl;
post( new Runnable() {
public void run() {
showToast( text );

View file

@ -799,7 +799,7 @@ public class GameUtils {
}
if ( null != lmi ) {
XwJNI.model_getPlayersLastScore( gamePtr, 0, lmi );
XwJNI.model_getPlayersLastScore( gamePtr, -1, lmi );
}
saveGame( context, gamePtr, gi, lock, false );

View file

@ -21,7 +21,19 @@ package org.eehouse.android.xw4.jni;
import android.content.Context;
import org.eehouse.android.xw4.R;
import org.eehouse.android.xw4.DbgUtils;
import org.eehouse.android.xw4.loc.LocUtils;
public class LastMoveInfo {
// Keep in sync with StackMoveType in movestak.h
private static final int ASSIGN_TYPE = 0;
private static final int MOVE_TYPE = 1;
private static final int TRADE_TYPE = 2;
private static final int PHONY_TYPE = 3;
public boolean isValid;
public String name;
public int moveType;
public int score;
@ -30,6 +42,31 @@ public class LastMoveInfo {
public String format( Context context )
{
return String.format( "%s did move type %d", name, moveType );
String result = null;
if ( isValid ) {
switch( moveType ) {
case ASSIGN_TYPE:
break;
case MOVE_TYPE:
if ( 0 == nTiles ) {
result = LocUtils.getString( context, R.string.lmi_pass_fmt,
name );
} else {
result = LocUtils.getString( context, R.string.lmi_move_fmt,
name, word, score );
}
break;
case TRADE_TYPE:
result = LocUtils.getString( context, R.string.lmi_trade_fmt,
name, nTiles );
break;
case PHONY_TYPE:
result = LocUtils.getString( context, R.string.lmi_phony_fmt,
name );
break;
}
}
DbgUtils.logf( "LastMoveInfo.format() => %s", result );
return result;
}
}

View file

@ -87,17 +87,13 @@ public interface UtilCtxt {
static final int STR_PHONY_REJECTED = 13;
static final int STRD_CUMULATIVE_SCORE = 14;
static final int STRS_NEW_TILES = 15;
static final int STR_PASSED = 16;
static final int STRSD_SUMMARYSCORED = 17;
static final int STRD_TRADED = 18;
static final int STR_LOSTTURN = 19;
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;
static final int STR_RESIGNED = 25;
static final int STR_WINNER = 26;
static final int STR_COMMIT_CONFIRM = 16;
static final int STR_BONUS_ALL = 17;
static final int STRD_TURN_SCORE = 18;
static final int STRD_REMAINS_HEADER = 19;
static final int STRD_REMAINS_EXPL = 20;
static final int STR_RESIGNED = 21;
static final int STR_WINNER = 22;
String getUserString( int stringCode );

View file

@ -189,18 +189,6 @@ public class UtilCtxtImpl implements UtilCtxt {
case UtilCtxt.STRS_NEW_TILES:
id = R.string.strs_new_tiles_fmt;
break;
case UtilCtxt.STR_PASSED:
id = R.string.str_passed;
break;
case UtilCtxt.STRSD_SUMMARYSCORED:
id = R.string.strsd_summaryscored_fmt;
break;
case UtilCtxt.STRD_TRADED:
id = R.string.strd_traded_fmt;
break;
case UtilCtxt.STR_LOSTTURN:
id = R.string.str_lostturn;
break;
case UtilCtxt.STR_COMMIT_CONFIRM:
id = R.string.str_commit_confirm;
break;

View file

@ -270,9 +270,9 @@ public class XwJNI {
boolean gameOver );
public static native int model_getNMoves( int gamePtr );
public static native int model_getNumTilesInTray( int gamePtr, int player );
public static native String model_getPlayersLastScore( int gamePtr,
int player,
LastMoveInfo lmi );
public static native void model_getPlayersLastScore( int gamePtr,
int player,
LastMoveInfo lmi );
// Server
public static native void server_reset( int gamePtr );
public static native void server_handleUndo( int gamePtr );

View file

@ -29,8 +29,7 @@
typedef XP_Bool (*LastScoreCallback)( void* closure, XP_S16 player,
LastMoveInfo* lmi,
XP_UCHAR* expl, XP_U16* explLen );
LastMoveInfo* lmi );
typedef enum {
CELL_NONE = 0x00

View file

@ -2189,15 +2189,10 @@ getFirstWord( const XP_UCHAR* word, XP_Bool XP_UNUSED(isLegal),
static void
scoreLastMove( ModelCtxt* model, MoveInfo* moveInfo, XP_U16 howMany,
LastMoveInfo* lmi, XP_UCHAR* buf, XP_U16* bufLen )
LastMoveInfo* lmi )
{
lmi->nTiles = moveInfo->nTiles;
if ( moveInfo->nTiles == 0 ) {
const XP_UCHAR* str = util_getUserString( model->vol.util, STR_PASSED );
XP_U16 len = XP_STRLEN( str );
*bufLen = len;
XP_STRNCPY( buf, str, len + 1 );
} else {
if ( 0 < moveInfo->nTiles ) {
XP_U16 score;
const XP_UCHAR* format;
WordNotifierInfo notifyInfo;
@ -2222,8 +2217,6 @@ scoreLastMove( ModelCtxt* model, MoveInfo* moveInfo, XP_U16 howMany,
model_destroy( tmpModel );
format = util_getUserString( model->vol.util, STRSD_SUMMARYSCORED );
*bufLen = XP_SNPRINTF( buf, *bufLen, format, data.word, score );
lmi->score = score;
XP_SNPRINTF( lmi->word, VSIZE(lmi->word), "%s", data.word );
}
@ -2375,10 +2368,10 @@ model_listWordsThrough( ModelCtxt* model, XP_U16 col, XP_U16 row,
#endif
XP_Bool
model_getPlayersLastScore( ModelCtxt* model, XP_S16 player,
LastMoveInfo* lmi,
XP_UCHAR* expl, XP_U16* explLen )
model_getPlayersLastScore( ModelCtxt* model, XP_S16 player, LastMoveInfo* lmi )
{
XP_LOGF( "%s(player=%d)", __func__, player );
StackCtxt* stack = model->vol.stack;
XP_S16 nEntries, which;
StackEntry entry;
@ -2386,39 +2379,36 @@ model_getPlayersLastScore( ModelCtxt* model, XP_S16 player,
XP_MEMSET( lmi, 0, sizeof(*lmi) );
XP_ASSERT( !!stack );
XP_ASSERT( player >= 0 );
nEntries = stack_getNEntries( stack );
for ( which = nEntries; which >= 0; ) {
if ( stack_getNthEntry( stack, --which, &entry ) ) {
if ( entry.playerNum == player ) {
if ( -1 == player || entry.playerNum == player ) {
found = XP_TRUE;
break;
}
}
}
if ( found ) { /* success? */
const XP_UCHAR* format;
XP_U16 nTiles;
lmi->name = model->vol.gi->players[player].name;
XP_ASSERT( -1 == player || player == entry.playerNum );
XP_LOGF( "%s: found move %d", __func__, which );
lmi->name = model->vol.gi->players[entry.playerNum].name;
lmi->moveType = entry.moveType;
switch ( entry.moveType ) {
case MOVE_TYPE:
scoreLastMove( model, &entry.u.move.moveInfo,
nEntries - which, lmi, expl, explLen );
scoreLastMove( model, &entry.u.move.moveInfo, nEntries - which,
lmi );
lmi->nTiles = entry.u.move.moveInfo.nTiles;
break;
case TRADE_TYPE:
nTiles = entry.u.trade.oldTiles.nTiles;
lmi->nTiles = entry.u.trade.oldTiles.nTiles;
format = util_getUserString( model->vol.util, STRD_TRADED );
*explLen = XP_SNPRINTF( expl, *explLen, format, nTiles );
break;
case PHONY_TYPE:
format = util_getUserString( model->vol.util, STR_LOSTTURN );
*explLen = XP_STRLEN( format );
XP_STRCAT( expl, format );
break;
case ASSIGN_TYPE:
found = XP_FALSE;
@ -2426,6 +2416,7 @@ model_getPlayersLastScore( ModelCtxt* model, XP_S16 player,
}
}
LOG_RETURNF( "%d", found );
return found;
} /* model_getPlayersLastScore */

View file

@ -272,8 +272,7 @@ XP_Bool getCurrentMoveScoreIfLegal( ModelCtxt* model, XP_S16 turn,
XP_S16 model_getPlayerScore( ModelCtxt* model, XP_S16 player );
XP_Bool model_getPlayersLastScore( ModelCtxt* model, XP_S16 player,
LastMoveInfo* info,
XP_UCHAR* expl, XP_U16* explLen );
LastMoveInfo* info );
#ifdef XWFEATURE_BOARDWORDS
void model_listWordsThrough( ModelCtxt* model, XP_U16 col, XP_U16 row,
XWStreamCtxt* stream );

View file

@ -29,13 +29,10 @@ extern "C" {
#endif
static XP_Bool
board_ScoreCallback( void* closure, XP_S16 player,
LastMoveInfo* lmi,
XP_UCHAR* expl, XP_U16* explLen)
board_ScoreCallback( void* closure, XP_S16 player, LastMoveInfo* lmi )
{
ModelCtxt* model = (ModelCtxt*)closure;
return model_getPlayersLastScore( model, player,
lmi, expl, explLen );
return model_getPlayersLastScore( model, player, lmi );
} /* board_ScoreCallback */
#ifdef XWFEATURE_SCOREONEPASS

View file

@ -45,11 +45,6 @@ enum {
STR_ROBOT_MOVED,
STRS_REMOTE_MOVED,
STR_PASSED,
STRSD_SUMMARYSCORED,
STRD_TRADED,
STR_LOSTTURN,
STR_LOCALPLAYERS,
STR_TOTALPLAYERS,
STR_REMOTE,

View file

@ -2015,14 +2015,12 @@ gtk_util_playerScoreHeld( XW_UtilCtxt* uc, XP_U16 player )
GtkGameGlobals* globals = (GtkGameGlobals*)uc->closure;
XP_UCHAR scoreExpl[128] = {0};
XP_U16 explLen = sizeof(scoreExpl);
LastMoveInfo lmi;
if ( model_getPlayersLastScore( globals->cGlobals.game.model,
player, &lmi, scoreExpl, &explLen ) ) {
formatLMI( &lmi, scoreExpl, VSIZE(scoreExpl) );
(void)gtkask( globals->window, scoreExpl, GTK_BUTTONS_OK, NULL );
player, &lmi ) ) {
XP_UCHAR buf[128];
formatLMI( &lmi, buf, VSIZE(buf) );
(void)gtkask( globals->window, buf, GTK_BUTTONS_OK, NULL );
}
}
#endif

View file

@ -314,15 +314,6 @@ linux_util_getUserString( XW_UtilCtxt* XP_UNUSED(uc), XP_U16 code )
case STRS_REMOTE_MOVED:
return (XP_UCHAR*)"Remote player \"%s\" moved:\n";
case STR_PASSED:
return (XP_UCHAR*)"Passed";
case STRSD_SUMMARYSCORED:
return (XP_UCHAR*)"%s:%d";
case STRD_TRADED:
return (XP_UCHAR*)"Traded %d";
case STR_LOSTTURN:
return (XP_UCHAR*)"Lost turn";
#ifndef XWFEATURE_STANDALONE_ONLY
case STR_LOCALPLAYERS:
return (XP_UCHAR*)"Local players";