Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2004:
[Freeciv-Dev] (PR#9417) gui-gtk-2.0 needs update_intel_dialog
Home

[Freeciv-Dev] (PR#9417) gui-gtk-2.0 needs update_intel_dialog

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#9417) gui-gtk-2.0 needs update_intel_dialog
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Sat, 18 Sep 2004 14:09:41 -0700
Reply-to: rt@xxxxxxxxxxx

<URL: http://rt.freeciv.org/Ticket/Display.html?id=9417 >

> [jdorje - Sun Jul 18 04:22:01 2004]:
> 
> gui-gtk-2.0 needs an implementation of update_intel_dialog.  This
> function is called when player info changes and should adjust the intel
> dialog accordingly.

Here's a patch.

Index: client/gui-gtk-2.0/inteldlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/inteldlg.c,v
retrieving revision 1.15
diff -u -r1.15 inteldlg.c
--- client/gui-gtk-2.0/inteldlg.c       3 Sep 2004 18:43:17 -0000       1.15
+++ client/gui-gtk-2.0/inteldlg.c       18 Sep 2004 21:08:47 -0000
@@ -37,7 +37,38 @@
 #include "inteldlg.h"
 
 /******************************************************************/
+static const char *table_text[] = {
+  N_("Ruler:"),
+  N_("Government:"),
+  N_("Capital:"),
+  N_("Gold:"),
+  NULL,
+  N_("Tax:"),
+  N_("Science:"),
+  N_("Luxury:"),
+  NULL,
+  N_("Researching:")
+};
+
+enum table_label {
+  LABEL_RULER,
+  LABEL_GOVERNMENT,
+  LABEL_CAPITAL,
+  LABEL_GOLD,
+  LABEL_SEP1,
+  LABEL_TAX,
+  LABEL_SCIENCE,
+  LABEL_LUXURY,
+  LABEL_SEP2,
+  LABEL_RESEARCHING,
+  LABEL_LAST
+};
+/******************************************************************/
 static GtkWidget *intel_dialog_shell;
+
+static GtkTreeStore *intel_diplstates;
+static GtkListStore *intel_techs;
+static GtkWidget *intel_table_labels[LABEL_LAST];
 /******************************************************************/
 
 
@@ -60,52 +91,17 @@
 /****************************************************************
 ...
 *****************************************************************/
-void intel_create_dialog(struct player *p)
+static void intel_create_dialog(struct player *p)
 {
   GtkWidget *notebook, *label, *sw, *view, *table, *alignment;
   GtkCellRenderer *rend;
   GtkTreeViewColumn *col;
 
-  GtkListStore *store;
-
-  GtkTreeIter diplstates[DS_LAST];
-  GtkTreeStore *tree;
-
-  char buf[64];
-  struct city *pcity;
-
   int i;
-  static const char *table_text[] = {
-    N_("Ruler:"),
-    N_("Government:"),
-    N_("Capital:"),
-    N_("Gold:"),
-    NULL,
-    N_("Tax:"),
-    N_("Science:"),
-    N_("Luxury:"),
-    NULL,
-    N_("Researching:")
-  };
-  enum table_label {
-    LABEL_RULER,
-    LABEL_GOVERNMENT,
-    LABEL_CAPITAL,
-    LABEL_GOLD,
-    LABEL_SEP1,
-    LABEL_TAX,
-    LABEL_SCIENCE,
-    LABEL_LUXURY,
-    LABEL_SEP2,
-    LABEL_RESEARCHING
-  };
  
  
-  my_snprintf(buf, sizeof(buf),
-             _("Foreign Intelligence: %s Empire"), get_nation_name(p->nation));
-
   intel_dialog_shell =
-    gtk_dialog_new_with_buttons(buf,
+    gtk_dialog_new_with_buttons(NULL,
       NULL,
       0,
       GTK_STOCK_CLOSE,
@@ -146,88 +142,22 @@
       gtk_table_attach(GTK_TABLE(table), label,
          0, 1, i, i+1, GTK_FILL, GTK_FILL|GTK_EXPAND, 0, 0);
 
-      switch (i) {
-       case LABEL_RULER:
-         my_snprintf(buf, sizeof(buf), "%s %s", 
-             get_ruler_title(p->government, p->is_male, p->nation), p->name);
-         break;
-       case LABEL_GOVERNMENT:
-         sz_strlcpy(buf, get_government_name(p->government));
-         break;
-       case LABEL_CAPITAL:
-         pcity = find_palace(p);
-         sz_strlcpy(buf, (!pcity) ? _("(Unknown)") : pcity->name);
-         break;
-       case LABEL_GOLD:
-         my_snprintf(buf, sizeof(buf), "%d", p->economic.gold);
-         break;
-       case LABEL_TAX:
-         my_snprintf(buf, sizeof(buf), "%d%%", p->economic.tax);
-         break;
-       case LABEL_SCIENCE:
-         my_snprintf(buf, sizeof(buf), "%d%%", p->economic.science);
-         break;
-       case LABEL_LUXURY:
-         my_snprintf(buf, sizeof(buf), "%d%%", p->economic.luxury);
-         break;
-       case LABEL_RESEARCHING:
-         if (p->research.researching != A_NOINFO) {
-           my_snprintf(buf, sizeof(buf), "%s(%d/%d)",
-               get_tech_name(p, p->research.researching),
-               p->research.bulbs_researched, total_bulbs_required(p));
-         } else {
-           my_snprintf(buf, sizeof(buf), _("(Unknown)"));
-         }
-         break;
-       default:
-         buf[0] = '\0';
-         break;
-      }
-
-      if (buf[0] != '\0') {
-       label = gtk_label_new(buf);
-       gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
-       gtk_table_attach(GTK_TABLE(table), label,
-           1, 2, i, i+1, GTK_FILL, GTK_FILL|GTK_EXPAND, 0, 0);
-      }
+      label = gtk_label_new(NULL);
+      intel_table_labels[i] = label;
+      gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
+      gtk_table_attach(GTK_TABLE(table), label,
+         1, 2, i, i+1, GTK_FILL, GTK_FILL|GTK_EXPAND, 0, 0);
     } else {
+      intel_table_labels[i] = NULL;
       gtk_table_set_row_spacing(GTK_TABLE(table), i, 12);
     }
   }
 
   /* diplomacy tab. */
-  tree = gtk_tree_store_new(1, G_TYPE_STRING);
-
-  for (i = 0; i < ARRAY_SIZE(diplstates); i++) {
-    GtkTreeIter it;
-    GValue v = { 0, };
-
-    gtk_tree_store_append(tree, &it, NULL);
-    g_value_init(&v, G_TYPE_STRING);
-    g_value_set_static_string(&v, diplstate_text(i));
-    gtk_tree_store_set_value(tree, &it, 0, &v);
-    g_value_unset(&v);
-    diplstates[i] = it;
-  }
+  intel_diplstates = gtk_tree_store_new(1, G_TYPE_STRING);
 
-  players_iterate(other) {
-    const struct player_diplstate *state;
-    GtkTreeIter it;
-    GValue v = { 0, };
-
-    if (other == p) {
-      continue;
-    }
-    state = pplayer_get_diplstate(p, other);
-    gtk_tree_store_append(tree, &it, &diplstates[state->type]);
-    g_value_init(&v, G_TYPE_STRING);
-    g_value_set_static_string(&v, other->name);
-    gtk_tree_store_set_value(tree, &it, 0, &v);
-    g_value_unset(&v);
-  } players_iterate_end;
-
-  view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree));
-  g_object_unref(tree);
+  view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(intel_diplstates));
+  g_object_unref(intel_diplstates);
   gtk_container_set_border_width(GTK_CONTAINER(view), 6);
   gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
 
@@ -254,22 +184,10 @@
   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), alignment, label);
 
   /* techs tab. */
-  store = gtk_list_store_new(2, G_TYPE_BOOLEAN, G_TYPE_STRING);
-
-  for(i=A_FIRST; i<game.num_tech_types; i++)
-    if(get_invention(p, i)==TECH_KNOWN) {
-      GtkTreeIter it;
-
-      gtk_list_store_append(store, &it);
+  intel_techs = gtk_list_store_new(2, G_TYPE_BOOLEAN, G_TYPE_STRING);
 
-      gtk_list_store_set(store, &it,
-        0, (get_invention(game.player_ptr, i)!=TECH_KNOWN),
-       1, advances[i].name,
-        -1);
-    }
-
-  view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
-  g_object_unref(store);
+  view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(intel_techs));
+  g_object_unref(intel_techs);
   gtk_container_set_border_width(GTK_CONTAINER(view), 6);
   gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(view), FALSE);
 
@@ -299,6 +217,8 @@
   gtk_notebook_append_page(GTK_NOTEBOOK(notebook), alignment, label);
 
   gtk_widget_show_all(GTK_DIALOG(intel_dialog_shell)->vbox);
+
+  update_intel_dialog(p);
 }
 
 /****************************************************************************
@@ -307,5 +227,110 @@
 ****************************************************************************/
 void update_intel_dialog(struct player *p)
 {
-  /* PORTME */
+  if (intel_dialog_shell) {
+    GtkTreeIter diplstates[DS_LAST];
+    char buf[64];
+    int i;
+
+    /* window title. */
+    my_snprintf(buf, sizeof(buf),
+       _("Foreign Intelligence: %s Empire"), get_nation_name(p->nation));
+    gtk_window_set_title(GTK_WINDOW(intel_dialog_shell), buf);
+
+    /* diplomacy tab. */
+    gtk_tree_store_clear(intel_diplstates);
+
+    for (i = 0; i < ARRAY_SIZE(diplstates); i++) {
+      GtkTreeIter it;
+      GValue v = { 0, };
+
+      gtk_tree_store_append(intel_diplstates, &it, NULL);
+      g_value_init(&v, G_TYPE_STRING);
+      g_value_set_static_string(&v, diplstate_text(i));
+      gtk_tree_store_set_value(intel_diplstates, &it, 0, &v);
+      g_value_unset(&v);
+      diplstates[i] = it;
+    }
+
+    players_iterate(other) {
+      const struct player_diplstate *state;
+      GtkTreeIter it;
+      GValue v = { 0, };
+
+      if (other == p) {
+       continue;
+      }
+      state = pplayer_get_diplstate(p, other);
+      gtk_tree_store_append(intel_diplstates, &it, &diplstates[state->type]);
+      g_value_init(&v, G_TYPE_STRING);
+      g_value_set_static_string(&v, other->name);
+      gtk_tree_store_set_value(intel_diplstates, &it, 0, &v);
+      g_value_unset(&v);
+    } players_iterate_end;
+
+    /* techs tab. */
+    gtk_list_store_clear(intel_techs);
+
+    for(i=A_FIRST; i<game.num_tech_types; i++)
+      if(get_invention(p, i)==TECH_KNOWN) {
+       GtkTreeIter it;
+
+       gtk_list_store_append(intel_techs, &it);
+
+       gtk_list_store_set(intel_techs, &it,
+           0, (get_invention(game.player_ptr, i)!=TECH_KNOWN),
+           1, advances[i].name,
+           -1);
+      }
+
+    /* table labels. */
+    for (i = 0; i < ARRAY_SIZE(intel_table_labels); i++) {
+      if (intel_table_labels[i]) {
+       struct city *pcity;
+
+       switch (i) {
+         case LABEL_RULER:
+           my_snprintf(buf, sizeof(buf), "%s %s", 
+               get_ruler_title(p->government, p->is_male, p->nation), p->name);
+           break;
+         case LABEL_GOVERNMENT:
+           sz_strlcpy(buf, get_government_name(p->government));
+           break;
+         case LABEL_CAPITAL:
+           pcity = find_palace(p);
+           sz_strlcpy(buf, (!pcity) ? _("(Unknown)") : pcity->name);
+           break;
+         case LABEL_GOLD:
+           my_snprintf(buf, sizeof(buf), "%d", p->economic.gold);
+           break;
+         case LABEL_TAX:
+           my_snprintf(buf, sizeof(buf), "%d%%", p->economic.tax);
+           break;
+         case LABEL_SCIENCE:
+           my_snprintf(buf, sizeof(buf), "%d%%", p->economic.science);
+           break;
+         case LABEL_LUXURY:
+           my_snprintf(buf, sizeof(buf), "%d%%", p->economic.luxury);
+           break;
+         case LABEL_RESEARCHING:
+           if (p->research.researching != A_NOINFO) {
+             my_snprintf(buf, sizeof(buf), "%s(%d/%d)",
+                 get_tech_name(p, p->research.researching),
+                 p->research.bulbs_researched, total_bulbs_required(p));
+           } else {
+             my_snprintf(buf, sizeof(buf), _("(Unknown)"));
+           }
+           break;
+         default:
+           buf[0] = '\0';
+           break;
+       }
+
+       if (buf[0] != '\0') {
+         gtk_label_set_text(GTK_LABEL(intel_table_labels[i]), buf);
+       }
+      }
+    }
+  }
 }
+

[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#9417) gui-gtk-2.0 needs update_intel_dialog, Vasco Alexandre da Silva Costa <=