<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40447 >
> [EMAIL PROTECTED] - Sun Aug 17 17:07:33 2008]: > > Whereas, there are map features to view how many turns until the > production of a unit, improvement, or wonder is built, and view how > many turns until the city grows to the next size: I suggest that we > also allow one to be able to view the number of traderoutes which > exist inside a city. > The number of traderoutes has become a dominant part of the freeciv > game since 2.0.0, meaning it is more important that we are able to > see what traderoutes (or how many) a city does have. I also do not > suggest that the default for this option be turned on, as nobody > will have a need to see the number of traderoutes in a city early > in the game (as caravans require Trade). However, later in the > game it becomes more important to see which cities do not still > have traderoutes. Attached patch adds the display of the number of traderoutes to both the full and small citybars. A view option controls whether it is displayed (shortcut ctrl-t; the shortcut for city worker output having been moved to ctrl-w). (The sdl gui seems to be missing the city output toggle shortcut...?) For the full citybar a new citybar icon ("trade") is added to data/misc/citybar.{png, spec}. Miraculously, despite my complete lack of gimp proficiency, it turned out not completely disgusting. ----------------------------------------------------------------------- ご主人様にお従い致します。
<<inline: citybar_with_trade.png>>
client/control.c | 22 ++++++ client/control.h | 2 + client/gui-gtk-2.0/menu.c | 14 ++++- client/gui-sdl/mapctrl.c | 7 ++ client/mapview_common.c | 166 ++++++++++++++++++++++++++++++++++++++------ client/mapview_common.h | 4 + client/options.c | 2 + client/options.h | 1 + client/tilespec.c | 1 + client/tilespec.h | 1 + data/misc/citybar.png | Bin 2852 -> 2721 bytes data/misc/citybar.spec | 2 + 12 files changed, 198 insertions(+), 24 deletions(-) diff --git a/client/control.c b/client/control.c index dabf911..01462a8 100644 --- a/client/control.c +++ b/client/control.c @@ -1690,6 +1690,19 @@ void request_toggle_city_productions(void) } /************************************************************************** + 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) @@ -2767,6 +2780,15 @@ void key_city_productions_toggle(void) } /************************************************************************** + 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 --git a/client/control.h b/client/control.h index ffc6257..59e7d8c 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_traderoutes(void); void request_toggle_terrain(void); void request_toggle_coastline(void); void request_toggle_roads_rails(void); @@ -144,6 +145,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_traderoutes_toggle(void); void key_terrain_toggle(void); void key_coastline_toggle(void); void key_roads_rails_toggle(void); diff --git a/client/gui-gtk-2.0/menu.c b/client/gui-gtk-2.0/menu.c index 1db317c..e111f1d 100644 --- a/client/gui-gtk-2.0/menu.c +++ b/client/gui-gtk-2.0/menu.c @@ -106,6 +106,7 @@ enum MenuID { 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 @@ static void view_menu_callback(gpointer callback_data, guint callback_action, * 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 @@ 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_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 @@ static GtkItemFactoryEntry menu_items[] = 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 @@ 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 _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 @@ void update_menus(void) * 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 --git a/client/gui-sdl/mapctrl.c b/client/gui-sdl/mapctrl.c index d11aa68..ff63f0c 100644 --- a/client/gui-sdl/mapctrl.c +++ b/client/gui-sdl/mapctrl.c @@ -2373,6 +2373,13 @@ bool map_event_handler(SDL_keysym Key) } return FALSE; + /* show city traderoutes - Ctrl+t */ + case SDLK_t: + if (LCTRL || RCTRL) { + key_city_traderoutes_toggle(); + } + return FALSE; + /* *** some additional shortcuts that work in the SDL client only *** */ /* show terrain - Ctrl+t */ diff --git a/client/mapview_common.c b/client/mapview_common.c index 52857f3..475dce1 100644 --- a/client/mapview_common.c +++ b/client/mapview_common.c @@ -1223,15 +1223,16 @@ static void show_full_citybar(struct canvas *pcanvas, 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 @@ static void show_full_citybar(struct canvas *pcanvas, 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 @@ static void show_full_citybar(struct canvas *pcanvas, } 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 @@ static void show_full_citybar(struct canvas *pcanvas, 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 @@ static void show_full_citybar(struct canvas *pcanvas, 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 @@ static void show_small_citybar(struct canvas *pcanvas, 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 @@ static void show_small_citybar(struct canvas *pcanvas, 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); + } + + 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); } - 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, + + 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 @@ void get_city_mapview_production(struct city *pcity, } } +/************************************************************************** + 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 --git a/client/mapview_common.h b/client/mapview_common.h index 6299a97..afee919 100644 --- a/client/mapview_common.h +++ b/client/mapview_common.h @@ -298,6 +298,10 @@ void get_city_mapview_name_and_growth(struct city *pcity, 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 --git a/client/options.c b/client/options.c index bff38c8..55f44ae 100644 --- a/client/options.c +++ b/client/options.c @@ -300,6 +300,7 @@ bool draw_map_grid = FALSE; 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 view_options[] = { 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 --git a/client/options.h b/client/options.h index ce3c8d7..610d61a 100644 --- a/client/options.h +++ b/client/options.h @@ -148,6 +148,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_traderoutes; extern bool draw_terrain; extern bool draw_coastline; extern bool draw_roads_rails; diff --git a/client/tilespec.c b/client/tilespec.c index 68434ea..0edbfa4 100644 --- a/client/tilespec.c +++ b/client/tilespec.c @@ -2284,6 +2284,7 @@ static void tileset_lookup_sprite_tags(struct tileset *t) 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 --git a/client/tilespec.h b/client/tilespec.h index 794e5f0..e96f406 100644 --- a/client/tilespec.h +++ b/client/tilespec.h @@ -215,6 +215,7 @@ struct citybar_sprites { struct sprite *shields, *food, + *trade, *occupied, *background; struct sprite_vector occupancy; diff --git a/data/misc/citybar.png b/data/misc/citybar.png index 382ab6b..9b2861e 100644 Binary files a/data/misc/citybar.png and b/data/misc/citybar.png differ diff --git a/data/misc/citybar.spec b/data/misc/citybar.spec index 229789a..e0dd114 100644 --- a/data/misc/citybar.spec +++ b/data/misc/citybar.spec @@ -8,6 +8,7 @@ options = "+spec3" artists = " Freim <...> + Madeline Book <[EMAIL PROTECTED]> (citybar.trade) " [file] @@ -25,6 +26,7 @@ tiles = { "row", "column", "tag" 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