Complete.Org: Mailing Lists: Archives: freeciv-dev: January 2003:
[Freeciv-Dev] (PR#2841) categorization of nations
Home

[Freeciv-Dev] (PR#2841) categorization of nations

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#2841) categorization of nations
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Fri, 31 Jan 2003 00:41:17 -0800
Reply-to: rt@xxxxxxxxxxxxxx

I have committed the non-GUI parts.  The only thing left that we have is
GTK support.

Vasco, it would be good if you could look at/commit this part. 
Otherwise I'll do it eventually...

jason

? client/gui-gtk/diff
Index: client/gui-gtk/dialogs.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/dialogs.c,v
retrieving revision 1.119
diff -u -r1.119 dialogs.c
--- client/gui-gtk/dialogs.c    2003/01/27 22:53:00     1.119
+++ client/gui-gtk/dialogs.c    2003/01/31 08:10:20
@@ -57,23 +57,34 @@
 
 /******************************************************************/
 static GtkWidget  *races_dialog_shell=NULL;
-static GtkWidget  *races_toggles_form;
-static GtkWidget  *races_by_name;
+static GtkWidget  *races_toggles_form[MAX_NUM_ITEMS];
+static GtkWidget  *races_by_name[MAX_NUM_ITEMS];
+static GtkWidget  *class[MAX_NUM_ITEMS];
+static GtkWidget  *legend[MAX_NUM_ITEMS];
+static GtkWidget  *legend_frame[MAX_NUM_ITEMS];
 static GtkWidget  *races_sex_toggles_form;
 static GtkWidget  *city_style_toggles_form;
 static GtkWidget  *races_ok_command;            /* ok button */
 static GtkWidget  *races_disc_command=NULL;     /* disc button */
 static GtkWidget  *races_quit_command=NULL;     /* quit button */
-static GtkWidget **races_toggles=NULL,          /* toggle race */
-                  *races_sex_toggles[2],        /* Male/Female */
-                 **city_style_toggles = NULL,
-                  *races_name;                  /* leader name */
-static GList      *leader_strings = NULL;
-static GList      *sorted_races_list = NULL; /* contains a list of race
-                                             ids sorted by the race
-                                             name. Is valid as long
-                                             as the races_dialog is
-                                             poped up. */
+ /* toggle race */
+static GtkWidget **races_toggles[MAX_NUM_ITEMS];
+static GtkWidget *races_sex_toggles[2];                /* Male/Female */
+static GtkWidget **city_style_toggles = NULL;
+static GtkWidget *leader_name;                 /* leader name */
+static GtkWidget *notebook;
+
+static int       num_classes;
+static char      *class_names[MAX_NUM_ITEMS];
+
+static GList *leader_strings = NULL;
+
+/*
+ * Contains a list of race ids sorted by the race name. Is valid as
+ * long as the races_dialog is poped up. 
+ */
+static GList *sorted_races_list[MAX_NUM_ITEMS];
+
 /******************************************************************/
 static GtkWidget  *notify_dialog_shell;
 
@@ -113,14 +124,18 @@
 static void races_toggles_callback(GtkWidget *w, gpointer race_id_p);
 static void races_sex_toggles_callback(GtkWidget *w, gpointer data);
 static void races_by_name_callback(GtkWidget *w, gpointer data);
-static void races_name_callback(GtkWidget *w, gpointer data);
+static void leader_name_callback(GtkWidget *w, gpointer data);
 static void city_style_toggles_callback(GtkWidget *w, gpointer data);
+static void switch_page_callback(GtkNotebook * notebook,
+                                GtkNotebookPage * page, gint page_num,
+                                gpointer data);
 
 static int selected_nation;
 static int selected_leader;
 static bool is_name_unique = FALSE;
 static int selected_sex;
 static int selected_city_style;
+static int selected_class;
 static int city_style_idx[64];  /* translation table basic style->city_style */
 static int city_style_ridx[64]; /* translation table the other way. they     */
                                 /* in fact limit the num of styles to 64     */
@@ -1797,11 +1812,25 @@
 *****************************************************************/
 void popup_races_dialog(void)
 {
+  int class_id;
+  int width, height;
+
   gtk_widget_set_sensitive(top_vbox, FALSE);
 
   create_races_dialog();
 
   gtk_widget_show(races_dialog_shell);
+
+  /* The first tab is visible. The others aren't. */
+  gdk_window_get_size(legend_frame[0]->window, &width, &height);
+
+  /* 
+   * This is a hack to expand the legend label to take all the
+   * available space. 
+   */
+  for (class_id = 0; class_id < num_classes; class_id++) {
+    gtk_widget_set_usize(GTK_WIDGET(legend[class_id]), width, -1);
+  }
 }
 
 /****************************************************************
@@ -1810,23 +1839,36 @@
 void popdown_races_dialog(void)
 {
   if (races_dialog_shell) {
+    int class_id;
+
     gtk_widget_set_sensitive(top_vbox, TRUE);
 
-    /* while dialog is being destroyed, it will toggle the race_toggle 
+    /* 
+     * While dialog is being destroyed, it will toggle the race_toggle
      * buttons in turn. eventually races_by_name_callback() will call
-     * select_random_race() will try to activate a now-destroyed 
-     * button with typical results. let's avoid that. 
-     * (this is one of the reasons I hate gtk) */
-    gtk_signal_disconnect_by_func(GTK_OBJECT(GTK_COMBO(races_by_name)->list),
-                                  GTK_SIGNAL_FUNC(races_by_name_callback), 
-                                  NULL);
-
+     * select_random_race() will try to activate a now-destroyed
+     * button with typical results. Let's avoid that. (this is one of
+     * the reasons I hate GTK).
+     */
+
+    gtk_signal_disconnect_by_func(GTK_OBJECT(notebook),
+                                 GTK_SIGNAL_FUNC(switch_page_callback),
+                                 NULL);
+
+    for (class_id = 0; class_id < num_classes; class_id++) {
+      gtk_signal_disconnect_by_func(GTK_OBJECT
+                                   (GTK_COMBO(races_by_name[class_id])->
+                                    list),
+                                   GTK_SIGNAL_FUNC(races_by_name_callback),
+                                   NULL);
+
+      g_list_free(sorted_races_list[class_id]);
+      sorted_races_list[class_id] = NULL;
+      free(races_toggles[class_id]);
+      races_toggles[class_id] = NULL;
+    }
     gtk_widget_destroy(races_dialog_shell);
     races_dialog_shell = NULL;
-    g_list_free(sorted_races_list);
-    sorted_races_list = NULL;
-    free(races_toggles);
-    races_toggles = NULL;
   }
 }
 
@@ -1851,10 +1893,10 @@
   
   /* weirdness happens by not doing it this way */
   sz_strlcpy(unique_name, 
-             gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(races_name)->entry)));
+             gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(leader_name)->entry)));
 
-  gtk_signal_handler_block_by_func(GTK_OBJECT(GTK_COMBO(races_name)->list), 
-                                   races_name_callback, NULL);
+  gtk_signal_handler_block_by_func(GTK_OBJECT(GTK_COMBO(leader_name)->list), 
+                                   leader_name_callback, NULL);
   g_list_free(leader_strings);
   leader_strings = NULL;
 
@@ -1863,15 +1905,15 @@
   for(j = 0; j < leader_num; j++) {
     leader_strings = g_list_append(leader_strings, leaders[j].name);
   }
-  gtk_combo_set_value_in_list(GTK_COMBO(races_name), FALSE, FALSE);
-  gtk_combo_set_popdown_strings(GTK_COMBO(races_name), leader_strings);
+  gtk_combo_set_value_in_list(GTK_COMBO(leader_name), FALSE, FALSE);
+  gtk_combo_set_popdown_strings(GTK_COMBO(leader_name), leader_strings);
 
-  gtk_signal_handler_unblock_by_func(GTK_OBJECT(GTK_COMBO(races_name)->list), 
-                                     races_name_callback, NULL);
+  gtk_signal_handler_unblock_by_func(GTK_OBJECT(GTK_COMBO(leader_name)->list), 
+                                     leader_name_callback, NULL);
   if (!is_name_unique) {
     /* initialize leader names */
     selected_leader = myrand(leader_num);
-    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(races_name)->entry),
+    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(leader_name)->entry),
                       leaders[selected_leader].name);
 
     /* initialize leader sex */
@@ -1879,7 +1921,7 @@
     gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(
                               races_sex_toggles[selected_sex ? 0 : 1]), TRUE);
   } else {
-    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(races_name)->entry), unique_name);
+    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(leader_name)->entry), unique_name);
   }
 }
 
@@ -1889,18 +1931,23 @@
 *****************************************************************/
 static void select_random_race(void)
 {
+  int class_id = selected_class;
+  int nations_in_class = g_list_length(sorted_races_list[class_id]);
+  int index;
+
   /* try to find a free nation */
-  while(TRUE) {
-    selected_nation = myrand(game.playable_nation_count);
-    if(GTK_WIDGET_SENSITIVE(races_toggles[g_list_index(sorted_races_list,
-                                      GINT_TO_POINTER(selected_nation))]))
+  while (TRUE) {
+    index = myrand(nations_in_class);
+    selected_nation =
+       GPOINTER_TO_INT(g_list_nth_data(sorted_races_list[class_id], index));
+    if (GTK_WIDGET_SENSITIVE(races_toggles[class_id][index])) {
       break;
+    }
   }
 
   /* initialize nation toggle array */
-  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(
-                              races_toggles[g_list_index(sorted_races_list,
-                              GINT_TO_POINTER(selected_nation))]), TRUE);
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON
+                             (races_toggles[class_id][index]), TRUE);
 
   /* initialize city style */
   selected_city_style =
@@ -1912,124 +1959,218 @@
 /****************************************************************
 ...
 *****************************************************************/
+static void switch_page_callback(GtkNotebook * notebook,
+                                GtkNotebookPage * page, gint page_num,
+                                gpointer data)
+{
+  selected_class = page_num;
+  select_random_race();
+}
+
+/****************************************************************
+...
+*****************************************************************/
 void create_races_dialog(void)
 {
-  int       per_row;
-  int       i;
-  GSList    *group = NULL;
+  int       i, class_id;
   GSList    *sgroup = NULL;
   GSList    *cgroup = NULL;
-  GtkWidget *frame, *label, *pop_downs_box;
-  GList     *race_names;
+  GtkWidget *frame, *label;
  
-  /* Makes the flag box a nicely proportioned rectangle,
-   * whatever the total size may be */
-  if (game.playable_nation_count > 8) {
-    per_row = sqrt(game.playable_nation_count) * 18 / 15;
-  } else {
-    /* Multiple rows would look silly here */ 
-    per_row = game.playable_nation_count;
-  }
-
   races_dialog_shell = gtk_dialog_new();
+  gtk_window_set_default_size(GTK_WINDOW(races_dialog_shell), 10, 650);
+  
   gtk_signal_connect(GTK_OBJECT(races_dialog_shell), "delete_event", 
                      GTK_SIGNAL_FUNC(deleted_callback), NULL);
 
   gtk_window_set_title(GTK_WINDOW(races_dialog_shell), 
                        _("What Nation Will You Be?"));
 
-  frame = gtk_frame_new(_("Select nation and name"));
+  frame = gtk_frame_new(_("Select a nation"));
   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(races_dialog_shell)->vbox),
-                     frame, FALSE, FALSE, 0);
+                     frame, TRUE, TRUE, 0);
 
-  /* ------- nation name toggles ------- */
+  /* ------- Add each nation to one of the class lists ------- */
 
-  races_toggles_form = gtk_table_new(per_row, 
-                              ((game.playable_nation_count-1) / per_row) + 1, 
-                              FALSE);
-  gtk_container_add(GTK_CONTAINER(frame), races_toggles_form);
+  num_classes = 1;
+  class_names[0] = _("All");
 
-  free(races_toggles);
-  races_toggles = fc_calloc(game.playable_nation_count, sizeof(GtkWidget*));
+  for (i = 0; i < game.playable_nation_count; i++) {
+    bool found = FALSE;
+    struct nation_type *nation = get_nation_by_idx(i);
 
-  for(i = 0; i < game.playable_nation_count; i++) {
-    sorted_races_list = g_list_append(sorted_races_list, GINT_TO_POINTER(i));
-  }
+    /* Find the nation's class. */
+    for (class_id = 1; class_id < num_classes; class_id++) {
+      if (strcmp(nation->class, class_names[class_id]) == 0) {
+       found = TRUE;
+       break;
+      }
+    }
 
-  sorted_races_list = g_list_sort(sorted_races_list, cmp_func);
+    /* Append a new class. */
+    if (!found && num_classes < MAX_NUM_ITEMS) {
+      class_id = num_classes++;
+      class_names[class_id] = nation->class;
+    }
 
-  for(i = 0; i < g_list_length(sorted_races_list); i++) {
-    gint nat_id = GPOINTER_TO_INT(g_list_nth_data(sorted_races_list, i));
-    GtkWidget *flag;
-    SPRITE *s;
+    /* Add the nation to the class list. */
+    sorted_races_list[class_id] =
+      g_list_append(sorted_races_list[class_id], GINT_TO_POINTER(i));
+
+    /* Add the nation to the "All" class. */
+    sorted_races_list[0] =
+       g_list_append(sorted_races_list[0], GINT_TO_POINTER(i));
+  }
+
+  /* ------- create class notebook and add pages ------- */
+
+  notebook = gtk_notebook_new();
+  gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP);
+  gtk_container_add(GTK_CONTAINER(frame), notebook);
+
+  for (class_id = 0; class_id < num_classes; class_id++) {
+    GtkWidget *page, *label, *hbox, *scrolledwin;
+    int nations_in_class = g_list_length(sorted_races_list[class_id]);
+    int per_row, rows;
+    GList *race_names = NULL;
+    GSList *group = NULL;
+
+    freelog(LOG_DEBUG, "  %s[%d] has %d nations",
+           skip_intl_qualifier_prefix(class_names[class_id]), class_id,
+           nations_in_class);
+    sorted_races_list[class_id] =
+       g_list_sort(sorted_races_list[class_id], cmp_func);
+
+    for (i = 0; i < nations_in_class; i++) {
+      race_names =
+         g_list_append(race_names,
+                       get_nation_by_idx(GPOINTER_TO_INT
+                                         (g_list_nth_data
+                                          (sorted_races_list[class_id], 
i)))->name);
+    }
 
-    races_toggles[i] = gtk_radio_button_new(group);
-    s = crop_blankspace(get_nation_by_idx(nat_id)->flag_sprite);
-    flag = gtk_pixmap_new(s->pixmap, s->mask);
-    gtk_misc_set_alignment(GTK_MISC(flag), 0, 0.5);
-    gtk_misc_set_padding(GTK_MISC(flag), 6, 4);
-
-    gtk_container_add(GTK_CONTAINER(races_toggles[i]), flag);
-    gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(races_toggles[i]), FALSE); 
-
-    group = gtk_radio_button_group(GTK_RADIO_BUTTON(races_toggles[i]));
-    gtk_table_attach_defaults(GTK_TABLE(races_toggles_form), races_toggles[i], 
-                             i%per_row, i%per_row+1, i/per_row, i/per_row+1);
-  } 
+    per_row = 8;
 
-  /* ------ choose nation by name -- and choose leader ------ */
- 
-  pop_downs_box = gtk_hbox_new(FALSE, 0);
-  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(races_dialog_shell)->vbox),
-                     pop_downs_box, FALSE, FALSE, 5);
- 
-  label = gtk_label_new(_("Nation:"));
-  races_by_name = gtk_combo_new();
-  gtk_editable_set_editable(GTK_EDITABLE(GTK_COMBO(races_by_name)->entry), 
-                            FALSE);
-  race_names = NULL;
+    if (nations_in_class == 0) {
+      rows = 0;
+    } else {
+      rows = ((nations_in_class - 1) / per_row) + 1;
+    }
 
-  for(i = 0; i < game.playable_nation_count; i++) {
-    race_names = g_list_append(race_names, get_nation_by_idx(
-          GPOINTER_TO_INT(g_list_nth_data(sorted_races_list, i)))->name);
-  }
+    page = gtk_vbox_new(FALSE, 1);
+    label = gtk_label_new(Q_(class_names[class_id]));
+    gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label);
+
+    scrolledwin = gtk_scrolled_window_new(NULL, NULL);
+    gtk_box_pack_start(GTK_BOX(page), scrolledwin,1,1,0);
+    gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolledwin),
+                                  GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+
+    races_toggles_form[class_id] = gtk_table_new(per_row, rows, FALSE);
+    gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW (scrolledwin),
+                                         races_toggles_form[class_id]);
+
+    races_toggles[class_id] =
+       fc_calloc(nations_in_class, sizeof(GtkWidget *));
+
+    /* ------ add nation flag array to page ------ */
+
+    for (i = 0; i < g_list_length(sorted_races_list[class_id]); i++) {
+      gint nat_id =
+         GPOINTER_TO_INT(g_list_nth_data(sorted_races_list[class_id], i));
+      SPRITE *s = crop_blankspace(get_nation_by_idx(nat_id)->flag_sprite);
+      GtkWidget *flag = gtk_pixmap_new(s->pixmap, s->mask);
+
+      races_toggles[class_id][i] = gtk_radio_button_new(group);
+      gtk_misc_set_alignment(GTK_MISC(flag), 0, 0.5);
+      gtk_misc_set_padding(GTK_MISC(flag), 6, 4);
+
+      gtk_container_add(GTK_CONTAINER(races_toggles[class_id][i]), flag);
+      gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON
+                                 (races_toggles[class_id][i]), FALSE);
+
+      group =
+         gtk_radio_button_group(GTK_RADIO_BUTTON
+                                (races_toggles[class_id][i]));
+      gtk_table_attach_defaults(GTK_TABLE(races_toggles_form[class_id]),
+                               races_toggles[class_id][i], i % per_row,
+                               i % per_row + 1, i / per_row,
+                               i / per_row + 1);
+    }
 
-  gtk_combo_set_popdown_strings(GTK_COMBO(races_by_name), race_names);
-  gtk_combo_set_value_in_list(GTK_COMBO(races_by_name), TRUE, FALSE);
-  gtk_box_pack_start(GTK_BOX(pop_downs_box), label, FALSE, FALSE, 4);
-  gtk_box_pack_start(GTK_BOX(pop_downs_box), races_by_name, FALSE, FALSE, 0);
-  
+    /* ------ add combobox to choose nation by name to page ------ */
 
-  races_name = gtk_combo_new();
+    hbox = gtk_hbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(page), hbox, FALSE, FALSE, 5);
 
-  label = gtk_label_new(_("Leader:"));
-  gtk_box_pack_end(GTK_BOX(pop_downs_box), races_name, FALSE, FALSE, 4);
-  gtk_box_pack_end(GTK_BOX(pop_downs_box), label, FALSE, FALSE, 0);
- 
-  GTK_WIDGET_SET_FLAGS(races_name, GTK_CAN_DEFAULT);
-  gtk_widget_grab_default(races_name);
+    label = gtk_label_new(_("Nation:"));
+    races_by_name[class_id] = gtk_combo_new();
+    gtk_editable_set_editable(GTK_EDITABLE
+                             (GTK_COMBO(races_by_name[class_id])->entry),
+                             FALSE);
+
+    gtk_combo_set_popdown_strings(GTK_COMBO(races_by_name[class_id]),
+                                 race_names);
+    gtk_combo_set_value_in_list(GTK_COMBO(races_by_name[class_id]), TRUE,
+                               FALSE);
+    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 4);
+    gtk_box_pack_start(GTK_BOX(hbox), races_by_name[class_id],
+                      FALSE, FALSE, 0);
+
+    /* ------ add info about class and legend to page ------ */
+
+    hbox = gtk_hbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(page), hbox, FALSE, FALSE, 5);
+    label = gtk_label_new(_("Class:"));
+    gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
+    class[class_id] = gtk_label_new("content");
+    gtk_box_pack_start(GTK_BOX(hbox), class[class_id], FALSE, FALSE, 0);
+
+    hbox = gtk_hbox_new(FALSE, 0);
+    gtk_box_pack_start(GTK_BOX(page), hbox, FALSE, FALSE, 5);
+    legend[class_id] = gtk_label_new("content");
+    gtk_label_set_line_wrap(GTK_LABEL(legend[class_id]), TRUE);
+    gtk_label_set_justify(GTK_LABEL(legend[class_id]), GTK_JUSTIFY_FILL);
+
+    legend_frame[class_id] = gtk_frame_new(_("Description"));
+    gtk_box_pack_start(GTK_BOX(hbox), legend_frame[class_id], TRUE, TRUE, 0);
+    gtk_container_add(GTK_CONTAINER(legend_frame[class_id]), legend[class_id]);
+    /* ------- contruction of one page finished ------- */
+  }
+
+  selected_class = 0;
 
   /* ------- leader sex toggles ------- */
 
-  frame = gtk_frame_new(_("Select your sex"));
+  frame = gtk_frame_new(_("Leader"));
   gtk_box_pack_start(GTK_BOX(GTK_DIALOG(races_dialog_shell)->vbox),
                      frame, FALSE, FALSE, 0);
 
-  races_sex_toggles_form = gtk_table_new(1, 2, TRUE);
+  races_sex_toggles_form = gtk_hbox_new(FALSE, 0);
   gtk_container_add(GTK_CONTAINER(frame), races_sex_toggles_form); 
 
   races_sex_toggles[0] = gtk_radio_button_new_with_label(sgroup, _("Male"));
   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON( races_sex_toggles[0]),
                               FALSE);
   sgroup = gtk_radio_button_group(GTK_RADIO_BUTTON(races_sex_toggles[0]));
-  gtk_table_attach_defaults(GTK_TABLE(races_sex_toggles_form),
-                            races_sex_toggles[0], 0, 1, 0, 1); 
+  gtk_box_pack_end(GTK_BOX(races_sex_toggles_form), races_sex_toggles[0],
+                  FALSE, FALSE, 0);
   races_sex_toggles[1] = gtk_radio_button_new_with_label(sgroup, _("Female"));
   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(races_sex_toggles[1]),
                               FALSE);
   sgroup = gtk_radio_button_group(GTK_RADIO_BUTTON(races_sex_toggles[1]));
-  gtk_table_attach_defaults(GTK_TABLE(races_sex_toggles_form),
-                            races_sex_toggles[1], 1, 2, 0, 1); 
+  gtk_box_pack_end(GTK_BOX(races_sex_toggles_form), races_sex_toggles[1],
+                  FALSE, FALSE, 0);
+  leader_name = gtk_combo_new();
+
+  label = gtk_label_new(_("Leader:"));
+  gtk_box_pack_start(GTK_BOX(races_sex_toggles_form), label, FALSE, FALSE,
+                    0);
+  gtk_box_pack_start(GTK_BOX(races_sex_toggles_form), leader_name, FALSE,
+                    FALSE, 4);
+ 
+  GTK_WIDGET_SET_FLAGS(leader_name, GTK_CAN_DEFAULT);
+  gtk_widget_grab_default(leader_name);
 
   /* ------- city style toggles ------- */
 
@@ -2106,10 +2247,17 @@
 
   /* ------- connect callback functions ------- */
 
-   for(i = 0; i < g_list_length(sorted_races_list); i++)
-     gtk_signal_connect(GTK_OBJECT( races_toggles[i]), "toggled",
-                        GTK_SIGNAL_FUNC( races_toggles_callback),
-                        g_list_nth_data(sorted_races_list, i));
+  for (class_id = 0; class_id < num_classes; class_id++) {
+    for (i = 0; i < g_list_length(sorted_races_list[class_id]); i++) {
+      gtk_signal_connect(GTK_OBJECT(races_toggles[class_id][i]), "toggled",
+                        GTK_SIGNAL_FUNC(races_toggles_callback),
+                        g_list_nth_data(sorted_races_list[class_id], i));
+    }
+
+    gtk_signal_connect(GTK_OBJECT(GTK_COMBO(races_by_name[class_id])->list),
+                      "selection_changed",
+                      GTK_SIGNAL_FUNC(races_by_name_callback), NULL);
+  }
 
   for(i = 0; i < 2; i++) {
     gtk_signal_connect(GTK_OBJECT(races_sex_toggles[i]), "toggled",
@@ -2121,9 +2269,9 @@
                        GTK_SIGNAL_FUNC(city_style_toggles_callback), NULL);
   }
 
-  gtk_signal_connect(GTK_OBJECT( GTK_COMBO(races_name)->list), 
+  gtk_signal_connect(GTK_OBJECT( GTK_COMBO(leader_name)->list), 
                      "selection_changed",
-                     GTK_SIGNAL_FUNC(races_name_callback), NULL);
+                     GTK_SIGNAL_FUNC(leader_name_callback), NULL);
 
   gtk_signal_connect(GTK_OBJECT(races_ok_command), "clicked",
                        GTK_SIGNAL_FUNC(races_buttons_callback), NULL);
@@ -2134,9 +2282,9 @@
   gtk_signal_connect(GTK_OBJECT(races_quit_command), "clicked",
                      GTK_SIGNAL_FUNC(races_buttons_callback), NULL);
 
-  gtk_signal_connect(GTK_OBJECT(GTK_COMBO(races_by_name)->list), 
-                     "selection_changed",
-                     GTK_SIGNAL_FUNC(races_by_name_callback), NULL);
+  gtk_signal_connect(GTK_OBJECT(notebook), "switch-page",
+                    GTK_SIGNAL_FUNC(switch_page_callback), NULL);
+
  
   /* ------- set initial selections ------- */
 
@@ -2152,20 +2300,26 @@
 /**************************************************************************
 ...
 **************************************************************************/ 
-static void races_by_name_callback(GtkWidget *w, gpointer data)
+static void races_by_name_callback(GtkWidget * w, gpointer data)
 {
-  int i;
-
-  for(i = 0; i < g_list_length(sorted_races_list); i++) {
-    if (strcmp(gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(races_by_name)->entry)),
-               get_nation_by_idx(GPOINTER_TO_INT(
-               g_list_nth_data(sorted_races_list, i)))->name) == 0) {
-      if (GTK_WIDGET_SENSITIVE(races_toggles[i])) {
-       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(races_toggles[i]), TRUE);
-       break;
+  int i, class_id = selected_class;
+  char *chosen =
+      gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(races_by_name[class_id])->
+                                  entry));
+
+  for (i = 0; i < g_list_length(sorted_races_list[class_id]); i++) {
+    if (strcmp(chosen,
+              get_nation_by_idx(GPOINTER_TO_INT
+                                (g_list_nth_data
+                                 (sorted_races_list[class_id],
+                                  i)))->name) == 0) {
+      if (GTK_WIDGET_SENSITIVE(races_toggles[class_id][i])) {
+       gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON
+                                   (races_toggles[class_id][i]), TRUE);
+       break;
       } else {
        /* That one's taken */
-       select_random_race();
+       select_random_race();
       }
     }
   }
@@ -2176,26 +2330,33 @@
 **************************************************************************/
 void races_toggles_set_sensitive(struct packet_nations_used *packet)
 {
-  int i;
+  int i, class_id;
 
-  for (i = 0; i < game.playable_nation_count; i++) {
-    gtk_widget_set_sensitive(races_toggles[g_list_index
-                                          (sorted_races_list,
-                                           GINT_TO_POINTER(i))], TRUE);
+  freelog(LOG_DEBUG, "%d nations used:", packet->num_nations_used);
+
+  for (class_id = 0; class_id < num_classes; class_id++) {
+    int nations_in_class = g_list_length(sorted_races_list[class_id]);
+
+    for (i = 0; i < nations_in_class; i++) {
+      gtk_widget_set_sensitive(races_toggles[class_id][i], TRUE);
+    }
+
+    for (i = 0; i < packet->num_nations_used; i++) {
+      int nation = packet->nations_used[i];
+
+      gtk_widget_set_sensitive(races_toggles[class_id][g_list_index
+                                                      (sorted_races_list
+                                                       [class_id],
+                                                       GINT_TO_POINTER
+                                                       (nation))], FALSE);
+    }
   }
 
-  freelog(LOG_DEBUG, "%d nations used:", packet->num_nations_used);
   for (i = 0; i < packet->num_nations_used; i++) {
     int nation = packet->nations_used[i];
 
     freelog(LOG_DEBUG, "  [%d]: %d = %s", i, nation,
            get_nation_name(nation));
-
-    gtk_widget_set_sensitive(races_toggles[g_list_index
-                                          (sorted_races_list,
-                                           GINT_TO_POINTER(nation))],
-                            FALSE);
-
     if (nation == selected_nation) {
       select_random_race();
     }
@@ -2205,11 +2366,11 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void races_name_callback(GtkWidget *w, gpointer data)
+static void leader_name_callback(GtkWidget *w, gpointer data)
 {
   Nation_Type_id nation = races_buttons_get_current();
   const char *leader =
-                  gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(races_name)->entry));
+                  gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(leader_name)->entry));
 
   if (check_nation_leader_name(nation, leader)) {
     is_name_unique = FALSE;
@@ -2224,20 +2385,31 @@
 /**************************************************************************
 ...
 **************************************************************************/
-static void races_toggles_callback(GtkWidget *w, gpointer race_id_p)
+static void races_toggles_callback(GtkWidget * w, gpointer race_id_p)
 {
-  /* don't do anything if signal is untoggling the button */
-  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
-    selected_nation = GPOINTER_TO_INT(race_id_p);
-    gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(races_by_name)->entry),
-                      get_nation_by_idx(selected_nation)->name);
-    select_random_leader();
+  int class_id = selected_class;
 
-    selected_city_style = 
-                      city_style_ridx[get_nation_city_style(selected_nation)];
-    gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(
-                              city_style_toggles[selected_city_style]), TRUE);
+  if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w))) {
+    /* don't do anything if signal is untoggling the button */
+    return;
   }
+
+  selected_nation = GPOINTER_TO_INT(race_id_p);
+
+  gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(races_by_name[class_id])->entry),
+                    get_nation_by_idx(selected_nation)->name);
+  gtk_label_set_text(GTK_LABEL(class[class_id]),
+                    get_nation_by_idx(selected_nation)->class);
+  gtk_label_set_text(GTK_LABEL(legend[class_id]),
+                    get_nation_by_idx(selected_nation)->legend);
+
+  select_random_leader();
+
+  selected_city_style =
+      city_style_ridx[get_nation_city_style(selected_nation)];
+  gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON
+                             (city_style_toggles[selected_city_style]),
+                             TRUE);
 }
 
 /**************************************************************************
@@ -2320,7 +2492,7 @@
     return;
   }
 
-  s = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(races_name)->entry));
+  s = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(leader_name)->entry));
 
   /* perform a minimum of sanity test on the name */
   packet.nation_no = selected;

[Prev in Thread] Current Thread [Next in Thread]