Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12384) use sprites for the citymap overlays
Home

[Freeciv-Dev] (PR#12384) use sprites for the citymap overlays

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12384) use sprites for the citymap overlays
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 28 Feb 2005 15:28:48 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch uses tileset sprites for the citymap overlays (the 't' 
behavior).  These sprites use alpha so the end result is much prettier 
(see the screenshot attached to the image).

Only one new file is needed: data/misc/overlays.  This contains the 
overlay colors (currently there are four of them, just like in the 
current code) as well as the worked and unworked-tile masks (at 50% and 
25% alpha, just like the current code).  The number of colors isn't 
limited so they may be added as the tileset authors like.

In loading the graphics, crop_sprite is used extensively.  First the 
color sprite is cropped using the overlay sprite to get the right alpha 
level.  Then the resulting sprite is cropped using the tile mask.  The 
tile mask thus becomes manditory (I've added it to trident).

My goal here is to give total control of the appearance to the tileset 
authors.  They should control colors as well as alpha levels.  However 
this behavior isn't used very much and it kindof replaced by the city 
outlines.  So another option is removing it (but having already done the 
work for it I see no need for that).

-jason

? data/misc/overlays.png
? data/misc/overlays.spec
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.199
diff -u -r1.199 mapview_common.c
--- client/mapview_common.c     28 Feb 2005 04:01:52 -0000      1.199
+++ client/mapview_common.c     28 Feb 2005 23:22:24 -0000
@@ -1106,14 +1106,8 @@
  *
  * This array can be added to without breaking anything elsewhere.
  */
-static enum color_std city_colors[] = {
-  COLOR_STD_RED,
-  COLOR_STD_YELLOW,
-  COLOR_STD_CYAN,
-  COLOR_STD_WHITE
-};
 static int color_index = 0;
-#define NUM_CITY_COLORS ARRAY_SIZE(city_colors)
+#define NUM_CITY_COLORS (sprites.city.worked_tile_overlay.size)
 
 
 /****************************************************************************
@@ -1712,19 +1706,31 @@
          && pcity->client.colored
          && map_to_city_map(&city_x, &city_y, pcity, ptile)) {
        enum city_tile_type worker = get_worker_city(pcity, city_x, city_y);
+       int index = pcity->client.color_index % NUM_CITY_COLORS;
 
-       put_city_worker(mapview.store,
-                       city_colors[pcity->client.color_index], worker,
-                       canvas_x2, canvas_y2);
-       if (worker == C_TILE_WORKER) {
+       switch (worker) {
+       case C_TILE_EMPTY:
+         canvas_put_sprite_full(mapview.store,
+                                canvas_x2, canvas_y2,
+                                sprites.city.unworked_tile_overlay.p[index]);
+         break;
+       case C_TILE_WORKER:
+         canvas_put_sprite_full(mapview.store,
+                                canvas_x2, canvas_y2,
+                                sprites.city.worked_tile_overlay.p[index]);
          put_city_tile_output(pcity, city_x, city_y,
                               mapview.store, canvas_x2, canvas_y2);
+         break;
+       case C_TILE_UNAVAILABLE:
+         break;
        }
       } else if (punit && punit->client.colored) {
+       int index = punit->client.color_index % NUM_CITY_COLORS;
+
        /* Draw citymap overlay for settlers. */
-       put_city_worker(mapview.store,
-                       city_colors[punit->client.color_index], C_TILE_EMPTY,
-                       canvas_x2, canvas_y2);
+       canvas_put_sprite_full(mapview.store,
+                              canvas_x2, canvas_y2,
+                              sprites.city.unworked_tile_overlay.p[index]);
       }
     }
   } gui_rect_iterate_end;
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.248
diff -u -r1.248 tilespec.c
--- client/tilespec.c   28 Feb 2005 20:24:38 -0000      1.248
+++ client/tilespec.c   28 Feb 2005 23:22:25 -0000
@@ -1269,6 +1269,7 @@
 {
   char buffer[512];
   const char dir_char[] = "nsew";
+  const int W = NORMAL_TILE_WIDTH, H = NORMAL_TILE_HEIGHT;
   int i;
   
   assert(sprite_hash != NULL);
@@ -1287,10 +1288,13 @@
 
   SET_SPRITE(right_arrow, "s.right_arrow");
   if (is_isometric) {
-    SET_SPRITE(black_tile, "t.black_tile");
     SET_SPRITE(dither_tile, "t.dither_tile");
   }
 
+  SET_SPRITE(black_tile, "t.black_tile");
+  SET_SPRITE(mask.worked_tile, "tx.mask.worked_tile");
+  SET_SPRITE(mask.unworked_tile, "tx.mask.unworked_tile");
+
   SET_SPRITE(tax_luxury, "s.tax_luxury");
   SET_SPRITE(tax_science, "s.tax_science");
   SET_SPRITE(tax_gold, "s.tax_gold");
@@ -1493,12 +1497,48 @@
   SET_SPRITE(tx.airbase,    "tx.airbase");
   SET_SPRITE(tx.fog,        "tx.fog");
 
-  if (load_sprite("grid.main.ns")) {
-    for (i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
-      my_snprintf(buffer, sizeof(buffer), "colors.player%d", i);
-      SET_SPRITE(colors.player[i], buffer);
+  /* Load color sprites. */
+  for (i = 0; i < MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS; i++) {
+    my_snprintf(buffer, sizeof(buffer), "colors.player%d", i);
+    SET_SPRITE(colors.player[i], buffer);
+  }
+  sprite_vector_init(&sprites.colors.overlays);
+  for (i = 0; ; i++) {
+    struct Sprite *sprite;
+
+    my_snprintf(buffer, sizeof(buffer), "tx.colors.overlay_%d", i);
+    sprite = load_sprite(buffer);
+    if (!sprite) {
+      break;
     }
+    sprite_vector_append(&sprites.colors.overlays, &sprite);
+  }
+  if (i == 0) {
+    freelog(LOG_FATAL, "Missing overlay-color sprite tx.colors.overlay_0.");
+    exit(EXIT_FAILURE);
+  }
 
+  /* Chop up and build the overlay graphics. */
+  sprite_vector_reserve(&sprites.city.worked_tile_overlay,
+                       sprite_vector_size(&sprites.colors.overlays));
+  sprite_vector_reserve(&sprites.city.unworked_tile_overlay,
+                       sprite_vector_size(&sprites.colors.overlays));
+  for (i = 0; i < sprite_vector_size(&sprites.colors.overlays); i++) {
+    struct Sprite *color, *color_mask;
+    struct Sprite *worked, *unworked;
+
+    color = *sprite_vector_get(&sprites.colors.overlays, i);
+    color_mask = crop_sprite(color, 0, 0, W, H, sprites.black_tile, 0, 0);
+    worked = crop_sprite(color_mask, 0, 0, W, H,
+                        sprites.mask.worked_tile, 0, 0);
+    unworked = crop_sprite(color_mask, 0, 0, W, H,
+                          sprites.mask.unworked_tile, 0, 0);
+    free_sprite(color_mask);
+    sprites.city.worked_tile_overlay.p[i] =  worked;
+    sprites.city.unworked_tile_overlay.p[i] = unworked;
+  }
+
+  if (load_sprite("grid.main.ns")) {
     SET_SPRITE(grid.unavailable, "grid.unavailable");
 
     for (i = 0; i < EDGE_COUNT; i++) {
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.112
diff -u -r1.112 tilespec.h
--- client/tilespec.h   28 Feb 2005 20:24:38 -0000      1.112
+++ client/tilespec.h   28 Feb 2005 23:22:25 -0000
@@ -224,6 +224,12 @@
     *black_tile,      /* only used for isometric view */
     *dither_tile;     /* only used for isometric view */
 
+  struct {
+    struct Sprite
+      *worked_tile,
+      *unworked_tile;
+  } mask;
+
   struct citizen_graphic {
     /* Each citizen type has up to MAX_NUM_CITIZEN_SPRITES different
      * sprites, as defined by the tileset. */
@@ -299,6 +305,8 @@
       *tile_tradenum[NUM_TILES_DIGITS],
       ***tile_wall,      /* only used for isometric view */
       ***tile;
+    struct sprite_vector worked_tile_overlay;
+    struct sprite_vector unworked_tile_overlay;
   } city;
   struct {
     struct Sprite
@@ -336,6 +344,8 @@
       *player_borders[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS][EDGE_COUNT][2];
   } grid;
   struct {
+    struct sprite_vector overlays;
+
     struct Sprite *player[MAX_NUM_PLAYERS + MAX_NUM_BARBARIANS];
   } colors;
 
Index: data/isophex.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isophex.tilespec,v
retrieving revision 1.8
diff -u -r1.8 isophex.tilespec
--- data/isophex.tilespec       28 Feb 2005 20:24:39 -0000      1.8
+++ data/isophex.tilespec       28 Feb 2005 23:22:25 -0000
@@ -58,6 +58,7 @@
 ; tag is used).
 files = 
   "misc/colors.spec",
+  "misc/overlays.spec",
   "isophex/terrain1.spec",
   "isophex/terrain2.spec",
   "isophex/darkness.spec",
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.31
diff -u -r1.31 isotrident.tilespec
--- data/isotrident.tilespec    25 Feb 2005 17:31:50 -0000      1.31
+++ data/isotrident.tilespec    28 Feb 2005 23:22:25 -0000
@@ -50,6 +50,7 @@
 ; tag is used).
 files = 
   "misc/colors.spec",
+  "misc/overlays.spec",
   "isotrident/terrain1.spec",
   "isotrident/terrain2.spec",
   "isotrident/tiles.spec",
Index: data/trident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident.tilespec,v
retrieving revision 1.31
diff -u -r1.31 trident.tilespec
--- data/trident.tilespec       25 Feb 2005 17:31:50 -0000      1.31
+++ data/trident.tilespec       28 Feb 2005 23:22:25 -0000
@@ -46,6 +46,7 @@
 ; tag is used).
 files = 
   "misc/colors.spec",
+  "misc/overlays.spec",
   "trident/tiles.spec",
   "misc/small.spec",
   "trident/units.spec",
Index: data/trident_shields.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident_shields.tilespec,v
retrieving revision 1.22
diff -u -r1.22 trident_shields.tilespec
--- data/trident_shields.tilespec       25 Feb 2005 17:31:50 -0000      1.22
+++ data/trident_shields.tilespec       28 Feb 2005 23:22:25 -0000
@@ -49,6 +49,7 @@
 ; tag is used).
 files = 
   "misc/colors.spec",
+  "misc/overlays.spec",
   "trident/tiles.spec",
   "misc/small.spec",
   "trident/units.spec",
Index: data/misc/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/misc/Makefile.am,v
retrieving revision 1.9
diff -u -r1.9 Makefile.am
--- data/misc/Makefile.am       25 Feb 2005 17:31:50 -0000      1.9
+++ data/misc/Makefile.am       28 Feb 2005 23:22:25 -0000
@@ -12,6 +12,8 @@
        colors.spec     \
        flags.spec      \
        intro.png       \
+       overlays.png    \
+       overlays.spec   \
        radar.png       \
        shields.spec    \
        small.png       \
Index: data/trident/tiles.png
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident/tiles.png,v
retrieving revision 1.8
diff -u -r1.8 tiles.png
Binary files /tmp/cvsMzLxA6 and tiles.png differ
Index: data/trident/tiles.spec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident/tiles.spec,v
retrieving revision 1.23
diff -u -r1.23 tiles.spec
--- data/trident/tiles.spec     20 Nov 2004 17:45:52 -0000      1.23
+++ data/trident/tiles.spec     28 Feb 2005 23:22:26 -0000
@@ -361,6 +361,7 @@
  12, 14, "tx.village"
  12, 15, "tx.fortress"
  13, 16, "tx.airbase"
+ 13, 0,  "t.black_tile"
  13, 17, "tx.fog"
  13, 18, "tx.fallout"
 

Attachment: overlays.tar.gz
Description: GNU Zip compressed data


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12384) use sprites for the citymap overlays, Jason Short <=