From 3ec97d5c07ae70f3f9d80a865715cc3b7a767761 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 4 Oct 2011 18:48:33 -0700 Subject: [PATCH] Turn "Turn done" into "Pass" when the pending score is 0. To do that I had to pass the score into draw_trayBegin since draw_drawPendingScore() isn't called until the first tile's placed. Note: as long as I'm messinng with this menuitem it should be disabled when it's not the player's turn. --- xwords4/android/XWords4/jni/drawwrapper.c | 8 ++--- .../android/XWords4/res/values/strings.xml | 2 ++ .../eehouse/android/xw4/BoardActivity.java | 18 +++++++++- .../org/eehouse/android/xw4/BoardView.java | 10 +++++- .../org/eehouse/android/xw4/jni/DrawCtx.java | 2 +- xwords4/common/draw.h | 8 +++-- xwords4/common/tray.c | 33 ++++++++++++------- xwords4/linux/cursesdraw.c | 5 +-- xwords4/linux/gtkdraw.c | 9 ++--- 9 files changed, 67 insertions(+), 28 deletions(-) diff --git a/xwords4/android/XWords4/jni/drawwrapper.c b/xwords4/android/XWords4/jni/drawwrapper.c index 3eb323a3b..578824e95 100644 --- a/xwords4/android/XWords4/jni/drawwrapper.c +++ b/xwords4/android/XWords4/jni/drawwrapper.c @@ -281,15 +281,15 @@ and_draw_vertScrollBoard( DrawCtx* XP_UNUSED(dctx), XP_Rect* XP_UNUSED(rect), static XP_Bool and_draw_trayBegin( DrawCtx* dctx, const XP_Rect* rect, XP_U16 owner, - DrawFocusState dfs ) + XP_S16 score, DrawFocusState dfs ) { - DRAW_CBK_HEADER( "trayBegin", "(Landroid/graphics/Rect;II)Z" ); + DRAW_CBK_HEADER( "trayBegin", "(Landroid/graphics/Rect;III)Z" ); jobject jrect = makeJRect( draw, JCACHE_RECT0, rect ); jboolean result = (*env)->CallBooleanMethod( env, draw->jdraw, mid, - jrect, owner, (jint)dfs ); - + jrect, owner, score, + (jint)dfs ); return result; } diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index 5fc7b8d93..0c9daca4e 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -1774,5 +1774,7 @@ Pick a site Tap word to search Look up %s at + + Pass 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 b60865d05..a3763e808 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -144,6 +144,7 @@ public class BoardActivity extends XWActivity private JNIThread m_jniThread; private JNIThread.GameStateInfo m_gsi; private boolean m_blockingDlgPosted = false; + private String m_doneOrigTitle = null; private String m_room; private String m_toastStr; @@ -597,12 +598,27 @@ public class BoardActivity extends XWActivity public boolean onPrepareOptionsMenu( Menu menu ) { super.onPrepareOptionsMenu( menu ); + boolean inTrade = false; if ( null != m_gsi ) { - boolean inTrade = m_gsi.inTrade; + inTrade = m_gsi.inTrade; menu.setGroupVisible( R.id.group_done, !inTrade ); } + if ( !inTrade ) { + MenuItem item = menu.findItem( R.id.board_menu_done ); + if ( null == m_doneOrigTitle ) { + m_doneOrigTitle = item.getTitle().toString(); + } + String title; + if ( 0 >= m_view.curPending() ) { + title = getString( R.string.pass ); + } else { + title = m_doneOrigTitle; + } + item.setTitle( title ); + } + return true; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java index 43d605753..f60fdcd43 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardView.java @@ -80,6 +80,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler, private int m_dictPtr = 0; private int m_lastSecsLeft; private int m_lastTimerPlayer; + private int m_pendingScore; private Handler m_viewHandler; // FontDims: exists to translate space available to the largest @@ -169,6 +170,7 @@ public class BoardView extends View implements DrawCtx, BoardHandler, m_viewHandler = new Handler(); } + @Override public boolean onTouchEvent( MotionEvent event ) { int action = event.getAction(); @@ -336,6 +338,11 @@ public class BoardView extends View implements DrawCtx, BoardHandler, m_jniThread.handle( JNIThread.JNICmd.CMD_INVALALL ); } + public int curPending() + { + return m_pendingScore; + } + // DrawCtxt interface implementation public boolean scoreBegin( Rect rect, int numPlayers, int[] scores, int remCount, int dfs ) @@ -582,9 +589,10 @@ public class BoardView extends View implements DrawCtx, BoardHandler, } } - public boolean trayBegin ( Rect rect, int owner, int dfs ) + public boolean trayBegin ( Rect rect, int owner, int score, int dfs ) { m_trayOwner = owner; + m_pendingScore = score; return true; } diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java index 1e4d88892..83ed1c179 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/DrawCtx.java @@ -57,7 +57,7 @@ public interface DrawCtx { int owner, int bonus, int hintAtts, int flags ); void drawBoardArrow ( Rect rect, int bonus, boolean vert, int hintAtts, int flags ); - boolean trayBegin ( Rect rect, int owner, int dfs ); + boolean trayBegin ( Rect rect, int owner, int score, int dfs ); void drawTile( Rect rect, String text, int val, int flags ); void drawTileMidDrag ( Rect rect, String text, int val, int owner, int flags ); diff --git a/xwords4/common/draw.h b/xwords4/common/draw.h index 96d681165..d66546bb0 100644 --- a/xwords4/common/draw.h +++ b/xwords4/common/draw.h @@ -129,7 +129,7 @@ typedef struct DrawCtxVTable { XP_S16 dist, DrawFocusState dfs ); XP_Bool DRAW_VTABLE_NAME(trayBegin) ( DrawCtx* dctx, const XP_Rect* rect, - XP_U16 owner, + XP_U16 owner, XP_S16 score, DrawFocusState dfs ); void DRAW_VTABLE_NAME(measureRemText) ( DrawCtx* dctx, const XP_Rect* r, XP_S16 nTilesLeft, @@ -257,8 +257,10 @@ struct DrawCtx { #define draw_dictChanged( dc, n, d ) CALL_DRAW_NAME2(dictChanged, (dc), (n), (d)) #define draw_boardBegin( dc,r,h,v,f ) CALL_DRAW_NAME4(boardBegin, (dc),\ (r),(h),(v),(f)) -#define draw_objFinished( dc, t, r, d ) CALL_DRAW_NAME3(objFinished, (dc), (t), (r), (d)) -#define draw_trayBegin( dc, r, o, f ) CALL_DRAW_NAME3(trayBegin,dc, r, o, f) +#define draw_objFinished( dc, t, r, d ) \ + CALL_DRAW_NAME3(objFinished, (dc), (t), (r), (d)) +#define draw_trayBegin( dc, r, o, s, f ) \ + CALL_DRAW_NAME4(trayBegin, dc, r, o, s, f) #define draw_vertScrollBoard( dc, r, d, f ) \ CALL_DRAW_NAME3(vertScrollBoard, (dc),(r),(d),(f)) #define draw_scoreBegin( dc, r, t, s, c, f ) \ diff --git a/xwords4/common/tray.c b/xwords4/common/tray.c index d81a78300..d9b9b9195 100644 --- a/xwords4/common/tray.c +++ b/xwords4/common/tray.c @@ -1,6 +1,6 @@ -/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE"; -*- */ +/* -*- compile-command: "cd ../linux && make MEMDEBUG=TRUE -j3"; -*- */ /* - * Copyright 1997 - 2009 by Eric House (xwords@eehouse.org). All rights + * Copyright 1997 - 2011 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -29,7 +29,9 @@ extern "C" { #endif /****************************** prototypes ******************************/ -static void drawPendingScore( BoardCtxt* board, XP_Bool hasCursor ); +static void drawPendingScore( BoardCtxt* board, XP_S16 turnScore, + XP_Bool hasCursor ); +static XP_S16 figurePendingScore( const BoardCtxt* board ); static XP_U16 countTilesToShow( BoardCtxt* board ); static void figureDividerRect( BoardCtxt* board, XP_Rect* rect ); @@ -130,8 +132,10 @@ drawTray( BoardCtxt* board ) const XP_S16 turn = board->selPlayer; PerTurnInfo* pti = board->selInfo; + XP_S16 turnScore = figurePendingScore( board ); + if ( draw_trayBegin( board->draw, &board->trayBounds, turn, - dfsFor( board, OBJ_TRAY ) ) ) { + turnScore, dfsFor( board, OBJ_TRAY ) ) ) { DictionaryCtxt* dictionary = model_getDictionary( board->model ); XP_S16 cursorBits = 0; XP_Bool cursorOnDivider = XP_FALSE; @@ -242,8 +246,7 @@ drawTray( BoardCtxt* board ) draw_drawTrayDivider( board->draw, ÷r, flags ); board->dividerInvalid = XP_FALSE; } - - drawPendingScore( board, + drawPendingScore( board, turnScore, (cursorBits & (1<<(MAX_TRAY_TILES-1))) != 0); } @@ -304,19 +307,25 @@ countTilesToShow( BoardCtxt* board ) return numToShow; } /* countTilesToShow */ +static XP_S16 +figurePendingScore( const BoardCtxt* board ) +{ + XP_S16 turnScore; + (void)getCurrentMoveScoreIfLegal( board->model, board->selPlayer, + (XWStreamCtxt*)NULL, + (WordNotifierInfo*)NULL, + &turnScore ); + return turnScore; +} + static void -drawPendingScore( BoardCtxt* board, XP_Bool hasCursor ) +drawPendingScore( BoardCtxt* board, XP_S16 turnScore, XP_Bool hasCursor ) { /* Draw the pending score down in the last tray's rect */ if ( countTilesToShow( board ) < MAX_TRAY_TILES ) { XP_U16 selPlayer = board->selPlayer; - XP_S16 turnScore = 0; XP_Rect lastTileR; - (void)getCurrentMoveScoreIfLegal( board->model, selPlayer, - (XWStreamCtxt*)NULL, - (WordNotifierInfo*)NULL, - &turnScore ); figureTrayTileRect( board, MAX_TRAY_TILES-1, &lastTileR ); draw_score_pendingScore( board->draw, &lastTileR, turnScore, selPlayer, diff --git a/xwords4/linux/cursesdraw.c b/xwords4/linux/cursesdraw.c index 0eaf07440..b6a35beb6 100644 --- a/xwords4/linux/cursesdraw.c +++ b/xwords4/linux/cursesdraw.c @@ -1,6 +1,6 @@ -/* -*-mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */ +/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */ /* - * Copyright 1997-2008 by Eric House (xwords@eehouse.org). All rights + * Copyright 1997-2011 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -91,6 +91,7 @@ static XP_Bool curses_draw_trayBegin( DrawCtx* XP_UNUSED(p_dctx), const XP_Rect* XP_UNUSED(rect), XP_U16 XP_UNUSED(owner), + XP_S16 XP_UNUSED(score), DrawFocusState XP_UNUSED(dfs) ) { return XP_TRUE; diff --git a/xwords4/linux/gtkdraw.c b/xwords4/linux/gtkdraw.c index eff227101..5d8326361 100644 --- a/xwords4/linux/gtkdraw.c +++ b/xwords4/linux/gtkdraw.c @@ -1,6 +1,6 @@ -/* -*- mode: C; fill-column: 78; c-basic-offset: 4; compile-command: "make MEMDEBUG=TRUE"; -*- */ +/* -*- compile-command: "make MEMDEBUG=TRUE -j3"; -*- */ /* - * Copyright 1997-2008 by Eric House (xwords@eehouse.org). All rights + * Copyright 1997-2011 by Eric House (xwords@eehouse.org). All rights * reserved. * * This program is free software; you can redistribute it and/or @@ -634,7 +634,8 @@ gtk_draw_invertCell( DrawCtx* XP_UNUSED(p_dctx), static XP_Bool gtk_draw_trayBegin( DrawCtx* p_dctx, const XP_Rect* XP_UNUSED(rect), - XP_U16 owner, DrawFocusState XP_UNUSED(dfs) ) + XP_U16 owner, XP_S16 XP_UNUSED(owner), + DrawFocusState XP_UNUSED(dfs) ) { GtkDrawCtx* dctx = (GtkDrawCtx*)p_dctx; dctx->trayOwner = owner; @@ -729,7 +730,7 @@ gtk_draw_drawTileMidDrag( DrawCtx* p_dctx, const XP_Rect* rect, const XP_UCHAR* textP, const XP_Bitmaps* bitmaps, XP_U16 val, XP_U16 owner, CellFlags flags ) { - gtk_draw_trayBegin( p_dctx, rect, owner, DFS_NONE ); + gtk_draw_trayBegin( p_dctx, rect, owner, 0, DFS_NONE ); gtkDrawTileImpl( p_dctx, rect, textP, bitmaps, val, flags | CELL_HIGHLIGHT, XP_FALSE ); }