mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-01-14 08:01:38 +01:00
Support new tri-part enabled type; add "game info" dialog/menu to test
read-only side; support new attributes for column head and nplayers label; hide labels as well as controls that go with them.
This commit is contained in:
parent
44abbc4493
commit
b80808bc57
5 changed files with 89 additions and 25 deletions
|
@ -50,6 +50,10 @@ enum {
|
||||||
STRD_TRADED,
|
STRD_TRADED,
|
||||||
STR_LOSTTURN,
|
STR_LOSTTURN,
|
||||||
|
|
||||||
|
STR_LOCALPLAYERS,
|
||||||
|
STR_TOTALPLAYERS,
|
||||||
|
STR_REMOTE,
|
||||||
|
|
||||||
STRS_VALUES_HEADER,
|
STRS_VALUES_HEADER,
|
||||||
|
|
||||||
STR_LAST
|
STR_LAST
|
||||||
|
|
|
@ -539,7 +539,7 @@ new_game( GtkWidget* widget, GtkAppGlobals* globals )
|
||||||
{
|
{
|
||||||
gboolean confirmed;
|
gboolean confirmed;
|
||||||
|
|
||||||
confirmed = newGameDialog( globals );
|
confirmed = newGameDialog( globals, XP_TRUE );
|
||||||
if ( confirmed ) {
|
if ( confirmed ) {
|
||||||
CurGameInfo* gi = &globals->cGlobals.params->gi;
|
CurGameInfo* gi = &globals->cGlobals.params->gi;
|
||||||
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
XP_Bool isClient = gi->serverRole == SERVER_ISCLIENT;
|
||||||
|
@ -568,6 +568,16 @@ new_game( GtkWidget* widget, GtkAppGlobals* globals )
|
||||||
|
|
||||||
} /* new_game */
|
} /* new_game */
|
||||||
|
|
||||||
|
static void
|
||||||
|
game_info( GtkWidget* widget, GtkAppGlobals* globals )
|
||||||
|
{
|
||||||
|
/* Anything to do if OK is clicked? Changed names etc. already saved. Try
|
||||||
|
server_do in case one's become a robot. */
|
||||||
|
if ( newGameDialog( globals, XP_FALSE ) ) {
|
||||||
|
(void)server_do( globals->cGlobals.game.server ); /* assign tiles, etc. */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
load_game( GtkWidget* widget, GtkAppGlobals* globals )
|
load_game( GtkWidget* widget, GtkAppGlobals* globals )
|
||||||
{
|
{
|
||||||
|
@ -689,6 +699,8 @@ makeMenus( GtkAppGlobals* globals, int argc, char** argv )
|
||||||
|
|
||||||
(void)createAddItem( fileMenu, "New game",
|
(void)createAddItem( fileMenu, "New game",
|
||||||
GTK_SIGNAL_FUNC(new_game), globals );
|
GTK_SIGNAL_FUNC(new_game), globals );
|
||||||
|
(void)createAddItem( fileMenu, "Game info",
|
||||||
|
GTK_SIGNAL_FUNC(game_info), globals );
|
||||||
|
|
||||||
(void)createAddItem( fileMenu, "Load game",
|
(void)createAddItem( fileMenu, "Load game",
|
||||||
GTK_SIGNAL_FUNC(load_game), globals );
|
GTK_SIGNAL_FUNC(load_game), globals );
|
||||||
|
|
|
@ -47,10 +47,13 @@ typedef struct GtkNewGameState {
|
||||||
GtkWidget* remoteChecks[MAX_NUM_PLAYERS];
|
GtkWidget* remoteChecks[MAX_NUM_PLAYERS];
|
||||||
#endif
|
#endif
|
||||||
GtkWidget* robotChecks[MAX_NUM_PLAYERS];
|
GtkWidget* robotChecks[MAX_NUM_PLAYERS];
|
||||||
|
GtkWidget* nameLabels[MAX_NUM_PLAYERS];
|
||||||
GtkWidget* nameFields[MAX_NUM_PLAYERS];
|
GtkWidget* nameFields[MAX_NUM_PLAYERS];
|
||||||
|
GtkWidget* passwdLabels[MAX_NUM_PLAYERS];
|
||||||
GtkWidget* passwdFields[MAX_NUM_PLAYERS];
|
GtkWidget* passwdFields[MAX_NUM_PLAYERS];
|
||||||
GtkWidget* nPlayersMenu;
|
GtkWidget* nPlayersMenu;
|
||||||
GtkWidget* roleMenu;
|
GtkWidget* roleMenu;
|
||||||
|
GtkWidget* nPlayersLabel;
|
||||||
|
|
||||||
GtkWidget* roleMenuItems[3];
|
GtkWidget* roleMenuItems[3];
|
||||||
} GtkNewGameState;
|
} GtkNewGameState;
|
||||||
|
@ -199,7 +202,7 @@ makeButton( char* text, GCallback func, gpointer data )
|
||||||
} /* makeButton */
|
} /* makeButton */
|
||||||
|
|
||||||
static GtkWidget*
|
static GtkWidget*
|
||||||
makeNewGameDialog( GtkNewGameState* state )
|
makeNewGameDialog( GtkNewGameState* state, XP_Bool isNewGame )
|
||||||
{
|
{
|
||||||
GtkWidget* dialog;
|
GtkWidget* dialog;
|
||||||
GtkWidget* vbox;
|
GtkWidget* vbox;
|
||||||
|
@ -209,6 +212,7 @@ makeNewGameDialog( GtkNewGameState* state )
|
||||||
GtkWidget* nPlayersMenu;
|
GtkWidget* nPlayersMenu;
|
||||||
GtkWidget* boardSizeMenu;
|
GtkWidget* boardSizeMenu;
|
||||||
GtkWidget* opt;
|
GtkWidget* opt;
|
||||||
|
GtkWidget* juggleButton;
|
||||||
CurGameInfo* gi;
|
CurGameInfo* gi;
|
||||||
short i;
|
short i;
|
||||||
char* roles[] = { "Standalone", "Host", "Guest" };
|
char* roles[] = { "Standalone", "Host", "Guest" };
|
||||||
|
@ -239,8 +243,8 @@ makeNewGameDialog( GtkNewGameState* state )
|
||||||
|
|
||||||
/* NPlayers menu */
|
/* NPlayers menu */
|
||||||
hbox = gtk_hbox_new( FALSE, 0 );
|
hbox = gtk_hbox_new( FALSE, 0 );
|
||||||
gtk_box_pack_start( GTK_BOX(hbox), gtk_label_new("Number of players"),
|
state->nPlayersLabel = gtk_label_new("");
|
||||||
FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(hbox), state->nPlayersLabel, FALSE, TRUE, 0 );
|
||||||
|
|
||||||
opt = gtk_option_menu_new();
|
opt = gtk_option_menu_new();
|
||||||
nPlayersMenu = gtk_menu_new();
|
nPlayersMenu = gtk_menu_new();
|
||||||
|
@ -260,10 +264,10 @@ makeNewGameDialog( GtkNewGameState* state )
|
||||||
gtk_widget_show( opt );
|
gtk_widget_show( opt );
|
||||||
gtk_box_pack_start( GTK_BOX(hbox), opt, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(hbox), opt, FALSE, TRUE, 0 );
|
||||||
|
|
||||||
gtk_box_pack_start( GTK_BOX(hbox),
|
juggleButton = makeButton( "Juggle", GTK_SIGNAL_FUNC(handle_juggle),
|
||||||
makeButton( "Juggle", GTK_SIGNAL_FUNC(handle_juggle),
|
state );
|
||||||
state ),
|
gtk_box_pack_start( GTK_BOX(hbox), juggleButton, FALSE, TRUE, 0 );
|
||||||
FALSE, TRUE, 0 );
|
gtk_widget_set_sensitive( juggleButton, isNewGame );
|
||||||
gtk_widget_show( hbox );
|
gtk_widget_show( hbox );
|
||||||
|
|
||||||
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
|
||||||
|
@ -294,6 +298,7 @@ makeNewGameDialog( GtkNewGameState* state )
|
||||||
|
|
||||||
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 );
|
||||||
gtk_widget_show( label );
|
gtk_widget_show( label );
|
||||||
|
state->nameLabels[i] = label;
|
||||||
|
|
||||||
gtk_box_pack_start( GTK_BOX(hbox), nameField, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(hbox), nameField, FALSE, TRUE, 0 );
|
||||||
gtk_widget_show( nameField );
|
gtk_widget_show( nameField );
|
||||||
|
@ -306,6 +311,7 @@ makeNewGameDialog( GtkNewGameState* state )
|
||||||
label = gtk_label_new("Passwd:");
|
label = gtk_label_new("Passwd:");
|
||||||
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 );
|
||||||
gtk_widget_show( label );
|
gtk_widget_show( label );
|
||||||
|
state->passwdLabels[i] = label;
|
||||||
|
|
||||||
gtk_box_pack_start( GTK_BOX(hbox), passwdField, FALSE, TRUE, 0 );
|
gtk_box_pack_start( GTK_BOX(hbox), passwdField, FALSE, TRUE, 0 );
|
||||||
gtk_widget_show( passwdField );
|
gtk_widget_show( passwdField );
|
||||||
|
@ -395,16 +401,43 @@ widgetForCol( const GtkNewGameState* state, XP_U16 player, NewGameColumn col )
|
||||||
return widget;
|
return widget;
|
||||||
} /* widgetForCol */
|
} /* widgetForCol */
|
||||||
|
|
||||||
static void
|
static GtkWidget*
|
||||||
gtk_newgame_col_enable( void* closure, XP_U16 player, NewGameColumn col,
|
labelForCol( const GtkNewGameState* state, XP_U16 player, NewGameColumn col )
|
||||||
XP_Bool enable )
|
|
||||||
{
|
{
|
||||||
GtkNewGameState* state = (GtkNewGameState*)closure;
|
GtkWidget* widget = NULL;
|
||||||
gtk_widget_set_sensitive( widgetForCol( state, player, col ), enable );
|
if ( col == NG_COL_NAME ) {
|
||||||
}
|
widget = state->nameLabels[player];
|
||||||
|
} else if ( col == NG_COL_PASSWD ) {
|
||||||
|
widget = state->passwdLabels[player];
|
||||||
|
}
|
||||||
|
return widget;
|
||||||
|
} /* widgetForCol */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gtk_newgame_attr_enable( void* closure, NewGameAttr attr, XP_Bool enable )
|
gtk_newgame_col_enable( void* closure, XP_U16 player, NewGameColumn col,
|
||||||
|
NewGameEnable enable )
|
||||||
|
{
|
||||||
|
GtkNewGameState* state = (GtkNewGameState*)closure;
|
||||||
|
GtkWidget* widget = widgetForCol( state, player, col );
|
||||||
|
GtkWidget* label = labelForCol( state, player, col );
|
||||||
|
|
||||||
|
if ( enable == NGEnableHidden ) {
|
||||||
|
gtk_widget_hide( widget );
|
||||||
|
if ( !!label ) {
|
||||||
|
gtk_widget_hide( label );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
gtk_widget_show( widget );
|
||||||
|
gtk_widget_set_sensitive( widget, enable == NGEnableEnabled );
|
||||||
|
if ( !!label ) {
|
||||||
|
gtk_widget_show( label );
|
||||||
|
gtk_widget_set_sensitive( label, enable == NGEnableEnabled );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} /* gtk_newgame_col_enable */
|
||||||
|
|
||||||
|
static void
|
||||||
|
gtk_newgame_attr_enable( void* closure, NewGameAttr attr, NewGameEnable enable )
|
||||||
{
|
{
|
||||||
GtkNewGameState* state = (GtkNewGameState*)closure;
|
GtkNewGameState* state = (GtkNewGameState*)closure;
|
||||||
GtkWidget* menu = NULL;
|
GtkWidget* menu = NULL;
|
||||||
|
@ -413,8 +446,9 @@ gtk_newgame_attr_enable( void* closure, NewGameAttr attr, XP_Bool enable )
|
||||||
} else if ( attr == NG_ATTR_ROLE ) {
|
} else if ( attr == NG_ATTR_ROLE ) {
|
||||||
menu = state->roleMenu;
|
menu = state->roleMenu;
|
||||||
}
|
}
|
||||||
XP_ASSERT( !!menu );
|
if ( !!menu ) {
|
||||||
gtk_widget_set_sensitive( menu, enable );
|
gtk_widget_set_sensitive( menu, enable == NGEnableEnabled );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -476,20 +510,24 @@ gtk_newgame_attr_set( void* closure, NewGameAttr attr, NGValue value )
|
||||||
gtk_menu_set_active( GTK_MENU(state->nPlayersMenu), i-1 );
|
gtk_menu_set_active( GTK_MENU(state->nPlayersMenu), i-1 );
|
||||||
} else if ( attr == NG_ATTR_ROLE ) {
|
} else if ( attr == NG_ATTR_ROLE ) {
|
||||||
|
|
||||||
|
} else if ( attr == NG_ATTR_REMHEADER ) {
|
||||||
|
/* ignored on GTK: no headers at all */
|
||||||
|
} else if ( attr == NG_ATTR_NPLAYHEADER ) {
|
||||||
|
gtk_label_set_text( GTK_LABEL(state->nPlayersLabel), value.ng_cp );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
newGameDialog( GtkAppGlobals* globals/* , GtkGameInfo* gameInfo */ )
|
newGameDialog( GtkAppGlobals* globals, XP_Bool isNewGame )
|
||||||
{
|
{
|
||||||
GtkNewGameState state;
|
GtkNewGameState state;
|
||||||
XP_MEMSET( &state, 0, sizeof(state) );
|
XP_MEMSET( &state, 0, sizeof(state) );
|
||||||
|
|
||||||
state.globals = globals;
|
state.globals = globals;
|
||||||
state.newGameCtxt = newg_make( MPPARM(globals->cGlobals.params
|
state.newGameCtxt = newg_make( MPPARM(globals->cGlobals.params
|
||||||
->util->mpool)
|
->util->mpool)
|
||||||
XP_TRUE, /* does gtk have concept of new
|
isNewGame,
|
||||||
game yet? */
|
globals->cGlobals.params->util,
|
||||||
gtk_newgame_col_enable,
|
gtk_newgame_col_enable,
|
||||||
gtk_newgame_attr_enable,
|
gtk_newgame_attr_enable,
|
||||||
gtk_newgame_col_get,
|
gtk_newgame_col_get,
|
||||||
|
@ -499,21 +537,22 @@ newGameDialog( GtkAppGlobals* globals/* , GtkGameInfo* gameInfo */ )
|
||||||
|
|
||||||
/* returns when button handler calls gtk_main_quit */
|
/* returns when button handler calls gtk_main_quit */
|
||||||
do {
|
do {
|
||||||
GtkWidget* dialog = makeNewGameDialog( &state );
|
GtkWidget* dialog = makeNewGameDialog( &state, isNewGame );
|
||||||
state.revert = FALSE;
|
state.revert = FALSE;
|
||||||
|
|
||||||
newg_load( state.newGameCtxt,
|
newg_load( state.newGameCtxt,
|
||||||
&globals->cGlobals.params->gi );
|
&globals->cGlobals.params->gi );
|
||||||
|
|
||||||
gtk_main();
|
gtk_main();
|
||||||
if ( !state.cancelled && !state.revert ) {
|
if ( !state.cancelled && !state.revert ) {
|
||||||
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 );
|
||||||
|
|
||||||
|
newg_destroy( state.newGameCtxt );
|
||||||
|
|
||||||
return !state.cancelled;
|
return !state.cancelled;
|
||||||
} /* newGameDialog */
|
} /* newGameDialog */
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
#include "gtkmain.h"
|
#include "gtkmain.h"
|
||||||
|
|
||||||
gboolean newGameDialog( GtkAppGlobals* globals );
|
gboolean newGameDialog( GtkAppGlobals* globals, XP_Bool isNewGame );
|
||||||
|
|
||||||
#endif /* _GTKNEWGAME_H_ */
|
#endif /* _GTKNEWGAME_H_ */
|
||||||
#endif /* PLATFORM_GTK */
|
#endif /* PLATFORM_GTK */
|
||||||
|
|
|
@ -532,6 +532,15 @@ linux_util_getUserString( XW_UtilCtxt* uc, XP_U16 code )
|
||||||
case STR_LOSTTURN:
|
case STR_LOSTTURN:
|
||||||
return (XP_UCHAR*)"Lost turn";
|
return (XP_UCHAR*)"Lost turn";
|
||||||
|
|
||||||
|
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||||
|
case STR_LOCALPLAYERS:
|
||||||
|
return (XP_UCHAR*)"Local players";
|
||||||
|
case STR_REMOTE:
|
||||||
|
return (XP_UCHAR*)"Remote";
|
||||||
|
#endif
|
||||||
|
case STR_TOTALPLAYERS:
|
||||||
|
return (XP_UCHAR*)"Total players";
|
||||||
|
|
||||||
case STRS_VALUES_HEADER:
|
case STRS_VALUES_HEADER:
|
||||||
return (XP_UCHAR*)"%s counts/values:\n";
|
return (XP_UCHAR*)"%s counts/values:\n";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue