<URL: http://bugs.freeciv.org/Ticket/Display.html?id=34421 >
gui-xaw and gui-win32 use different unit background colours depending
on their type in helpdialog. This is based to unit move_type and to
nothing else. This means helicopters and amphibious units get the same
colour. And once we merge AIR_MOVING to HELI_MOVING, also air units
will get the same colour.
This patch adds client common function unit_color_type() that checks
also other unit properties to determine which kind of background
colour should be given to it.
- ML
diff -Nurd -X.diff_ignore freeciv/client/climisc.c freeciv/client/climisc.c
--- freeciv/client/climisc.c 2006-07-17 23:56:54.000000000 +0300
+++ freeciv/client/climisc.c 2007-01-24 10:02:32.000000000 +0200
@@ -1097,3 +1097,36 @@
return FALSE;
}
+
+/****************************************************************************
+ Determines which color type should be used for unit background.
+ This is only guesswork based on unit properties. One should not
+ take UNIT_BG_FLYING seriously meaning that unit can fly - custom
+ ruleset might have units with similar properties but explains these
+ properties by some other means than by flying.
+****************************************************************************/
+enum unit_bg_color_type unit_color_type(const struct unit_type *punittype)
+{
+ struct unit_class *pclass = get_unit_class(punittype);
+
+ if (pclass->hp_loss_pct > 0) {
+ return UNIT_BG_HP_LOSS;
+ }
+
+ if (pclass->move_type == LAND_MOVING) {
+ return UNIT_BG_LAND;
+ }
+ if (pclass->move_type == SEA_MOVING) {
+ return UNIT_BG_SEA;
+ }
+
+ assert(pclass->move_type == HELI_MOVING
+ || pclass->move_type == AIR_MOVING);
+
+ if (unit_class_flag(pclass, UCF_TERRAIN_SPEED)) {
+ /* Unit moves on both sea and land by speed determined by terrain */
+ return UNIT_BG_AMPHIBIOUS;
+ }
+
+ return UNIT_BG_FLYING;
+}
diff -Nurd -X.diff_ignore freeciv/client/climisc.h freeciv/client/climisc.h
--- freeciv/client/climisc.h 2006-07-17 23:56:54.000000000 +0300
+++ freeciv/client/climisc.h 2007-01-24 10:02:09.000000000 +0200
@@ -118,4 +118,12 @@
bool can_units_do_connect(struct unit_list *punits,
enum unit_activity activity);
+enum unit_bg_color_type { UNIT_BG_HP_LOSS,
+ UNIT_BG_LAND,
+ UNIT_BG_SEA,
+ UNIT_BG_AMPHIBIOUS,
+ UNIT_BG_FLYING };
+
+enum unit_bg_color_type unit_color_type(const struct unit_type *punittype);
+
#endif /* FC__CLIMISC_H */
diff -Nurd -X.diff_ignore freeciv/client/gui-win32/helpdlg.c freeciv/client/gui-win32/helpdlg.c
--- freeciv/client/gui-win32/helpdlg.c 2007-01-19 04:18:26.000000000 +0200
+++ freeciv/client/gui-win32/helpdlg.c 2007-01-24 10:07:54.000000000 +0200
@@ -655,12 +655,23 @@
/* Give tile a background color, based on the type of unit
* FIXME: make a new set of colors for this. */
- switch (get_unit_move_type(utype)) {
- case LAND_MOVING: bg_color = COLOR_OVERVIEW_LAND; break;
- case SEA_MOVING: bg_color = COLOR_OVERVIEW_OCEAN; break;
- case HELI_MOVING: bg_color = COLOR_OVERVIEW_MY_UNIT; break;
- case AIR_MOVING: bg_color = COLOR_OVERVIEW_ENEMY_CITY; break;
- default: bg_color = COLOR_OVERVIEW_UNKNOWN; break;
+ switch (unit_color_type(utype)) {
+ case UNIT_BG_LAND:
+ bg_color = COLOR_OVERVIEW_LAND;
+ break;
+ case UNIT_BG_SEA:
+ bg_color = COLOR_OVERVIEW_OCEAN;
+ break;
+ case UNIT_BG_HP_LOSS:
+ case UNIT_BG_AMPHIBIOUS:
+ bg_color = COLOR_OVERVIEW_MY_UNIT;
+ break;
+ case UNIT_BG_FLYING:
+ bg_color = COLOR_OVERVIEW_ENEMY_CITY;
+ break;
+ default:
+ bg_color = COLOR_OVERVIEW_UNKNOWN;
+ break;
}
brush = brush_alloc(get_color(tileset, bg_color));
diff -Nurd -X.diff_ignore freeciv/client/gui-xaw/graphics.c freeciv/client/gui-xaw/graphics.c
--- freeciv/client/gui-xaw/graphics.c 2006-08-18 10:52:04.000000000 +0300
+++ freeciv/client/gui-xaw/graphics.c 2007-01-24 10:11:00.000000000 +0200
@@ -579,12 +579,23 @@
/* Give tile a background color, based on the type of unit */
/* Should there be colors like COLOR_MAPVIEW_LAND etc? -ev */
- switch (get_unit_move_type(punittype)) {
- case LAND_MOVING: bg_color = COLOR_OVERVIEW_LAND; break;
- case SEA_MOVING: bg_color = COLOR_OVERVIEW_OCEAN; break;
- case HELI_MOVING: bg_color = COLOR_OVERVIEW_MY_UNIT; break;
- case AIR_MOVING: bg_color = COLOR_OVERVIEW_ENEMY_CITY; break;
- default: bg_color = COLOR_OVERVIEW_UNKNOWN; break;
+ switch (unit_color_type(punittype)) {
+ case UNIT_BG_LAND:
+ bg_color = COLOR_OVERVIEW_LAND;
+ break;
+ case UNIT_BG_SEA:
+ bg_color = COLOR_OVERVIEW_OCEAN;
+ break;
+ case UNIT_BG_HP_LOSS:
+ case UNIT_BG_AMPHIBIOUS:
+ bg_color = COLOR_OVERVIEW_MY_UNIT;
+ break;
+ case UNIT_BG_FLYING:
+ bg_color = COLOR_OVERVIEW_ENEMY_CITY;
+ break;
+ default:
+ bg_color = COLOR_OVERVIEW_UNKNOWN;
+ break;
}
XSetForeground(display, fill_bg_gc,
get_color(tileset, bg_color)->color.pixel);
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev