mirror of
git://xwords.git.sourceforge.net/gitroot/xwords/xwords
synced 2025-02-06 20:45:54 +01:00
add timer to gtk's new-game dialog
This commit is contained in:
parent
42e3ccef50
commit
25cce2c7f3
3 changed files with 63 additions and 7 deletions
|
@ -45,6 +45,7 @@ struct NewGameCtx {
|
|||
XP_U16 nPlayersShown; /* real nPlayers lives in gi */
|
||||
XP_U16 nPlayersTotal; /* used only until changedNPlayers set */
|
||||
XP_U16 nLocalPlayers; /* not changed except in newg_load */
|
||||
XP_U16 timerSeconds;
|
||||
DeviceRole role;
|
||||
XP_Bool isNewGame;
|
||||
XP_Bool changedNPlayers;
|
||||
|
@ -149,6 +150,10 @@ newg_load( NewGameCtx* ngc, const CurGameInfo* gi )
|
|||
(*ngc->enableAttrProc)( closure, NG_ATTR_NPLAYERS, ngc->isNewGame?
|
||||
TRI_ENAB_ENABLED : TRI_ENAB_DISABLED );
|
||||
|
||||
ngc->timerSeconds = gi->gameSeconds;
|
||||
value.ng_u16 = ngc->timerSeconds;
|
||||
(*ngc->setAttrProc)( closure, NG_ATTR_TIMER, value );
|
||||
|
||||
setRoleStrings( ngc );
|
||||
considerEnable( ngc );
|
||||
|
||||
|
@ -225,6 +230,8 @@ newg_store( NewGameCtx* ngc, CurGameInfo* gi,
|
|||
gi->serverRole = ngc->role;
|
||||
makeLocal = ngc->role != SERVER_ISSERVER;
|
||||
#endif
|
||||
gi->gameSeconds = ngc->timerSeconds;
|
||||
gi->timerEnabled = gi->gameSeconds > 0;
|
||||
|
||||
for ( player = 0; player < MAX_NUM_PLAYERS; ++player ) {
|
||||
storePlayer( ngc, player, &gi->players[player] );
|
||||
|
@ -250,17 +257,23 @@ void
|
|||
newg_attrChanged( NewGameCtx* ngc, NewGameAttr attr, NGValue value )
|
||||
{
|
||||
XP_Bool changed = XP_FALSE;
|
||||
if ( attr == NG_ATTR_NPLAYERS ) {
|
||||
switch ( attr ) {
|
||||
case NG_ATTR_NPLAYERS:
|
||||
if ( ngc->nPlayersShown != value.ng_u16 ) {
|
||||
ngc->nPlayersShown = value.ng_u16;
|
||||
ngc->changedNPlayers = XP_TRUE;
|
||||
changed = XP_TRUE;
|
||||
}
|
||||
break;
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
} else if ( NG_ATTR_ROLE == attr ) {
|
||||
case NG_ATTR_ROLE:
|
||||
changed = changeRole( ngc, value.ng_role );
|
||||
break;
|
||||
#endif
|
||||
} else {
|
||||
case NG_ATTR_TIMER:
|
||||
ngc->timerSeconds = value.ng_u16;
|
||||
break;
|
||||
default:
|
||||
XP_ASSERT( 0 );
|
||||
}
|
||||
|
||||
|
|
|
@ -59,6 +59,7 @@ typedef enum {
|
|||
NG_ATTR_NPLAYERS
|
||||
,NG_ATTR_NPLAYHEADER
|
||||
,NG_ATTR_CANJUGGLE
|
||||
,NG_ATTR_TIMER
|
||||
} NewGameAttr;
|
||||
|
||||
typedef union NGValue {
|
||||
|
|
|
@ -61,6 +61,7 @@ typedef struct GtkNewGameState {
|
|||
GtkWidget* nPlayersCombo;
|
||||
GtkWidget* nPlayersLabel;
|
||||
GtkWidget* juggleButton;
|
||||
GtkWidget* timerField;
|
||||
} GtkNewGameState;
|
||||
|
||||
static void
|
||||
|
@ -232,6 +233,30 @@ addPhoniesCombo( GtkNewGameState* state, GtkWidget* parent )
|
|||
gtk_box_pack_start( GTK_BOX(parent), hbox, FALSE, TRUE, 0 );
|
||||
}
|
||||
|
||||
static void
|
||||
on_timer_changed( GtkEditable *editable, gpointer data )
|
||||
{
|
||||
GtkNewGameState* state = (GtkNewGameState*)data;
|
||||
XP_ASSERT( GTK_ENTRY(state->timerField) == GTK_ENTRY(editable) );
|
||||
gchar* text = gtk_editable_get_chars( editable, 0, -1 );
|
||||
NGValue value = { .ng_u16 = atoi(text) };
|
||||
newg_attrChanged( state->newGameCtxt, NG_ATTR_TIMER, value );
|
||||
}
|
||||
|
||||
static void
|
||||
addTimerWidget( GtkNewGameState* state, GtkWidget* parent )
|
||||
{
|
||||
GtkWidget* hbox = gtk_box_new( GTK_ORIENTATION_HORIZONTAL, 0 );
|
||||
gtk_box_pack_start( GTK_BOX(parent), hbox, FALSE, TRUE, 0 );
|
||||
GtkWidget* label = gtk_label_new( "Timer seconds (per move in duplicate case):" );
|
||||
gtk_box_pack_start( GTK_BOX(hbox), label, FALSE, TRUE, 0 );
|
||||
state->timerField = gtk_entry_new();
|
||||
g_signal_connect( state->timerField, "changed",
|
||||
(GCallback)on_timer_changed, state );
|
||||
gtk_entry_set_input_purpose( GTK_ENTRY(state->timerField), GTK_INPUT_PURPOSE_NUMBER );
|
||||
gtk_box_pack_start( GTK_BOX(hbox), state->timerField, FALSE, TRUE, 0 );
|
||||
}
|
||||
|
||||
static GtkWidget*
|
||||
makeNewGameDialog( GtkNewGameState* state )
|
||||
{
|
||||
|
@ -411,6 +436,8 @@ makeNewGameDialog( GtkNewGameState* state )
|
|||
gtk_widget_show( hbox );
|
||||
gtk_box_pack_start( GTK_BOX(vbox), hbox, FALSE, TRUE, 0 );
|
||||
|
||||
addTimerWidget( state, vbox );
|
||||
|
||||
/* buttons at the bottom */
|
||||
hbox = gtk_box_new( GTK_ORIENTATION_HORIZONTAL, 0 );
|
||||
gtk_box_pack_start( GTK_BOX(hbox),
|
||||
|
@ -571,19 +598,34 @@ static void
|
|||
gtk_newgame_attr_set( void* closure, NewGameAttr attr, NGValue value )
|
||||
{
|
||||
GtkNewGameState* state = (GtkNewGameState*)closure;
|
||||
if ( attr == NG_ATTR_NPLAYERS ) {
|
||||
switch( attr ) {
|
||||
case NG_ATTR_NPLAYERS: {
|
||||
XP_U16 ii = value.ng_u16;
|
||||
XP_LOGF( "%s: setting menu %d", __func__, ii-1 );
|
||||
gtk_combo_box_set_active( GTK_COMBO_BOX(state->nPlayersCombo), ii-1 );
|
||||
}
|
||||
break;
|
||||
#ifndef XWFEATURE_STANDALONE_ONLY
|
||||
} else if ( attr == NG_ATTR_ROLE ) {
|
||||
case NG_ATTR_ROLE:
|
||||
gtk_combo_box_set_active( GTK_COMBO_BOX(state->roleCombo),
|
||||
value.ng_role );
|
||||
} else if ( attr == NG_ATTR_REMHEADER ) {
|
||||
break;
|
||||
case NG_ATTR_REMHEADER:
|
||||
/* ignored on GTK: no headers at all */
|
||||
break;
|
||||
#endif
|
||||
} else if ( attr == NG_ATTR_NPLAYHEADER ) {
|
||||
case NG_ATTR_NPLAYHEADER:
|
||||
gtk_label_set_text( GTK_LABEL(state->nPlayersLabel), value.ng_cp );
|
||||
break;
|
||||
case NG_ATTR_TIMER: {
|
||||
gchar buf[32];
|
||||
snprintf( buf, VSIZE(buf), "%d", value.ng_u16 );
|
||||
gtk_label_set_text( GTK_LABEL(state->timerField), buf );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
XP_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue