Пример #1
0
/**
 * show_properties_dialog
 *
 * Description:
 * displays the properties dialog
 **/
void
show_properties_dialog (void)
{
  GtkWidget *notebook;
  GtkWidget *cpage;
  GtkWidget *gpage;
  GtkWidget *kpage;
  GtkWidget *label;
  GtkWidget *hbox;
  GtkWidget *vbox;
  GtkWidget *typemenu;
  GtkWidget *pmapmenu;
  GtkWidget *chkbox;
  GtkWidget *table;
  GtkWidget *dbut;
  GtkWidget *frame;
  GtkWidget *w;
  GtkWidget *controls_list;

  if (propbox)
    return;

  propbox = gtk_dialog_new_with_buttons (_("Robots Preferences"),
					 GTK_WINDOW (app),
					 GTK_DIALOG_DESTROY_WITH_PARENT,
					 GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
					 NULL);
  gtk_dialog_set_has_separator (GTK_DIALOG (propbox), FALSE);
  gtk_container_set_border_width (GTK_CONTAINER (propbox), 5);
  gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (propbox)->vbox), 2);
  /* Set up notebook and add it to hbox of the gtk_dialog */
  g_signal_connect (G_OBJECT (propbox), "destroy",
		    G_CALLBACK (gtk_widget_destroyed), &propbox);

  notebook = gtk_notebook_new ();
  gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
  gtk_box_pack_start (GTK_BOX (GTK_DIALOG (propbox)->vbox), notebook,
		      TRUE, TRUE, 0);

  /* The configuration page */
  cpage = gtk_vbox_new (FALSE, 18);
  gtk_container_set_border_width (GTK_CONTAINER (cpage), 12);

  frame = games_frame_new (_("Game Type"));
  gtk_box_pack_start (GTK_BOX (cpage), frame, FALSE, FALSE, 0);

  vbox = gtk_vbox_new (FALSE, 6);
  gtk_container_add (GTK_CONTAINER (frame), vbox);

  hbox = gtk_hbox_new (TRUE, 0);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

  typemenu = gtk_combo_box_new_text ();
  g_signal_connect (G_OBJECT (typemenu), "changed",
		    G_CALLBACK (type_selection), NULL);
  fill_typemenu (typemenu);
  gtk_box_pack_start (GTK_BOX (hbox), typemenu, TRUE, TRUE, 0);

  frame = games_frame_new (_("Options"));
  gtk_box_pack_start (GTK_BOX (cpage), frame, FALSE, FALSE, 0);
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (frame), vbox);

  chkbox = gtk_check_button_new_with_mnemonic (_("_Use safe moves"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chkbox),
				properties.safe_moves);
  g_signal_connect (G_OBJECT (chkbox), "clicked",
		    (GCallback) safe_cb, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), chkbox, TRUE, TRUE, 0);
  gtk_widget_set_tooltip_text (chkbox,
                               _("Prevent accidental moves that result in getting killed."));

  chkbox = gtk_check_button_new_with_mnemonic (_("U_se super safe moves"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chkbox),
				properties.super_safe_moves);
  g_signal_connect (G_OBJECT (chkbox), "clicked",
		    (GCallback) super_safe_cb, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), chkbox, TRUE, TRUE, 0);
  gtk_widget_set_tooltip_text (chkbox,
                               _("Prevents all moves that result in getting killed."));

  frame = games_frame_new (_("Sound"));
  gtk_box_pack_start (GTK_BOX (cpage), frame, FALSE, FALSE, 0);
  vbox = gtk_vbox_new (TRUE, 6);
  gtk_container_add (GTK_CONTAINER (frame), vbox);

  chkbox = gtk_check_button_new_with_mnemonic (_("_Enable sounds"));
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (chkbox), properties.sound);
  g_signal_connect (G_OBJECT (chkbox), "clicked",
		    (GCallback) sound_cb, NULL);
  gtk_box_pack_start (GTK_BOX (vbox), chkbox, TRUE, TRUE, 0);
  gtk_widget_set_tooltip_text (chkbox,
                               _("Play sounds for events like winning a level and dying."));

  label = gtk_label_new_with_mnemonic (_("Game"));
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), cpage, label);


  /* The graphics page */
  gpage = gtk_vbox_new (FALSE, 18);
  gtk_container_set_border_width (GTK_CONTAINER (gpage), 12);

  frame = games_frame_new (_("Graphics Theme"));
  gtk_box_pack_start (GTK_BOX (gpage), frame, FALSE, FALSE, 0);

  table = gtk_table_new (2, 2, FALSE);
  gtk_table_set_row_spacings (GTK_TABLE (table), 6);
  gtk_table_set_col_spacings (GTK_TABLE (table), 12);
  gtk_container_add (GTK_CONTAINER (frame), table);

  label = gtk_label_new_with_mnemonic (_("_Image theme:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);

  pmapmenu = make_theme_menu ();
  g_signal_connect (G_OBJECT (pmapmenu), "changed",
		    G_CALLBACK (pmap_selection), NULL);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), pmapmenu);

  gtk_table_attach_defaults (GTK_TABLE (table), pmapmenu, 1, 2, 0, 1);

  label = gtk_label_new_with_mnemonic (_("_Background color:"));
  gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
  gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);

  w = gtk_color_button_new ();
  gtk_color_button_set_color (GTK_COLOR_BUTTON (w), &properties.bgcolour);
  g_signal_connect (G_OBJECT (w), "color_set",
		    G_CALLBACK (bg_color_callback), NULL);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), w);

  gtk_table_attach_defaults (GTK_TABLE (table), w, 1, 2, 1, 2);

  label = gtk_label_new_with_mnemonic (_("Appearance"));
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), gpage, label);

  /* The keyboard page */
  kpage = gtk_vbox_new (FALSE, 18);
  gtk_container_set_border_width (GTK_CONTAINER (kpage), 12);

  frame = games_frame_new (_("Keyboard Controls"));
  gtk_box_pack_start (GTK_BOX (kpage), frame, TRUE, TRUE, 0);
  vbox = gtk_vbox_new (FALSE, 6);
  gtk_container_add (GTK_CONTAINER (frame), vbox);

  controls_list = games_controls_list_new (KEY_PREFERENCES_GROUP);
  games_controls_list_add_controls (GAMES_CONTROLS_LIST (controls_list),
				    "key00", _("Key to move NW"), default_keys[0],
				    "key01", _("Key to move N"), default_keys[1],
				    "key02", _("Key to move NE"), default_keys[2],
				    "key03", _("Key to move W"), default_keys[3],
				    "key05", _("Key to move E"), default_keys[5],
				    "key06", _("Key to move SW"), default_keys[6],
				    "key07", _("Key to move S"), default_keys[7],
				    "key08", _("Key to move SE"), default_keys[8],
                                    "key04", _("Key to hold"), default_keys[4],
				    "key09", _("Key to teleport"), default_keys[9],
				    "key10", _("Key to teleport randomly"), default_keys[10],
				    "key11", _("Key to wait"), default_keys[11],
                                    NULL);

  gtk_box_pack_start (GTK_BOX (vbox), controls_list, TRUE, TRUE, 0);

  hbox = gtk_hbutton_box_new ();
  gtk_button_box_set_layout (GTK_BUTTON_BOX (hbox), GTK_BUTTONBOX_START);
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);

  dbut = gtk_button_new_with_mnemonic (_("_Restore Defaults"));
  g_signal_connect (G_OBJECT (dbut), "clicked",
		    G_CALLBACK (defkey_cb), (gpointer) default_keys);
  gtk_box_pack_start (GTK_BOX (hbox), dbut, FALSE, FALSE, 0);

  label = gtk_label_new_with_mnemonic (_("Keyboard"));
  gtk_notebook_append_page (GTK_NOTEBOOK (notebook), kpage, label);


  g_signal_connect (G_OBJECT (propbox), "delete_event",
		    G_CALLBACK (delete_cb), NULL);
  g_signal_connect (G_OBJECT (propbox), "response",
		    G_CALLBACK (apply_cb), NULL);

  gtk_window_set_modal (GTK_WINDOW (propbox), TRUE);
  gtk_widget_show_all (propbox);
}
Пример #2
0
Файл: setup.c Проект: GNOME/tali
void
setup_game (void)
{
  GtkWidget *box, *box2, *label, *button, *frame;
  GtkWidget *grid;
  GtkWidget *combo;
  gchar *ts;
  int i;

  if (setupdialog) {
    gtk_window_present (GTK_WINDOW (setupdialog));
    return;
  }

  setupdialog = gtk_dialog_new_with_buttons (_("Preferences"),
					     GTK_WINDOW (window),
					     GTK_DIALOG_USE_HEADER_BAR, NULL);
  gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (setupdialog))), 2);
  gtk_window_set_resizable (GTK_WINDOW (setupdialog), FALSE);
  g_signal_connect (G_OBJECT (setupdialog), "delete_event",
		    G_CALLBACK (setupdialog_destroy), NULL);
  g_signal_connect (G_OBJECT (setupdialog), "response",
		    G_CALLBACK (do_setup), NULL);

  grid = gtk_grid_new ();
  gtk_container_set_border_width (GTK_CONTAINER (grid), 5);
  gtk_grid_set_row_spacing (GTK_GRID (grid), 18);
  gtk_grid_set_column_spacing (GTK_GRID (grid), 18);

  gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (setupdialog))), 
                      grid, FALSE, FALSE, 0);

  frame = games_frame_new (_("Human Players"));
  gtk_grid_attach (GTK_GRID (grid), frame, 0, 0, 1, 1);

  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_container_add (GTK_CONTAINER (frame), box);

	/*--- Spinner (number of humans) ---*/
  OriginalNumberOfHumans = NumberOfHumans;
  box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_box_pack_start (GTK_BOX (box), box2, FALSE, FALSE, 0);
  label = gtk_label_new_with_mnemonic (_("_Number of players:"));

  gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
  HumanAdj = gtk_adjustment_new ((gfloat) NumberOfHumans, 1.0,
				 6.0, 1.0, 6.0, 0.0);
  HumanSpinner = gtk_spin_button_new (GTK_ADJUSTMENT (HumanAdj), 10, 0);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), HumanSpinner);

  g_signal_connect (G_OBJECT (HumanAdj), "value_changed",
		    G_CALLBACK (MaxPlayersCheck), HumanAdj);

  gtk_box_pack_start (GTK_BOX (box2), HumanSpinner, TRUE, TRUE, 0);


  frame = games_frame_new (_("Computer Opponents"));
  gtk_grid_attach (GTK_GRID (grid), frame, 0, 1, 1, 1);

  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_container_add (GTK_CONTAINER (frame), box);

	/*--- Button ---*/
  button = gtk_check_button_new_with_mnemonic (_("_Delay between rolls"));
  gtk_box_pack_start (GTK_BOX (box), button, FALSE, FALSE, 0);
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), DoDelay);
  g_signal_connect (G_OBJECT (button), "clicked",
		    G_CALLBACK (set_as_int), &tmpDoDelay);

	/*--- Spinner (number of computers) ---*/
  OriginalNumberOfComputers = NumberOfComputers;
  box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
  gtk_box_pack_start (GTK_BOX (box), box2, FALSE, FALSE, 0);
  label = gtk_label_new_with_mnemonic (_("N_umber of opponents:"));
  gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);

  ComputerAdj = gtk_adjustment_new ((gfloat) NumberOfComputers,
				    0.0, 5.0, 1.0, 5.0, 0.0);
  ComputerSpinner = gtk_spin_button_new (GTK_ADJUSTMENT (ComputerAdj), 10, 0);
  gtk_label_set_mnemonic_widget (GTK_LABEL (label), ComputerSpinner);

  g_signal_connect (G_OBJECT (ComputerAdj), "value_changed",
		    G_CALLBACK (MaxPlayersCheck), ComputerAdj);
  gtk_box_pack_start (GTK_BOX (box2), ComputerSpinner, TRUE, TRUE, 0);

  box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
  gtk_box_pack_start (GTK_BOX (box), box2, FALSE, FALSE, 0);
  label = gtk_label_new_with_mnemonic (_("_Difficulty:"));
  gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);
  combo = gtk_combo_box_text_new ();
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("difficulty", "Easy"));
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("difficulty", "Medium"));
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("difficulty", "Hard"));
  skill_level = 0;
  while (NUM_TRIALS > skill_level_table[skill_level].trials &&
         skill_level < (SKILL_LEVEL_TABLE_SIZE - 1)) skill_level++;
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), skill_level);
  g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (SetSkillLevel),
                    combo);
  gtk_box_pack_start (GTK_BOX (box2), combo, FALSE, FALSE, 0);

    /*--- Combo (yahtzee or kismet style ----*/

  frame = games_frame_new (_("Game Type"));
  gtk_grid_attach (GTK_GRID (grid), frame, 0, 2, 1, 1);
  combo = gtk_combo_box_text_new ();
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("game type", "Regular"));
  gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (combo), C_("game type", "Colors"));
  gtk_combo_box_set_active (GTK_COMBO_BOX (combo), game_type);
  NewGameType = game_type;
  g_signal_connect (G_OBJECT (combo), "changed", G_CALLBACK (SetGameType),
                    combo);
  gtk_container_add (GTK_CONTAINER (frame), combo);

	/*--- PLAYER NAMES FRAME ----*/
  frame = games_frame_new (_("Player Names"));
  gtk_grid_attach (GTK_GRID (grid), frame, 1, 0, 1, 3);

  box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
  gtk_container_add (GTK_CONTAINER (frame), box);

  for (i = 0; i < MAX_NUMBER_OF_PLAYERS; i++) {
    box2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);

    gtk_box_pack_start (GTK_BOX (box), box2, FALSE, FALSE, 0);
    ts = g_strdup_printf ("_%1d:", i + 1);
    label = gtk_label_new_with_mnemonic (ts);
    g_free (ts);
    gtk_box_pack_start (GTK_BOX (box2), label, FALSE, FALSE, 0);

    PlayerNames[i] = gtk_entry_new ();
    gtk_label_set_mnemonic_widget (GTK_LABEL (label), PlayerNames[i]);
    ts = g_strdup_printf ("PlayerName%1d", i + 1);
    gtk_widget_set_name (PlayerNames[i], ts);
    g_free (ts);
    gtk_entry_set_text (GTK_ENTRY (PlayerNames[i]), players[i].name);
    gtk_box_pack_start (GTK_BOX (box2), PlayerNames[i], FALSE, FALSE, 0);
  }

  gtk_widget_show_all (setupdialog);
}
Пример #3
0
int
Tetris::gameProperties(GtkAction *action, void *d)
{
	GtkWidget *notebook;
	GtkWidget *vbox;
	GtkWidget *label;
	GtkWidget *frame;
	GtkWidget *table;
	GtkWidget *fvbox;
	GtkObject *adj;
	GtkWidget *controls_list;

	Tetris *t = (Tetris*) d;

	if (t->setupdialog) {
		gtk_window_present (GTK_WINDOW(t->setupdialog));
		return FALSE;
	}

	/* create the dialog */
	t->setupdialog =
		gtk_dialog_new_with_buttons(_("Gnometris Preferences"),
					    GTK_WINDOW (t->w),
					    (GtkDialogFlags)0,
					    GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE,
					    NULL);
	gtk_dialog_set_has_separator (GTK_DIALOG (t->setupdialog), FALSE);
	gtk_container_set_border_width (GTK_CONTAINER (t->setupdialog), 5);
	gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (t->setupdialog)->vbox), 2);
	g_signal_connect (t->setupdialog, "close",
			  G_CALLBACK (setupdialogDestroy), d);
	g_signal_connect (t->setupdialog, "response",
			  G_CALLBACK (setupdialogResponse), d);

	notebook = gtk_notebook_new ();
	gtk_container_set_border_width (GTK_CONTAINER (notebook), 5);
	gtk_box_pack_start (GTK_BOX(GTK_DIALOG(t->setupdialog)->vbox), notebook,
			    TRUE, TRUE, 0);

	/* game page */
	vbox = gtk_vbox_new (FALSE, 18);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
	label = gtk_label_new (_("Game"));
	gtk_notebook_append_page (GTK_NOTEBOOK(notebook), vbox, label);

	frame = games_frame_new (_("Setup"));
	table = gtk_table_new (3, 2, FALSE);
	gtk_table_set_row_spacings (GTK_TABLE (table), 6);
	gtk_table_set_col_spacings (GTK_TABLE (table), 12);

	/* pre-filled rows */
	label = gtk_label_new_with_mnemonic (_("_Number of pre-filled rows:"));
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
			  (GtkAttachOptions) GTK_FILL,
			  (GtkAttachOptions) 0,
			  0, 0);

	adj = gtk_adjustment_new (t->line_fill_height, 0, LINES-1, 1, 5, 0);
	t->fill_height_spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 10, 0);
	gtk_spin_button_set_update_policy
		(GTK_SPIN_BUTTON (t->fill_height_spinner), GTK_UPDATE_ALWAYS);
	gtk_spin_button_set_snap_to_ticks
		(GTK_SPIN_BUTTON (t->fill_height_spinner), TRUE);
	g_signal_connect (t->fill_height_spinner, "value_changed",
			  G_CALLBACK (lineFillHeightChanged), t);
	gtk_table_attach_defaults (GTK_TABLE (table), t->fill_height_spinner, 1, 2, 0, 1);
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), t->fill_height_spinner);

	/* pre-filled rows density */
	label = gtk_label_new_with_mnemonic (_("_Density of blocks in a pre-filled row:"));
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
			  (GtkAttachOptions) GTK_FILL,
			  (GtkAttachOptions) 0,
			  0, 0);

	adj = gtk_adjustment_new (t->line_fill_prob, 0, 10, 1, 5, 0);
	t->fill_prob_spinner = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 10, 0);
	gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (t->fill_prob_spinner),
					  GTK_UPDATE_ALWAYS);
	gtk_spin_button_set_snap_to_ticks
		(GTK_SPIN_BUTTON (t->fill_prob_spinner), TRUE);
	g_signal_connect (t->fill_prob_spinner, "value_changed",
		          G_CALLBACK (lineFillProbChanged), t);
	gtk_table_attach_defaults (GTK_TABLE (table), t->fill_prob_spinner, 1, 2, 1, 2);
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), t->fill_prob_spinner);

	/* starting level */
	label = gtk_label_new_with_mnemonic (_("_Starting level:"));
	gtk_misc_set_alignment (GTK_MISC (label), 0, 0.5);
	gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
			  (GtkAttachOptions) GTK_FILL,
			  (GtkAttachOptions) 0,
			  0, 0);

	adj = gtk_adjustment_new (t->startingLevel, 1, 20, 1, 5, 0);
	t->sentry = gtk_spin_button_new (GTK_ADJUSTMENT (adj), 10.0, 0);
	gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (t->sentry),
					   GTK_UPDATE_ALWAYS);
	gtk_spin_button_set_snap_to_ticks (GTK_SPIN_BUTTON (t->sentry), TRUE);
	g_signal_connect (t->sentry, "value_changed",
			  G_CALLBACK (startingLevelChanged), t);
	gtk_table_attach_defaults (GTK_TABLE (table), t->sentry, 1, 2, 2, 3);
	gtk_label_set_mnemonic_widget (GTK_LABEL (label), t->sentry);

	gtk_container_add (GTK_CONTAINER (frame), table);
	gtk_box_pack_start (GTK_BOX (vbox), frame,
			    FALSE, FALSE, 0);

	frame = games_frame_new (_("Operation"));
	fvbox = gtk_vbox_new (FALSE, 6);

	/* sound */
	t->sound_toggle =
		gtk_check_button_new_with_mnemonic (_("_Enable sounds"));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (t->sound_toggle),
				     games_sound_is_enabled ());
	g_signal_connect (t->sound_toggle, "clicked",
			  G_CALLBACK (setSound), d);
	gtk_box_pack_start (GTK_BOX (fvbox), t->sound_toggle, 0, 0, 0);

	/* preview next block */
	t->do_preview_toggle =
		gtk_check_button_new_with_mnemonic (_("_Preview next block"));
	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (t->do_preview_toggle),
				     do_preview);
	g_signal_connect (t->do_preview_toggle, "clicked",
			  G_CALLBACK (setSelectionPreview), d);
	gtk_box_pack_start (GTK_BOX (fvbox), t->do_preview_toggle, 0, 0, 0);

	/* random blocks */
	t->random_block_colors_toggle =
		gtk_check_button_new_with_mnemonic (_("_Use random block colors"));
	gtk_toggle_button_set_active
		(GTK_TOGGLE_BUTTON (t->random_block_colors_toggle),
		 random_block_colors);
	g_signal_connect (t->random_block_colors_toggle, "clicked",
			  G_CALLBACK (setSelectionBlocks), d);
	gtk_box_pack_start (GTK_BOX (fvbox), t->random_block_colors_toggle,
			    0, 0, 0);

	/* rotate counter clock wise */
 	t->rotate_counter_clock_wise_toggle =
		gtk_check_button_new_with_mnemonic (_("_Rotate blocks counterclockwise"));
 	gtk_toggle_button_set_active
		(GTK_TOGGLE_BUTTON (t->rotate_counter_clock_wise_toggle),
		 rotateCounterClockWise);
	g_signal_connect (t->rotate_counter_clock_wise_toggle, "clicked",
			  G_CALLBACK (setRotateCounterClockWise), d);
 	gtk_box_pack_start (GTK_BOX (fvbox), t->rotate_counter_clock_wise_toggle,
			    0, 0, 0);

	t->useTargetToggle = gtk_check_button_new_with_mnemonic (_("Show _where the block will land"));
	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (t->useTargetToggle),
				      t->useTarget);
	g_signal_connect (t->useTargetToggle, "clicked",
			  G_CALLBACK (setTarget), d);
 	gtk_box_pack_start (GTK_BOX (fvbox), t->useTargetToggle,
			    0, 0, 0);

	gtk_container_add (GTK_CONTAINER (frame), fvbox);
	gtk_box_pack_start (GTK_BOX (vbox), frame,
			    FALSE, FALSE, 0);

	frame = games_frame_new (_("Theme"));
	table = gtk_table_new (2, 2, FALSE);
	gtk_container_set_border_width (GTK_CONTAINER (table), 0);
	gtk_table_set_row_spacings (GTK_TABLE (table), 6);
	gtk_table_set_col_spacings (GTK_TABLE (table), 12);

	/* controls page */
	vbox = gtk_vbox_new (FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
	label = gtk_label_new (_("Controls"));
	gtk_notebook_append_page (GTK_NOTEBOOK(notebook), vbox, label);

	frame = games_frame_new (_("Keyboard Controls"));
	gtk_container_add (GTK_CONTAINER (vbox), frame);

	fvbox = gtk_vbox_new (FALSE, 6);
	gtk_container_add (GTK_CONTAINER (frame), fvbox);

	controls_list = games_controls_list_new (KEY_CONTROLS_GROUP);
	games_controls_list_add_controls (GAMES_CONTROLS_LIST (controls_list),
					  KEY_MOVE_LEFT, _("Move left"), GDK_Left,
					  KEY_MOVE_RIGHT, _("Move right"), GDK_Right,
					  KEY_MOVE_DOWN, _("Move down"), GDK_Down,
					  KEY_MOVE_DROP, _("Drop"), GDK_Pause,
					  KEY_MOVE_ROTATE, _("Rotate"), GDK_Up,
					  KEY_MOVE_PAUSE, _("Pause"), GDK_space,
					  NULL);

	gtk_box_pack_start (GTK_BOX (fvbox), controls_list, TRUE, TRUE, 0);

	/* theme page */
	vbox = gtk_vbox_new (FALSE, 0);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 12);
	label = gtk_label_new (_("Theme"));
	gtk_notebook_append_page (GTK_NOTEBOOK(notebook), vbox, label);

	frame = games_frame_new (_("Block Style"));
	gtk_container_add (GTK_CONTAINER (vbox), frame);

	fvbox = gtk_vbox_new (FALSE, 6);
	gtk_container_add (GTK_CONTAINER (frame), fvbox);

	GtkWidget *omenu = gtk_combo_box_new_text ();
	const ThemeTableEntry *entry = ThemeTable;
	while (entry->id) {
		gtk_combo_box_append_text (GTK_COMBO_BOX (omenu), entry->name);
		entry++;
	}
	gtk_combo_box_set_active (GTK_COMBO_BOX (omenu), t->themeno);
	g_signal_connect (omenu, "changed", G_CALLBACK (setSelection), t);
	gtk_box_pack_start (GTK_BOX (fvbox), omenu, FALSE, FALSE, 0);

	t->theme_preview = new Preview();
	t->theme_preview->setTheme (t->themeno);
	gtk_box_pack_start(GTK_BOX(fvbox), t->theme_preview->getWidget(), TRUE, TRUE, 0);

	t->theme_preview->previewBlock(4, 0, 0);

	gtk_widget_show_all (t->setupdialog);
	gtk_action_set_sensitive(t->new_game_action, FALSE);

	return TRUE;
}
Пример #4
0
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);

}