static gboolean configure_event_cb (GtkWidget *widget, GdkEventConfigure *event, gpointer data) { int tilesize, ts_x, ts_y; int i; /* Compute the new tile size based on the size of the * drawing area, rounded down. */ ts_x = event->width / BOARDWIDTH; ts_y = event->height / BOARDHEIGHT; if (ts_x * BOARDWIDTH > event->width) ts_x--; if (ts_y * BOARDHEIGHT > event->height) ts_y--; tilesize = MIN (ts_x, ts_y); gnibbles_load_pixmap (tilesize); gnibbles_load_logo (tilesize); clutter_actor_set_size (CLUTTER_ACTOR (stage), BOARDWIDTH * tilesize, BOARDWIDTH * tilesize); if (game_running ()) { if (board) { gnibbles_board_rescale (board, tilesize); gnibbles_boni_rescale (boni, tilesize); for (i=0; i<properties->numworms; i++) gnibbles_worm_rescale (worms[i], tilesize); if (warpmanager) gnibbles_warpmanager_rescale (warpmanager, tilesize); } } else { if (logo) hide_logo (); if (board) gnibbles_board_rescale (board, tilesize); render_logo (); } /* But, has the tile size changed? */ if (properties->tilesize == tilesize) { /* We must always re-load the logo. */ gnibbles_load_logo (tilesize); return FALSE; } properties->tilesize = tilesize; gnibbles_properties_set_tile_size (tilesize); return FALSE; }
static gboolean new_game_2_cb (GtkWidget * widget, gpointer data) { if (!paused) { if (!keyboard_id) keyboard_id = g_signal_connect (G_OBJECT (stage), "key-press-event", G_CALLBACK (key_press_cb), NULL); #ifdef GGZ_CLIENT if (!main_id && ggz_network_mode && network_is_host ()) { main_id = g_timeout_add (GAMEDELAY * (properties->gamespeed + NETDELAY), (GSourceFunc) network_loop, NULL); } else #endif if (!main_id && !ggz_network_mode) { main_id = g_timeout_add (GAMEDELAY * properties->gamespeed, (GSourceFunc) main_loop, NULL); } #ifdef GGZ_CLIENT if (!add_bonus_id && network_is_host ()) { #else if (!add_bonus_id) { #endif add_bonus_id = g_timeout_add (BONUSDELAY * properties->gamespeed, (GSourceFunc) add_bonus_cb, NULL); } } dummy_id = 0; return FALSE; } gboolean new_game (void) { int i; gtk_action_set_sensitive (new_network_action, FALSE); if (ggz_network_mode) { gtk_action_set_sensitive (pause_action, FALSE); } else { gtk_action_set_sensitive (pause_action, TRUE); } gtk_action_set_sensitive (end_game_action, TRUE); gtk_action_set_sensitive (preferences_action, !ggz_network_mode); if (game_running ()) { end_game (FALSE); main_id = 0; } if (ggz_network_mode || !properties->random) { current_level = properties->startlevel; } else { current_level = rand () % MAXLEVEL + 1; } hide_logo (); gnibbles_init (); gnibbles_board_level_new (board, current_level); gnibbles_board_level_add_bonus (board, 1); for (i = 0; i < properties->numworms; i++) { if (!clutter_actor_get_stage (worms[i]->actors)) clutter_container_add_actor (CLUTTER_CONTAINER (stage), worms[i]->actors); gnibbles_worm_show (worms[i]); } paused = 0; gtk_action_set_visible (pause_action, !paused); gtk_action_set_visible (resume_action, paused); gtk_action_set_visible (player_list_action, ggz_network_mode); if (restart_id) { g_source_remove (restart_id); restart_id = 0; } if (add_bonus_id) { g_source_remove (add_bonus_id); add_bonus_id = 0; } if (dummy_id) g_source_remove (dummy_id); dummy_id = g_timeout_add_seconds (1, (GSourceFunc) new_game_2_cb, NULL); network_gui_update (); return TRUE; }
void gnibbles_preferences_cb (GtkWidget * widget, gpointer data) { GtkWidget *notebook; GtkWidget *label; GtkWidget *frame; GtkWidget *button; GtkWidget *levelspinner; GtkWidget *vbox, *vbox2; GtkObject *adjustment; GtkWidget *label2; GtkWidget *table, *table2; GtkWidget *omenu; GtkWidget *controls; gchar *buffer; gint i; gint running = 0; if (pref_dialog) { gtk_window_present (GTK_WINDOW (pref_dialog)); return; } if (!paused) { unpause = 1; pause_game_cb (NULL, 0); } if (game_running ()) running = 1; pref_dialog = gtk_dialog_new_with_buttons (_("Nibbles Preferences"), GTK_WINDOW (window), 0, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); gtk_dialog_set_has_separator (GTK_DIALOG (pref_dialog), FALSE); gtk_container_set_border_width (GTK_CONTAINER (pref_dialog), 5); gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (pref_dialog)->vbox), 2); notebook = gtk_notebook_new (); gtk_container_set_border_width (GTK_CONTAINER (notebook), 5); gtk_container_add (GTK_CONTAINER (GTK_DIALOG (pref_dialog)->vbox), notebook); label = gtk_label_new (_("Game")); table = gtk_table_new (1, 2, FALSE); gtk_table_set_col_spacings (GTK_TABLE (table), 18); gtk_container_set_border_width (GTK_CONTAINER (table), 12); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), table, label); frame = games_frame_new (_("Speed")); if (running) gtk_widget_set_sensitive (frame, FALSE); gtk_table_attach (GTK_TABLE (table), frame, 0, 1, 0, 1, 0, GTK_FILL | GTK_EXPAND, 0, 0); vbox = gtk_vbox_new (FALSE, 6); gtk_container_add (GTK_CONTAINER (frame), vbox); button = gtk_radio_button_new_with_label (NULL, _("Nibbles newbie")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); if (properties->gamespeed == 4) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_connect (GTK_OBJECT (button), "toggled", G_CALLBACK (game_speed_cb), (gpointer) 4); button = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), _("My second day")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); if (properties->gamespeed == 3) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_connect (GTK_OBJECT (button), "toggled", G_CALLBACK (game_speed_cb), (gpointer) 3); button = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), _("Not too shabby")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); if (properties->gamespeed == 2) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_connect (GTK_OBJECT (button), "toggled", G_CALLBACK (game_speed_cb), (gpointer) 2); button = gtk_radio_button_new_with_label (gtk_radio_button_get_group (GTK_RADIO_BUTTON (button)), _("Finger-twitching good")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); if (properties->gamespeed == 1) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_connect (GTK_OBJECT (button), "toggled", G_CALLBACK (game_speed_cb), (gpointer) 1); /* Options */ frame = games_frame_new (_("Options")); gtk_table_attach_defaults (GTK_TABLE (table), frame, 1, 2, 0, 1); vbox = gtk_vbox_new (FALSE, 6); gtk_container_add (GTK_CONTAINER (frame), vbox); button = gtk_check_button_new_with_mnemonic (_("_Play levels in random order")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); if (running || ggz_network_mode) gtk_widget_set_sensitive (button, FALSE); if (properties->random) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_connect (GTK_OBJECT (button), "toggled", G_CALLBACK (random_order_cb), NULL); button = gtk_check_button_new_with_mnemonic (_("_Enable fake bonuses")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); if (running) gtk_widget_set_sensitive (button, FALSE); if (properties->fakes) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_connect (GTK_OBJECT (button), "toggled", G_CALLBACK (fake_bonus_cb), NULL); button = gtk_check_button_new_with_mnemonic (_("E_nable sounds")); gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0); if (properties->sound) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE); g_signal_connect (GTK_OBJECT (button), "toggled", G_CALLBACK (sound_cb), NULL); table2 = gtk_table_new (3, 2, FALSE); gtk_box_pack_start (GTK_BOX (vbox), table2, FALSE, FALSE, 0); gtk_table_set_row_spacings (GTK_TABLE (table2), 6); gtk_table_set_col_spacings (GTK_TABLE (table2), 12); gtk_container_set_border_width (GTK_CONTAINER (table2), 0); label2 = gtk_label_new_with_mnemonic (_("_Starting level:")); start_level_label = label2; gtk_widget_set_name (label2, "StartLevelLabel"); gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); if (properties->random) gtk_widget_set_sensitive (GTK_WIDGET (label2), FALSE); if (running) gtk_widget_set_sensitive (GTK_WIDGET (label2), FALSE); gtk_table_attach (GTK_TABLE (table2), label2, 0, 1, 0, 1, GTK_FILL, 0, 0, 0); adjustment = gtk_adjustment_new ((gfloat) properties->startlevel, 1.0, MAXLEVEL, 1.0, 5.0, 0.0); levelspinner = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 0, 0); start_level_spin_button = levelspinner; gtk_widget_set_name (levelspinner, "StartLevelSpinButton"); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (levelspinner), FALSE); gtk_label_set_mnemonic_widget (GTK_LABEL (label2), levelspinner); if (properties->random) gtk_widget_set_sensitive (GTK_WIDGET (levelspinner), FALSE); if (running) gtk_widget_set_sensitive (GTK_WIDGET (levelspinner), FALSE); gtk_table_attach_defaults (GTK_TABLE (table2), levelspinner, 1, 2, 0, 1); g_signal_connect (GTK_OBJECT (adjustment), "value_changed", G_CALLBACK (start_level_cb), levelspinner); label2 = gtk_label_new_with_mnemonic (_("Number of _human players:")); gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); gtk_table_attach (GTK_TABLE (table2), label2, 0, 1, 1, 2, GTK_FILL, 0, 0, 0); if (running || ggz_network_mode) gtk_widget_set_sensitive (label2, FALSE); adjustment = gtk_adjustment_new ((gfloat) properties->human, 0.0, NUMWORMS, 1.0, 1.0, 0.0); num_human = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 0, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (num_human), FALSE); gtk_label_set_mnemonic_widget (GTK_LABEL (label2), num_human); gtk_table_attach_defaults (GTK_TABLE (table2), num_human, 1, 2, 1, 2); if (running || ggz_network_mode) gtk_widget_set_sensitive (num_human, FALSE); g_signal_connect (GTK_OBJECT (adjustment), "value_changed", G_CALLBACK (num_worms_cb), num_human); label2 = gtk_label_new_with_mnemonic (_("Number of _AI players:")); gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); gtk_table_attach (GTK_TABLE (table2), label2, 0, 1, 2, 3, GTK_FILL, 0, 0, 0); if (running || ggz_network_mode) gtk_widget_set_sensitive (label2, FALSE); adjustment = gtk_adjustment_new ((gfloat) properties->ai, 0.0, NUMWORMS, 1.0, 1.0, 0.0); num_ai = gtk_spin_button_new (GTK_ADJUSTMENT (adjustment), 0, 0); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (num_ai), FALSE); gtk_label_set_mnemonic_widget (GTK_LABEL (label2), num_ai); gtk_table_attach_defaults (GTK_TABLE (table2), num_ai, 1, 2, 2, 3); if (running || ggz_network_mode) gtk_widget_set_sensitive (num_ai, FALSE); g_signal_connect (GTK_OBJECT (adjustment), "value_changed", G_CALLBACK (num_worms_cb), num_ai); for (i = 0; i < NUMWORMS; i++) { char up_key[64]; char down_key[64]; char left_key[64]; char right_key[64]; buffer = g_strdup_printf ("%s %d", _("Worm"), i + 1); label = gtk_label_new (buffer); g_free (buffer); vbox = gtk_vbox_new (FALSE, 18); gtk_container_set_border_width (GTK_CONTAINER (vbox), 12); gtk_notebook_append_page (GTK_NOTEBOOK (notebook), vbox, label); frame = games_frame_new (_("Keyboard Controls")); controls = games_controls_list_new (KEY_PREFERENCES_GROUP); g_snprintf (left_key, sizeof (left_key), KEY_WORM_LEFT, i); g_snprintf (right_key, sizeof (right_key), KEY_WORM_RIGHT, i); g_snprintf (up_key, sizeof (up_key), KEY_WORM_UP, i); g_snprintf (down_key, sizeof (down_key), KEY_WORM_DOWN, i); games_controls_list_add_controls (GAMES_CONTROLS_LIST (controls), left_key, _("Move left"), GDK_Left, right_key, _("Move right"), GDK_Right, up_key, _("Move up"), GDK_Up, down_key, _("Move down"), GDK_Down, NULL); gtk_container_add (GTK_CONTAINER (frame), controls); gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0); frame = games_frame_new (_("Options")); gtk_box_pack_start (GTK_BOX (vbox), frame, FALSE, FALSE, 0); vbox2 = gtk_vbox_new (FALSE, 6); gtk_container_add (GTK_CONTAINER (frame), vbox2); button = gtk_check_button_new_with_mnemonic (_("_Use relative movement")); gtk_box_pack_start (GTK_BOX (vbox2), button, FALSE, FALSE, 0); table2 = gtk_table_new (1, 2, FALSE); gtk_table_set_col_spacings (GTK_TABLE (table2), 12); gtk_box_pack_start (GTK_BOX (vbox2), table2, FALSE, FALSE, 0); label2 = gtk_label_new_with_mnemonic (_("_Worm color:")); gtk_misc_set_alignment (GTK_MISC (label2), 0, 0.5); gtk_table_attach (GTK_TABLE (table2), label2, 0, 1, 0, 1, 0, 0, 0, 0); omenu = gtk_combo_box_new_text (); gtk_label_set_mnemonic_widget (GTK_LABEL (label2), omenu); gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), _("Red")); gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), _("Green")); gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), _("Blue")); gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), _("Yellow")); gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), _("Cyan")); gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), _("Purple")); gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), _("Gray")); g_signal_connect (GTK_OBJECT (omenu), "changed", G_CALLBACK (set_worm_color_cb), GINT_TO_POINTER (i)); gtk_combo_box_set_active (GTK_COMBO_BOX (omenu), properties->wormprops[i]->color - WORMRED); gtk_table_attach_defaults (GTK_TABLE (table2), omenu, 1, 2, 0, 1); set_worm_controls_sensitivity (i, properties->wormprops[i]->relmove); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), properties->wormprops[i]->relmove); g_signal_connect (G_OBJECT (button), "toggled", G_CALLBACK (worm_relative_movement_cb), GINT_TO_POINTER (i)); } g_signal_connect (G_OBJECT (pref_dialog), "response", G_CALLBACK (apply_cb), NULL); g_signal_connect (G_OBJECT (pref_dialog), "destroy", G_CALLBACK (destroy_cb), NULL); g_signal_connect (G_OBJECT (pref_dialog), "close", G_CALLBACK (destroy_cb), NULL); gtk_widget_show_all (pref_dialog); }