<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40710 >

This transaction appears to have no content
Hi,

I have made a patch adding in the Economic report dialog (GTK client
only) a list of all the traderoutes. The total amount of trade is also
displayed.

The patch is based on SVN version 15463.

Only one file modified client/gui-gtk-2.0/repodlgs.c

Hope that's help.
Mitchum



Hi,

I have made a patch adding in the Economic report dialog (GTK client only) a list of all the traderoutes. The total amount of trade is also displayed.

The patch is based on SVN version 15463.

Only one file modified client/gui-gtk-2.0/repodlgs.c

Hope that's help.
Mitchum



--- SAV_repodlgs.c	2009-02-01 20:18:55.000000000 +0100
+++ repodlgs.c	2009-02-07 10:02:25.000000000 +0100
@@ -49,6 +49,7 @@
 #include "packhand_gen.h"
 #include "control.h"
 #include "reqtree.h"
+#include "plrdlg.h" /* for get_flag() */
 #include "text.h"
 
 #include "canvas.h"
@@ -76,6 +77,7 @@
 };
 
 static void create_economy_report_dialog(bool make_modal);
+static void traderoutes_selection_changed_callback(GtkTreeSelection *selection);
 static void economy_command_callback(struct gui_dialog *dlg, int response,
                                      gpointer data);
 static void economy_selection_callback(GtkTreeSelection *selection,
@@ -85,7 +87,12 @@
 static struct gui_dialog *economy_dialog_shell = NULL;
 static GtkWidget *economy_label2;
 static GtkListStore *economy_store;
+static GtkWidget *traderoutes_label;
+static GtkWidget *traderoutes_view;
+static GtkListStore *traderoutes_store;
+static int total_trade=0;
 static GtkTreeSelection *economy_selection;
+static GtkTreeSelection *traderoutes_selection;
 static GtkWidget *sellall_command, *sellobsolete_command;
 static int economy_dialog_shell_is_modal;
 
@@ -646,6 +653,16 @@
     /* TRANS: Upkeep total, count*cost */
     _("U Total")
   };
+  const char *titlestrade[8] = {
+    _("Our City"),
+    _("Size"),
+    _("Dest City"),
+    _("Flag"),
+    _("Nation"),
+    _("Size"),
+    _("Distance"),
+    _("Trade")
+  };
   int i;
 
   static GType model_types[5] = {
@@ -655,16 +672,37 @@
     G_TYPE_INT,
     G_TYPE_INT
   };
-  GtkWidget *view, *sw, *align;
+  static GType traderoutes[8] = {
+    G_TYPE_STRING,
+    G_TYPE_INT,
+    G_TYPE_STRING,
+    G_TYPE_NONE,
+    G_TYPE_STRING,
+    G_TYPE_INT,
+    G_TYPE_INT,
+    G_TYPE_INT
+  };
+  GtkWidget *frame, *hbox, *vbox, *view, *sw, *align;
 
   model_types[0] = GDK_TYPE_PIXBUF;
+  traderoutes[3] = GDK_TYPE_PIXBUF;
 
   gui_dialog_new(&economy_dialog_shell, GTK_NOTEBOOK(top_notebook), NULL);
   gui_dialog_set_title(economy_dialog_shell, _("Economy"));
-
+    
   align = gtk_alignment_new(0.5, 0.0, 0.0, 1.0);
   gtk_box_pack_start(GTK_BOX(economy_dialog_shell->vbox), align,
       TRUE, TRUE, 0);
+    
+  hbox = gtk_hbox_new(FALSE, 0);
+  gtk_container_add(GTK_CONTAINER(align), hbox);
+    
+  /* Model list in left side  */
+  frame = gtk_frame_new(_("Buildings"));
+  gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 2);
+
+  vbox = gtk_vbox_new(FALSE, 0);
+  gtk_container_add(GTK_CONTAINER(frame), vbox);
 
   economy_store = gtk_list_store_newv(ARRAY_SIZE(model_types), model_types);
 
@@ -673,7 +711,7 @@
 				      GTK_SHADOW_ETCHED_IN);
   gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
 				 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
-  gtk_container_add(GTK_CONTAINER(align), sw);
+  gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
 
   view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(economy_store));
   g_object_unref(economy_store);
@@ -715,8 +753,7 @@
   gtk_container_add(GTK_CONTAINER(sw), view);
 
   economy_label2 = gtk_label_new(_("Total Cost:"));
-  gtk_box_pack_start(GTK_BOX(economy_dialog_shell->vbox), economy_label2,
-      FALSE, FALSE, 0);
+  gtk_box_pack_start(GTK_BOX(vbox), economy_label2, FALSE, FALSE, 0);
   gtk_misc_set_padding(GTK_MISC(economy_label2), 5, 5);
 
   sellobsolete_command =
@@ -728,7 +765,58 @@
     gui_dialog_add_button(economy_dialog_shell, _("Sell _All"),
 	ECONOMY_SELL_ALL);
   gtk_widget_set_sensitive(sellall_command, FALSE);
+    
+  /* The traderoutes list in right side  */
+  frame = gtk_frame_new(_("City Traderoutes"));
+  gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, FALSE, 2);
+
+  vbox = gtk_vbox_new(FALSE, 0);
+  gtk_container_add(GTK_CONTAINER(frame), vbox);
+
+  traderoutes_store = gtk_list_store_newv(ARRAY_SIZE(traderoutes), traderoutes);
+
+  sw = gtk_scrolled_window_new(NULL,NULL);
+  gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
+				      GTK_SHADOW_ETCHED_IN);
+  gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
+				 GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
+  gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
 
+  traderoutes_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(traderoutes_store));
+  g_object_unref(traderoutes_store);
+  gtk_widget_set_name(traderoutes_view, "small_font");
+  gtk_tree_view_columns_autosize(GTK_TREE_VIEW(traderoutes_view));
+  traderoutes_selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(traderoutes_view));
+  gtk_tree_selection_set_mode(traderoutes_selection, GTK_SELECTION_MULTIPLE);
+  g_signal_connect(traderoutes_selection, "changed",
+	                 G_CALLBACK(traderoutes_selection_changed_callback), NULL);
+
+  for (i=0; i<ARRAY_SIZE(traderoutes); i++) {
+    GtkCellRenderer *renderer;
+    GtkTreeViewColumn *col;
+
+    if (traderoutes[i] == GDK_TYPE_PIXBUF) {
+      renderer = gtk_cell_renderer_pixbuf_new();
+
+      col = gtk_tree_view_column_new_with_attributes(titlestrade[i], renderer,
+	  "pixbuf", i, NULL);
+    } else {
+      renderer = gtk_cell_renderer_text_new();
+
+      col = gtk_tree_view_column_new_with_attributes(titlestrade[i], renderer,
+	  "text", i, NULL);
+      gtk_tree_view_column_set_sort_column_id(col, i);
+            
+    }
+    gtk_tree_view_append_column(GTK_TREE_VIEW(traderoutes_view), col);
+  }
+  gtk_container_add(GTK_CONTAINER(sw), traderoutes_view);
+
+  traderoutes_label = gtk_label_new(_("Total Trade:"));
+  gtk_box_pack_start(GTK_BOX(vbox), traderoutes_label, FALSE, FALSE, 0);
+  gtk_misc_set_padding(GTK_MISC(traderoutes_label), 5, 5);
+
+  /* Close button and update */  
   gui_dialog_add_button(economy_dialog_shell,
       GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
 
@@ -745,6 +833,61 @@
   gtk_tree_view_focus(GTK_TREE_VIEW(view));
 }
 
+/***************************************************************************
+  Update the value displayed by the "total trade" label in the ecconomic
+  report, or make it blank if nothing can be bought.
+***************************************************************************/
+static void update_total_trade(void)
+{
+  GtkWidget *label, *view;
+  GList *rows, *p;
+  GtkTreeModel *model;
+  GtkTreeSelection *sel;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  gpointer res;
+  int selected_trade = 0;
+
+  view = traderoutes_view;
+  label = traderoutes_label;
+
+  if (!view || !label) {
+    return;
+  }
+
+  sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(view));
+  rows = gtk_tree_selection_get_selected_rows(sel, &model);
+
+  for (p = rows; p != NULL; p = p->next) {
+    path = p->data;
+    if (gtk_tree_model_get_iter(model, &iter, path)) {
+      gtk_tree_model_get(model, &iter, 7, &res, -1);
+      if (res != NULL) {
+        selected_trade +=GPOINTER_TO_INT(res);
+      }
+    }
+    gtk_tree_path_free(path);
+  }
+  g_list_free(rows);
+
+  if (selected_trade > 0) {
+    char buf[128];
+    my_snprintf(buf, sizeof(buf), _("Total Trade: %d    Selected Trade: %d"), 
+                       total_trade, selected_trade);
+    gtk_label_set_text(GTK_LABEL(label), buf);
+  } else {
+    gtk_label_set_text(GTK_LABEL(label), NULL);
+  }
+}
+
+/******************************************************************
+  Update total trade label when the user makes a change in the 
+  selection of traderoutes.
+******************************************************************/
+static void traderoutes_selection_changed_callback(GtkTreeSelection *selection)
+{
+  update_total_trade();
+}
 
 /****************************************************************
   Called when a building type is selected in the economy list.
@@ -858,10 +1001,13 @@
   if(!is_report_dialogs_frozen() && economy_dialog_shell) {
     int tax, total_impr, total_unit, i, entries_used, nbr_impr;
     char economy_total[48];
+    char trade_total[24];
     struct improvement_entry entries[B_LAST];
     struct unit_entry entries_units[U_LAST];
     GtkTreeIter it;
     GValue value = { 0, };
+    GdkPixbuf *img;
+    struct city *pcitydest;
 
     gtk_list_store_clear(economy_store);
 
@@ -908,6 +1054,50 @@
     my_snprintf(economy_total, sizeof(economy_total),
 		_("Income: %d    Total Costs: %d"), tax, total_impr + total_unit); 
     gtk_label_set_text(GTK_LABEL(economy_label2), economy_total);
+      
+    /* Update traderoutes list for each cities */  
+    gtk_list_store_clear(traderoutes_store);
+    total_trade = 0;
+    city_list_iterate(client.conn.playing->cities, pcity) {
+      for (i = 0; i < NUM_TRADEROUTES; i++) {
+        if (pcity->trade[i] <= 0 
+		     && pcity->trade_value[i] <= 0) {
+             continue;
+        }
+
+        total_trade += pcity->trade_value[i];
+
+        /* Display infos of the dest city trade */	  
+        pcitydest = game_find_city_by_number(pcity->trade[i]);  
+        gtk_list_store_append(traderoutes_store, &it);          
+        gtk_list_store_set(traderoutes_store, &it, 
+                                    0, pcity->name, 
+                                    1, pcity->size, 
+                                    2, pcitydest->name, 
+                                    5, pcitydest->size, 
+                                    6, map_distance(pcity->tile, pcitydest->tile),
+                                    7, pcity->trade_value[i], 
+                                    -1);
+
+         /* Get Nation name and flag */  
+        g_value_init(&value, G_TYPE_STRING);
+        g_value_set_static_string(&value, 
+                              nation_adjective_translation(pcitydest->owner->nation));
+        gtk_list_store_set_value(traderoutes_store, &it, 4, &value);
+        g_value_unset(&value);
+	  
+        img = get_flag(pcitydest->owner->nation);
+        if (img != NULL) {
+          gtk_list_store_set(traderoutes_store, &it, 3, img, -1);
+          g_object_unref(img);
+        }	  
+      }
+    } city_list_iterate_end;      
+
+    /* Total trade */  
+    my_snprintf(trade_total, sizeof(trade_total),
+                       _("Total Trade: %d"), total_trade); 
+    gtk_label_set_text(GTK_LABEL(traderoutes_label), trade_total);      
   }  
 }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to