[Freeciv-Dev] Re: [patch] "turns-to-grow" on the map overview (PR#1328)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Raimar Falke wrote:
On Mon, Mar 04, 2002 at 03:37:48PM -0500, Jason Short wrote:
<snip: a patch to add the "city turns to grow" to the mapview city
descriptions>
Partly applied. Please add the option (options.c, menus,
control.c,...) and change the other GUIs.
Here's an updated patch.
I've added the option, and added support for XAW. There is still no
support for win32 or MUI, and I'm not sure that I'll be able to add such
support.
There's only one problem that I know of: for lack of anything better, I
bind the menu entry to control-r. In xaw, this doesn't work for some
reason.
jason
? test.pl
? topology
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.72
diff -u -r1.72 control.c
--- client/control.c 2002/02/26 19:57:07 1.72
+++ client/control.c 2002/03/15 13:19:36
@@ -868,6 +868,18 @@
}
/**************************************************************************
+ 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 ^= TRUE;
+ update_map_canvas_visible();
+}
+
+/**************************************************************************
Toggle display of city productions
**************************************************************************/
void request_toggle_city_productions(void)
@@ -1348,6 +1360,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.27
diff -u -r1.27 control.h
--- client/control.h 2002/02/19 16:41:17 1.27
+++ client/control.h 2002/03/15 13:19:36
@@ -64,6 +64,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);
@@ -97,6 +98,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.54
diff -u -r1.54 options.c
--- client/options.c 2002/03/14 04:54:23 1.54
+++ client/options.c 2002/03/15 13:19:36
@@ -83,6 +83,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;
@@ -103,6 +104,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.14
diff -u -r1.14 options.h
--- client/options.h 2002/03/13 12:02:10 1.14
+++ client/options.h 2002/03/15 13:19:36
@@ -55,6 +55,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.228
diff -u -r1.228 packhand.c
--- client/packhand.c 2002/03/08 15:38:18 1.228
+++ client/packhand.c 2002/03/15 13:19:37
@@ -356,10 +356,15 @@
/* Check if city desciptions should be updated */
if (draw_city_names && strcmp(pcity->name, packet->name) != 0) {
update_descriptions = TRUE;
- }
- if (draw_city_productions &&
- ((pcity->is_building_unit != packet->is_building_unit) ||
- (pcity->currently_building != packet->currently_building))) {
+ } else if (draw_city_productions &&
+ (pcity->is_building_unit != packet->is_building_unit ||
+ pcity->currently_building != packet->currently_building ||
+ 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)) {
update_descriptions = TRUE;
}
Index: client/gui-gtk/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/mapview.c,v
retrieving revision 1.121
diff -u -r1.121 mapview.c
--- client/gui-gtk/mapview.c 2002/03/02 23:47:54 1.121
+++ client/gui-gtk/mapview.c 2002/03/15 13:19:38
@@ -1328,7 +1328,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;
@@ -1336,14 +1336,50 @@
get_canvas_xy(x, y, &canvas_x, &canvas_y);
if (draw_city_names) {
- my_snprintf(buffer, sizeof(buffer), "%s", pcity->name);
+ int turns = 0, w2 = 0;
+
+ my_snprintf(buffer, sizeof(buffer),
+ draw_city_growth ? "%s " : "%s", pcity->name);
w = gdk_string_width(main_font, 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(city_productions_font, buffer2);
+ }
+
draw_shadowed_string(map_canvas->window, main_font,
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 +
main_font->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]);
+ }
+
+ draw_shadowed_string(map_canvas->window, city_productions_font,
+ toplevel->style->black_gc,
+ civ_gc,
+ canvas_x + NORMAL_TILE_WIDTH / 2 - (w + w2) / 2 +
w,
+ canvas_y + NORMAL_TILE_HEIGHT + main_font->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.66
diff -u -r1.66 menu.c
--- client/gui-gtk/menu.c 2002/02/17 22:40:42 1.66
+++ client/gui-gtk/menu.c 2002/03/15 13:19:39
@@ -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,
@@ -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.95
diff -u -r1.95 mapview.c
--- client/gui-xaw/mapview.c 2002/02/26 10:27:41 1.95
+++ client/gui-xaw/mapview.c 2002/03/15 13:19:40
@@ -784,12 +784,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/03/15 13:19:40
@@ -128,6 +128,7 @@
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 +277,7 @@
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 +504,10 @@
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/03/15 13:19:40
@@ -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] |
- [Freeciv-Dev] Re: [patch] "turns-to-grow" on the map overview (PR#1328),
jdorje <=
|
|