Complete.Org: Mailing Lists: Archives: freeciv-dev: February 2005:
[Freeciv-Dev] (PR#12215) use a spinning circle for the focus unit
Home

[Freeciv-Dev] (PR#12215) use a spinning circle for the focus unit

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: [Freeciv-Dev] (PR#12215) use a spinning circle for the focus unit
From: "Jason Short" <jdorje@xxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 12 Feb 2005 13:08:49 -0800
Reply-to: bugs@xxxxxxxxxxx

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

Here's an updated patch.

- I updated it for the changed real_time_callback code.  I added a 50-ms
minimum on callbacks to prevent animation from flooding the CPU.

- I removed the extra layer.  The selection circle is just put on the
bottom of the unit layer.  Note this means it gets drawn on top of
cities.  This could be changed, I suppose.

- I removed the selection from trident but added it to trident_shields.
 Isophex may use it but it'll take some more work to create a
proper-sized circle.

I think it should now be completely working.

-jason

? data/isotrident/select.png
? data/trident/select.png
Index: client/civclient.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.c,v
retrieving revision 1.213
diff -u -r1.213 civclient.c
--- client/civclient.c  12 Feb 2005 18:47:18 -0000      1.213
+++ client/civclient.c  12 Feb 2005 21:04:45 -0000
@@ -706,7 +706,9 @@
                               seconds - floor(seconds) + 0.001);
   }
 
-  return MAX(time_until_next_call, 0.0);
+  /* Make sure we wait at least 50 ms, otherwise we may not give any other
+   * code time to run. */
+  return MAX(time_until_next_call, 0.05);
 }
 
 /**************************************************************************
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.156
diff -u -r1.156 control.c
--- client/control.c    12 Feb 2005 18:47:18 -0000      1.156
+++ client/control.c    12 Feb 2005 21:04:45 -0000
@@ -400,25 +400,21 @@
 **************************************************************************/
 double blink_active_unit(void)
 {
-  static bool is_shown;
   static struct unit *pblinking_unit;
   static struct timer *blink_timer = NULL;
-  const double blink_time = 0.5;
 
+  const double blink_time = get_focus_unit_toggle_timeout();
   struct unit *punit = punit_focus;
   bool need_update = FALSE;
 
   if (punit) {
     if (punit != pblinking_unit) {
-      
-      /* When the focus unit changes, we reset the is_shown flag. */
       pblinking_unit = punit;
-      is_shown = TRUE;
+      reset_focus_unit_state();
       need_update = TRUE;
     } else {
       if (read_timer_seconds(blink_timer) > blink_time) {
-       /* Reverse the shown status. */
-       is_shown = !is_shown;
+       toggle_focus_unit_state();
        need_update = TRUE;
       }
     }
@@ -426,7 +422,6 @@
       /* If we lag, we don't try to catch up.  Instead we just start a
        * new blink_time on every update. */
       blink_timer = renew_timer_start(blink_timer, TIMER_USER, TIMER_ACTIVE);
-      set_focus_unit_hidden_state(!is_shown);
       refresh_unit_mapcanvas(punit, punit->tile, TRUE);
     }
 
Index: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.235
diff -u -r1.235 tilespec.c
--- client/tilespec.c   11 Feb 2005 16:57:59 -0000      1.235
+++ client/tilespec.c   12 Feb 2005 21:04:47 -0000
@@ -195,11 +195,7 @@
  */
 
 
-/*
-  If focus_unit_hidden is true, then no units at
-  the location of the foc unit are ever drawn.
-*/
-static bool focus_unit_hidden = FALSE;
+int focus_unit_state = 0;
 
 static struct Sprite* lookup_sprite_tag_alt(const char *tag, const char *alt,
                                            bool required, const char *what,
@@ -1417,6 +1413,14 @@
     sprites.unit.vet_lev[i] = load_sprite(buffer);
   }
 
+  sprites.unit.select[0] = NULL;
+  if (load_sprite("unit.select0")) {
+    for (i = 0; i < NUM_TILES_SELECT; i++) {
+      my_snprintf(buffer, sizeof(buffer), "unit.select%d", i);
+      SET_SPRITE(unit.select[i], buffer);
+    }
+  }
+
   SET_SPRITE(city.disorder, "city.disorder");
 
   for(i=0; i<NUM_TILES_DIGITS; i++) {
@@ -2932,6 +2936,12 @@
       bool stacked = ptile && (unit_list_size(ptile->units) > 1);
       bool backdrop = !pcity;
 
+      if (ptile && punit == get_unit_in_focus() && sprites.unit.select[0]) {
+       /* Special case for drawing the selection rectangle.  The blinking
+        * unit is handled separately, inside get_drawable_unit(). */
+       ADD_SPRITE_SIMPLE(sprites.unit.select[focus_unit_state]);
+      }
+
       sprs += fill_unit_sprite_array(sprs, punit, stacked, backdrop);
     }
     break;
@@ -3146,12 +3156,41 @@
   return color;
 }
 
-/**********************************************************************
-  Set focus_unit_hidden (q.v.) variable to given value.
-***********************************************************************/
-void set_focus_unit_hidden_state(bool hide)
+/****************************************************************************
+  Return the amount of time between calls to toggle_focus_unit_state.
+  The main loop needs to call toggle_focus_unit_state about this often
+  to do the active-unit animation.
+****************************************************************************/
+double get_focus_unit_toggle_timeout(void)
 {
-  focus_unit_hidden = hide;
+  if (sprites.unit.select[0]) {
+    return 0.1;
+  } else {
+    return 0.5;
+  }
+}
+
+/****************************************************************************
+  Reset the focus unit state.  This should be called when changing
+  focus units.
+****************************************************************************/
+void reset_focus_unit_state(void)
+{
+  focus_unit_state = 0;
+}
+
+/****************************************************************************
+  Toggle/increment the focus unit state.  This should be called once
+  every get_focus_unit_toggle_timeout() seconds.
+****************************************************************************/
+void toggle_focus_unit_state(void)
+{
+  focus_unit_state++;
+  if (sprites.unit.select[0]) {
+    focus_unit_state %= NUM_TILES_SELECT;
+  } else {
+    focus_unit_state %= 2;
+  }
 }
 
 /**********************************************************************
@@ -3169,7 +3208,7 @@
     return NULL;
 
   if (punit != pfocus
-      || !focus_unit_hidden
+      || sprites.unit.select[0] || focus_unit_state == 0
       || !same_pos(punit->tile, pfocus->tile))
     return punit;
   else
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.102
diff -u -r1.102 tilespec.h
--- client/tilespec.h   11 Feb 2005 16:57:59 -0000      1.102
+++ client/tilespec.h   12 Feb 2005 21:04:47 -0000
@@ -138,7 +138,9 @@
 enum color_std player_color(const struct player *pplayer);
 enum color_std overview_tile_color(struct tile *ptile);
 
-void set_focus_unit_hidden_state(bool hide);
+double get_focus_unit_toggle_timeout(void);
+void reset_focus_unit_state(void);
+void toggle_focus_unit_state(void);
 struct unit *get_drawable_unit(struct tile *ptile, bool citymode);
 
 
@@ -151,6 +153,7 @@
 #define NUM_TILES_CITIZEN CITIZEN_LAST
 #define NUM_TILES_HP_BAR 11
 #define NUM_TILES_DIGITS 10
+#define NUM_TILES_SELECT 4
 #define MAX_NUM_CITIZEN_SPRITES 6
 
 /* This could be moved to common/map.h if there's more use for it. */
@@ -248,6 +251,7 @@
     struct Sprite
       *hp_bar[NUM_TILES_HP_BAR],
       *vet_lev[MAX_VET_LEVELS],
+      *select[NUM_TILES_SELECT],
       *auto_attack,
       *auto_settler,
       *auto_explore,
Index: data/isotrident.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident.tilespec,v
retrieving revision 1.28
diff -u -r1.28 isotrident.tilespec
--- data/isotrident.tilespec    11 Feb 2005 16:58:00 -0000      1.28
+++ data/isotrident.tilespec    12 Feb 2005 21:04:47 -0000
@@ -55,6 +55,7 @@
   "misc/small.spec",
   "trident/units.spec",
   "isotrident/unitextras.spec",
+  "isotrident/select.spec",
   "misc/flags.spec",
   "misc/buildings.spec",
   "misc/space.spec",
Index: data/trident_shields.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident_shields.tilespec,v
retrieving revision 1.20
diff -u -r1.20 trident_shields.tilespec
--- data/trident_shields.tilespec       11 Feb 2005 16:58:00 -0000      1.20
+++ data/trident_shields.tilespec       12 Feb 2005 21:04:47 -0000
@@ -51,6 +51,7 @@
   "trident/tiles.spec",
   "misc/small.spec",
   "trident/units.spec",
+  "trident/select.spec",
   "misc/flags.spec",
   "trident/roads.spec",
   "misc/buildings.spec",
Index: data/isotrident/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/isotrident/Makefile.am,v
retrieving revision 1.7
diff -u -r1.7 Makefile.am
--- data/isotrident/Makefile.am 6 Feb 2005 22:11:11 -0000       1.7
+++ data/isotrident/Makefile.am 12 Feb 2005 21:04:47 -0000
@@ -12,6 +12,8 @@
        morecities.spec \
        nuke.spec       \
        nuke.png        \
+       select.png      \
+       select.spec     \
        terrain1.spec   \
        terrain1.png    \
        terrain2.spec   \
Index: data/isotrident/select.spec
===================================================================
RCS file: data/isotrident/select.spec
diff -N data/isotrident/select.spec
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/isotrident/select.spec 12 Feb 2005 21:04:47 -0000
@@ -0,0 +1,28 @@
+[spec]
+
+; Format and options of this spec file:
+options = "+spec3"
+
+[info]
+
+artists = "
+    Jason Dorje Short <jdorje@xxxxxxxxxxx>
+"
+
+[file]
+gfx = "isotrident/select"
+
+[grid_main]
+
+x_top_left = 0
+y_top_left = 0
+dx = 64
+dy = 32
+pixel_border = 0
+
+tiles = { "row", "column", "tag"
+  0, 0, "unit.select0"
+  0, 1, "unit.select1"
+  0, 2, "unit.select2"
+  0, 3, "unit.select3"
+}
Index: data/trident/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident/Makefile.am,v
retrieving revision 1.9
diff -u -r1.9 Makefile.am
--- data/trident/Makefile.am    6 Feb 2005 22:11:11 -0000       1.9
+++ data/trident/Makefile.am    12 Feb 2005 21:04:47 -0000
@@ -13,6 +13,8 @@
        fog.spec        \
        roads.png       \
        roads.spec      \
+       select.png      \
+       select.spec     \
        tiles.png       \
        tiles.spec      \
        units.png       \
Index: data/trident/select.spec
===================================================================
RCS file: data/trident/select.spec
diff -N data/trident/select.spec
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ data/trident/select.spec    12 Feb 2005 21:04:47 -0000
@@ -0,0 +1,28 @@
+[spec]
+
+; Format and options of this spec file:
+options = "+spec3"
+
+[info]
+
+artists = "
+    Jason Dorje Short <jdorje@xxxxxxxxxxx>
+"
+
+[file]
+gfx = "trident/select"
+
+[grid_main]
+
+x_top_left = 0
+y_top_left = 0
+dx = 30
+dy = 30
+pixel_border = 0
+
+tiles = { "row", "column", "tag"
+  0, 0, "unit.select0"
+  0, 1, "unit.select1"
+  0, 2, "unit.select2"
+  0, 3, "unit.select3"
+}

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