Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#1328) [patch] "turns-to-grow" on the map overview
Home

[Freeciv-Dev] (PR#1328) [patch] "turns-to-grow" on the map overview

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Cc: freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] (PR#1328) [patch] "turns-to-grow" on the map overview
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Tue, 5 Nov 2002 18:51:52 -0800
Reply-to: rt@xxxxxxxxxxxxxx

Attached is an update of this patch.

Changes:
- Updated for current CVS.
- GTK2 support.  This is lacking because it doesn't use colors the way
the other clients do.  I'm not familiar with Pango (yet).

jason

? anarchy-game.diff.gz
? city_turns_to_grow-2.diff
? city_turns_to_grow.diff
? config.h.diff
? convert_xpm.diff
? debian.diff
? diff
? dont_crop_null_mask.diff
? freeciv-patches.tgz
? ggz.diff
? gtk2_dont_crop_null_mask.diff
? gtk_dont_crop_null_mask.diff
? ndebug-warning.diff
? normalize_map_pos.diff
? normalize_real_map_pos.diff
? option_callback.diff
? png
? popdown_city_report_dialog-2.diff
? popdown_city_report_dialog.diff
? rc
? strace.output
? test.pl
? tileset_switching-3.diff
? xaw_png-2.diff
? xaw_png.diff
? client/gui-gtk-2.0/diff
? client/gui-stub/stub-update.diff
? data/civclient.dsc
? data/civclient.dsc.in
? data/civserver.dsc
? data/civserver.dsc.in
? data/civserver.room
? m4/ggz.m4
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.85
diff -u -r1.85 control.c
--- client/control.c    2002/11/01 17:51:12     1.85
+++ client/control.c    2002/11/06 02:48:27
@@ -945,7 +945,19 @@
   draw_city_names ^= 1;
   update_map_canvas_visible();
 }
+ 
+ /**************************************************************************
+ Toggle display of city growth (turns-to-grow)
+**************************************************************************/
+void request_toggle_city_growth(void)
+{
+  if (get_client_state() != CLIENT_GAME_RUNNING_STATE)
+    return;
 
+  draw_city_growth = !draw_city_growth;
+  update_map_canvas_visible();
+}
+
 /**************************************************************************
  Toggle display of city productions
 **************************************************************************/
@@ -1743,6 +1755,15 @@
 void key_city_names_toggle(void)
 {
   request_toggle_city_names();
+}
+
+/**************************************************************************
+  Toggles the "show city growth turns" option by passing off the
+  request to another function...
+**************************************************************************/
+void key_city_growth_toggle(void)
+{
+  request_toggle_city_growth();
 }
 
 /**************************************************************************
Index: client/control.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.h,v
retrieving revision 1.29
diff -u -r1.29 control.h
--- client/control.h    2002/11/01 17:51:12     1.29
+++ client/control.h    2002/11/06 02:48:27
@@ -66,6 +66,7 @@
 void request_unit_wakeup(struct unit *punit);
 void request_toggle_map_grid(void);
 void request_toggle_city_names(void);
+void request_toggle_city_growth(void);
 void request_toggle_city_productions(void);
 void request_toggle_terrain(void);
 void request_toggle_coastline(void);
@@ -99,6 +100,7 @@
 
 void key_cancel_action(void);
 void key_city_names_toggle(void);
+void key_city_growth_toggle(void);
 void key_city_productions_toggle(void);
 void key_terrain_toggle(void);
 void key_coastline_toggle(void);
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.66
diff -u -r1.66 options.c
--- client/options.c    2002/11/01 18:11:42     1.66
+++ client/options.c    2002/11/06 02:48:28
@@ -118,6 +118,7 @@
 
 bool draw_map_grid = FALSE;
 bool draw_city_names = TRUE;
+bool draw_city_growth = TRUE;
 bool draw_city_productions = FALSE;
 bool draw_terrain = TRUE;
 bool draw_coastline = FALSE;
@@ -138,6 +139,7 @@
 view_option view_options[] = {
   VIEW_OPTION(draw_map_grid),
   VIEW_OPTION(draw_city_names),
+  VIEW_OPTION(draw_city_growth),
   VIEW_OPTION(draw_city_productions),
   VIEW_OPTION(draw_terrain),
   VIEW_OPTION(draw_coastline),
Index: client/options.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.h,v
retrieving revision 1.21
diff -u -r1.21 options.h
--- client/options.h    2002/11/01 18:11:42     1.21
+++ client/options.h    2002/11/06 02:48:28
@@ -75,6 +75,7 @@
 
 extern bool draw_map_grid;
 extern bool draw_city_names;
+extern bool draw_city_growth;
 extern bool draw_city_productions;
 extern bool draw_terrain;
 extern bool draw_coastline;
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.257
diff -u -r1.257 packhand.c
--- client/packhand.c   2002/11/01 17:51:12     1.257
+++ client/packhand.c   2002/11/06 02:48:29
@@ -337,6 +337,12 @@
                pcity->shield_surplus != packet->shield_surplus ||
                pcity->shield_stock != packet->shield_stock)) {
       update_descriptions = TRUE;
+    } else if (draw_city_names && draw_city_growth &&
+              (pcity->food_stock != packet->food_stock ||
+               pcity->food_surplus != packet->food_surplus)) {
+      /* If either the food stock or surplus have changed, the time-to-grow
+        is likely to have changed as well. */
+      update_descriptions = TRUE;
     }
 
     /* update the descriptions if necessary */
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.127
diff -u -r1.127 mapview.c
--- client/gui-gtk/mapview.c    2002/08/25 11:20:56     1.127
+++ client/gui-gtk/mapview.c    2002/11/06 02:48:31
@@ -1317,7 +1317,7 @@
 **************************************************************************/
 static void show_desc_at_tile(int x, int y)
 {
-  static char buffer[512];
+  static char buffer[512], buffer2[32];
   struct city *pcity;
   if ((pcity = map_get_city(x, y))) {
     int canvas_x, canvas_y;
@@ -1325,14 +1325,51 @@
 
     get_canvas_xy(x, y, &canvas_x, &canvas_y);
     if (draw_city_names) {
-      my_snprintf(buffer, sizeof(buffer), "%s", pcity->name);
-      gdk_string_extents(main_fontset, buffer, NULL, NULL, &w, &ascent, NULL);
+      int turns = 0, w2 = 0;
+
+      my_snprintf(buffer, sizeof(buffer),
+                  draw_city_growth ? "%s " : "%s", pcity->name);
+      w = gdk_string_width(main_fontset, buffer);
+
+      if (draw_city_growth && pcity->owner == game.player_idx) {
+        turns = city_turns_to_grow(pcity);
+        if (turns == 0) {
+          snprintf(buffer2, sizeof(buffer2), "X");
+        } else if (turns == FC_INFINITY) {
+          snprintf(buffer2, sizeof(buffer2), "-");
+        } else {
+          /* Negative turns means we're shrinking, but that's handled
+             down below. */
+          snprintf(buffer2, sizeof(buffer2), "%d", abs(turns));
+        }
+
+        w2 = gdk_string_width(prod_fontset, buffer2);
+      }
+
       gtk_draw_shadowed_string(map_canvas->window, main_fontset,
                               toplevel->style->black_gc,
                               toplevel->style->white_gc,
-                              canvas_x + NORMAL_TILE_WIDTH / 2 - w / 2,
+                              canvas_x + NORMAL_TILE_WIDTH / 2 - (w + w2) / 2,
                               canvas_y + NORMAL_TILE_HEIGHT +
-                              ascent, buffer);
+                              main_fontset->ascent, buffer);
+
+      if (draw_city_growth && pcity->owner == game.player_idx) {
+        if (turns <= 0) {
+          /* A blocked or shrinking city has its growth status shown in red. */
+          gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_RED]);
+        } else {
+          gdk_gc_set_foreground(civ_gc, colors_standard[COLOR_STD_WHITE]);
+        }
+
+        gtk_draw_shadowed_string(map_canvas->window, prod_fontset,
+                                toplevel->style->black_gc,
+                                civ_gc,
+                                canvas_x + NORMAL_TILE_WIDTH / 2
+                                - (w + w2) / 2 + w,
+                                canvas_y + NORMAL_TILE_HEIGHT
+                                + main_fontset->ascent,
+                                buffer2);
+      }
     }
 
     if (draw_city_productions && (pcity->owner==game.player_idx)) {
Index: client/gui-gtk/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/menu.c,v
retrieving revision 1.69
diff -u -r1.69 menu.c
--- client/gui-gtk/menu.c       2002/06/23 16:06:24     1.69
+++ client/gui-gtk/menu.c       2002/11/06 02:48:32
@@ -79,6 +79,7 @@
 
   MENU_VIEW_SHOW_MAP_GRID,
   MENU_VIEW_SHOW_CITY_NAMES,
+  MENU_VIEW_SHOW_CITY_GROWTH_TURNS,
   MENU_VIEW_SHOW_CITY_PRODUCTIONS,
   MENU_VIEW_SHOW_TERRAIN,
   MENU_VIEW_SHOW_COASTLINE,
@@ -226,8 +227,14 @@
       key_map_grid_toggle();
     break;
   case MENU_VIEW_SHOW_CITY_NAMES:
-    if (draw_city_names ^ GTK_CHECK_MENU_ITEM(widget)->active)
+    if (draw_city_names ^ GTK_CHECK_MENU_ITEM(widget)->active) {
       key_city_names_toggle();
+      menus_set_sensitive("<main>/_View/City G_rowth", draw_city_names);
+    }
+    break;
+  case MENU_VIEW_SHOW_CITY_GROWTH_TURNS:
+    if (draw_city_growth ^ GTK_CHECK_MENU_ITEM(widget)->active)
+      key_city_growth_toggle();
     break;
   case MENU_VIEW_SHOW_CITY_PRODUCTIONS:
     if (draw_city_productions ^ GTK_CHECK_MENU_ITEM(widget)->active)
@@ -598,6 +605,8 @@
        view_menu_callback,     MENU_VIEW_SHOW_MAP_GRID,                
"<CheckItem>"   },
   { "/" N_("View") "/" N_("City _Names"),              "<control>n",
        view_menu_callback,     MENU_VIEW_SHOW_CITY_NAMES,              
"<CheckItem>"   },
+  { "/" N_("View") "/" N_("City G_rowth"),             "<control>r",
+       view_menu_callback,     MENU_VIEW_SHOW_CITY_GROWTH_TURNS,       
"<CheckItem>"   },
   { "/" N_("View") "/" N_("City _Productions"),                "<control>p",
        view_menu_callback,     MENU_VIEW_SHOW_CITY_PRODUCTIONS,        
"<CheckItem>"   },
   { "/" N_("View") "/sep1",                            NULL,
@@ -981,6 +990,8 @@
 
     menus_set_active("<main>/_View/Map _Grid", draw_map_grid);
     menus_set_active("<main>/_View/City _Names", draw_city_names);
+    menus_set_sensitive("<main>/_View/City G_rowth", draw_city_names);
+    menus_set_active("<main>/_View/City G_rowth", draw_city_growth);
     menus_set_active("<main>/_View/City _Productions", draw_city_productions);
     menus_set_active("<main>/_View/Terrain", draw_terrain);
     menus_set_active("<main>/_View/Coastline", draw_coastline);
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.14
diff -u -r1.14 mapview.c
--- client/gui-gtk-2.0/mapview.c        2002/11/02 21:27:44     1.14
+++ client/gui-gtk-2.0/mapview.c        2002/11/06 02:48:33
@@ -1343,26 +1343,66 @@
 **************************************************************************/
 static void show_desc_at_tile(PangoLayout *layout, int x, int y)
 {
-  static char buffer[512];
+  static char buffer[512], buffer2[32];
   struct city *pcity;
   if ((pcity = map_get_city(x, y))) {
     int canvas_x, canvas_y;
-    PangoRectangle rect;
+    PangoRectangle rect, rect2;
 
     get_canvas_xy(x, y, &canvas_x, &canvas_y);
     if (draw_city_names) {
-      my_snprintf(buffer, sizeof(buffer), "%s", pcity->name);
+      int turns = 0;
+
+      my_snprintf(buffer, sizeof(buffer),
+                  draw_city_growth ? "%s  " : "%s", pcity->name);
       
       pango_layout_set_font_description(layout, main_font);
       pango_layout_set_text(layout, buffer, -1);
-
       pango_layout_get_pixel_extents(layout, &rect, NULL);
+
+      if (draw_city_growth && pcity->owner == game.player_idx) {
+       turns = city_turns_to_grow(pcity);
+        if (turns == 0) {
+          snprintf(buffer2, sizeof(buffer2), "X");
+        } else if (turns == FC_INFINITY) {
+          snprintf(buffer2, sizeof(buffer2), "-");
+        } else {
+          /* Negative turns means we're shrinking, but that's handled
+             down below. */
+          snprintf(buffer2, sizeof(buffer2), "%d", abs(turns));
+        }
+
+       pango_layout_set_font_description(layout, city_productions_font);
+       pango_layout_set_text(layout, buffer2, -1);
+       pango_layout_get_pixel_extents(layout, &rect2, NULL);
+      } else {
+       rect2.width = 0;
+      }
+
+      pango_layout_set_font_description(layout, main_font);
+      pango_layout_set_text(layout, buffer, -1);
       gtk_draw_shadowed_string(map_canvas->window,
                           toplevel->style->black_gc,
                           toplevel->style->white_gc,
-                          canvas_x + NORMAL_TILE_WIDTH / 2 - rect.width / 2,
+                          canvas_x + NORMAL_TILE_WIDTH / 2
+                              - (rect.width + rect2.width) / 2,
                           canvas_y + NORMAL_TILE_HEIGHT +
                           PANGO_ASCENT(rect), layout);
+
+      if (draw_city_growth && pcity->owner == game.player_idx) {
+       /* FIXME: use different color for a blocked/shrinking city. */
+       pango_layout_set_font_description(layout, city_productions_font);
+       pango_layout_set_text(layout, buffer2, -1);
+       gtk_draw_shadowed_string(map_canvas->window,
+                       toplevel->style->black_gc,
+                       toplevel->style->white_gc,
+                       canvas_x + NORMAL_TILE_WIDTH / 2
+                                - (rect.width + rect2.width) / 2
+                                + rect.width,
+                       canvas_y + NORMAL_TILE_HEIGHT +
+                       PANGO_ASCENT(rect) + rect.height / 2 - rect2.height / 
2, layout);
+
+      }
     }
 
     if (draw_city_productions && (pcity->owner==game.player_idx)) {
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.7
diff -u -r1.7 menu.c
--- client/gui-gtk-2.0/menu.c   2002/10/13 21:45:24     1.7
+++ client/gui-gtk-2.0/menu.c   2002/11/06 02:48:34
@@ -80,6 +80,7 @@
 
   MENU_VIEW_SHOW_MAP_GRID,
   MENU_VIEW_SHOW_CITY_NAMES,
+  MENU_VIEW_SHOW_CITY_GROWTH_TURNS,
   MENU_VIEW_SHOW_CITY_PRODUCTIONS,
   MENU_VIEW_SHOW_TERRAIN,
   MENU_VIEW_SHOW_COASTLINE,
@@ -227,8 +228,14 @@
       key_map_grid_toggle();
     break;
   case MENU_VIEW_SHOW_CITY_NAMES:
-    if (draw_city_names ^ GTK_CHECK_MENU_ITEM(widget)->active)
+    if (draw_city_names ^ GTK_CHECK_MENU_ITEM(widget)->active) {
       key_city_names_toggle();
+      menus_set_sensitive("<main>/_View/City G_rowth", draw_city_names);
+    }
+    break;
+  case MENU_VIEW_SHOW_CITY_GROWTH_TURNS:
+    if (draw_city_growth ^ GTK_CHECK_MENU_ITEM(widget)->active)
+      key_city_growth_toggle();
     break;
   case MENU_VIEW_SHOW_CITY_PRODUCTIONS:
     if (draw_city_productions ^ GTK_CHECK_MENU_ITEM(widget)->active)
@@ -599,6 +606,8 @@
        view_menu_callback,     MENU_VIEW_SHOW_MAP_GRID,                
"<CheckItem>"   },
   { "/" N_("View") "/" N_("City _Names"),              "<control>n",
        view_menu_callback,     MENU_VIEW_SHOW_CITY_NAMES,              
"<CheckItem>"   },
+  { "/" N_("View") "/" N_("City G_rowth"),             "<control>r",
+       view_menu_callback,     MENU_VIEW_SHOW_CITY_GROWTH_TURNS,       
"<CheckItem>"   },
   { "/" N_("View") "/" N_("City _Productions"),                "<control>p",
        view_menu_callback,     MENU_VIEW_SHOW_CITY_PRODUCTIONS,        
"<CheckItem>"   },
   { "/" N_("View") "/sep1",                            NULL,
@@ -976,6 +985,8 @@
 
     menus_set_active("<main>/_View/Map _Grid", draw_map_grid);
     menus_set_active("<main>/_View/City _Names", draw_city_names);
+    menus_set_sensitive("<main>/_View/City G_rowth", draw_city_names);
+    menus_set_active("<main>/_View/City G_rowth", draw_city_growth);
     menus_set_active("<main>/_View/City _Productions", draw_city_productions);
     menus_set_active("<main>/_View/Terrain", draw_terrain);
     menus_set_active("<main>/_View/Coastline", draw_coastline);
Index: client/gui-xaw/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/mapview.c,v
retrieving revision 1.99
diff -u -r1.99 mapview.c
--- client/gui-xaw/mapview.c    2002/08/24 14:37:48     1.99
+++ client/gui-xaw/mapview.c    2002/11/06 02:48:34
@@ -780,12 +780,34 @@
         continue;
 
       if((pcity=map_get_city(rx, ry))) {
-
        if (draw_city_names) {
+         char buf[512];
+
+          if (draw_city_growth) {
+            /* In other GUIs, we draw the turns-to-grow in a different
+             * font.  Here that would require redefining
+             * draw_shadowed_string(), so it's just done the Easy Way
+             * instead. */
+            int turns = city_turns_to_grow(pcity);
+
+            if (turns == FC_INFINITY) {
+              snprintf(buf, sizeof(buf), "%s -", pcity->name);
+            } else if (turns > 0) {
+              snprintf(buf, sizeof(buf), "%s %d", pcity->name, turns);
+            } else if (turns == 0) {
+              snprintf(buf, sizeof(buf), "%s X", pcity->name);
+            } else {
+              /* turns < 0 */
+              snprintf(buf, sizeof(buf), "%s (%d)", pcity->name, -turns);
+            }
+          } else {
+            snprintf(buf, sizeof(buf), "%s", pcity->name);
+          }
+
          draw_shadowed_string(main_font_struct, font_gc,
-                              x*NORMAL_TILE_WIDTH+NORMAL_TILE_WIDTH/2,
+                              x*NORMAL_TILE_WIDTH + NORMAL_TILE_WIDTH/2,
                               (y+1)*NORMAL_TILE_HEIGHT,
-                              pcity->name);
+                              buf);
        }
 
        if (draw_city_productions && (pcity->owner==game.player_idx)) {
Index: client/gui-xaw/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.c,v
retrieving revision 1.49
diff -u -r1.49 menu.c
--- client/gui-xaw/menu.c       2002/02/11 13:55:48     1.49
+++ client/gui-xaw/menu.c       2002/11/06 02:48:35
@@ -128,6 +128,8 @@
 static struct MenuEntry view_menu_entries[]={
     { { N_("Map Grid"), 0             }, "ctl-g", MENU_VIEW_SHOW_MAP_GRID, 0 },
     { { N_("City Names"), 0           }, "ctl-n", MENU_VIEW_SHOW_CITY_NAMES, 0 
},
+    { { N_("City Growth"), 0          }, "ctl-r",
+      MENU_VIEW_SHOW_CITY_GROWTH, 0 },
     { { N_("City Productions"), 0     }, "ctl-p", 
MENU_VIEW_SHOW_CITY_PRODUCTIONS, 0 },
     { { 0                             },      "", MENU_SEPARATOR_LINE, 0 },
     { { N_("Terrain"), 0              },      "", MENU_VIEW_SHOW_TERRAIN, 0 },
@@ -276,6 +278,8 @@
     XtSetSensitive(menus[MENU_VIEW]->button, True);
     XtSetSensitive(menus[MENU_KINGDOM]->button, True);
 
+    menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_CITY_GROWTH,
+                        draw_city_names);
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_TERRAIN, 1);
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_COASTLINE, !draw_terrain);
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_ROADS_RAILS, 1);
@@ -502,6 +506,11 @@
     break;
   case MENU_VIEW_SHOW_CITY_NAMES:
     key_city_names_toggle();
+    menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_CITY_GROWTH,
+                        draw_city_names);
+    break;
+  case MENU_VIEW_SHOW_CITY_GROWTH:
+    key_city_growth_toggle();
     break;
   case MENU_VIEW_SHOW_CITY_PRODUCTIONS:
     key_city_productions_toggle();
Index: client/gui-xaw/menu.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.h,v
retrieving revision 1.13
diff -u -r1.13 menu.h
--- client/gui-xaw/menu.h       2001/04/20 22:16:01     1.13
+++ client/gui-xaw/menu.h       2002/11/06 02:48:35
@@ -50,6 +50,7 @@
 
   MENU_VIEW_SHOW_MAP_GRID,
   MENU_VIEW_SHOW_CITY_NAMES,
+  MENU_VIEW_SHOW_CITY_GROWTH,
   MENU_VIEW_SHOW_CITY_PRODUCTIONS,
   MENU_VIEW_SHOW_TERRAIN,
   MENU_VIEW_SHOW_COASTLINE,

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