[four-in-a-row] Do not allow computer vs. computer games



commit 854ea7206f326fadd624108888262fc363b1a5b9
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Feb 4 21:13:42 2014 -0600

    Do not allow computer vs. computer games

 data/org.gnome.four-in-a-row.gschema.xml |    9 +---
 src/prefs.c                              |   84 +++++++-----------------------
 2 files changed, 21 insertions(+), 72 deletions(-)
---
diff --git a/data/org.gnome.four-in-a-row.gschema.xml b/data/org.gnome.four-in-a-row.gschema.xml
index 1dac37f..5a2dd72 100644
--- a/data/org.gnome.four-in-a-row.gschema.xml
+++ b/data/org.gnome.four-in-a-row.gschema.xml
@@ -1,13 +1,8 @@
 <schemalist>
   <schema id="org.gnome.four-in-a-row" path="/org/gnome/four-in-a-row/">
-    <key name="player1" type="i">
+    <key name="opponent" type="i">
       <default>0</default>
-      <summary>Level of Player One</summary>
-      <description>Zero is human; one through three correspond to the level of the computer 
player.</description>
-    </key>
-    <key name="player2" type="i">
-      <default>1</default>
-      <summary>Level of Player Two</summary>
+      <summary>Opponent</summary>
       <description>Zero is human; one through three correspond to the level of the computer 
player.</description>
     </key>
     <key name="theme-id" type="i">
diff --git a/src/prefs.c b/src/prefs.c
index 12be1bb..411df84 100644
--- a/src/prefs.c
+++ b/src/prefs.c
@@ -48,8 +48,7 @@ extern Theme theme[];
 extern gint n_themes;
 
 static GtkWidget *prefsbox = NULL;
-static GtkWidget *combobox1;
-static GtkWidget *combobox2;
+static GtkWidget *combobox;
 static GtkWidget *combobox_theme;
 static GtkWidget *checkbutton_sound;
 
@@ -118,24 +117,7 @@ on_toggle_sound (GtkToggleButton * t, gpointer data)
 }
 
 static void
-on_select_player1 (GtkWidget * w, gpointer data)
-{
-  GtkTreeIter iter;
-  gint value;
-
-  if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX (w), &iter))
-    return;
-  gtk_tree_model_get (GTK_TREE_MODEL (gtk_combo_box_get_model (GTK_COMBO_BOX (w))), &iter, 1, &value, -1);
-
-  p.level[PLAYER1] = value;
-  g_settings_set_int (settings, "player1", value);
-  scorebox_reset ();
-  who_starts = PLAYER2;                /* This gets reversed in game_reset. */
-  game_reset ();
-}
-
-static void
-on_select_player2 (GtkWidget * w, gpointer data)
+on_select_opponent (GtkWidget * w, gpointer data)
 {
   GtkTreeIter iter;
   gint value;
@@ -145,7 +127,7 @@ on_select_player2 (GtkWidget * w, gpointer data)
   gtk_tree_model_get (GTK_TREE_MODEL (gtk_combo_box_get_model (GTK_COMBO_BOX (w))), &iter, 1, &value, -1);
 
   p.level[PLAYER2] = value;
-  g_settings_set_int (settings, "player2", value);
+  g_settings_set_int (settings, "opponent", value);
   scorebox_reset ();
   who_starts = PLAYER2;                /* This gets reversed in game_reset. */
   game_reset ();
@@ -155,8 +137,8 @@ void
 prefs_init (void)
 {
   p.do_sound = g_settings_get_boolean (settings, "sound");
-  p.level[PLAYER1] = g_settings_get_int (settings, "player1");
-  p.level[PLAYER2] = g_settings_get_int (settings, "player2");
+  p.level[PLAYER1] = 0;                /* Human. Always human. */
+  p.level[PLAYER2] = g_settings_get_int (settings, "opponent");
   p.keypress[MOVE_LEFT] = g_settings_get_int (settings, "key-left");
   p.keypress[MOVE_RIGHT] = g_settings_get_int (settings, "key-right");
   p.keypress[MOVE_DROP] = g_settings_get_int (settings, "key-drop");
@@ -212,66 +194,38 @@ prefsbox_open (void)
   label = gtk_label_new (_("Game"));
   gtk_notebook_append_page (GTK_NOTEBOOK (notebook), grid, label);
 
-  label = gtk_label_new (_("Player One:"));
+  label = gtk_label_new (_("Opponent:"));
   gtk_widget_set_hexpand (label, TRUE);
   gtk_grid_attach (GTK_GRID (grid), label, 0, 0, 1, 1);
 
-  combobox1 = gtk_combo_box_new ();
+  combobox = gtk_combo_box_new ();
   renderer = gtk_cell_renderer_text_new ();
-  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox1), renderer, TRUE);
-  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox1), renderer, "text", 0);
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox), renderer, TRUE);
+  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox), renderer, "text", 0);
   model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
-  gtk_combo_box_set_model (GTK_COMBO_BOX (combobox1), GTK_TREE_MODEL (model));
+  gtk_combo_box_set_model (GTK_COMBO_BOX (combobox), GTK_TREE_MODEL (model));
   gtk_list_store_append (model, &iter);
   gtk_list_store_set (model, &iter, 0, _("Human"), 1, LEVEL_HUMAN, -1);
   if (p.level[PLAYER1] == LEVEL_HUMAN)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
+    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
   gtk_list_store_append (model, &iter);
   gtk_list_store_set (model, &iter, 0, _("Level one"), 1, LEVEL_WEAK, -1);
   if (p.level[PLAYER1] == LEVEL_WEAK)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
+    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
   gtk_list_store_append (model, &iter);
   gtk_list_store_set (model, &iter, 0, _("Level two"), 1, LEVEL_MEDIUM, -1);
   if (p.level[PLAYER1] == LEVEL_MEDIUM)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
+    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
   gtk_list_store_append (model, &iter);
   gtk_list_store_set (model, &iter, 0, _("Level three"), 1, LEVEL_STRONG, -1);
   if (p.level[PLAYER1] == LEVEL_STRONG)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox1), &iter);
-  g_signal_connect (combobox1, "changed", G_CALLBACK (on_select_player1), NULL);
-  gtk_grid_attach (GTK_GRID (grid), combobox1, 1, 0, 1, 1);
-
-  label = gtk_label_new (_("Player Two:"));
-  gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
-
-  combobox2 = gtk_combo_box_new ();
-  renderer = gtk_cell_renderer_text_new ();
-  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combobox2), renderer, TRUE);
-  gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combobox2), renderer, "text", 0);
-  model = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_INT);
-  gtk_combo_box_set_model (GTK_COMBO_BOX (combobox2), GTK_TREE_MODEL (model));
-  gtk_list_store_append (model, &iter);
-  gtk_list_store_set (model, &iter, 0, _("Human"), 1, LEVEL_HUMAN, -1);
-  if (p.level[PLAYER2] == LEVEL_HUMAN)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
-  gtk_list_store_append (model, &iter);
-  gtk_list_store_set (model, &iter, 0, _("Level one"), 1, LEVEL_WEAK, -1);
-  if (p.level[PLAYER2] == LEVEL_WEAK)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
-  gtk_list_store_append (model, &iter);
-  gtk_list_store_set (model, &iter, 0, _("Level two"), 1, LEVEL_MEDIUM, -1);
-  if (p.level[PLAYER2] == LEVEL_MEDIUM)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
-  gtk_list_store_append (model, &iter);
-  gtk_list_store_set (model, &iter, 0, _("Level three"), 1, LEVEL_STRONG, -1);
-  if (p.level[PLAYER2] == LEVEL_STRONG)
-    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox2), &iter);
-  g_signal_connect (combobox2, "changed", G_CALLBACK (on_select_player2), NULL);
-  gtk_grid_attach (GTK_GRID (grid), combobox2, 1, 1, 1, 1);
+    gtk_combo_box_set_active_iter (GTK_COMBO_BOX (combobox), &iter);
+  g_signal_connect (combobox, "changed", G_CALLBACK (on_select_opponent), NULL);
+  gtk_grid_attach (GTK_GRID (grid), combobox, 1, 0, 1, 1);
 
   label = gtk_label_new_with_mnemonic (_("_Theme:"));
   gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5);
-  gtk_grid_attach (GTK_GRID (grid), label, 0, 2, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), label, 0, 1, 1, 1);
 
   combobox_theme = gtk_combo_box_text_new ();
   for (i = 0; i < n_themes; i++) {
@@ -279,11 +233,11 @@ prefsbox_open (void)
                                    _(theme_get_title (i)));
   }
   gtk_label_set_mnemonic_widget (GTK_LABEL (label), combobox_theme);
-  gtk_grid_attach (GTK_GRID (grid), combobox_theme, 1, 2, 1, 1);
+  gtk_grid_attach (GTK_GRID (grid), combobox_theme, 1, 1, 1, 1);
 
   checkbutton_sound =
     gtk_check_button_new_with_mnemonic (_("E_nable sounds"));
-  gtk_grid_attach (GTK_GRID (grid), checkbutton_sound, 0, 3, 2, 1);
+  gtk_grid_attach (GTK_GRID (grid), checkbutton_sound, 0, 2, 2, 1);
 
   /* keyboard tab */
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]