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

Upon play testing it was found that after all it is
somewhat annoying using the total buy cost label in
the city report without the fix in 40599. Attached
is the S2_1 backport.


-----------------------------------------------------------------------
言っただろう。
diff --git a/client/gui-gtk-2.0/cityrep.c b/client/gui-gtk-2.0/cityrep.c
index 99eb2ee..32cde71 100644
--- a/client/gui-gtk-2.0/cityrep.c
+++ b/client/gui-gtk-2.0/cityrep.c
@@ -72,6 +72,7 @@ static void city_command_callback(struct gui_dialog *dlg, int response,
                                   gpointer data);
 
 static void city_selection_changed_callback(GtkTreeSelection *selection);
+static void update_total_buy_cost(void);
 
 static void create_select_menu(GtkWidget *item);
 static void create_change_menu(GtkWidget *item);
@@ -1219,8 +1220,8 @@ void city_report_dialog_update_city(struct city *pcity)
     /* update. */
     if (found) {
       update_row(TREE_ITER_PTR(it), pcity);
-
       select_menu_cached = FALSE;
+      update_total_buy_cost();
     } else {
       city_report_dialog_update();
     }
@@ -1589,62 +1590,76 @@ static void popup_select_menu(GtkMenuShell *menu, gpointer data)
   select_menu_cached = TRUE;
 }
 
-/****************************************************************
-...
-*****************************************************************/
-static void city_selection_changed_callback(GtkTreeSelection *selection)
+/***************************************************************************
+  Update the value displayed by the "total buy cost" label in the city
+  report, or make it blank if nothing can be bought.
+***************************************************************************/
+static void update_total_buy_cost(void)
 {
-  int n;
+  GtkWidget *label, *view;
+  GList *rows, *p;
+  GtkTreeModel *model;
+  GtkTreeSelection *sel;
+  GtkTreePath *path;
+  GtkTreeIter iter;
+  gpointer res;
+  struct city *pcity;
   int total = 0;
 
-  n = gtk_tree_selection_count_selected_rows(selection);
+  view = city_view;
+  label = city_total_buy_cost_label;
 
-  if (n == 0) {
-    gtk_widget_set_sensitive(city_production_command, FALSE);
-    gtk_widget_set_sensitive(city_governor_command, FALSE);
-    gtk_widget_set_sensitive(city_center_command, FALSE);
-    gtk_widget_set_sensitive(city_popup_command, FALSE);
-    gtk_widget_set_sensitive(city_buy_command, FALSE);
-  } else {
-    GList *rows, *p;
-    GtkTreeModel *model;
-    GtkTreePath *path;
-    GtkTreeIter iter;
-    gpointer res;
-    struct city *pcity;
+  if (!view || !label) {
+    return;
+  }
 
-    gtk_widget_set_sensitive(city_production_command,
-			     can_client_issue_orders());
-    gtk_widget_set_sensitive(city_governor_command,
-                             can_client_issue_orders());
-    gtk_widget_set_sensitive(city_center_command, TRUE);
-    gtk_widget_set_sensitive(city_popup_command, TRUE);
-    gtk_widget_set_sensitive(city_buy_command, can_client_issue_orders());
-
-    rows = gtk_tree_selection_get_selected_rows(selection, &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, 0, &res, -1);
-        pcity = res;
-        if (pcity != NULL) {
-          total += city_buy_cost(pcity);
-        }
+  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, 0, &res, -1);
+      pcity = res;
+      if (pcity != NULL) {
+        total += city_buy_cost(pcity);
       }
-      gtk_tree_path_free(path);
     }
-    g_list_free(rows);
+    gtk_tree_path_free(path);
   }
+  g_list_free(rows);
 
   if (total > 0) {
-    char buf[64];
+    char buf[128];
     my_snprintf(buf, sizeof(buf), _("Total Buy Cost: %d"), total);
-    gtk_label_set_text(GTK_LABEL(city_total_buy_cost_label), buf);
+    gtk_label_set_text(GTK_LABEL(label), buf);
   } else {
-    gtk_label_set_text(GTK_LABEL(city_total_buy_cost_label), NULL);
+    gtk_label_set_text(GTK_LABEL(label), NULL);
   }
 }
 
+/***************************************************************************
+  Update city report button sensitivity and total buy cost label when the
+  user makes a change in the selection of cities.
+***************************************************************************/
+static void city_selection_changed_callback(GtkTreeSelection *selection)
+{
+  int n;
+
+  n = gtk_tree_selection_count_selected_rows(selection);
+
+  gtk_widget_set_sensitive(city_production_command,
+                           n > 0 && can_client_issue_orders());
+  gtk_widget_set_sensitive(city_governor_command,
+                           n > 0 && can_client_issue_orders());
+  gtk_widget_set_sensitive(city_center_command, n > 0);
+  gtk_widget_set_sensitive(city_popup_command, n > 0);
+  gtk_widget_set_sensitive(city_buy_command,
+                           n > 0 && can_client_issue_orders());
+
+  update_total_buy_cost();
+}
+
 /****************************************************************
  After a selection rectangle is defined, make the cities that
  are hilited on the canvas exclusively hilited in the
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to