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

Patch implements a view option that when enabled appends the
buy cost of a city's current production to the production
string in the citybar/city description. So for example the
user would see "Settlers 8/76" where the 8 is the number of
turns until the production is completed, and the 76 the gold
it would cost to buy the production right now.


-----------------------------------------------------------------------
値段を隠そうとしないで!
 client/control.c          |   22 ++++++++++++++++++++++
 client/control.h          |    2 ++
 client/gui-gtk-2.0/menu.c |    9 +++++++++
 client/mapview_common.c   |   22 ++++++++++++++++++++++
 client/options.c          |    2 ++
 client/options.h          |    1 +
 6 files changed, 58 insertions(+), 0 deletions(-)

diff --git a/client/control.c b/client/control.c
index 2925528..66cac9c 100644
--- a/client/control.c
+++ b/client/control.c
@@ -1627,6 +1627,19 @@ void request_toggle_city_productions(void)
 }
 
 /**************************************************************************
+ Toggle display of city buycost
+**************************************************************************/
+void request_toggle_city_buycost(void)
+{
+  if (!can_client_change_view()) {
+    return;
+  }
+
+  draw_city_buycost ^= 1;
+  update_map_canvas_visible();
+}
+
+/**************************************************************************
  Toggle display of city traderoutes
 **************************************************************************/
 void request_toggle_city_traderoutes(void)
@@ -2701,6 +2714,15 @@ void key_city_productions_toggle(void)
 }
 
 /**************************************************************************
+  Toggles the showing of the buy cost of the current production in the
+  city descriptions.
+**************************************************************************/
+void key_city_buycost_toggle(void)
+{
+  request_toggle_city_buycost();
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void key_city_traderoutes_toggle(void)
diff --git a/client/control.h b/client/control.h
index 63b7f0c..bbf9e60 100644
--- a/client/control.h
+++ b/client/control.h
@@ -107,6 +107,7 @@ void request_toggle_map_borders(void);
 void request_toggle_city_names(void);
 void request_toggle_city_growth(void);
 void request_toggle_city_productions(void);
+void request_toggle_city_buycost(void);
 void request_toggle_city_traderoutes(void);
 void request_toggle_terrain(void);
 void request_toggle_coastline(void);
@@ -152,6 +153,7 @@ void key_center_capital(void);
 void key_city_names_toggle(void);
 void key_city_growth_toggle(void);
 void key_city_productions_toggle(void);
+void key_city_buycost_toggle(void);
 void key_city_traderoutes_toggle(void);
 void key_terrain_toggle(void);
 void key_coastline_toggle(void);
diff --git a/client/gui-gtk-2.0/menu.c b/client/gui-gtk-2.0/menu.c
index ba77872..8387651 100644
--- a/client/gui-gtk-2.0/menu.c
+++ b/client/gui-gtk-2.0/menu.c
@@ -100,6 +100,7 @@ enum MenuID {
   MENU_VIEW_SHOW_CITY_NAMES,
   MENU_VIEW_SHOW_CITY_GROWTH_TURNS,
   MENU_VIEW_SHOW_CITY_PRODUCTIONS,
+  MENU_VIEW_SHOW_CITY_BUYCOST,
   MENU_VIEW_SHOW_CITY_TRADEROUTES,
   MENU_VIEW_SHOW_CITY_WORKERS,
   MENU_VIEW_SHOW_TERRAIN,
@@ -330,6 +331,11 @@ static void view_menu_callback(gpointer callback_data, guint callback_action,
     if (draw_city_productions ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_city_productions_toggle();
     break;
+  case MENU_VIEW_SHOW_CITY_BUYCOST:
+    if (draw_city_buycost ^ GTK_CHECK_MENU_ITEM(widget)->active) {
+      key_city_buycost_toggle();
+    }
+    break;
   case MENU_VIEW_SHOW_CITY_TRADEROUTES:
     if (draw_city_traderoutes ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_city_traderoutes_toggle();
@@ -786,6 +792,8 @@ static GtkItemFactoryEntry menu_items[]	=
 	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") "/" N_("City Buy Cost"),		NULL,
+	view_menu_callback,	MENU_VIEW_SHOW_CITY_BUYCOST,		"<CheckItem>"	},
   { "/" N_("View") "/" N_("City Traderoutes"),		"<control>t",
 	view_menu_callback,	MENU_VIEW_SHOW_CITY_TRADEROUTES,	"<CheckItem>"	},
   { "/" N_("View") "/" N_("Draw city worker map grid"),	"t",
@@ -1332,6 +1340,7 @@ void update_menus(void)
 
     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 Buy Cost", draw_city_buycost);
     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);
diff --git a/client/mapview_common.c b/client/mapview_common.c
index 909dd21..44c0cca 100644
--- a/client/mapview_common.c
+++ b/client/mapview_common.c
@@ -2094,6 +2094,26 @@ struct city *find_city_near_tile(const struct tile *ptile)
 }
 
 /**************************************************************************
+  Append the buy cost of the current production of the given city to the
+  already NULL-terminated buffer. Does nothing if draw_city_buycost is
+  set to FALSE, or if it does not make sense to buy the current production
+  (e.g. coinage).
+**************************************************************************/
+static void append_city_buycost_string(const struct city *pcity,
+                                       char *buffer, int buffer_len)
+{
+  if (!pcity || !buffer || buffer_len < 1) {
+    return;
+  }
+
+  if (!draw_city_buycost || !city_can_buy(pcity)) {
+    return;
+  }
+
+  cat_snprintf(buffer, buffer_len, "/%d", city_buy_cost(pcity));
+}
+
+/**************************************************************************
   Find the mapview city production text for the given city, and place it
   into the buffer.
 **************************************************************************/
@@ -2127,6 +2147,8 @@ void get_city_mapview_production(struct city *pcity,
 		  improvement_name_translation(pcity->production.value));
     }
   }
+
+  append_city_buycost_string(pcity, buffer, buffer_len);
 }
 
 static enum update_type needed_updates = UPDATE_NONE;
diff --git a/client/options.c b/client/options.c
index 99afbc6..0853222 100644
--- a/client/options.c
+++ b/client/options.c
@@ -292,6 +292,7 @@ bool draw_map_grid = FALSE;
 bool draw_city_names = TRUE;
 bool draw_city_growth = TRUE;
 bool draw_city_productions = FALSE;
+bool draw_city_buycost = FALSE;
 bool draw_city_traderoutes = FALSE;
 bool draw_terrain = TRUE;
 bool draw_coastline = FALSE;
@@ -320,6 +321,7 @@ view_option view_options[] = {
   VIEW_OPTION(draw_city_names),
   VIEW_OPTION(draw_city_growth),
   VIEW_OPTION(draw_city_productions),
+  VIEW_OPTION(draw_city_buycost),
   VIEW_OPTION(draw_city_traderoutes),
   VIEW_OPTION(draw_terrain),
   VIEW_OPTION(draw_coastline),
diff --git a/client/options.h b/client/options.h
index aee53c2..f41e6dd 100644
--- a/client/options.h
+++ b/client/options.h
@@ -130,6 +130,7 @@ extern bool draw_map_grid;
 extern bool draw_city_names;
 extern bool draw_city_growth;
 extern bool draw_city_productions;
+extern bool draw_city_buycost;
 extern bool draw_city_traderoutes;
 extern bool draw_terrain;
 extern bool draw_coastline;
 client/control.c          |   22 ++++++++++++++++++++++
 client/control.h          |    2 ++
 client/gui-gtk-2.0/menu.c |    9 +++++++++
 client/mapview_common.c   |   23 +++++++++++++++++++++++
 client/options.c          |    2 ++
 client/options.h          |    1 +
 6 files changed, 59 insertions(+), 0 deletions(-)

diff --git a/client/control.c b/client/control.c
index 55cd896..9913ddf 100644
--- a/client/control.c
+++ b/client/control.c
@@ -1704,6 +1704,19 @@ void request_toggle_city_productions(void)
 }
 
 /**************************************************************************
+ Toggle display of city buycost
+**************************************************************************/
+void request_toggle_city_buycost(void)
+{
+  if (!can_client_change_view()) {
+    return;
+  }
+
+  draw_city_buycost ^= 1;
+  update_map_canvas_visible();
+}
+
+/**************************************************************************
  Toggle display of city traderoutes
 **************************************************************************/
 void request_toggle_city_traderoutes(void)
@@ -2786,6 +2799,15 @@ void key_city_growth_toggle(void)
 }
 
 /**************************************************************************
+  Toggles the showing of the buy cost of the current production in the
+  city descriptions.
+**************************************************************************/
+void key_city_buycost_toggle(void)
+{
+  request_toggle_city_buycost();
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void key_city_productions_toggle(void)
diff --git a/client/control.h b/client/control.h
index 59e7d8c..32f5adb 100644
--- a/client/control.h
+++ b/client/control.h
@@ -100,6 +100,7 @@ void request_toggle_map_borders(void);
 void request_toggle_city_names(void);
 void request_toggle_city_growth(void);
 void request_toggle_city_productions(void);
+void request_toggle_city_buycost(void);
 void request_toggle_city_traderoutes(void);
 void request_toggle_terrain(void);
 void request_toggle_coastline(void);
@@ -145,6 +146,7 @@ void key_center_capital(void);
 void key_city_names_toggle(void);
 void key_city_growth_toggle(void);
 void key_city_productions_toggle(void);
+void key_city_buycost_toggle(void);
 void key_city_traderoutes_toggle(void);
 void key_terrain_toggle(void);
 void key_coastline_toggle(void);
diff --git a/client/gui-gtk-2.0/menu.c b/client/gui-gtk-2.0/menu.c
index f837955..330bfbc 100644
--- a/client/gui-gtk-2.0/menu.c
+++ b/client/gui-gtk-2.0/menu.c
@@ -109,6 +109,7 @@ enum MenuID {
   MENU_VIEW_SHOW_CITY_NAMES,
   MENU_VIEW_SHOW_CITY_GROWTH_TURNS,
   MENU_VIEW_SHOW_CITY_PRODUCTIONS,
+  MENU_VIEW_SHOW_CITY_BUYCOST,
   MENU_VIEW_SHOW_CITY_TRADEROUTES,
   MENU_VIEW_SHOW_TERRAIN,
   MENU_VIEW_SHOW_COASTLINE,
@@ -350,6 +351,11 @@ static void view_menu_callback(gpointer callback_data, guint callback_action,
     if (draw_city_productions ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_city_productions_toggle();
     break;
+  case MENU_VIEW_SHOW_CITY_BUYCOST:
+    if (draw_city_buycost ^ GTK_CHECK_MENU_ITEM(widget)->active) {
+      key_city_buycost_toggle();
+    }
+    break;
   case MENU_VIEW_SHOW_CITY_TRADEROUTES:
     if (draw_city_traderoutes ^ GTK_CHECK_MENU_ITEM(widget)->active) {
       key_city_traderoutes_toggle();
@@ -845,6 +851,8 @@ static GtkItemFactoryEntry menu_items[]	=
 	"<CheckItem>"	},
   { "/" N_("View") "/" N_("City _Productions"),		"<control>p",
 	view_menu_callback,	MENU_VIEW_SHOW_CITY_PRODUCTIONS,	"<CheckItem>"	},
+  { "/" N_("View") "/" N_("City Buy Cost"),		NULL,
+	view_menu_callback,	MENU_VIEW_SHOW_CITY_BUYCOST,		"<CheckItem>"	},
   { "/" N_("View") "/" N_("City _Traderoutes"),		"<control>t",
 	view_menu_callback,	MENU_VIEW_SHOW_CITY_TRADEROUTES,	"<CheckItem>"	},
   { "/" N_("View") "/sep1",				NULL,
@@ -1463,6 +1471,7 @@ void update_menus(void)
 
     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 Buy Cost", draw_city_buycost);
     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);
diff --git a/client/mapview_common.c b/client/mapview_common.c
index 11f9402..f2604eb 100644
--- a/client/mapview_common.c
+++ b/client/mapview_common.c
@@ -2177,6 +2177,27 @@ struct city *find_city_near_tile(const struct tile *ptile)
 }
 
 /**************************************************************************
+  Append the buy cost of the current production of the given city to the
+  already NULL-terminated buffer. Does nothing if draw_city_buycost is
+  set to FALSE, or if it does not make sense to buy the current production
+  (e.g. coinage).
+**************************************************************************/
+static void append_city_buycost_string(const struct city *pcity,
+                                       char *buffer, int buffer_len)
+{
+  if (!pcity || !buffer || buffer_len < 1) {
+    return;
+  }
+
+  if (!draw_city_buycost || !city_can_buy(pcity)) {
+    return;
+  }
+
+  cat_snprintf(buffer, buffer_len, "/%d",
+               city_production_buy_gold_cost(pcity));
+}
+
+/**************************************************************************
   Find the mapview city production text for the given city, and place it
   into the buffer.
 **************************************************************************/
@@ -2197,6 +2218,8 @@ void get_city_mapview_production(struct city *pcity,
   } else {
     cat_snprintf(buffer, buffer_len, " %d", turns);
   }
+
+  append_city_buycost_string(pcity, buffer, buffer_len);
 }
 
 /**************************************************************************
diff --git a/client/options.c b/client/options.c
index ba89dfb..0139480 100644
--- a/client/options.c
+++ b/client/options.c
@@ -315,6 +315,7 @@ bool draw_map_grid = FALSE;
 bool draw_city_names = TRUE;
 bool draw_city_growth = TRUE;
 bool draw_city_productions = FALSE;
+bool draw_city_buycost = FALSE;
 bool draw_city_traderoutes = FALSE;
 bool draw_terrain = TRUE;
 bool draw_coastline = FALSE;
@@ -345,6 +346,7 @@ view_option view_options[] = {
   VIEW_OPTION(draw_city_names),
   VIEW_OPTION(draw_city_growth),
   VIEW_OPTION(draw_city_productions),
+  VIEW_OPTION(draw_city_buycost),
   VIEW_OPTION(draw_city_traderoutes),
   VIEW_OPTION(draw_terrain),
   VIEW_OPTION(draw_coastline),
diff --git a/client/options.h b/client/options.h
index 876bada..4181775 100644
--- a/client/options.h
+++ b/client/options.h
@@ -150,6 +150,7 @@ extern bool draw_map_grid;
 extern bool draw_city_names;
 extern bool draw_city_growth;
 extern bool draw_city_productions;
+extern bool draw_city_buycost;
 extern bool draw_city_traderoutes;
 extern bool draw_terrain;
 extern bool draw_coastline;
_______________________________________________
Freeciv-dev mailing list
Freeciv-dev@gna.org
https://mail.gna.org/listinfo/freeciv-dev

Reply via email to