Refer to players as "remote" rather than "not local" to be consistent

with Palm and PPC; fix juggle bug by adjusting lines after moving them.
This commit is contained in:
ehouse 2006-06-08 01:26:18 +00:00
parent e58d397c2b
commit 956c169d08
3 changed files with 43 additions and 50 deletions

View file

@ -91,35 +91,34 @@ void
newg_load( NewGameCtx* ngc, const CurGameInfo* gi ) newg_load( NewGameCtx* ngc, const CurGameInfo* gi )
{ {
void* closure = ngc->closure; void* closure = ngc->closure;
NGValue cValue; NGValue value;
NGValue aValue;
XP_U16 i; XP_U16 i;
ngc->nPlayers = gi->nPlayers; ngc->nPlayers = gi->nPlayers;
aValue.ng_u16 = ngc->nPlayers; value.ng_u16 = ngc->nPlayers;
(*ngc->setAttrProc)( closure, NG_ATTR_NPLAYERS, aValue ); (*ngc->setAttrProc)( closure, NG_ATTR_NPLAYERS, value );
(*ngc->enableAttrProc)( closure, NG_ATTR_NPLAYERS, ngc->isNewGame ); (*ngc->enableAttrProc)( closure, NG_ATTR_NPLAYERS, ngc->isNewGame );
ngc->role = gi->serverRole; ngc->role = gi->serverRole;
aValue.ng_role = ngc->role; value.ng_role = ngc->role;
(*ngc->setAttrProc)( closure, NG_ATTR_ROLE, aValue ); (*ngc->setAttrProc)( closure, NG_ATTR_ROLE, value );
(*ngc->enableAttrProc)( closure, NG_ATTR_ROLE, ngc->isNewGame ); (*ngc->enableAttrProc)( closure, NG_ATTR_ROLE, ngc->isNewGame );
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) { for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
cValue.ng_bool = gi->players[i].isLocal; value.ng_bool = !gi->players[i].isLocal;
(*ngc->setColProc)(closure, i, NG_COL_LOCAL, cValue ); (*ngc->setColProc)(closure, i, NG_COL_REMOTE, value );
#endif #endif
cValue.ng_cp = gi->players[i].name; value.ng_cp = gi->players[i].name;
(*ngc->setColProc)(closure, i, NG_COL_NAME, cValue ); (*ngc->setColProc)(closure, i, NG_COL_NAME, value );
cValue.ng_cp = gi->players[i].password; value.ng_cp = gi->players[i].password;
(*ngc->setColProc)(closure, i, NG_COL_PASSWD, cValue ); (*ngc->setColProc)(closure, i, NG_COL_PASSWD, value );
cValue.ng_bool = gi->players[i].isRobot; value.ng_bool = gi->players[i].isRobot;
(*ngc->setColProc)(closure, i, NG_COL_ROBOT, cValue ); (*ngc->setColProc)(closure, i, NG_COL_ROBOT, value );
} }
adjustAllRows( ngc, XP_TRUE ); adjustAllRows( ngc, XP_TRUE );
@ -141,7 +140,7 @@ cpToGI( NGValue value, const void* cbClosure )
switch ( cpcl->col ) { switch ( cpcl->col ) {
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
case NG_COL_LOCAL: case NG_COL_REMOTE:
pl->isLocal = value.ng_bool; pl->isLocal = value.ng_bool;
break; break;
#endif #endif
@ -189,8 +188,11 @@ void
newg_colChanged( NewGameCtx* ngc, XP_U16 player, NewGameColumn col, newg_colChanged( NewGameCtx* ngc, XP_U16 player, NewGameColumn col,
NGValue value ) NGValue value )
{ {
XP_ASSERT( player < ngc->nPlayers ); /* Sometimes we'll get this notification for inactive rows, e.g. when
adjustOneRow( ngc, player, XP_FALSE ); setting default values. */
if ( player < ngc->nPlayers ) {
adjustOneRow( ngc, player, XP_FALSE );
}
} }
void void
@ -240,7 +242,7 @@ deepCopy( NGValue value, const void* closure )
DeepValue* dvp = (DeepValue*)closure; DeepValue* dvp = (DeepValue*)closure;
switch ( dvp->col ) { switch ( dvp->col ) {
case NG_COL_ROBOT: case NG_COL_ROBOT:
case NG_COL_LOCAL: case NG_COL_REMOTE:
dvp->value.ng_bool = value.ng_bool; dvp->value.ng_bool = value.ng_bool;
break; break;
case NG_COL_NAME: case NG_COL_NAME:
@ -302,18 +304,12 @@ newg_juggle( NewGameCtx* ngc )
(*ngc->getColProc)(closure, pos[0], col, deepCopy, &tmpValues[col] ); (*ngc->getColProc)(closure, pos[0], col, deepCopy, &tmpValues[col] );
} }
/* Strings must be copied */
/* for ( col = 0; col < sizeof(strCols)/sizeof(strCols[0]); ++col ) { */
/* NewGameColumn strCol = strCols[col]; */
/* tmpValues[strCol].ng_cp = copyString( MPPARM(ngc->mpool) */
/* tmpValues[strCol].ng_cp ); */
/* } */
cur = 0; cur = 0;
while ( ++cur < nPlayers ) { while ( ++cur < nPlayers ) {
XP_LOGF( "%s: copying player %d to player %d", __FUNCTION__, XP_LOGF( "%s: copying player %d to player %d", __FUNCTION__,
pos[cur], pos[cur-1] ); pos[cur], pos[cur-1] );
copyFromTo( ngc, pos[cur], pos[cur-1] ); copyFromTo( ngc, pos[cur], pos[cur-1] );
adjustOneRow( ngc, pos[cur-1], XP_FALSE );
} }
--cur; --cur;
@ -323,11 +319,7 @@ newg_juggle( NewGameCtx* ngc )
(*ngc->setColProc)(closure, pos[cur], col, tmpValues[col].value ); (*ngc->setColProc)(closure, pos[cur], col, tmpValues[col].value );
deepFree( &tmpValues[col] ); deepFree( &tmpValues[col] );
} }
/* copied strings must be freed */ adjustOneRow( ngc, pos[cur], XP_FALSE );
/* for ( col = 0; col < sizeof(strCols)/sizeof(strCols[0]); ++col ) { */
/* NewGameColumn strCol = strCols[col]; */
/* XP_FREE( ngc->mpool, (void*)tmpValues[strCol].ng_cp ); */
/* } */
} }
} /* newg_juggle */ } /* newg_juggle */
@ -359,7 +351,6 @@ adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force )
XP_MEMSET( enable, 0, sizeof(enable) ); XP_MEMSET( enable, 0, sizeof(enable) );
XP_Bool isLocal = XP_TRUE; XP_Bool isLocal = XP_TRUE;
DeepValue dValue; DeepValue dValue;
/* NGValue value; */
/* If there aren't this many players, all are disabled */ /* If there aren't this many players, all are disabled */
if ( player >= ngc->nPlayers ) { if ( player >= ngc->nPlayers ) {
@ -368,12 +359,13 @@ adjustOneRow( NewGameCtx* ngc, XP_U16 player, XP_Bool force )
} else { } else {
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
/* If standalone or client, local is disabled */ /* If standalone or client, remote is disabled */
if ( ngc->role == SERVER_ISSERVER ) { if ( ngc->role == SERVER_ISSERVER ) {
enable[NG_COL_LOCAL] = XP_TRUE; enable[NG_COL_REMOTE] = XP_TRUE;
dValue.col = NG_COL_LOCAL; dValue.col = NG_COL_REMOTE;
(*ngc->getColProc)( ngc->closure, player, NG_COL_LOCAL, deepCopy, &dValue ); (*ngc->getColProc)( ngc->closure, player, NG_COL_REMOTE,
isLocal = dValue.value.ng_bool; deepCopy, &dValue );
isLocal = !dValue.value.ng_bool;
} }
#endif #endif

View file

@ -42,7 +42,7 @@ typedef struct NewGameCtx NewGameCtx;
typedef enum { typedef enum {
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
NG_COL_LOCAL NG_COL_REMOTE
#endif #endif
,NG_COL_NAME ,NG_COL_NAME
,NG_COL_ROBOT ,NG_COL_ROBOT

View file

@ -44,7 +44,7 @@ typedef struct GtkNewGameState {
short nCols; /* for board size */ short nCols; /* for board size */
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
GtkWidget* localChecks[MAX_NUM_PLAYERS]; GtkWidget* remoteChecks[MAX_NUM_PLAYERS];
#endif #endif
GtkWidget* robotChecks[MAX_NUM_PLAYERS]; GtkWidget* robotChecks[MAX_NUM_PLAYERS];
GtkWidget* nameFields[MAX_NUM_PLAYERS]; GtkWidget* nameFields[MAX_NUM_PLAYERS];
@ -129,9 +129,9 @@ handle_juggle( GtkWidget* item, GtkNewGameState* state )
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
static void static void
handle_local_toggled( GtkWidget* item, GtkNewGameState* state ) handle_remote_toggled( GtkWidget* item, GtkNewGameState* state )
{ {
callChangedWithIndex( state, item, state->localChecks, NG_COL_LOCAL ); callChangedWithIndex( state, item, state->remoteChecks, NG_COL_REMOTE );
} }
#endif #endif
@ -271,15 +271,15 @@ makeNewGameDialog( GtkNewGameState* state )
for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) { for ( i = 0; i < MAX_NUM_PLAYERS; ++i ) {
GtkWidget* label = gtk_label_new("Name:"); GtkWidget* label = gtk_label_new("Name:");
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
GtkWidget* localCheck = gtk_check_button_new_with_label( "Local" ); GtkWidget* remoteCheck = gtk_check_button_new_with_label( "Remote" );
#endif #endif
GtkWidget* nameField = gtk_entry_new(); GtkWidget* nameField = gtk_entry_new();
GtkWidget* passwdField = gtk_entry_new_with_max_length( 6 ); GtkWidget* passwdField = gtk_entry_new_with_max_length( 6 );
GtkWidget* robotCheck = gtk_check_button_new_with_label( "Robot" ); GtkWidget* robotCheck = gtk_check_button_new_with_label( "Robot" );
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
g_signal_connect( GTK_OBJECT(localCheck), "toggled", g_signal_connect( GTK_OBJECT(remoteCheck), "toggled",
GTK_SIGNAL_FUNC(handle_local_toggled), state ); GTK_SIGNAL_FUNC(handle_remote_toggled), state );
#endif #endif
g_signal_connect( GTK_OBJECT(robotCheck), "toggled", g_signal_connect( GTK_OBJECT(robotCheck), "toggled",
GTK_SIGNAL_FUNC(handle_robot_toggled), state ); GTK_SIGNAL_FUNC(handle_robot_toggled), state );
@ -287,9 +287,9 @@ makeNewGameDialog( GtkNewGameState* state )
hbox = gtk_hbox_new( FALSE, 0 ); hbox = gtk_hbox_new( FALSE, 0 );
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
gtk_box_pack_start( GTK_BOX(hbox), localCheck, FALSE, TRUE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), remoteCheck, FALSE, TRUE, 0 );
gtk_widget_show( localCheck ); gtk_widget_show( remoteCheck );
state->localChecks[i] = localCheck; state->remoteChecks[i] = remoteCheck;
#endif #endif
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 ); gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 );
@ -385,8 +385,8 @@ widgetForCol( const GtkNewGameState* state, XP_U16 player, NewGameColumn col )
} else if ( col == NG_COL_PASSWD ) { } else if ( col == NG_COL_PASSWD ) {
widget = state->passwdFields[player]; widget = state->passwdFields[player];
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
} else if ( col == NG_COL_LOCAL ) { } else if ( col == NG_COL_REMOTE ) {
widget = state->localChecks[player]; widget = state->remoteChecks[player];
#endif #endif
} else if ( col == NG_COL_ROBOT ) { } else if ( col == NG_COL_ROBOT ) {
widget = state->robotChecks[player]; widget = state->robotChecks[player];
@ -432,7 +432,7 @@ gtk_newgame_col_set( void* closure, XP_U16 player, NewGameColumn col,
gtk_entry_set_text( GTK_ENTRY(widget), cp ); gtk_entry_set_text( GTK_ENTRY(widget), cp );
break; break;
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
case NG_COL_LOCAL: case NG_COL_REMOTE:
#endif #endif
case NG_COL_ROBOT: case NG_COL_ROBOT:
gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(widget), gtk_toggle_button_set_state( GTK_TOGGLE_BUTTON(widget),
@ -451,7 +451,7 @@ gtk_newgame_col_get( void* closure, XP_U16 player, NewGameColumn col,
GtkWidget* widget = widgetForCol( state, player, col ); GtkWidget* widget = widgetForCol( state, player, col );
switch ( col ) { switch ( col ) {
#ifndef XWFEATURE_STANDALONE_ONLY #ifndef XWFEATURE_STANDALONE_ONLY
case NG_COL_LOCAL: case NG_COL_REMOTE:
#endif #endif
case NG_COL_ROBOT: case NG_COL_ROBOT:
value.ng_bool = value.ng_bool =
@ -510,6 +510,7 @@ newGameDialog( GtkAppGlobals* globals/* , GtkGameInfo* gameInfo */ )
newg_store( state.newGameCtxt, &globals->cGlobals.params->gi ); newg_store( state.newGameCtxt, &globals->cGlobals.params->gi );
} }
newg_destroy( state.newGameCtxt );
gtk_widget_destroy( dialog ); gtk_widget_destroy( dialog );
} while ( state.revert ); } while ( state.revert );