add new field canHideRack to GameStateInfo and use it to disable menu.

This commit is contained in:
Eric House 2013-11-17 13:54:21 -08:00
parent cae89a60a8
commit 0cc45ad865
7 changed files with 40 additions and 26 deletions

View file

@ -1399,6 +1399,21 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getGi
XWJNI_END();
}
static const SetInfo gsi_ints[] = {
ARR_MEMBER( GameStateInfo, visTileCount ),
ARR_MEMBER( GameStateInfo, trayVisState ),
};
static const SetInfo gsi_bools[] = {
ARR_MEMBER( GameStateInfo,canHint ),
ARR_MEMBER( GameStateInfo, canRedo ),
ARR_MEMBER( GameStateInfo, inTrade ),
ARR_MEMBER( GameStateInfo, tradeTilesSelected ),
ARR_MEMBER( GameStateInfo, canChat ),
ARR_MEMBER( GameStateInfo, canShuffle ),
ARR_MEMBER( GameStateInfo, curTurnSelected ),
ARR_MEMBER( GameStateInfo, canHideRack ),
};
JNIEXPORT void JNICALL
Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState
( JNIEnv* env, jclass C, jint gamePtr, jobject jgsi )
@ -1407,15 +1422,8 @@ Java_org_eehouse_android_xw4_jni_XwJNI_game_1getState
GameStateInfo info;
game_getState( &state->game, &info );
setInt( env, jgsi, "visTileCount", info.visTileCount );
setInt( env, jgsi, "trayVisState", info.trayVisState );
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, "canChat", info.canChat );
setBool( env, jgsi, "canShuffle", info.canShuffle );
setBool( env, jgsi, "curTurnSelected", info.curTurnSelected );
setInts( env, jgsi, (void*)&info, gsi_ints, VSIZE(gsi_ints) );
setBools( env, jgsi, (void*)&info, gsi_bools, VSIZE(gsi_bools) );
XWJNI_END();
}

View file

@ -726,8 +726,6 @@ public class BoardActivity extends XWActivity
MenuItem item;
int strId;
updateMenus( menu );
if ( null != m_gsi ) {
inTrade = m_gsi.inTrade;
menu.setGroupVisible( R.id.group_done, !inTrade );
@ -740,11 +738,21 @@ public class BoardActivity extends XWActivity
}
item = menu.findItem( R.id.board_menu_tray );
item.setTitle( strId );
hideShowItem( menu, R.id.board_menu_flip, m_gsi.visTileCount >= 1 );
hideShowItem( menu, R.id.board_menu_toggle, m_gsi.visTileCount >= 1 );
hideShowItem( menu, R.id.board_menu_juggle, m_gsi.canShuffle );
hideShowItem( menu, R.id.board_menu_undo_current, m_gsi.canRedo );
hideShowItem( menu, R.id.board_menu_hint_prev, m_gsi.canHint );
hideShowItem( menu, R.id.board_menu_hint_next, m_gsi.canHint );
hideShowItem( menu, R.id.board_menu_chat,
BuildConstants.CHAT_SUPPORTED && m_gsi.canChat );
hideShowItem( menu, R.id.board_menu_tray,
!inTrade && m_gsi.canHideRack );
}
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_tray, !inTrade );
Utils.setItemVisible( menu, R.id.board_menu_trade_cancel, inTrade );
Utils.setItemVisible( menu, R.id.board_menu_trade_commit,
@ -2161,20 +2169,6 @@ public class BoardActivity extends XWActivity
}
}
private void updateMenus( Menu menu )
{
if ( null != m_gsi ) {
hideShowItem( menu, R.id.board_menu_flip, m_gsi.visTileCount >= 1 );
hideShowItem( menu, R.id.board_menu_toggle, m_gsi.visTileCount >= 1 );
hideShowItem( menu, R.id.board_menu_juggle, m_gsi.canShuffle );
hideShowItem( menu, R.id.board_menu_undo_current, m_gsi.canRedo );
hideShowItem( menu, R.id.board_menu_hint_prev, m_gsi.canHint );
hideShowItem( menu, R.id.board_menu_hint_next, m_gsi.canHint );
hideShowItem( menu, R.id.board_menu_chat,
BuildConstants.CHAT_SUPPORTED && m_gsi.canChat );
}
}
private void adjustTradeVisibility()
{
m_toolbar.setVisibility( m_inTrade? View.GONE : View.VISIBLE );

View file

@ -112,6 +112,7 @@ public class JNIThread extends Thread {
public boolean canChat;
public boolean canShuffle;
public boolean curTurnSelected;
public boolean canHideRack;
public GameStateInfo clone() {
GameStateInfo obj = null;
try {

View file

@ -697,6 +697,14 @@ board_canShuffle( const BoardCtxt* board )
TRAY_REVEALED == board->trayVisState );
}
XP_Bool
board_canHideRack( const BoardCtxt* board )
{
XP_Bool result = board->boardObscuresTray || !board->gameOver;
LOG_RETURNF( "%d", result );
return result;
}
XP_Bool
board_canTogglePending( const BoardCtxt* board )
{

View file

@ -122,6 +122,7 @@ XP_U16 board_getYOffset( const BoardCtxt* board );
XP_Bool board_curTurnSelected( const BoardCtxt* board );
XP_U16 board_visTileCount( const BoardCtxt* board );
XP_Bool board_canShuffle( const BoardCtxt* board );
XP_Bool board_canHideRack( const BoardCtxt* board );
XP_Bool board_canTogglePending( const BoardCtxt* board );
XP_Bool board_canHint( const BoardCtxt* board );

View file

@ -324,6 +324,7 @@ game_getState( const XWGame* game, GameStateInfo* gsi )
gsi->inTrade = board_inTrade( game->board, &gsi->tradeTilesSelected );
gsi->canChat = !!game->comms && comms_canChat( game->comms );
gsi->canShuffle = board_canShuffle( game->board );
gsi->canHideRack = board_canHideRack( game->board );
}
void

View file

@ -42,6 +42,7 @@ typedef struct _GameStateInfo {
XP_Bool canChat;
XP_Bool canShuffle;
XP_Bool curTurnSelected;
XP_Bool canHideRack;
} GameStateInfo;
typedef struct XWGame {