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: Thu, 10 Feb 2005 23:52:26 -0800
Reply-to: bugs@xxxxxxxxxxx

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

This patch allows a spinning circle for the focus unit.  The only 
problem with it is it breaks the timeout calculations!  Incredibly, 
real_timer_callback uses a boolean check on the callback function to 
determine if a second should be removed from the timeout counter.

The other issue is that I added a new mapview layer to make it.  It's 
probably safe to stick it in on the unit layer.

Oh, and it doesn't look very good in trident.  It may not be possible to 
do this in non-iso-view because the unit takes up too much of the tile.

-jason

? select.c
? select.png
? data/isotrident/select.png
? data/trident/select.png
Index: client/civclient.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/civclient.h,v
retrieving revision 1.38
diff -u -r1.38 civclient.h
--- client/civclient.h  12 Dec 2004 03:44:47 -0000      1.38
+++ client/civclient.h  11 Feb 2005 07:49:24 -0000
@@ -22,7 +22,7 @@
  * called. TIMER_INTERVAL has to stay 500 because real_timer_callback
  * also updates the timeout info.
  */
-#define TIMER_INTERVAL 500
+#define TIMER_INTERVAL get_focus_unit_toggle_timeout()
 
 void handle_packet_input(void *packet, int type);
 
Index: client/control.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/control.c,v
retrieving revision 1.155
diff -u -r1.155 control.c
--- client/control.c    9 Feb 2005 16:23:12 -0000       1.155
+++ client/control.c    11 Feb 2005 07:49:24 -0000
@@ -398,20 +398,16 @@
 **************************************************************************/
 void blink_active_unit(void)
 {
-  static bool is_shown;
   static struct unit *pblinking_unit;
   struct unit *punit;
 
   if ((punit = punit_focus)) {
     if (punit != pblinking_unit) {
-      /* When the focus unit changes, we reset the is_shown flag. */
+      reset_focus_unit_state();
       pblinking_unit = punit;
-      is_shown = TRUE;
     } else {
-      /* Reverse the shown status. */
-      is_shown = !is_shown;
+      toggle_focus_unit_state();
     }
-    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.234
diff -u -r1.234 tilespec.c
--- client/tilespec.c   10 Feb 2005 17:59:45 -0000      1.234
+++ client/tilespec.c   11 Feb 2005 07:49:25 -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,
@@ -1424,6 +1420,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++) {
@@ -2934,6 +2938,13 @@
     }
     break;
 
+  case LAYER_UNDERUNIT:
+    if (do_draw_unit && ptile && punit == get_unit_in_focus()
+       && sprites.unit.select[0]) {
+      ADD_SPRITE_SIMPLE(sprites.unit.select[focus_unit_state]);
+    }
+    break;
+
   case LAYER_UNIT:
     if (do_draw_unit) {
       bool stacked = ptile && (unit_list_size(ptile->units) > 1);
@@ -3153,12 +3164,32 @@
   return color;
 }
 
+int get_focus_unit_toggle_timeout(void)
+{
+  if (sprites.unit.select[0]) {
+    return 100;
+  } else {
+    return 500;
+  }
+}
+
+void reset_focus_unit_state(void)
+{
+  
+  focus_unit_state = 0;
+}
+
 /**********************************************************************
   Set focus_unit_hidden (q.v.) variable to given value.
 ***********************************************************************/
-void set_focus_unit_hidden_state(bool hide)
+void toggle_focus_unit_state(void)
 {
-  focus_unit_hidden = hide;
+  focus_unit_state++;
+  if (sprites.unit.select[0]) {
+    focus_unit_state %= NUM_TILES_SELECT;
+  } else {
+    focus_unit_state %= 2;
+  }
 }
 
 /**********************************************************************
@@ -3176,7 +3207,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.101
diff -u -r1.101 tilespec.h
--- client/tilespec.h   6 Feb 2005 22:11:11 -0000       1.101
+++ client/tilespec.h   11 Feb 2005 07:49:25 -0000
@@ -88,6 +88,7 @@
   LAYER_SPECIAL2,
   LAYER_FOG,
   LAYER_CITY2,
+  LAYER_UNDERUNIT,
   LAYER_UNIT,
   LAYER_SPECIAL3,
   LAYER_GRID2,
@@ -138,7 +139,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);
+int 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 +154,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 +252,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.27
diff -u -r1.27 isotrident.tilespec
--- data/isotrident.tilespec    6 Feb 2005 22:11:11 -0000       1.27
+++ data/isotrident.tilespec    11 Feb 2005 07:49:25 -0000
@@ -57,6 +57,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.tilespec
===================================================================
RCS file: /home/freeciv/CVS/freeciv/data/trident.tilespec,v
retrieving revision 1.29
diff -u -r1.29 trident.tilespec
--- data/trident.tilespec       6 Feb 2005 22:11:11 -0000       1.29
+++ data/trident.tilespec       11 Feb 2005 07:49:25 -0000
@@ -50,6 +50,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/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 11 Feb 2005 07:49:25 -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/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    11 Feb 2005 07:49:25 -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 = 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"
+}

Attachment: select.tar.gz
Description: Unix tar archive

PNG image


[Prev in Thread] Current Thread [Next in Thread]
  • [Freeciv-Dev] (PR#12215) use a spinning circle for the focus unit, Jason Short <=