[Freeciv-Dev] (PR#12501) accessors for the unit upkeep/unhappy overlays
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12501 >
The unit overlays to show unhappiness and upkeep are drawn in
mapview_common. This is probably okay (these overlays are a special
case for the supported-units canvases, and aren't easy to draw from
within fill_sprite_array) but they should use accessors so they don't
have to access the named_sprite array directly.
-jason
? data/misc/citybar.png
? data/misc/citybar.spec
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.213
diff -u -r1.213 mapview_common.c
--- client/mapview_common.c 13 Mar 2005 17:53:44 -0000 1.213
+++ client/mapview_common.c 13 Mar 2005 18:27:00 -0000
@@ -968,20 +968,17 @@
struct canvas *pcanvas,
int canvas_x, int canvas_y)
{
- int unhappy = CLIP(0, punit->unhappiness, 2);
+ struct Sprite *sprite;
- /* draw overlay pixmaps */
- if (unhappy > 0) {
- canvas_put_sprite_full(pcanvas, canvas_x, canvas_y,
- sprites.upkeep.unhappy[unhappy - 1]);
+ sprite = get_unit_unhappy_sprite(tileset, punit);
+ if (sprite) {
+ canvas_put_sprite_full(pcanvas, canvas_x, canvas_y, sprite);
}
output_type_iterate(o) {
- int upkeep = CLIP(0, punit->upkeep[o], 2);
-
- if (upkeep > 0 && sprites.upkeep.output[o][upkeep - 1]) {
- canvas_put_sprite_full(pcanvas, canvas_x, canvas_y,
- sprites.upkeep.output[o][upkeep - 1]);
+ sprite = get_unit_upkeep_sprite(tileset, o, punit);
+ if (sprite) {
+ canvas_put_sprite_full(pcanvas, canvas_x, canvas_y, sprite);
}
} output_type_iterate_end;
}
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.266
diff -u -r1.266 tilespec.c
--- client/tilespec.c 13 Mar 2005 17:53:44 -0000 1.266
+++ client/tilespec.c 13 Mar 2005 18:27:01 -0000
@@ -3950,6 +3950,43 @@
return sprites.indicator[indicator][index];
}
+/****************************************************************************
+ Return a sprite for the unhappiness of the unit - to be shown as an
+ overlay on the unit in the city support dialog, for instance.
+
+ May return NULL if there's no unhappiness.
+****************************************************************************/
+struct Sprite *get_unit_unhappy_sprite(struct tileset *t,
+ const struct unit *punit)
+{
+ const int unhappy = CLIP(0, punit->unhappiness, 2);
+
+ if (unhappy > 0) {
+ return sprites.upkeep.unhappy[unhappy - 1];
+ } else {
+ return NULL;
+ }
+}
+
+/****************************************************************************
+ Return a sprite for the upkeep of the unit - to be shown as an overlay
+ on the unit in the city support dialog, for instance.
+
+ May return NULL if there's no unhappiness.
+****************************************************************************/
+struct Sprite *get_unit_upkeep_sprite(struct tileset *t,
+ Output_type_id otype,
+ const struct unit *punit)
+{
+ const int upkeep = CLIP(0, punit->upkeep[otype], 2);
+
+ if (upkeep > 0) {
+ return sprites.upkeep.output[otype][upkeep - 1];
+ } else {
+ return NULL;
+ }
+}
+
/**************************************************************************
Loads the sprite. If the sprite is already loaded a reference
counter is increased. Can return NULL if the sprite couldn't be
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.127
diff -u -r1.127 tilespec.h
--- client/tilespec.h 11 Mar 2005 17:11:26 -0000 1.127
+++ client/tilespec.h 13 Mar 2005 18:27:02 -0000
@@ -368,6 +368,11 @@
struct Sprite *get_attention_crosshair_sprite(void);
struct Sprite *get_indicator_sprite(enum indicator_type indicator,
int index);
+struct Sprite *get_unit_unhappy_sprite(struct tileset *t,
+ const struct unit *punit);
+struct Sprite *get_unit_upkeep_sprite(struct tileset *t,
+ Output_type_id otype,
+ const struct unit *punit);
/* These variables contain the size of the tiles used within the game.
*
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12501) accessors for the unit upkeep/unhappy overlays,
Jason Short <=
|
|