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

D'oh, hit the send button accidantely prematurely in previous mail... why do 
they have to make it next to the attach file button? ;) 

Wanted to note that in order to keep the compatibility with the GTK client the 
terrain toggle combo could be moved to the key combo ctrl-shift-t (see 
attached). This suggestion assumes that the GTK client is used more widely 
than the SDL one, of wich I don't really have the faintest idea about...

Greetings,
Nico

diff -Nur -X.diff_ignore trunk/client/control.c changed/client/control.c
--- trunk/client/control.c	2008-08-23 15:52:24.000000000 +0200
+++ changed/client/control.c	2008-08-23 19:42:40.000000000 +0200
@@ -1683,6 +1683,19 @@
 }
 
 /**************************************************************************
+ Toggle display of city traderoutes
+**************************************************************************/
+void request_toggle_city_traderoutes(void)
+{
+  if (!can_client_change_view()) {
+    return;
+  }
+
+  draw_city_traderoutes ^= 1;
+  update_map_canvas_visible();
+}
+
+/**************************************************************************
  Toggle display of terrain
 **************************************************************************/
 void request_toggle_terrain(void)
@@ -2760,6 +2773,15 @@
 }
 
 /**************************************************************************
+  Handle client request to toggle drawing of traderoute information
+  by the city name for cities visible on the main map view.
+**************************************************************************/
+void key_city_traderoutes_toggle(void)
+{
+  request_toggle_city_traderoutes();
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void key_terrain_toggle(void)
diff -Nur -X.diff_ignore trunk/client/control.h changed/client/control.h
--- trunk/client/control.h	2008-07-27 21:46:43.000000000 +0200
+++ changed/client/control.h	2008-08-23 19:42:40.000000000 +0200
@@ -98,6 +98,7 @@
 void request_toggle_city_names(void);
 void request_toggle_city_growth(void);
 void request_toggle_city_productions(void);
+void request_toggle_city_traderoutes(void);
 void request_toggle_terrain(void);
 void request_toggle_coastline(void);
 void request_toggle_roads_rails(void);
@@ -142,6 +143,7 @@
 void key_city_names_toggle(void);
 void key_city_growth_toggle(void);
 void key_city_productions_toggle(void);
+void key_city_traderoutes_toggle(void);
 void key_terrain_toggle(void);
 void key_coastline_toggle(void);
 void key_roads_rails_toggle(void);
diff -Nur -X.diff_ignore trunk/client/gui-gtk-2.0/menu.c changed/client/gui-gtk-2.0/menu.c
--- trunk/client/gui-gtk-2.0/menu.c	2008-08-02 22:46:09.000000000 +0200
+++ changed/client/gui-gtk-2.0/menu.c	2008-08-23 19:42:40.000000000 +0200
@@ -106,6 +106,7 @@
   MENU_VIEW_SHOW_CITY_NAMES,
   MENU_VIEW_SHOW_CITY_GROWTH_TURNS,
   MENU_VIEW_SHOW_CITY_PRODUCTIONS,
+  MENU_VIEW_SHOW_CITY_TRADEROUTES,
   MENU_VIEW_SHOW_TERRAIN,
   MENU_VIEW_SHOW_COASTLINE,
   MENU_VIEW_SHOW_ROADS_RAILS,
@@ -334,6 +335,7 @@
          * city name), can draw the city growth even without drawing
          * the city name. But the old method cannot. */
         menus_set_sensitive("<main>/_View/City G_rowth", draw_city_names);
+        menus_set_sensitive("<main>/_View/City _Traderoutes", draw_city_names);
       }
     }
     break;
@@ -345,6 +347,11 @@
     if (draw_city_productions ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_city_productions_toggle();
     break;
+  case MENU_VIEW_SHOW_CITY_TRADEROUTES:
+    if (draw_city_traderoutes ^ GTK_CHECK_MENU_ITEM(widget)->active) {
+      key_city_traderoutes_toggle();
+    }
+    break;
   case MENU_VIEW_SHOW_TERRAIN:
     if (draw_terrain ^ GTK_CHECK_MENU_ITEM(widget)->active) {
       key_terrain_toggle();
@@ -822,7 +829,7 @@
 	NULL,			0,					"<Tearoff>"	},
   { "/" N_("View") "/" N_("City Outlines"), "<control>y",
     view_menu_callback, MENU_VIEW_SHOW_CITY_OUTLINES, "<CheckItem>"},
-  { "/" N_("View") "/" N_("City Output"), "<control>t",
+  { "/" N_("View") "/" N_("City Output"), "<control>w",
     view_menu_callback, MENU_VIEW_SHOW_CITY_OUTPUT, "<CheckItem>"},
   { "/" N_("View") "/" N_("Map _Grid"),			"<control>g",
 	view_menu_callback,	MENU_VIEW_SHOW_MAP_GRID,		"<CheckItem>"	},
@@ -835,6 +842,8 @@
 	"<CheckItem>"	},
   { "/" N_("View") "/" N_("City _Productions"),		"<control>p",
 	view_menu_callback,	MENU_VIEW_SHOW_CITY_PRODUCTIONS,	"<CheckItem>"	},
+  { "/" N_("View") "/" N_("City _Traderoutes"),		"<control>t",
+	view_menu_callback,	MENU_VIEW_SHOW_CITY_TRADEROUTES,	"<CheckItem>"	},
   { "/" N_("View") "/sep1",				NULL,
 	NULL,			0,					"<Separator>"	},
   { "/" N_("View") "/" N_("Terrain"),                   NULL,
@@ -1443,12 +1452,15 @@
      * the city name. But the old method cannot. */
     if (draw_full_citybar) {
       menus_set_sensitive("<main>/_View/City G_rowth", TRUE);
+      menus_set_sensitive("<main>/_View/City _Traderoutes", TRUE);
     } else {
       menus_set_sensitive("<main>/_View/City G_rowth", draw_city_names);
+      menus_set_sensitive("<main>/_View/City _Traderoutes", 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/City _Traderoutes", draw_city_traderoutes);
     menus_set_active("<main>/_View/Terrain", draw_terrain);
     menus_set_active("<main>/_View/Coastline", draw_coastline);
     menus_set_sensitive("<main>/_View/Coastline", !draw_terrain);
diff -Nur -X.diff_ignore trunk/client/gui-sdl/mapctrl.c changed/client/gui-sdl/mapctrl.c
--- trunk/client/gui-sdl/mapctrl.c	2008-07-27 21:46:35.000000000 +0200
+++ changed/client/gui-sdl/mapctrl.c	2008-08-23 19:50:02.000000000 +0200
@@ -2375,10 +2375,15 @@
 
       /* *** some additional shortcuts that work in the SDL client only *** */
         
-      /* show terrain - Ctrl+t */ 
+      /* show city traderoutes	- Ctrl+t 
+       * show terrain 		- Ctrl+Shift+t  */ 
       case SDLK_t:
         if (LCTRL || RCTRL) {
-          key_terrain_toggle();
+          if (LSHIFT || RCTRL) {
+            key_terrain_toggle();
+          } else {
+            key_city_traderoutes_toggle();
+          }
         }
         return FALSE;
   
diff -Nur -X.diff_ignore trunk/client/mapview_common.c changed/client/mapview_common.c
--- trunk/client/mapview_common.c	2008-07-27 21:46:43.000000000 +0200
+++ changed/client/mapview_common.c	2008-08-23 19:42:40.000000000 +0200
@@ -1223,15 +1223,16 @@
 			      struct city *pcity, int *width, int *height)
 {
   const struct citybar_sprites *citybar = get_citybar_sprites(tileset);
-  static char name[512], growth[32], prod[512], size[32];
-  enum color_std growth_color;
+  static char name[512], growth[32], prod[512], size[32], traderoutes[32];
+  enum color_std growth_color, traderoutes_color;
   struct color *owner_color;
   struct {
     int x, y, w, h;
   } name_rect = {0, 0, 0, 0}, growth_rect = {0, 0, 0, 0},
     prod_rect = {0, 0, 0, 0}, size_rect = {0, 0, 0, 0},
     flag_rect = {0, 0, 0, 0}, occupy_rect = {0, 0, 0, 0},
-    food_rect = {0, 0, 0, 0}, shield_rect = {0, 0, 0, 0};
+    food_rect = {0, 0, 0, 0}, shield_rect = {0, 0, 0, 0},
+    traderoutes_rect = {0,}, trade_rect = {0,};
   int width1 = 0, width2 = 0, height1 = 0, height2 = 0;
   struct sprite *bg = citybar->background;
   struct sprite *flag = get_city_flag_sprite(tileset, pcity);
@@ -1250,8 +1251,11 @@
   const bool should_draw_productions
     = can_see_inside && draw_city_productions;
   const bool should_draw_growth = can_see_inside && draw_city_growth;
+  const bool should_draw_traderoutes = can_see_inside
+    && draw_city_traderoutes;
   const bool should_draw_lower_bar
-    = should_draw_productions || should_draw_growth;
+    = should_draw_productions || should_draw_growth
+    || should_draw_traderoutes;
 
 
   if (width != NULL) {
@@ -1303,25 +1307,38 @@
   }
 
   if (should_draw_lower_bar) {
+    width2 = 0;
+    height2 = 0;
 
     if (should_draw_productions) {
       get_city_mapview_production(pcity, prod, sizeof(prod));
       get_text_size(&prod_rect.w, &prod_rect.h, FONT_CITY_PROD, prod);
 
       get_sprite_dimensions(citybar->shields, &shield_rect.w, &shield_rect.h);
+      width2 += shield_rect.w + prod_rect.w + border;
+      height2 = MAX(height2, shield_rect.h);
+      height2 = MAX(height2, prod_rect.h + border);
     }
 
     if (should_draw_growth) {
       get_text_size(&growth_rect.w, &growth_rect.h, FONT_CITY_PROD, growth);
       get_sprite_dimensions(citybar->food, &food_rect.w, &food_rect.h);
+      width2 += food_rect.w + growth_rect.w + border;
+      height2 = MAX(height2, food_rect.h);
+      height2 = MAX(height2, growth_rect.h + border);
     }
 
-    width2 = (prod_rect.w + growth_rect.w + shield_rect.w + food_rect.w
-	      + 2 * border);
-    height2 = MAX(shield_rect.h,
-		  MAX(prod_rect.h + border,
-		      MAX(growth_rect.h + border,
-			  food_rect.h)));
+    if (should_draw_traderoutes) {
+      get_city_mapview_traderoutes(pcity, traderoutes,
+                                   sizeof(traderoutes),
+                                   &traderoutes_color);
+      get_text_size(&traderoutes_rect.w, &traderoutes_rect.h,
+                    FONT_CITY_PROD, traderoutes);
+      get_sprite_dimensions(citybar->trade, &trade_rect.w, &trade_rect.h);
+      width2 += trade_rect.w + traderoutes_rect.w + border;
+      height2 = MAX(height2, trade_rect.h);
+      height2 = MAX(height2, traderoutes_rect.h + border);
+    }
   }
 
   *width = MAX(width1, width2);
@@ -1354,8 +1371,23 @@
       prod_rect.y = canvas_y + height1 + (height2 - prod_rect.h) / 2;
     }
 
+    if (should_draw_traderoutes) {
+      traderoutes_rect.x = canvas_x + (*width + 1) / 2
+        - traderoutes_rect.w - border / 2;
+      traderoutes_rect.y = canvas_y + height1
+        + (height2 - traderoutes_rect.h) / 2;
+
+      trade_rect.x = traderoutes_rect.x - border / 2 - trade_rect.w;
+      trade_rect.y = canvas_y + height1 + (height2 - trade_rect.h) / 2;
+    }
+
     if (should_draw_growth) {
-      growth_rect.x = canvas_x + (*width + 1) / 2 - growth_rect.w - border / 2;
+      growth_rect.x = canvas_x + (*width + 1) / 2
+        - growth_rect.w - border / 2;
+      if (traderoutes_rect.w > 0) {
+        growth_rect.x = growth_rect.x
+          - traderoutes_rect.w - border / 2 - trade_rect.w - border / 2;
+      }
       growth_rect.y = canvas_y + height1 + (height2 - growth_rect.h) / 2;
 
       food_rect.x = growth_rect.x - border / 2 - food_rect.w;
@@ -1405,6 +1437,14 @@
                       get_color(tileset, COLOR_MAPVIEW_CITYTEXT), prod);
     }
 
+    if (should_draw_traderoutes) {
+      canvas_put_sprite_full(pcanvas, trade_rect.x, trade_rect.y,
+                             citybar->trade);
+      canvas_put_text(pcanvas, traderoutes_rect.x, traderoutes_rect.y,
+                      FONT_CITY_PROD,
+                      get_color(tileset, traderoutes_color), traderoutes);
+    }
+
     if (should_draw_growth) {
       canvas_put_sprite_full(pcanvas, food_rect.x, food_rect.y, citybar->food);
       canvas_put_text(pcanvas, growth_rect.x, growth_rect.y,
@@ -1445,13 +1485,14 @@
 			   int canvas_x, int canvas_y,
 			   struct city *pcity, int *width, int *height)
 {
-  static char name[512], growth[32], prod[512];
-  enum color_std growth_color;
+  static char name[512], growth[32], prod[512], traderoutes[32];
+  enum color_std growth_color, traderoutes_color;
   struct {
     int x, y, w, h;
   } name_rect = {0, 0, 0, 0}, growth_rect = {0, 0, 0, 0},
-    prod_rect = {0, 0, 0, 0};
-  int extra_width = 0, total_width, total_height;
+    prod_rect = {0, 0, 0, 0}, traderoutes_rect = {0,};
+  int total_width, total_height;
+  int spacer_width = 0;
 
   *width = *height = 0;
 
@@ -1459,29 +1500,63 @@
   canvas_y += tileset_citybar_offset_y(tileset);
 
   if (draw_city_names) {
+    int drawposx;
+
+    /* HACK: put a character's worth of space between the two
+     * strings if needed. */
+    get_text_size(&spacer_width, NULL, FONT_CITY_NAME, "M");
+
+    total_width = 0;
+    total_height = 0;
+
     get_city_mapview_name_and_growth(pcity, name, sizeof(name),
                                     growth, sizeof(growth), &growth_color);
 
     get_text_size(&name_rect.w, &name_rect.h, FONT_CITY_NAME, name);
+    total_width += name_rect.w;
+    total_height = MAX(total_height, name_rect.h);
 
     if (draw_city_growth) {
       get_text_size(&growth_rect.w, &growth_rect.h, FONT_CITY_PROD, growth);
-      /* HACK: put a character's worth of space between the two strings. */
-      get_text_size(&extra_width, NULL, FONT_CITY_NAME, "M");
+      total_width += spacer_width + growth_rect.w;
+      total_height = MAX(total_height, growth_rect.h);
     }
-    total_width = name_rect.w + extra_width + growth_rect.w;
-    total_height = MAX(name_rect.h, growth_rect.h);
-    canvas_put_text(pcanvas,
-		    canvas_x - total_width / 2, canvas_y,
+
+    if (draw_city_traderoutes) {
+      get_city_mapview_traderoutes(pcity, traderoutes,
+                                   sizeof(traderoutes),
+                                   &traderoutes_color);
+      get_text_size(&traderoutes_rect.w, &traderoutes_rect.h,
+                    FONT_CITY_PROD, traderoutes);
+      total_width += spacer_width + traderoutes_rect.w;
+      total_height = MAX(total_height, traderoutes_rect.h);
+    }
+
+    drawposx = canvas_x;
+    drawposx -= total_width / 2;
+    canvas_put_text(pcanvas, drawposx, canvas_y,
 		    FONT_CITY_NAME,
 		    get_color(tileset, COLOR_MAPVIEW_CITYTEXT), name);
+    drawposx += name_rect.w;
+
     if (draw_city_growth) {
-      canvas_put_text(pcanvas,
-		      canvas_x - total_width / 2 + name_rect.w + extra_width,
+      drawposx += spacer_width;
+      canvas_put_text(pcanvas, drawposx,
 		      canvas_y + total_height - growth_rect.h,
 		      FONT_CITY_PROD,
 		      get_color(tileset, growth_color), growth);
+      drawposx += growth_rect.w;
     }
+
+    if (draw_city_traderoutes) {
+      drawposx += spacer_width;
+      canvas_put_text(pcanvas, drawposx,
+		      canvas_y + total_height - traderoutes_rect.h,
+		      FONT_CITY_PROD,
+		      get_color(tileset, traderoutes_color), traderoutes);
+      drawposx += traderoutes_rect.w;
+    }
+
     canvas_y += total_height + 3;
 
     *width = MAX(*width, total_width);
@@ -1986,6 +2061,51 @@
   }
 }
 
+/**************************************************************************
+  Find the mapview city traderoutes text for the given city, and place it
+  into the buffer. Sets 'pcolor' to the preferred color the text should
+  be drawn in if it is non-NULL.
+**************************************************************************/
+void get_city_mapview_traderoutes(struct city *pcity,
+                                  char *traderoutes_buffer,
+                                  size_t traderoutes_buffer_len,
+                                  enum color_std *pcolor)
+{
+  int num_traderoutes = 0, i;
+
+  if (!traderoutes_buffer || traderoutes_buffer_len <= 0) {
+    return;
+  }
+
+  if (!pcity) {
+    traderoutes_buffer[0] = '\0';
+    if (pcolor) {
+      *pcolor = COLOR_MAPVIEW_CITYTEXT;
+    }
+    return;
+  }
+
+  for (i = 0; i < NUM_TRADEROUTES; i++) {
+    if (pcity->trade[i] <= 0 && pcity->trade_value[i] <= 0) {
+      continue;
+    }
+    num_traderoutes++;
+  }
+
+  my_snprintf(traderoutes_buffer, traderoutes_buffer_len,
+              "%d/%d", num_traderoutes, NUM_TRADEROUTES);
+
+  if (pcolor) {
+    if (num_traderoutes == NUM_TRADEROUTES) {
+      *pcolor = COLOR_OVERVIEW_LAND; /* green */
+    } else if (num_traderoutes == 0) {
+      *pcolor = COLOR_MAPVIEW_CITYGROWTH_BLOCKED; /* red */
+    } else {
+      *pcolor = COLOR_MAPVIEW_SELECTION; /* yellow */
+    }
+  }
+}
+
 /***************************************************************************/
 static enum update_type needed_updates = UPDATE_NONE;
 static bool callback_queued = FALSE;
diff -Nur -X.diff_ignore trunk/client/mapview_common.h changed/client/mapview_common.h
--- trunk/client/mapview_common.h	2008-07-27 21:46:43.000000000 +0200
+++ changed/client/mapview_common.h	2008-08-23 19:42:40.000000000 +0200
@@ -298,6 +298,10 @@
 				      char *growth_buffer,
 				      size_t growth_buffer_len,
 				      enum color_std *grwoth_color);
+void get_city_mapview_traderoutes(struct city *pcity,
+                                  char *traderoutes_buffer,
+                                  size_t traderoutes_buffer_len,
+                                  enum color_std *traderoutes_color);
 
 void init_mapview_decorations(void);
 bool map_canvas_resized(int width, int height);
diff -Nur -X.diff_ignore trunk/client/options.c changed/client/options.c
--- trunk/client/options.c	2008-08-02 22:46:10.000000000 +0200
+++ changed/client/options.c	2008-08-23 19:42:40.000000000 +0200
@@ -300,6 +300,7 @@
 bool draw_city_names = TRUE;
 bool draw_city_growth = TRUE;
 bool draw_city_productions = FALSE;
+bool draw_city_traderoutes = FALSE;
 bool draw_terrain = TRUE;
 bool draw_coastline = FALSE;
 bool draw_roads_rails = TRUE;
@@ -329,6 +330,7 @@
   VIEW_OPTION(draw_city_names),
   VIEW_OPTION(draw_city_growth),
   VIEW_OPTION(draw_city_productions),
+  VIEW_OPTION(draw_city_traderoutes),
   VIEW_OPTION(draw_terrain),
   VIEW_OPTION(draw_coastline),
   VIEW_OPTION(draw_roads_rails),
diff -Nur -X.diff_ignore trunk/client/options.h changed/client/options.h
--- trunk/client/options.h	2008-08-02 22:46:10.000000000 +0200
+++ changed/client/options.h	2008-08-23 19:42:40.000000000 +0200
@@ -148,6 +148,7 @@
 extern bool draw_city_names;
 extern bool draw_city_growth;
 extern bool draw_city_productions;
+extern bool draw_city_traderoutes;
 extern bool draw_terrain;
 extern bool draw_coastline;
 extern bool draw_roads_rails;
diff -Nur -X.diff_ignore trunk/client/tilespec.c changed/client/tilespec.c
--- trunk/client/tilespec.c	2008-08-23 15:52:24.000000000 +0200
+++ changed/client/tilespec.c	2008-08-23 19:42:40.000000000 +0200
@@ -2284,6 +2284,7 @@
 
   SET_SPRITE(citybar.shields, "citybar.shields");
   SET_SPRITE(citybar.food, "citybar.food");
+  SET_SPRITE(citybar.trade, "citybar.trade");
   SET_SPRITE(citybar.occupied, "citybar.occupied");
   SET_SPRITE(citybar.background, "citybar.background");
   sprite_vector_init(&t->sprites.citybar.occupancy);
diff -Nur -X.diff_ignore trunk/client/tilespec.h changed/client/tilespec.h
--- trunk/client/tilespec.h	2008-07-27 21:46:43.000000000 +0200
+++ changed/client/tilespec.h	2008-08-23 19:42:40.000000000 +0200
@@ -215,6 +215,7 @@
   struct sprite
     *shields,
     *food,
+    *trade,
     *occupied,
     *background;
   struct sprite_vector occupancy;
diff -Nur -X.diff_ignore trunk/data/misc/citybar.spec changed/data/misc/citybar.spec
--- trunk/data/misc/citybar.spec	2008-07-27 21:45:10.000000000 +0200
+++ changed/data/misc/citybar.spec	2008-08-23 19:42:40.000000000 +0200
@@ -8,6 +8,7 @@
 
 artists = "
      Freim <...>
+     Madeline Book <[EMAIL PROTECTED]> (citybar.trade)
 "
 
 [file]
@@ -25,6 +26,7 @@
 
   0,  0, "citybar.shields"
   0,  1, "citybar.food"
+  0,  2, "citybar.trade"
 
 }
 
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to