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

Here you go.


----------------------------------------------------------------------
はいこれ
>From 90aafdce6a7cba212eac1de3fb95241cbc275bb9 Mon Sep 17 00:00:00 2001
From: Madeline Book <[EMAIL PROTECTED]>
Date: Tue, 13 May 2008 18:48:29 -0400
Subject: [PATCH] Citybar improvements 2.1.4 version.

---
 client/gui-gtk-2.0/menu.c |   19 ++++++-
 client/mapview_common.c   |  126 +++++++++++++++++++++++++++++++-------------
 client/options.c          |   13 ++++-
 client/options.h          |    7 ---
 client/packhand.c         |   31 +++++------
 5 files changed, 133 insertions(+), 63 deletions(-)

diff --git a/client/gui-gtk-2.0/menu.c b/client/gui-gtk-2.0/menu.c
index 0d3d1e9..009ec01 100644
--- a/client/gui-gtk-2.0/menu.c
+++ b/client/gui-gtk-2.0/menu.c
@@ -312,7 +312,13 @@ static void view_menu_callback(gpointer callback_data, guint callback_action,
   case MENU_VIEW_SHOW_CITY_NAMES:
     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);
+
+      if (!draw_full_citybar) {
+        /* The "full" city bar (i.e. the new way of drawing the
+         * 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);
+      }
     }
     break;
   case MENU_VIEW_SHOW_CITY_GROWTH_TURNS:
@@ -1307,7 +1313,16 @@ void update_menus(void)
     menus_set_sensitive("<main>/_View/National _Borders", game.info.borders > 0);
     menus_set_active("<main>/_View/National _Borders", draw_borders);
     menus_set_active("<main>/_View/City _Names", draw_city_names);
-    menus_set_sensitive("<main>/_View/City G_rowth", draw_city_names);
+
+    /* The "full" city bar (i.e. the new way of drawing the
+     * city name), can draw the city growth even without drawing
+     * the city name. But the old method cannot. */
+    if (draw_full_citybar) {
+      menus_set_sensitive("<main>/_View/City G_rowth", TRUE);
+    } else {
+      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);
diff --git a/client/mapview_common.c b/client/mapview_common.c
index aa8fb51..89e56e5 100644
--- a/client/mapview_common.c
+++ b/client/mapview_common.c
@@ -1219,10 +1219,6 @@ static void show_full_citybar(struct canvas *pcanvas,
 			      struct city *pcity, int *width, int *height)
 {
   const struct citybar_sprites *citybar = get_citybar_sprites(tileset);
-  const bool line1 = draw_city_names;
-  const bool line2 = ((draw_city_productions || draw_city_growth)
-		      && (!game.player_ptr
-			  || city_owner(pcity) == game.player_ptr));
   static char name[512], growth[32], prod[512], size[32];
   enum color_std growth_color;
   struct color *owner_color;
@@ -1242,17 +1238,36 @@ static void show_full_citybar(struct canvas *pcanvas,
   const int border = 6;
   const enum client_font FONT_CITY_SIZE = FONT_CITY_NAME; /* TODO: new font */
 
-  get_sprite_dimensions(bg, &bg_w, &bg_h);
-  *width = *height = 0;
+  /* We can see the city's production or growth values if
+   * we are observing or playing as the owner of the city. */
+  const bool can_see_inside = (client_is_observer()
+                               || city_owner(pcity) == game.player_ptr);
+  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_lower_bar = (should_draw_productions
+                                      || should_draw_growth);
+
+
+  if (width != NULL) {
+    *width = 0;
+  }
+  if (height != NULL) {
+    *height = 0;
+  }
 
-  if (!line1 && !line2) {
+  if (!draw_city_names && !should_draw_lower_bar) {
     return;
   }
 
+
   /* First: calculate rect dimensions (but not positioning). */
+
+  get_sprite_dimensions(bg, &bg_w, &bg_h);
   get_city_mapview_name_and_growth(pcity, name, sizeof(name),
 				   growth, sizeof(growth), &growth_color);
-  if (line1) {
+
+  if (draw_city_names) {
     my_snprintf(size, sizeof(size), "%d", pcity->size);
 
     get_text_size(&size_rect.w, &size_rect.h, FONT_CITY_SIZE, size);
@@ -1281,14 +1296,20 @@ static void show_full_citybar(struct canvas *pcanvas,
 		      MAX(name_rect.h + border,
 			  size_rect.h + border)));
   }
-  if (line2) {
-    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);
+  if (should_draw_lower_bar) {
+
+    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);
+    }
 
-    get_text_size(&growth_rect.w, &growth_rect.h, FONT_CITY_PROD, growth);
-    get_sprite_dimensions(citybar->food, &food_rect.w, &food_rect.h);
+    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 = (prod_rect.w + growth_rect.w + shield_rect.w + food_rect.w
 	      + 2 * border);
@@ -1301,8 +1322,10 @@ static void show_full_citybar(struct canvas *pcanvas,
   *width = MAX(width1, width2);
   *height = height1 + height2;
 
+
   /* Next fill in X and Y locations. */
-  if (line1) {
+
+  if (draw_city_names) {
     flag_rect.x = canvas_x - *width / 2;
     flag_rect.y = canvas_y + (height1 - flag_rect.h) / 2;
 
@@ -1316,29 +1339,39 @@ static void show_full_citybar(struct canvas *pcanvas,
     size_rect.x = canvas_x + (*width + 1) / 2 - size_rect.w - border / 2;
     size_rect.y = canvas_y + (height1 - size_rect.h) / 2;
   }
-  if (line2) {
-    shield_rect.x = canvas_x - *width / 2;
-    shield_rect.y = canvas_y + height1 + (height2 - shield_rect.h) / 2;
 
-    prod_rect.x = shield_rect.x + shield_rect.w + border / 2;
-    prod_rect.y = canvas_y + height1 + (height2 - prod_rect.h) / 2;
+  if (should_draw_lower_bar) {
+    if (should_draw_productions) {
+      shield_rect.x = canvas_x - *width / 2;
+      shield_rect.y = canvas_y + height1 + (height2 - shield_rect.h) / 2;
 
-    growth_rect.x = canvas_x + (*width + 1) / 2 - growth_rect.w - border / 2;
-    growth_rect.y = canvas_y + height1 + (height2 - growth_rect.h) / 2;
+      prod_rect.x = shield_rect.x + shield_rect.w + border / 2;
+      prod_rect.y = canvas_y + height1 + (height2 - prod_rect.h) / 2;
+    }
+
+    if (should_draw_growth) {
+      growth_rect.x = canvas_x + (*width + 1) / 2 - growth_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;
-    food_rect.y = canvas_y + height1 + (height2 - food_rect.h) / 2;
+      food_rect.x = growth_rect.x - border / 2 - food_rect.w;
+      food_rect.y = canvas_y + height1 + (height2 - food_rect.h) / 2;
+    }
   }
 
+
   /* Now draw. */
+
+  /* Draw the city bar's background. */
   for (x = 0; x < *width; x += bg_w) {
     for (y = 0; y < *height; y += bg_h) {
       canvas_put_sprite(pcanvas, canvas_x - *width / 2 + x, canvas_y + y,
 			bg, 0, 0, *width - x, *height - y);
     }
   }
+
   owner_color = get_player_color(tileset, city_owner(pcity));
-  if (line1) {
+
+  if (draw_city_names) {
     canvas_put_sprite_full(pcanvas, flag_rect.x, flag_rect.y, flag);
     canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
 		    flag_rect.x + flag_rect.w - 1, canvas_y,
@@ -1356,17 +1389,26 @@ static void show_full_citybar(struct canvas *pcanvas,
 		    FONT_CITY_NAME,
 		    get_color(tileset, COLOR_MAPVIEW_CITYTEXT), size);
   }
-  if (line2) {
-    canvas_put_sprite_full(pcanvas, shield_rect.x, shield_rect.y,
-			   citybar->shields);
-    canvas_put_text(pcanvas, prod_rect.x, prod_rect.y,
-		    FONT_CITY_PROD,
-		    get_color(tileset, COLOR_MAPVIEW_CITYTEXT), prod);
-    canvas_put_sprite_full(pcanvas, food_rect.x, food_rect.y, citybar->food);
-    canvas_put_text(pcanvas, growth_rect.x, growth_rect.y,
-		    FONT_CITY_PROD,
-		    get_color(tileset, growth_color), growth);
+
+  if (should_draw_lower_bar) {
+
+    if (should_draw_productions) {
+      canvas_put_sprite_full(pcanvas, shield_rect.x, shield_rect.y,
+                             citybar->shields);
+      canvas_put_text(pcanvas, prod_rect.x, prod_rect.y,
+                      FONT_CITY_PROD,
+                      get_color(tileset, COLOR_MAPVIEW_CITYTEXT), prod);
+    }
+
+    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,
+                      FONT_CITY_PROD,
+                      get_color(tileset, growth_color), growth);
+    }
   }
+
+  /* Draw the city bar's outline. */
   canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
 		  canvas_x - *width / 2, canvas_y,
 		  *width, 0);
@@ -1379,7 +1421,10 @@ static void show_full_citybar(struct canvas *pcanvas,
   canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
 		  canvas_x - *width / 2 + *width, canvas_y,
 		  0, *height);
-  if (line1 && line2) {
+
+  /* Draw the dividing line if we drew both the
+   * upper and lower parts. */
+  if (draw_city_names && should_draw_lower_bar) {
     canvas_put_line(pcanvas, owner_color, LINE_NORMAL,
 		    canvas_x - *width / 2, canvas_y + height1 - 1,
 		    *width, 0);
@@ -1488,7 +1533,14 @@ void show_city_descriptions(int canvas_x, int canvas_y,
   const int offset_y = tileset_citybar_offset_y(tileset);
   int new_max_width = max_desc_width, new_max_height = max_desc_height;
 
-  if (!draw_city_names && !draw_city_productions) {
+  if (draw_full_citybar && !(draw_city_names
+                             || draw_city_productions
+                             || draw_city_growth)) {
+    return;
+  }
+
+  if (!draw_full_citybar && !(draw_city_names
+                              || draw_city_productions)) {
     return;
   }
 
diff --git a/client/options.c b/client/options.c
index 19ead9e..f72717b 100644
--- a/client/options.c
+++ b/client/options.c
@@ -36,6 +36,7 @@
 #include "cma_fec.h"
 #include "dialogs_g.h"
 #include "mapview_common.h"
+#include "menu_g.h"
 #include "options.h"
 #include "overview_common.h"
 #include "plrdlg_common.h"
@@ -91,6 +92,7 @@ bool show_task_icons = TRUE;
 bool update_city_text_in_refresh_tile = TRUE;
 
 static void reqtree_show_icons_callback(struct client_option *option);
+static void draw_full_citybar_changed_callback(struct client_option *option);
 
 const char *client_option_class_names[COC_MAX] = {
   N_("Graphics"),
@@ -184,7 +186,7 @@ static client_option common_options[] = {
 			"containing useful information beneath each city. "
 			"Disabling this option will display only the city's "
 			"name and optionally, production."),
-		     COC_GRAPHICS, mapview_redraw_callback),
+		     COC_GRAPHICS, draw_full_citybar_changed_callback),
   GEN_BOOL_OPTION_CB(reqtree_show_icons,
                      N_("Show icons in the technology tree"),
                      N_("Setting this option will display icons "
@@ -881,3 +883,12 @@ static void reqtree_show_icons_callback(struct client_option *option)
    * be recalculated */
   popdown_all_game_dialogs();
 }
+
+/****************************************************************************
+  Callback for when the draw_full_citybar option is changed.
+****************************************************************************/
+static void draw_full_citybar_changed_callback(struct client_option *option)
+{
+  update_menus();
+  update_map_canvas_visible();
+}
diff --git a/client/options.h b/client/options.h
index 5ce18b1..31268ea 100644
--- a/client/options.h
+++ b/client/options.h
@@ -145,14 +145,7 @@ extern bool draw_borders;
 extern bool draw_full_citybar;
 extern bool draw_unit_shields;
 
-/* It would probably be better to have function calls for these checks. */
-#define DRAW_CITY_PRODUCTIONS (draw_city_productions \
-			       || (draw_full_citybar && draw_city_growth))
-#define DRAW_CITY_GROWTH (draw_city_growth \
-			  || (draw_full_citybar && draw_city_productions))
-
 extern bool player_dlg_show_dead_players;
-
 extern bool reqtree_show_icons;
 
 typedef struct {
diff --git a/client/packhand.c b/client/packhand.c
index 6eca07a..c858dc3 100644
--- a/client/packhand.c
+++ b/client/packhand.c
@@ -448,22 +448,21 @@ void handle_city_info(struct packet_city_info *packet)
   } else {
     name_changed = (strcmp(city_name(pcity), packet->name) != 0);
 
-    /* Check if city desciptions should be updated */
-    if (draw_city_names && name_changed) {
-      update_descriptions = TRUE;
-    } else if (DRAW_CITY_PRODUCTIONS
-	       && (pcity->production.is_unit != packet->production_is_unit
-		   || pcity->production.value != packet->production_value
-		   || pcity->surplus[O_SHIELD] != packet->surplus[O_SHIELD]
-		   || pcity->shield_stock != packet->shield_stock)) {
-      update_descriptions = TRUE;
-    } else if (draw_city_names && DRAW_CITY_GROWTH &&
-	       (pcity->food_stock != packet->food_stock ||
-		pcity->surplus[O_FOOD] != packet->surplus[O_FOOD])) {
-      /* If either the food stock or surplus have changed, the time-to-grow
-	 is likely to have changed as well. */
-      update_descriptions = TRUE;
-    }
+    /* Descriptions should probably be updated if the
+     * city name, production or time-to-grow changes.
+     * Note that if either the food stock or surplus
+     * have changed, the time-to-grow is likely to
+     * have changed as well. */
+    update_descriptions = (draw_city_names && name_changed)
+      || (draw_city_productions
+          && (pcity->production.is_unit != packet->production_is_unit
+              || pcity->production.value != packet->production_value
+              || pcity->surplus[O_SHIELD] != packet->surplus[O_SHIELD]
+              || pcity->shield_stock != packet->shield_stock))
+      || (draw_city_growth
+          && (pcity->food_stock != packet->food_stock
+              || pcity->surplus[O_FOOD] != packet->surplus[O_FOOD]));
+
     assert(pcity->id == packet->id);
   }
   
-- 
1.5.5.1

_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to