From c9c498786e56eed794ddb4e53611d37c456babf1 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Fri, 9 Sep 2011 19:04:25 -0700 Subject: [PATCH] add to game state whether any tiles selected. Use that to disable 'commit exchange' button when there's nothing to commit, and get rid of error message used when committing nothing since it's now impossible (on Android). --- xwords4/android/XWords4/jni/xwjni.c | 1 + xwords4/android/XWords4/res/values/strings.xml | 4 +--- .../src/org/eehouse/android/xw4/BoardActivity.java | 9 +++++++-- .../src/org/eehouse/android/xw4/jni/JNIThread.java | 1 + xwords4/common/board.c | 7 +++++-- xwords4/common/board.h | 2 +- xwords4/common/game.c | 2 +- xwords4/common/game.h | 1 + 8 files changed, 18 insertions(+), 9 deletions(-) diff --git a/xwords4/android/XWords4/jni/xwjni.c b/xwords4/android/XWords4/jni/xwjni.c index 8e660940a..1016e4f05 100644 --- a/xwords4/android/XWords4/jni/xwjni.c +++ b/xwords4/android/XWords4/jni/xwjni.c @@ -1182,6 +1182,7 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState setBool( env, jgsi, "canHint", info.canHint ); setBool( env, jgsi, "canRedo", info.canRedo); setBool( env, jgsi, "inTrade", info.inTrade ); + setBool( env, jgsi, "tradeTilesSelected", info.tradeTilesSelected ); setBool( env, jgsi, "gameIsConnected", info.gameIsConnected ); setBool( env, jgsi, "canShuffle", info.canShuffle ); diff --git a/xwords4/android/XWords4/res/values/strings.xml b/xwords4/android/XWords4/res/values/strings.xml index f66e7bc0f..1c723912f 100644 --- a/xwords4/android/XWords4/res/values/strings.xml +++ b/xwords4/android/XWords4/res/values/strings.xml @@ -135,8 +135,6 @@ New pieces must contact others already in place (or the middle square on the first move) You can\'t do that; it\'s not your turn! No peeking at the robot\'s tiles! - Please tap to select tiles to be - exchanged. Too few tiles left to exchange. Tile assignment can\'t be undone. The hint feature is disabled for this game. Enable it for a new game using the Settings dialog. @@ -546,7 +544,7 @@ exchanged. Use the buttons to commit your turn or exit exchange mode. - Entering exchange mode + Tap to select tiles... To start a basic networked two-player game in %s: 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 cc3da1713..4190d2817 100644 --- a/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java +++ b/xwords4/android/XWords4/src/org/eehouse/android/xw4/BoardActivity.java @@ -1078,7 +1078,9 @@ public class BoardActivity extends XWActivity resid = R.string.str_no_peek_robot_tiles; break; case UtilCtxt.ERR_NO_EMPTY_TRADE: - resid = R.string.str_no_empty_trade; + // This should not be possible as the button's + // disabled when no tiles selected. + Assert.fail(); break; case UtilCtxt.ERR_TOO_FEW_TILES_LEFT_TO_TRADE: resid = R.string.str_too_few_tiles_left_to_trade; @@ -1223,9 +1225,9 @@ public class BoardActivity extends XWActivity updateToolbar(); if ( m_inTrade != m_gsi.inTrade ) { m_inTrade = m_gsi.inTrade; - adjustTradeVisibility(); m_view.setInTrade( m_inTrade ); } + adjustTradeVisibility(); } break; } @@ -1437,6 +1439,9 @@ public class BoardActivity extends XWActivity { m_toolbar.setVisibility( m_inTrade? View.GONE : View.VISIBLE ); m_tradeButtons.setVisibility( m_inTrade? View.VISIBLE : View.GONE ); + if ( m_inTrade ) { + m_exchCommmitButton.setEnabled( m_gsi.tradeTilesSelected ); + } } private void setBackgroundColor() 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 5be520ba8..15a1d5b76 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 @@ -94,6 +94,7 @@ public class JNIThread extends Thread { public boolean canHint; public boolean canRedo; public boolean inTrade; + public boolean tradeTilesSelected; public boolean gameIsConnected; public boolean canShuffle; public GameStateInfo clone() { diff --git a/xwords4/common/board.c b/xwords4/common/board.c index f79dfb960..5bc71e17a 100644 --- a/xwords4/common/board.c +++ b/xwords4/common/board.c @@ -1596,9 +1596,12 @@ board_flip( BoardCtxt* board ) } /* board_flip */ XP_Bool -board_inTrade( const BoardCtxt* board ) +board_inTrade( const BoardCtxt* board, XP_Bool* anySelected ) { const PerTurnInfo* pti = &board->pti[board->selPlayer]; + if ( !!anySelected ) { + *anySelected = 0 != pti->traySelBits; + } return pti->tradeInProgress; } @@ -2101,7 +2104,7 @@ board_beginTrade( BoardCtxt* board ) XP_Bool board_endTrade( BoardCtxt* board ) { - XP_Bool result = board_inTrade( board ); + XP_Bool result = board_inTrade( board, NULL ); if ( result ) { PerTurnInfo* pti = board->selInfo; invalSelTradeWindow( board ); diff --git a/xwords4/common/board.h b/xwords4/common/board.h index 92750cf33..dc5fc0cb0 100644 --- a/xwords4/common/board.h +++ b/xwords4/common/board.h @@ -100,7 +100,7 @@ XP_Bool board_draw( BoardCtxt* board ); XP_Bool board_get_flipped( const BoardCtxt* board ); XP_Bool board_flip( BoardCtxt* board ); -XP_Bool board_inTrade( const BoardCtxt* board ); +XP_Bool board_inTrade( const BoardCtxt* board, XP_Bool* anySelected ); XP_Bool board_get_showValues( const BoardCtxt* board ); XP_Bool board_toggle_showValues( BoardCtxt* board ); XP_Bool board_replaceTiles( BoardCtxt* board ); diff --git a/xwords4/common/game.c b/xwords4/common/game.c index 12137b899..20485d761 100644 --- a/xwords4/common/game.c +++ b/xwords4/common/game.c @@ -283,7 +283,7 @@ game_getState( const XWGame* game, GameStateInfo* gsi ) gsi->visTileCount = board_visTileCount( game->board ); gsi->canHint = board_canHint( game->board ); gsi->canRedo = board_canTogglePending( game->board ); - gsi->inTrade = board_inTrade( game->board ); + gsi->inTrade = board_inTrade( game->board, &gsi->tradeTilesSelected ); gsi->gameIsConnected = !!game->comms && comms_canChat( game->comms ); gsi->canShuffle = board_canShuffle( game->board ); } diff --git a/xwords4/common/game.h b/xwords4/common/game.h index d8fcbff15..927d2fa17 100644 --- a/xwords4/common/game.h +++ b/xwords4/common/game.h @@ -93,6 +93,7 @@ typedef struct _GameStateInfo { XP_Bool canHint; XP_Bool canRedo; XP_Bool inTrade; + XP_Bool tradeTilesSelected; XP_Bool gameIsConnected; XP_Bool canShuffle; } GameStateInfo;