From 45979f547aa0e4e8ccb2fabb247943b0c162b6b6 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sun, 18 Jun 2006 19:02:47 +0000 Subject: [PATCH] disable juggle button if only one player active; copy all four players when saving game state after dismissal. --- xwords4/common/nwgamest.c | 25 +++++++++++++++++++++---- xwords4/common/nwgamest.h | 1 + xwords4/linux/gtknewgame.c | 23 +++++++++++++---------- xwords4/wince/ceginfo.c | 4 +++- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/xwords4/common/nwgamest.c b/xwords4/common/nwgamest.c index 0a85c4b3a..f5de193a0 100644 --- a/xwords4/common/nwgamest.c +++ b/xwords4/common/nwgamest.c @@ -46,6 +46,7 @@ struct NewGameCtx { Connectedness role; #endif XP_Bool isNewGame; + NewGameEnable juggleEnabled; MPSLOT }; @@ -55,7 +56,7 @@ static void enableOne( NewGameCtx* ngc, XP_U16 player, NewGameColumn col, static void adjustAllRows( NewGameCtx* ngc, XP_Bool force ); static void adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force ); static void setRoleStrings( NewGameCtx* ngc ); - +static void considerEnableJuggle( NewGameCtx* ngc ); NewGameCtx* newg_make( MPFORMAL XP_Bool isNewGame, @@ -108,6 +109,7 @@ newg_load( NewGameCtx* ngc, const CurGameInfo* gi ) NGEnableEnabled : NGEnableDisabled ); #endif setRoleStrings( ngc ); + considerEnableJuggle( ngc ); for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) { @@ -169,19 +171,20 @@ cpToGI( NGValue value, const void* cbClosure ) void newg_store( NewGameCtx* ngc, CurGameInfo* gi ) { - XP_U16 nPlayers; void* closure = ngc->closure; NGCopyClosure cpcl; cpcl.ngc = ngc; cpcl.gi = gi; - gi->nPlayers = nPlayers = ngc->nPlayers; + gi->nPlayers = ngc->nPlayers; #ifndef XWFEATURE_STANDALONE_ONLY gi->serverRole = ngc->role; #endif - for ( cpcl.player = 0; cpcl.player < nPlayers; ++cpcl.player ) { + for ( cpcl.player = 0; + cpcl.player < (sizeof(gi->players)/sizeof(gi->players[0])); + ++cpcl.player ) { for ( cpcl.col = 0; cpcl.col < NG_NUM_COLS; ++cpcl.col ) { (*ngc->getColProc)( closure, cpcl.player, cpcl.col, cpToGI, &cpcl ); @@ -206,6 +209,7 @@ newg_attrChanged( NewGameCtx* ngc, NewGameAttr attr, NGValue value ) XP_LOGF( "%s(%d)", __FUNCTION__ ); if ( attr == NG_ATTR_NPLAYERS ) { ngc->nPlayers = value.ng_u16; + considerEnableJuggle( ngc ); #ifndef XWFEATURE_STANDALONE_ONLY } else if ( NG_ATTR_ROLE == attr ) { ngc->role = value.ng_role; @@ -422,6 +426,19 @@ setRoleStrings( NewGameCtx* ngc ) (*ngc->setAttrProc)( closure, NG_ATTR_NPLAYHEADER, value ); } /* setRoleStrings */ +static void +considerEnableJuggle( NewGameCtx* ngc ) +{ + NewGameEnable newEnable; + newEnable = (ngc->isNewGame && ngc->nPlayers > 1)? + NGEnableEnabled : NGEnableDisabled; + + if ( newEnable != ngc->juggleEnabled ) { + (*ngc->enableAttrProc)( ngc->closure, NG_ATTR_CANJUGGLE, newEnable ); + ngc->juggleEnabled = newEnable; + } +} /* considerEnableJuggle */ + #ifdef CPLUS } #endif diff --git a/xwords4/common/nwgamest.h b/xwords4/common/nwgamest.h index 52ed71977..85b64048c 100644 --- a/xwords4/common/nwgamest.h +++ b/xwords4/common/nwgamest.h @@ -57,6 +57,7 @@ typedef enum { #endif NG_ATTR_NPLAYERS ,NG_ATTR_NPLAYHEADER + ,NG_ATTR_CANJUGGLE } NewGameAttr; typedef enum { NGEnableHidden, diff --git a/xwords4/linux/gtknewgame.c b/xwords4/linux/gtknewgame.c index 84101e393..d6cc8b3ee 100644 --- a/xwords4/linux/gtknewgame.c +++ b/xwords4/linux/gtknewgame.c @@ -54,6 +54,7 @@ typedef struct GtkNewGameState { GtkWidget* nPlayersMenu; GtkWidget* roleMenu; GtkWidget* nPlayersLabel; + GtkWidget* juggleButton; GtkWidget* roleMenuItems[3]; } GtkNewGameState; @@ -212,7 +213,6 @@ makeNewGameDialog( GtkNewGameState* state, XP_Bool isNewGame ) GtkWidget* nPlayersMenu; GtkWidget* boardSizeMenu; GtkWidget* opt; - GtkWidget* juggleButton; CurGameInfo* gi; short i; char* roles[] = { "Standalone", "Host", "Guest" }; @@ -264,10 +264,10 @@ makeNewGameDialog( GtkNewGameState* state, XP_Bool isNewGame ) gtk_widget_show( opt ); gtk_box_pack_start( GTK_BOX(hbox), opt, FALSE, TRUE, 0 ); - juggleButton = makeButton( "Juggle", GTK_SIGNAL_FUNC(handle_juggle), - state ); - gtk_box_pack_start( GTK_BOX(hbox), juggleButton, FALSE, TRUE, 0 ); - gtk_widget_set_sensitive( juggleButton, isNewGame ); + state->juggleButton = makeButton( "Juggle", + GTK_SIGNAL_FUNC(handle_juggle), + state ); + gtk_box_pack_start( GTK_BOX(hbox), state->juggleButton, FALSE, TRUE, 0 ); gtk_widget_show( hbox ); gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 ); @@ -440,14 +440,17 @@ static void gtk_newgame_attr_enable( void* closure, NewGameAttr attr, NewGameEnable enable ) { GtkNewGameState* state = (GtkNewGameState*)closure; - GtkWidget* menu = NULL; + GtkWidget* widget = NULL; if ( attr == NG_ATTR_NPLAYERS ) { - menu = state->nPlayersMenu; + widget = state->nPlayersMenu; } else if ( attr == NG_ATTR_ROLE ) { - menu = state->roleMenu; + widget = state->roleMenu; + } else if ( attr == NG_ATTR_CANJUGGLE ) { + widget = state->juggleButton; } - if ( !!menu ) { - gtk_widget_set_sensitive( menu, enable == NGEnableEnabled ); + + if ( !!widget ) { + gtk_widget_set_sensitive( widget, enable == NGEnableEnabled ); } } diff --git a/xwords4/wince/ceginfo.c b/xwords4/wince/ceginfo.c index b2f256d37..262f58cfe 100755 --- a/xwords4/wince/ceginfo.c +++ b/xwords4/wince/ceginfo.c @@ -196,7 +196,6 @@ loadFromGameInfo( HWND hDlg, CEAppGlobals* globals, GameInfoState* giState ) if ( !giState->isNewGame ) { ceEnOrDisable( hDlg, IDC_DICTCOMBO, XP_FALSE ); - ceEnOrDisable( hDlg, GIJUGGLE_BUTTON, XP_FALSE ); } } /* loadFromGameInfo */ @@ -318,6 +317,9 @@ resIDForAttr( NewGameAttr attr ) case NG_ATTR_NPLAYHEADER: resID = IDC_TOTAL_LABEL; break; + case NG_ATTR_CANJUGGLE: + resID = GIJUGGLE_BUTTON; + break; } XP_ASSERT( resID != 0 ); return resID;