From b5d6c513a634aaacc1484f0a23c6ccda79e460d9 Mon Sep 17 00:00:00 2001 From: Eric House Date: Tue, 3 Dec 2013 07:06:48 -0800 Subject: [PATCH] add canUndo to GameStateInfo and use to hide the undo menu --- xwords4/android/XWords4/jni/xwjni.c | 1 + .../src/org/eehouse/android/xw4/BoardActivity.java | 3 ++- .../src/org/eehouse/android/xw4/jni/JNIThread.java | 1 + xwords4/common/board.c | 3 ++- xwords4/common/game.c | 1 + xwords4/common/game.h | 1 + xwords4/common/model.c | 12 ++++++++++++ xwords4/common/model.h | 2 +- 8 files changed, 21 insertions(+), 3 deletions(-) diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 6f0b39f12..7487bb623 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -1409,6 +1409,7 @@ static const SetInfo gsi_ints[] = { }; static const SetInfo gsi_bools[] = { ARR_MEMBER( GameStateInfo,canHint ), + ARR_MEMBER( GameStateInfo, canUndo ), ARR_MEMBER( GameStateInfo, canRedo ), ARR_MEMBER( GameStateInfo, inTrade ), ARR_MEMBER( GameStateInfo, tradeTilesSelected ), 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 8adea27aa..968cdcb0d 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -764,10 +764,11 @@ public class BoardActivity extends XWActivity !inTrade && m_gsi.canHideRack ); Utils.setItemVisible( menu, R.id.board_menu_trade, m_gsi.canTrade ); + Utils.setItemVisible( menu, R.id.board_menu_undo_last, + m_gsi.canUndo ); } Utils.setItemVisible( menu, R.id.board_menu_invite, 0 < m_missing ); - Utils.setItemVisible( menu, R.id.board_menu_undo_last, !inTrade ); Utils.setItemVisible( menu, R.id.board_menu_trade_cancel, inTrade ); Utils.setItemVisible( menu, R.id.board_menu_trade_commit, diff --git a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java index e15d12413..f8e1cc8f9 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/jni/JNIThread.java @@ -105,6 +105,7 @@ public class JNIThread extends Thread { public int visTileCount; public int trayVisState; public boolean canHint; + public boolean canUndo; public boolean canRedo; public boolean inTrade; public boolean tradeTilesSelected; diff --git a/xwords4/common/board.c b/xwords4/common/board.c index 59d42a798..012dc1c46 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -704,7 +704,8 @@ board_canShuffle( const BoardCtxt* board ) XP_Bool board_canHideRack( const BoardCtxt* board ) { - XP_Bool result = board->boardObscuresTray || !board->gameOver; + XP_Bool result = 0 <= server_getCurrentTurn( board->server ) + && (board->boardObscuresTray || !board->gameOver); LOG_RETURNF( "%d", result ); return result; } diff --git a/xwords4/common/game.c b/xwords4/common/game.c index baa24f274..bc145c207 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -321,6 +321,7 @@ game_getState( const XWGame* game, GameStateInfo* gsi ) gsi->trayVisState = board_getTrayVisState( board ); gsi->visTileCount = board_visTileCount( board ); gsi->canHint = !gameOver && board_canHint( board ); + gsi->canUndo = model_canUndo( game->model ); gsi->canRedo = board_canTogglePending( board ); gsi->inTrade = board_inTrade( board, &gsi->tradeTilesSelected ); gsi->canChat = !!game->comms && comms_canChat( game->comms ); diff --git a/xwords4/common/game.h b/xwords4/common/game.h index babb0218f..882a60e2f 100644 --- a/xwords4/common/game.h +++ b/xwords4/common/game.h @@ -36,6 +36,7 @@ typedef struct _GameStateInfo { XP_U16 visTileCount; XW_TrayVisState trayVisState; XP_Bool canHint; + XP_Bool canUndo; XP_Bool canRedo; XP_Bool inTrade; XP_Bool tradeTilesSelected; diff --git a/xwords4/common/model.c b/xwords4/common/model.c index 8016f4fb7..bedaefa22 100644 --- a/xwords4/common/model.c +++ b/xwords4/common/model.c @@ -822,6 +822,18 @@ model_rejectPreviousMove( ModelCtxt* model, PoolContext* pool, XP_U16* turn ) *turn = entry.playerNum; } /* model_rejectPreviousMove */ +XP_Bool +model_canUndo( const ModelCtxt* model ) +{ + const StackCtxt* stack = model->vol.stack; + XP_U16 nStackEntries = stack_getNEntries( stack ); + + /* More than just tile assignment? */ + XP_Bool result = nStackEntries > model->nPlayers; + LOG_RETURNF( "%d", result ); + return result; +} + /* Undo a move, but only if it's the move we're expecting to undo (as * indicated by *moveNumP, if >= 0). */ diff --git a/xwords4/common/model.h b/xwords4/common/model.h index 28634005c..dff98fc3d 100644 --- a/xwords4/common/model.h +++ b/xwords4/common/model.h @@ -192,7 +192,7 @@ void model_commitRejectedPhony( ModelCtxt* model, XP_S16 player ); void model_makeTileTrade( ModelCtxt* model, XP_S16 player, const TrayTileSet* oldTiles, const TrayTileSet* newTiles ); - +XP_Bool model_canUndo( const ModelCtxt* model ); XP_Bool model_undoLatestMoves( ModelCtxt* model, PoolContext* pool, XP_U16 nMovesSought, XP_U16* turn, XP_S16* moveNum );