Complete.Org: Mailing Lists: Archives: freeciv-dev: November 2002:
[Freeciv-Dev] (PR#2369) iso-view eye candy
Home

[Freeciv-Dev] (PR#2369) iso-view eye candy

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: undisclosed-recipients:;
Subject: [Freeciv-Dev] (PR#2369) iso-view eye candy
From: "Jason Short via RT" <rt@xxxxxxxxxxxxxx>
Date: Wed, 20 Nov 2002 09:16:33 -0800
Reply-to: rt@xxxxxxxxxxxxxx

This patch provides a rework of the Eye Candy system:

- Eye candy is supported for all terrain types.  Of course it might not 
make much sense for some.

- Eye candy types are linked after we receive ruleset data.  This will 
allow things to work under alternate rulesets (untested).

- The number of eye candy sprites is not limited to two per terrain type.

- Only one eye candy can be shown per terrain type (of course, you could 
just make another graphic with the combination).

- A view option is provided controlling whether eye candy is drawn. 
(There's no MUI support, and win32 support is untested.)

- I've converted eyecandy.xpm to a PNG.

- eyecandy.spec gets some updates because of the ruleset issue.  Is 
there a better way to do this?

I think this is an elegant way to give tileset authors a _lot_ of 
control over what is displayed.  Now the tilesets need to catch up.

jason

Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.86
diff -u -r1.86 control.c
--- client/control.c    2002/11/14 09:14:50     1.86
+++ client/control.c    2002/11/20 17:09:42
@@ -1106,6 +1106,18 @@
 }
 
 /**************************************************************************
+ Toggle display eyecandy
+**************************************************************************/
+void request_toggle_eyecandy(void)
+{
+  if (get_client_state() != CLIENT_GAME_RUNNING_STATE)
+    return;
+
+  draw_eyecandy = !draw_eyecandy;
+  update_map_canvas_visible();
+}
+
+/**************************************************************************
 ...
 **************************************************************************/
 void request_center_focus_unit(void)
@@ -1848,4 +1860,12 @@
 void key_fog_of_war_toggle(void)
 {
   request_toggle_fog_of_war();
+}
+
+/**************************************************************************
+  A key was pressed to toggle eyecandy.
+**************************************************************************/
+void key_eyecandy_toggle(void)
+{
+  request_toggle_eyecandy();
 }
Index: client/control.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.h,v
retrieving revision 1.29
diff -u -r1.29 control.h
--- client/control.h    2002/11/01 17:51:12     1.29
+++ client/control.h    2002/11/20 17:09:42
@@ -79,6 +79,7 @@
 void request_toggle_units(void);
 void request_toggle_focus_unit(void);
 void request_toggle_fog_of_war(void);
+void request_toggle_eyecandy(void);
 
 void wakeup_sentried_units(int x, int y);
 
@@ -112,6 +113,7 @@
 void key_units_toggle(void);
 void key_focus_unit_toggle(void);
 void key_fog_of_war_toggle(void);
+void key_eyecandy_toggle(void);
 void key_end_turn(void);
 void key_map_grid_toggle(void);
 void key_move_north(void);
Index: client/options.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.c,v
retrieving revision 1.72
diff -u -r1.72 options.c
--- client/options.c    2002/11/19 23:04:27     1.72
+++ client/options.c    2002/11/20 17:09:43
@@ -140,6 +140,7 @@
 bool draw_units = TRUE;
 bool draw_focus_unit = FALSE;
 bool draw_fog_of_war = TRUE;
+bool draw_eyecandy = TRUE;
 
 #define VIEW_OPTION(name) { #name, &name }
 #define VIEW_OPTION_TERMINATOR { NULL, NULL }
@@ -160,6 +161,7 @@
   VIEW_OPTION(draw_units),
   VIEW_OPTION(draw_focus_unit),
   VIEW_OPTION(draw_fog_of_war),
+  VIEW_OPTION(draw_eyecandy),
   VIEW_OPTION_TERMINATOR
 };
 
Index: client/options.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/options.h,v
retrieving revision 1.24
diff -u -r1.24 options.h
--- client/options.h    2002/11/14 09:22:09     1.24
+++ client/options.h    2002/11/20 17:09:43
@@ -88,6 +88,7 @@
 extern bool draw_units;
 extern bool draw_focus_unit;
 extern bool draw_fog_of_war;
+extern bool draw_eyecandy;
 
 typedef struct {
   const char *name;
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.90
diff -u -r1.90 tilespec.c
--- client/tilespec.c   2002/11/19 23:04:27     1.90
+++ client/tilespec.c   2002/11/20 17:09:44
@@ -902,6 +902,25 @@
     } else {
       tt->sprite[0] = NULL;
     }
+
+    /* Load eyecandy sprites.  These are drawn over the terrain to give
+     * visual variety.  Any number of them may exist. */
+    for (i = 0; ; i++) {
+      snprintf(buffer1, sizeof(buffer1), "ec.%s%d",
+              tt->terrain_name, i + 1);
+      if (!hash_lookup_data(sprite_hash, buffer1)) {
+       break;
+      }
+    }
+    tt->ec.count = i;
+    if (tt->ec.count > 0) {
+      tt->ec.sprites = fc_malloc(tt->ec.count * sizeof(*tt->ec.sprites));
+    }
+    for (i = 0; i < tt->ec.count; i++) {
+      snprintf(buffer1, sizeof(buffer1), "ec.%s%d",
+              tt->terrain_name, i + 1);
+      tt->ec.sprites[i] = hash_lookup_data(sprite_hash, buffer1);
+    }
   } else {
     for(i=0; i<NUM_DIRECTION_NSEW; i++) {
       nsew = nsew_str(i);
@@ -1240,6 +1259,7 @@
   int tileno, dir, i;
   struct city *pcity;
   struct Sprite **save_sprs = sprs;
+  struct tile_type *tt;
 
   *solid_bg = 0;
 
@@ -1249,6 +1269,7 @@
   pcity = map_get_city(x, y);
   tspecial = map_get_special(x, y);
   ttype = map_get_terrain(x, y);
+  tt = get_tile_type(ttype);
 
   /* A little hack to avoid drawing seperate T_RIVER isometric tiles. */
   if (ttype == T_RIVER) {
@@ -1284,7 +1305,7 @@
          *sprs++ = sprites.tx.river_outlet[dir];
       }
     } else {
-      *sprs++ = get_tile_type(ttype)->sprite[0];
+      *sprs++ = tt->sprite[0];
 
       switch (ttype) {
         case T_HILLS:
@@ -1334,6 +1355,18 @@
        *sprs++ = sprites.tx.spec_river[tileno];
       }
     }
+
+    if (draw_eyecandy && !tspecial && tt->ec.count > 0) {
+      /* The formula to determine placement of eye candy is pretty
+       * random -- we don't want any visible pattern, but we do want it
+       * to be deterministic.  Where the eyecandy goes doesn't matter, but
+       * it shouldn't shift around with each redraw. */
+      assert(tt->ec.count + 1 <= 193);
+      i = ((map_inx(x, y) * 53) % 193) % (tt->ec.count + 1);
+      if (i < tt->ec.count) {
+       *sprs++ = tt->ec.sprites[i];
+      }
+    }
   } else {
     *solid_bg = 1;
 
@@ -2031,4 +2064,12 @@
 
   hash_free(sprite_hash);
   sprite_hash = NULL;
+
+  for (i = 0; i < T_COUNT; i++) {
+    struct tile_type *tt = get_tile_type(i);
+    if (tt->ec.count > 0) {
+      free(tt->ec.sprites);
+      tt->ec.count = 0;
+    }
+  }
 }
Index: client/gui-gtk/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk/menu.c,v
retrieving revision 1.70
diff -u -r1.70 menu.c
--- client/gui-gtk/menu.c       2002/11/14 09:14:54     1.70
+++ client/gui-gtk/menu.c       2002/11/20 17:09:45
@@ -93,6 +93,7 @@
   MENU_VIEW_SHOW_UNITS,
   MENU_VIEW_SHOW_FOCUS_UNIT,
   MENU_VIEW_SHOW_FOG_OF_WAR,
+  MENU_VIEW_SHOW_EYECANDY,
   MENU_VIEW_CENTER_VIEW,
 
   MENU_ORDER_BUILD_CITY,     /* shared with BUILD_WONDER */
@@ -286,6 +287,10 @@
     if (draw_fog_of_war ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_fog_of_war_toggle();
     break;
+  case MENU_VIEW_SHOW_EYECANDY:
+    if (draw_eyecandy ^ GTK_CHECK_MENU_ITEM(widget)->active)
+      key_eyecandy_toggle();
+    break;
   case MENU_VIEW_CENTER_VIEW:
     center_on_unit();
     break;
@@ -633,6 +638,12 @@
        view_menu_callback,     MENU_VIEW_SHOW_FOG_OF_WAR,              
"<CheckItem>"   },
   { "/" N_("View") "/sep2",                            NULL,
        NULL,                   0,                                      
"<Separator>"   },
+  { "/" N_("View") "/" N_("Eye candy"),        NULL,
+       view_menu_callback,     MENU_VIEW_SHOW_EYECANDY,
+       "<CheckItem>" },
+  { "/" N_("View") "/sep3",                            NULL,
+       NULL,                   0,
+       "<Separator>"   },
   { "/" N_("View") "/" N_("_Center View"),             "c",
        view_menu_callback,     MENU_VIEW_CENTER_VIEW                           
        },
   /* Orders menu ... */
@@ -997,6 +1008,8 @@
     menus_set_active("<main>/_View/Focus Unit", draw_focus_unit);
     menus_set_sensitive("<main>/_View/Focus Unit", !draw_units);
     menus_set_active("<main>/_View/Fog of War", draw_fog_of_war);
+    menus_set_active("<main>/_View/Eye candy",
+                    draw_eyecandy);
 
     /* Remaining part of this function: Update Orders menu */
 
Index: client/gui-gtk-2.0/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/menu.c,v
retrieving revision 1.8
diff -u -r1.8 menu.c
--- client/gui-gtk-2.0/menu.c   2002/11/14 09:14:55     1.8
+++ client/gui-gtk-2.0/menu.c   2002/11/20 17:09:45
@@ -94,6 +94,7 @@
   MENU_VIEW_SHOW_UNITS,
   MENU_VIEW_SHOW_FOCUS_UNIT,
   MENU_VIEW_SHOW_FOG_OF_WAR,
+  MENU_VIEW_SHOW_EYECANDY,
   MENU_VIEW_CENTER_VIEW,
 
   MENU_ORDER_BUILD_CITY,     /* shared with BUILD_WONDER */
@@ -287,6 +288,10 @@
     if (draw_fog_of_war ^ GTK_CHECK_MENU_ITEM(widget)->active)
       key_fog_of_war_toggle();
     break;
+  case MENU_VIEW_SHOW_EYECANDY:
+    if (draw_eyecandy ^ GTK_CHECK_MENU_ITEM(widget)->active)
+      key_eyecandy_toggle();
+    break;
   case MENU_VIEW_CENTER_VIEW:
     center_on_unit();
     break;
@@ -634,6 +639,12 @@
        view_menu_callback,     MENU_VIEW_SHOW_FOG_OF_WAR,              
"<CheckItem>"   },
   { "/" N_("View") "/sep2",                            NULL,
        NULL,                   0,                                      
"<Separator>"   },
+  { "/" N_("View") "/" N_("Eye candy"),        NULL,
+       view_menu_callback,     MENU_VIEW_SHOW_EYECANDY,
+       "<CheckItem>" },
+  { "/" N_("View") "/sep3",                            NULL,
+       NULL,                   0,
+       "<Separator>"   },
   { "/" N_("View") "/" N_("_Center View"),             "c",
        view_menu_callback,     MENU_VIEW_CENTER_VIEW                           
        },
   /* Orders menu ... */
@@ -992,6 +1003,8 @@
     menus_set_active("<main>/_View/Focus Unit", draw_focus_unit);
     menus_set_sensitive("<main>/_View/Focus Unit", !draw_units);
     menus_set_active("<main>/_View/Fog of War", draw_fog_of_war);
+    menus_set_active("<main>/_View/Eye candy",
+                    draw_eyecandy);
 
     /* Remaining part of this function: Update Orders menu */
 
Index: client/gui-win32/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-win32/menu.c,v
retrieving revision 1.12
diff -u -r1.12 menu.c
--- client/gui-win32/menu.c     2002/11/14 09:14:59     1.12
+++ client/gui-win32/menu.c     2002/11/20 17:09:46
@@ -95,6 +95,7 @@
   IDM_VIEW_UNITS,
   IDM_VIEW_FOCUS_UNIT,
   IDM_VIEW_FOG_OF_WAR,
+  IDM_VIEW_EYECANDY,
 
   IDM_ORDERS_MENU,
   IDM_ORDERS_BUILDCITY,
@@ -315,6 +316,8 @@
   {N_("Focus Unit"),IDM_VIEW_FOCUS_UNIT},
   {N_("Fog of War"),IDM_VIEW_FOG_OF_WAR},
   {"",IDM_SEPARATOR},
+  {NULL, 0},
+  {N_("Eye Candy"), IDM_VIEW_EYECANDY},
   {N_("Center View") "\tC",IDM_VIEW_CENTER},
   {NULL,0},
   {N_("_Orders"),IDM_SUBMENU},
@@ -634,6 +637,11 @@
       CheckMenuItem(menu,IDM_VIEW_FOG_OF_WAR,MF_BYCOMMAND |
                    (draw_fog_of_war?MF_CHECKED:MF_UNCHECKED));
       break;
+    case IDM_VIEW_EYECANDY:
+      key_eyecandy_toggle();
+      CheckMenuItem(menu, IDM_VIEW_EYECANDY, MF_BYCOMMAND
+                   | (draw_eyecandy ? MF_CHECKED : MF_UNCHECKED));
+      break;
     case IDM_VIEW_CENTER:
       center_on_unit();
       break;
@@ -1039,6 +1047,7 @@
                    (draw_focus_unit?MF_CHECKED:MF_UNCHECKED));
       CheckMenuItem(menu,IDM_VIEW_FOG_OF_WAR,MF_BYCOMMAND |
                    (draw_fog_of_war?MF_CHECKED:MF_UNCHECKED));
-      
+      CheckMenuItem(menu, IDM_VIEW_EYECANDY, MF_BYCOMMAND |
+                   (draw_eyecandy ? MF_CHECKED : MF_UNCHECKED));
     }
 }
Index: client/gui-xaw/menu.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-xaw/menu.c,v
retrieving revision 1.50
diff -u -r1.50 menu.c
--- client/gui-xaw/menu.c       2002/11/14 09:15:01     1.50
+++ client/gui-xaw/menu.c       2002/11/20 17:09:46
@@ -144,6 +144,9 @@
     { { N_("Focus Unit"), 0           },      "", MENU_VIEW_SHOW_FOCUS_UNIT, 0 
},
     { { N_("Fog of War"), 0           },      "", MENU_VIEW_SHOW_FOG_OF_WAR, 0 
},
     { { 0                             },      "", MENU_SEPARATOR_LINE, 0 },
+    { { N_("Eye candy"), 0  },      "",
+      MENU_VIEW_SHOW_EYECANDY, 0},
+    { { 0                             },      "", MENU_SEPARATOR_LINE, 0 },
     { { N_("Center View"), 0          },     "c", MENU_VIEW_CENTER_VIEW, 0 },
     { { 0,                            },       0, MENU_END_OF_LIST, 0 }
 };
@@ -289,6 +292,7 @@
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_UNITS, 1);
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_FOCUS_UNIT, !draw_units);
     menu_entry_sensitive(MENU_VIEW, MENU_VIEW_SHOW_FOG_OF_WAR, 1);
+    menu_entry_sensitive(MENU_VIEW, MENU_VIEW_EYECANDY, 1);
 
     menu_entry_sensitive(MENU_GAME, MENU_GAME_OPTIONS, 1);
     menu_entry_sensitive(MENU_GAME, MENU_GAME_MSG_OPTIONS, 1);
@@ -544,6 +548,9 @@
     break;
   case MENU_VIEW_SHOW_FOG_OF_WAR:
     key_fog_of_war_toggle();
+    break;
+  case MENU_VIEW_EYECANDY:
+    key_eyecandy_toggle();
     break;
   case MENU_VIEW_CENTER_VIEW:
     request_center_focus_unit();
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/11/20 17:09:46
@@ -63,6 +63,7 @@
   MENU_VIEW_SHOW_UNITS,
   MENU_VIEW_SHOW_FOCUS_UNIT,
   MENU_VIEW_SHOW_FOG_OF_WAR,
+  MENU_VIEW_SHOW_EYECANDY,
   MENU_VIEW_CENTER_VIEW,
 
   MENU_ORDER_BUILD_CITY,
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.132
diff -u -r1.132 map.h
--- common/map.h        2002/11/03 23:22:44     1.132
+++ common/map.h        2002/11/20 17:09:47
@@ -137,6 +137,12 @@
     struct Sprite *sprite;
   } special[2];
 
+  /* Eye candy sprites for this terrain. */
+  struct {
+    int count;
+    struct Sprite **sprites;
+  } ec;
+
   int road_trade_incr;
   int road_time;
 
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.3
diff -u -r1.3 isotrident.tilespec
--- data/isotrident.tilespec    2002/11/18 19:51:41     1.3
+++ data/isotrident.tilespec    2002/11/20 17:09:47
@@ -46,5 +46,6 @@
   "misc/space.spec",
   "misc/treaty.spec",
   "isotrident/nuke.spec",
+  "isotrident/eyecandy.spec",
   "isotrident/cities.spec",
   "isotrident/morecities.spec"

PNG image

[spec]

; Format and options of this spec file:
options = "+spec2"

[info]

artists = "
    Daniel Speyer <dspeyer@xxxxxxxxxxxx>
"

[file]
gfx = "isotrident/eyecandy"

[grid_main]

x_top_left = 1
y_top_left = 1
dx = 64
dy = 32
is_pixel_border = 1

tiles = { "row", "column","tag"

  0, 1, "ec.Desert1"
  0, 2, "ec.Desert2"

  1, 1, "ec.Plains1"
  1, 2, "ec.Plains2"

  2, 1, "ec.Grass1"
  2, 2, "ec.Grass2"

  6, 1, "ec.Tundra1"
  6, 2, "ec.Tundra2"

  8, 1, "ec.Swamp1" 
  8, 2, "ec.Swamp2"

  9, 1, "ec.Jungle1"
  9, 2, "ec.Jungle2"
}

[Prev in Thread] Current Thread [Next in Thread]