Complete.Org: Mailing Lists: Archives: freeciv-dev: April 2000:
[Freeciv-Dev] gtk gui enhancements
Home

[Freeciv-Dev] gtk gui enhancements

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] gtk gui enhancements
From: Richard Atkins <rja@xxxxxxxxxxx>
Date: Thu, 13 Apr 2000 17:24:59 +1000 (EST)

Hi all,

Here's a couple of patches I've whipped up to fix a couple of things that
were annoying me in the gtk client:

1) When editing a worklist, the available targets did not update, meaning
I could put two barracks on the worklist (accidentally of course).

2) When browsing the tech help pages, I can't see far back down a tech
tree, and I can't click on a tech in the tree to go to its help.

The patch in wldlg.c.diff fixes 1) for wonders and improvements, by
performing an extra check in worklist_populate_targets() to see if a
building is already in the worklist. It also causes updates to be done
whenever "Prepend", "Insert" or "Delete" are selected. These updates could
be optimized, as at the moment they are only calling
worklist_populate_targets(), instead of anything more efficient.

The patch in helpdlg.c.diff fixes 2) by making the tree build to 20 levels
deep, but only expanded to 3 levels. It adds two buttons to control the
expansion of the tech tree ("Expand all" and "Collapse all"), and a few
callbacks to handle clicks on tree nodes or either button.

The help patch might make the tech tree a little hard to navigate when the
whole tree is expanded, and it is easy to slip and go to a tech's help
page instead of expand or collapse the tree under that tech.

If you have any problems with these, let me know what you think needs to
be done, and I'll do it.

Thanks,
        Richard
--------
       Richard Atkins  rja@xxxxxxxxxxx
       http://www.pcug.org.au/~rja/

       "All these moments will be lost in
       time, like tears in the rain."
                              Blade Runner
                                         --------
--- client/gui-gtk/helpdlg.c.orig       Wed Apr 12 16:46:30 2000
+++ client/gui-gtk/helpdlg.c    Wed Apr 12 17:25:25 2000
@@ -42,6 +42,8 @@
 
 #include "helpdlg.h"
 
+#define TECH_TREE_DEPTH         20
+#define TECH_TREE_EXPANDED_DEPTH 3
 
 extern GtkWidget *toplevel;
 
@@ -56,6 +58,9 @@
 GtkWidget *            help_frame;
 GtkWidget *            help_text;
 GtkWidget *            help_text_scrolled;
+GtkWidget *             help_tree_expand;
+GtkWidget *             help_tree_collapse;
+GtkWidget *             help_tree_buttons_hbox;
 GtkWidget *            help_vbox;
 GtkWidget *            unit_tile;
 GtkWidget *            help_box;
@@ -168,7 +173,7 @@
 ...
 **************************************************************************/
 static void create_tech_tree(GtkCTree *ctree, int tech, int levels,
-                            GtkCTreeNode *parent)
+                            int expanded_levels, GtkCTreeNode *parent)
 {
   GtkCTreeNode *l;
   gchar        *text[1];
@@ -184,6 +189,7 @@
     bg = COLOR_STD_RED;
     l = gtk_ctree_insert_node(ctree, parent, NULL, text, 10,
                                NULL, NULL, NULL, NULL, TRUE, TRUE);
+    gtk_ctree_node_set_row_data(ctree, l, (gpointer)tech);
     gtk_ctree_node_set_background(ctree, l, colors_standard[bg]);
     return;
   }
@@ -203,19 +209,53 @@
 
   l = gtk_ctree_insert_node(ctree, parent, NULL, text, 10,
                                 NULL, NULL, NULL, NULL, leaf, TRUE);
+  gtk_ctree_node_set_row_data(ctree, l, (gpointer)tech);
   gtk_ctree_node_set_background(ctree, l, colors_standard[bg]);
+  if (expanded_levels > 0) {
+    gtk_ctree_expand(ctree, l);
+    expanded_levels--;
+  } else {
+    gtk_ctree_collapse(ctree, l);
+  }
 
   if ( --levels <= 0 )
       return;
 
   if ( advances[tech].req[0] != A_NONE )
-    create_tech_tree(ctree, advances[tech].req[0], levels, l);
+    create_tech_tree(ctree, advances[tech].req[0], levels, expanded_levels, l);
   if ( advances[tech].req[1] != A_NONE )
-    create_tech_tree(ctree, advances[tech].req[1], levels, l);
+    create_tech_tree(ctree, advances[tech].req[1], levels, expanded_levels, l);
   return;
 }
 
 /**************************************************************************
+Called when a tech in the tree is selected
+**************************************************************************/
+static void help_tech_tree_select_callback(GtkCTree *ctree, GtkCTreeNode 
*node, gpointer data)
+{
+  int tech = (int)gtk_ctree_node_get_row_data(GTK_CTREE(ctree), 
GTK_CTREE_NODE(node));
+  select_help_item_string(advances[tech].name, HELP_TECH);
+}
+
+/**************************************************************************
+Called "Expand all" button is clicked
+**************************************************************************/
+static void help_tech_tree_expand_callback(GtkWidget *w, gpointer data)
+{
+  GtkCTree *ctree = GTK_CTREE(data);
+  gtk_ctree_expand_recursive(ctree, gtk_ctree_node_nth(ctree, 0));
+}
+
+/**************************************************************************
+Called "Collapse all" button is clicked
+**************************************************************************/
+static void help_tech_tree_collapse_callback(GtkWidget *w, gpointer data)
+{
+  GtkCTree *ctree = GTK_CTREE(data);
+  gtk_ctree_collapse_recursive(ctree, gtk_ctree_node_nth(ctree, 0));
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 static void help_hyperlink_callback(GtkWidget *w, enum help_page_type type)
@@ -421,6 +461,9 @@
   gtk_ctree_set_expander_style(GTK_CTREE(help_tree),
                                  GTK_CTREE_EXPANDER_CIRCULAR);
 
+  gtk_signal_connect(GTK_OBJECT(help_tree), "tree_select_row",
+                    GTK_SIGNAL_FUNC(help_tech_tree_select_callback), NULL);
+
   help_tree_scrolled = gtk_scrolled_window_new(NULL, NULL);
   gtk_container_add(GTK_CONTAINER(help_tree_scrolled), help_tree);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(help_tree_scrolled),
@@ -428,6 +471,22 @@
 
   gtk_box_pack_start( GTK_BOX( help_box ), help_tree_scrolled, TRUE, TRUE, 0 );
 
+  help_tree_expand = gtk_button_new_with_label(_("Expand All"));
+  help_tree_collapse = gtk_button_new_with_label(_("Collapse All"));
+  gtk_signal_connect(GTK_OBJECT(help_tree_expand), "clicked",
+                    GTK_SIGNAL_FUNC(help_tech_tree_expand_callback),
+                    help_tree);
+  gtk_signal_connect(GTK_OBJECT(help_tree_collapse), "clicked",
+                    GTK_SIGNAL_FUNC(help_tech_tree_collapse_callback),
+                    help_tree);
+  help_tree_buttons_hbox = gtk_hbox_new(TRUE, 5);
+  gtk_box_pack_start(GTK_BOX(help_tree_buttons_hbox), help_tree_expand,
+                    FALSE, FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(help_tree_buttons_hbox), help_tree_collapse,
+                    FALSE, FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(help_box), help_tree_buttons_hbox,
+                    FALSE, FALSE, 0);
+
   button = gtk_button_new_with_label( _("Close") );
   gtk_box_pack_start( GTK_BOX( GTK_DIALOG(help_dialog_shell)->action_area ),
       button, TRUE, TRUE, 0 );
@@ -621,9 +680,11 @@
 
     gtk_clist_freeze(GTK_CLIST(help_tree));
     gtk_clist_clear(GTK_CLIST(help_tree));
-    create_tech_tree(GTK_CTREE(help_tree), i, 3, NULL);
+    create_tech_tree(GTK_CTREE(help_tree), i, TECH_TREE_DEPTH,
+                    TECH_TREE_EXPANDED_DEPTH, NULL);
     gtk_clist_thaw(GTK_CLIST(help_tree));
     gtk_widget_show_all(help_tree_scrolled);
+    gtk_widget_show_all(help_tree_buttons_hbox);
 
     helptext_tech(buf, i, pitem->text);
     if (advances[i].helptext) {
--- client/gui-gtk/wldlg.c.orig Wed Apr 12 16:46:15 2000
+++ client/gui-gtk/wldlg.c      Wed Apr 12 16:59:41 2000
@@ -919,11 +919,11 @@
        where++;
     }
   } else if (idx >= pdialog->worklist_avail_num_improvements) {
-    /* target is an improvement or wonder */
+    /* target is a unit */
     insert_into_worklist(pdialog, where, target+B_LAST);
     where++;
   } else {
-    /* target is a unit */
+    /* target is an improvement or wonder */
     insert_into_worklist(pdialog, where, target);
     where++;
   }
@@ -939,6 +939,15 @@
   /* Re-select the item that was previously selected. */
   if (where < len)
     gtk_clist_select_row((GtkCList *)pdialog->worklist, where, 0);
+
+  if (idx < pdialog->worklist_avail_num_improvements) {
+    /* Update the list of available targets */
+    worklist_populate_targets(pdialog);
+    update_clist(pdialog->avail, pdialog->worklist_avail_names_ptrs);
+
+    /* Select the next available target */
+    gtk_clist_select_row((GtkCList *)pdialog->avail, idx, 0);
+  }
 }
 
 /****************************************************************
@@ -948,12 +957,13 @@
 {
   struct worklist_dialog *pdialog = (struct worklist_dialog *)data;
   GList *selection = GTK_CLIST(pdialog->worklist)->selection;
-  int i, j, k;
+  int i, j, k, id;
 
   if (! selection)
     return;
 
   k = (int)selection->data;
+  id = pdialog->worklist_ids[k];
 
   /* Find the last element in the worklist */
   for (i = 0; i < MAX_LEN_WORKLIST; i++)
@@ -984,6 +994,12 @@
      if there is such an item. */
   if (k < i)
     gtk_clist_select_row((GtkCList *)pdialog->worklist, k, 0);
+
+  if (id < B_LAST) {
+    /* Update the list of available targets */
+    worklist_populate_targets(pdialog);
+    update_clist(pdialog->avail, pdialog->worklist_avail_names_ptrs);
+  }
 }
 
 /****************************************************************
@@ -1230,10 +1246,10 @@
 *****************************************************************/
 void worklist_populate_targets(struct worklist_dialog *pdialog)
 {
-  int i, n;
+  int i, j, n;
   struct player *pplr = game.player_ptr;
   int advanced_tech;
-  int can_build, can_eventually_build;
+  int can_build, can_eventually_build, is_building;
   
 
   n = 0;
@@ -1253,6 +1269,18 @@
     can_build = can_player_build_improvement(pplr,i);
     can_eventually_build = could_player_eventually_build_improvement(pplr,i);
 
+    /* Is the player already going to build this improvement? */
+    j = 0;
+    is_building = FALSE;
+    while ((j < MAX_LEN_WORKLIST) && 
+          (pdialog->worklist_ids[j] != WORKLIST_END)) {
+      if (pdialog->worklist_ids[j] == i) {
+       is_building = TRUE;
+       break;
+      }
+      j++;
+    }
+
     /* If there's a city, can the city build the improvement? */
     if (pdialog->pcity) {
       can_build = can_build && can_build_improvement(pdialog->pcity, i);
@@ -1260,8 +1288,9 @@
        can_eventually_build_improvement(pdialog->pcity, i);
     }
     
-    if (( advanced_tech && can_eventually_build) ||
-       (!advanced_tech && can_build)) {
+    if ((( advanced_tech && can_eventually_build) ||
+        (!advanced_tech && can_build)) &&
+       !is_building) {
       worklist_id_to_name(pdialog->worklist_avail_names[n],
                          i, 0, pdialog->pcity);
       pdialog->worklist_avail_names_ptrs[n]=pdialog->worklist_avail_names[n];
@@ -1272,11 +1301,11 @@
 
   /*     + Second, units. */
   for(i=0; i<game.num_unit_types; i++) {
-    /* Can the player (eventually) build this improvement? */
+    /* Can the player (eventually) build this unit? */
     can_build = can_player_build_unit(pplr,i);
     can_eventually_build = can_player_eventually_build_unit(pplr,i);
 
-    /* If there's a city, can the city build the improvement? */
+    /* If there's a city, can the city build the unit? */
     if (pdialog->pcity) {
       can_build = can_build && can_build_unit(pdialog->pcity, i);
       can_eventually_build = can_eventually_build &&

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] gtk gui enhancements, Richard Atkins <=