Complete.Org: Mailing Lists: Archives: freeciv-dev: October 2004:
[Freeciv-Dev] (PR#10575) city dialog tooltips
Home

[Freeciv-Dev] (PR#10575) city dialog tooltips

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: jdorje@xxxxxxxxxxxxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#10575) city dialog tooltips
From: "Vasco Alexandre da Silva Costa" <vasc@xxxxxxxxxxxxxx>
Date: Tue, 19 Oct 2004 15:20:00 -0700
Reply-to: rt@xxxxxxxxxxx

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

This changes from a tooltip to a popup like the map middle click,
changes the font to monospace and replaces my_snprintf with cat_snprintf
calls.

Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.50
diff -u -r1.50 citydlg_common.c
--- client/citydlg_common.c     16 Oct 2004 00:00:10 -0000      1.50
+++ client/citydlg_common.c     19 Oct 2004 22:17:04 -0000
@@ -380,6 +380,28 @@
 }
 
 /**************************************************************************
+  Return text describing the food input.
+**************************************************************************/
+void get_city_dialog_food_text(const struct city *pcity,
+                              char *buf, size_t bufsz)
+{
+  buf[0] = '\0';
+
+  cat_snprintf(buf, bufsz,
+              "%+3d : Farmers\n", pcity->food_prod);
+  cat_snprintf(buf, bufsz,
+              "%+3d : Consumed by citizens\n", -2 * pcity->size);
+  if (pcity->food_upkeep > 0) {
+    cat_snprintf(buf, bufsz,
+                "%+3d : Unit upkeep\n", -pcity->food_upkeep);
+  }
+  cat_snprintf(buf, bufsz,
+              "=== : Adds up to\n");
+  cat_snprintf(buf, bufsz,
+              "%3d : Total surplus", pcity->food_surplus);
+}
+
+/**************************************************************************
   Provide a list of all citizens in the city, in order.  "index"
   should be the happiness index (currently [0..4]; 4 = final
   happiness).  "citizens" should be an array large enough to hold all
Index: client/citydlg_common.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.h,v
retrieving revision 1.27
diff -u -r1.27 citydlg_common.h
--- client/citydlg_common.h     29 Sep 2004 02:24:18 -0000      1.27
+++ client/citydlg_common.h     19 Oct 2004 22:17:04 -0000
@@ -54,6 +54,9 @@
 void get_city_dialog_production_row(char *buf[], size_t column_size, int id,
                                    bool is_unit, struct city *pcity);
 
+void get_city_dialog_food_text(const struct city *pcity,
+                              char *buffer, size_t bufsz);
+
 void get_city_citizen_types(struct city *pcity, int index,
                            struct citizen_type *citizens);
 void city_rotate_specialist(struct city *pcity, int citizen_index);
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.410
diff -u -r1.410 packhand.c
--- client/packhand.c   19 Oct 2004 18:11:21 -0000      1.410
+++ client/packhand.c   19 Oct 2004 22:17:05 -0000
@@ -456,7 +456,10 @@
   pcity->tile_trade=packet->tile_trade;
   pcity->corruption=packet->corruption;
   pcity->shield_waste=packet->shield_waste;
-    
+
+  pcity->food_upkeep = packet->food_upkeep;
+  pcity->shield_upkeep = packet->shield_upkeep;
+
   pcity->luxury_total=packet->luxury_total;
   pcity->tax_total=packet->tax_total;
   pcity->science_total=packet->science_total;
@@ -730,6 +733,8 @@
     pcity->shield_surplus     = 0;
     pcity->trade_prod         = 0;
     pcity->corruption         = 0;
+    pcity->food_upkeep = 0;
+    pcity->shield_upkeep = 0;
     pcity->luxury_total       = 0;
     pcity->tax_total          = 0;
     pcity->science_total      = 0;
Index: client/gui-gtk-2.0/citydlg.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/citydlg.c,v
retrieving revision 1.96
diff -u -r1.96 citydlg.c
--- client/gui-gtk-2.0/citydlg.c        19 Oct 2004 16:35:33 -0000      1.96
+++ client/gui-gtk-2.0/citydlg.c        19 Oct 2004 22:17:08 -0000
@@ -127,6 +127,7 @@
     struct unit_node_vector supported_units;
     struct unit_node_vector present_units;
 
+    GtkWidget *info_ebox[NUM_INFO_FIELDS];
     GtkWidget *info_label[NUM_INFO_FIELDS];
   } overview;
  
@@ -140,6 +141,7 @@
     GtkWidget *map_canvas;
     GtkWidget *map_canvas_pixmap;
     GtkWidget *widget;
+    GtkWidget *info_ebox[NUM_INFO_FIELDS];
     GtkWidget *info_label[NUM_INFO_FIELDS];
   } happiness;
 
@@ -185,7 +187,9 @@
 static gboolean keyboard_handler(GtkWidget * widget, GdkEventKey * event,
                                 struct city_dialog *pdialog);
 
-static GtkWidget *create_city_info_table(GtkWidget **info_label);
+static GtkWidget *create_city_info_table(struct city_dialog *pdialog,
+                                        GtkWidget **info_ebox,
+                                        GtkWidget **info_label);
 static void create_and_append_overview_page(struct city_dialog *pdialog);
 static void create_and_append_worklist_page(struct city_dialog *pdialog);
 static void create_and_append_happiness_page(struct city_dialog *pdialog);
@@ -198,7 +202,8 @@
 
 static void city_dialog_update_title(struct city_dialog *pdialog);
 static void city_dialog_update_citizens(struct city_dialog *pdialog);
-static void city_dialog_update_information(GtkWidget **info_label,
+static void city_dialog_update_information(GtkWidget **info_ebox,
+                                          GtkWidget **info_label,
                                            struct city_dialog *pdialog);
 static void city_dialog_update_map(struct city_dialog *pdialog);
 static void city_dialog_update_building(struct city_dialog *pdialog);
@@ -357,7 +362,8 @@
 
   city_dialog_update_title(pdialog);
   city_dialog_update_citizens(pdialog);
-  city_dialog_update_information(pdialog->overview.info_label, pdialog);
+  city_dialog_update_information(pdialog->overview.info_ebox,
+                                pdialog->overview.info_label, pdialog);
   city_dialog_update_map(pdialog);
   city_dialog_update_building(pdialog);
   city_dialog_update_improvement_list(pdialog);
@@ -372,7 +378,8 @@
 
     refresh_worklist(pdialog->production.worklist);
 
-    city_dialog_update_information(pdialog->happiness.info_label, pdialog);
+    city_dialog_update_information(pdialog->happiness.info_ebox,
+                                  pdialog->happiness.info_label, pdialog);
     refresh_happiness_dialog(pdialog->pcity);
 
     refresh_cma_dialog(pdialog->pcity, REFRESH_ALL);
@@ -482,14 +489,68 @@
   return FALSE;
 }
 
+/**************************************************************************
+...
+**************************************************************************/
+static gboolean show_info_button_release(GtkWidget *w, GdkEventButton *ev,
+                                        gpointer data)
+{
+  gtk_grab_remove(w);
+  gdk_pointer_ungrab(GDK_CURRENT_TIME);
+  gtk_widget_destroy(w);
+  return FALSE;
+}
+
+/****************************************************************
+...
+*****************************************************************/
+static gboolean show_info_popup(GtkWidget *w, GdkEventButton *ev,
+                               gpointer data)
+{
+  struct city_dialog *pdialog = g_object_get_data(G_OBJECT(w), "pdialog");
+
+  if (ev->button == 1) {
+    GtkWidget *p, *label;
+    char buf[1024];
+    
+    switch (GPOINTER_TO_UINT(data)) {
+    case FOOD:
+      get_city_dialog_food_text(pdialog->pcity, buf, sizeof(buf));
+      break;
+    default:
+      buf[0] = '\0';
+      break;
+    }
+    
+    p = gtk_window_new(GTK_WINDOW_POPUP);
+    gtk_widget_set_name(p, "Freeciv");
+    gtk_container_set_border_width(GTK_CONTAINER(p), 4);
+    gtk_window_set_position(GTK_WINDOW(p), GTK_WIN_POS_MOUSE);
+
+    label = gtk_label_new(buf);
+    gtk_widget_set_name(label, "city info label");
+    gtk_container_add(GTK_CONTAINER(p), label);
+    gtk_widget_show_all(p);
+
+    gdk_pointer_grab(p->window, TRUE, GDK_BUTTON_RELEASE_MASK,
+                    NULL, NULL, ev->time);
+    gtk_grab_add(p);
+
+    g_signal_connect_after(p, "button_release_event",
+                           G_CALLBACK(show_info_button_release), NULL);
+  }
+  return TRUE;
+}
 /****************************************************************
  used once in the overview page and once in the happiness page
  **info_label points to the info_label in the respective struct
 ****************************************************************/
-static GtkWidget *create_city_info_table(GtkWidget **info_label)
+static GtkWidget *create_city_info_table(struct city_dialog *pdialog,
+                                        GtkWidget **info_ebox,
+                                        GtkWidget **info_label)
 {
   int i;
-  GtkWidget *hbox, *table, *label;
+  GtkWidget *hbox, *table, *label, *ebox;
 
   static const char *output_label[NUM_INFO_FIELDS] = { N_("Food:"),
     N_("Prod:"),
@@ -523,12 +584,20 @@
     gtk_table_attach(GTK_TABLE(table), label, 0, 1, i, i + 1, GTK_FILL, 0,
                     0, 0);
 
+    ebox = gtk_event_box_new();
+    g_object_set_data(G_OBJECT(ebox), "pdialog", pdialog);
+    g_signal_connect(ebox, "button_press_event",
+       G_CALLBACK(show_info_popup), GUINT_TO_POINTER(i));
+    info_ebox[i] = ebox;
+
     label = gtk_label_new("");
     info_label[i] = label;
     gtk_widget_set_name(label, "city label");  /* ditto */
     gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
 
-    gtk_table_attach(GTK_TABLE(table), label, 1, 2, i, i + 1, GTK_FILL, 0,
+    gtk_container_add(GTK_CONTAINER(ebox), label);
+
+    gtk_table_attach(GTK_TABLE(table), ebox, 1, 2, i, i + 1, GTK_FILL, 0,
                     0, 0);
   }
 
@@ -577,7 +646,9 @@
   frame = gtk_frame_new(_("Info"));
   gtk_box_pack_start(GTK_BOX(top), frame, FALSE, FALSE, 0);
 
-  table = create_city_info_table(pdialog->overview.info_label);
+  table = create_city_info_table(pdialog,
+                                pdialog->overview.info_ebox,
+                                pdialog->overview.info_label);
   gtk_container_add(GTK_CONTAINER(frame), table);
 
   frame = gtk_frame_new(_("City map"));
@@ -864,7 +935,9 @@
   align = gtk_alignment_new(0.5, 0.5, 0, 0);
   gtk_container_add(GTK_CONTAINER(vbox), align);
   
-  table = create_city_info_table(pdialog->happiness.info_label);
+  table = create_city_info_table(pdialog,
+                                pdialog->happiness.info_ebox,
+                                pdialog->happiness.info_label);
   gtk_container_add(GTK_CONTAINER(align), table);
 
   gtk_widget_show_all(page);
@@ -1072,6 +1145,9 @@
   }
 }
 
+
+
+
 /****************************************************************
 ...
 *****************************************************************/
@@ -1299,7 +1375,8 @@
 /****************************************************************
 ...
 *****************************************************************/
-static void city_dialog_update_information(GtkWidget **info_label,
+static void city_dialog_update_information(GtkWidget **info_ebox,
+                                          GtkWidget **info_label,
                                            struct city_dialog *pdialog)
 {
   int i, style;
@@ -1329,7 +1406,7 @@
 
   my_snprintf(buf[GRANARY], sizeof(buf[GRANARY]), "%d/%-d",
              pcity->food_stock, city_granary_size(pcity->size));
-       
+
   granaryturns = city_turns_to_grow(pcity);
   if (granaryturns == 0) {
     my_snprintf(buf[GROWTH], sizeof(buf[GROWTH]), _("blocked"));
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.252
diff -u -r1.252 city.c
--- common/city.c       19 Oct 2004 06:46:57 -0000      1.252
+++ common/city.c       19 Oct 2004 22:17:11 -0000
@@ -2038,6 +2038,8 @@
 
   /* loop over units, subtracting appropriate amounts of food, shields,
    * gold etc -- SKi */
+  pcity->food_upkeep = 0;
+  pcity->shield_upkeep = 0;
   unit_list_iterate(pcity->units_supported, this_unit) {
     struct unit_type *ut = unit_type(this_unit);
     int shield_cost = utype_shield_cost(ut, g);
@@ -2086,6 +2088,7 @@
     if (shield_cost > 0) {
       adjust_city_free_cost(&free_shield, &shield_cost);
       if (shield_cost > 0) {
+       pcity->shield_upkeep += shield_cost;
        pcity->shield_surplus -= shield_cost;
        this_unit->upkeep = shield_cost;
       }
@@ -2093,6 +2096,7 @@
     if (food_cost > 0) {
       adjust_city_free_cost(&free_food, &food_cost);
       if (food_cost > 0) {
+       pcity->food_upkeep += food_cost;
        pcity->food_surplus -= food_cost;
        this_unit->upkeep_food = food_cost;
       }
@@ -2391,7 +2395,8 @@
   int i;
   struct city *pcity;
 
-  pcity = fc_malloc(sizeof(struct city));
+  pcity = fc_malloc(sizeof(*pcity));
+  memset(pcity, 0, sizeof(*pcity));
 
   pcity->id = 0;
   pcity->owner = pplayer->player_no;
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.164
diff -u -r1.164 city.h
--- common/city.h       19 Oct 2004 06:46:57 -0000      1.164
+++ common/city.h       19 Oct 2004 22:17:11 -0000
@@ -240,6 +240,9 @@
   int shield_prod, shield_surplus, shield_waste; 
   int trade_prod, corruption, tile_trade;
 
+  /* Upkeeps (gold upkeep is done globally, not per-city). */
+  int food_upkeep, shield_upkeep;
+
   /* Cached values for CPU savings. */
   int shield_bonus, luxury_bonus, tax_bonus, science_bonus;
 
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.55
diff -u -r1.55 packets.def
--- common/packets.def  25 Sep 2004 22:18:41 -0000      1.55
+++ common/packets.def  19 Oct 2004 22:17:11 -0000
@@ -398,6 +398,7 @@
   UINT8 specialists[SP_COUNT];
 
   UINT16 food_prod, shield_prod, trade_prod;
+  UINT16 food_upkeep, shield_upkeep;
   SINT16 food_surplus, shield_surplus, tile_trade;
   UINT16 food_stock, shield_stock, corruption;
 
Index: data/freeciv.rc-2.0
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/freeciv.rc-2.0,v
retrieving revision 1.20
diff -u -r1.20 freeciv.rc-2.0
--- data/freeciv.rc-2.0 18 Oct 2004 23:49:27 -0000      1.20
+++ data/freeciv.rc-2.0 19 Oct 2004 22:17:18 -0000
@@ -1,3 +1,8 @@
+style "city_info_label"
+{
+  font_name = "Monospace 8"
+}
+
 style "city_label"
 {
   font_name = "Monospace 8"
@@ -75,6 +80,7 @@
   font_name = "Serif 10"
 }
 
+widget "Freeciv*.city info label"      style   "city_info_label"
 widget "Freeciv*.city label"           style   "city_label"
 widget "Freeciv*.notify label"         style   "notify_label"
 widget "Freeciv*.spaceship label"      style   "spaceship_label"
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.277
diff -u -r1.277 citytools.c
--- server/citytools.c  19 Oct 2004 06:46:57 -0000      1.277
+++ server/citytools.c  19 Oct 2004 22:17:19 -0000
@@ -1588,6 +1588,9 @@
   packet->trade_prod=pcity->trade_prod;
   packet->tile_trade=pcity->tile_trade;
   packet->corruption=pcity->corruption;
+
+  packet->food_upkeep = pcity->food_upkeep;
+  packet->shield_upkeep = pcity->shield_upkeep;
   
   packet->shield_waste=pcity->shield_waste;
     

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