[gnome-games] quadrapassel: Implement the 'show where block will land' feature



commit 059940c7321a927e7895521ff5f9ba26baaf5c3b
Author: Robert Ancell <robert ancell canonical com>
Date:   Mon Feb 6 19:36:57 2012 +1100

    quadrapassel: Implement the 'show where block will land' feature

 .../data/org.gnome.quadrapassel.gschema.xml.in     |    6 +-
 quadrapassel/src/game-view.vala                    |   40 ++++++++++++++++++++
 quadrapassel/src/game.vala                         |   19 +++++++++-
 quadrapassel/src/quadrapassel.vala                 |   15 ++++++-
 4 files changed, 73 insertions(+), 7 deletions(-)
---
diff --git a/quadrapassel/data/org.gnome.quadrapassel.gschema.xml.in b/quadrapassel/data/org.gnome.quadrapassel.gschema.xml.in
index a318800..f7e4f06 100644
--- a/quadrapassel/data/org.gnome.quadrapassel.gschema.xml.in
+++ b/quadrapassel/data/org.gnome.quadrapassel.gschema.xml.in
@@ -21,10 +21,10 @@
       <_summary>Whether to preview the next block</_summary>
       <_description>Whether to preview the next block.</_description>
     </key>
-    <key name="use-target" type="b">
+    <key name="show-shadow" type="b">
       <default>false</default>
-      <_summary>Whether to provide a target</_summary>
-      <_description>Whether to provide a graphical representation of where a block will land.</_description>
+      <_summary>Whether to show where the moving piece will land</_summary>
+      <_description>Whether to show where the moving piece will land.</_description>
     </key>
     <key name="random-block-colors" type="b">
       <default>false</default>
diff --git a/quadrapassel/src/game-view.vala b/quadrapassel/src/game-view.vala
index ef42a06..0ae2ee6 100644
--- a/quadrapassel/src/game-view.vala
+++ b/quadrapassel/src/game-view.vala
@@ -64,6 +64,16 @@ public class GameView : GtkClutter.Embed
     /* The shape currently falling */
     private Clutter.Group? shape = null;
 
+    /* Shadow of falling piece */
+    private Clutter.Clone? shape_shadow = null;
+    
+    private bool _show_shadow = false;
+    public bool show_shadow
+    {
+        get { return _show_shadow; }
+        set { _show_shadow = value; update_shadow (); }
+    }
+
     /* Overlay to draw messages on */
     private TextOverlay text_overlay;
 
@@ -128,6 +138,8 @@ public class GameView : GtkClutter.Embed
         shape = new Clutter.Group ();
         playing_field.add (shape);
         shape.set_position (game.shape.x * cell_size, game.shape.y * cell_size);
+        update_shadow ();
+
         foreach (var block in game.shape.blocks)
         {
             var actor = new BlockActor (block, block_textures[block.color]);
@@ -142,11 +154,34 @@ public class GameView : GtkClutter.Embed
     {
         play_sound ("slide");
         shape.animate (Clutter.AnimationMode.EASE_IN_QUAD, 30, "x", (float) game.shape.x * cell_size);
+        if (shape_shadow != null)
+            shape_shadow.set_position (game.shape.x * cell_size, game.shadow_y * cell_size);
+    }
+    
+    private void update_shadow ()
+    {
+        if (show_shadow)
+        {
+            if (shape_shadow == null)
+            {
+                shape_shadow = new Clutter.Clone (shape);
+                shape_shadow.set_opacity (32);
+                playing_field.add (shape_shadow);
+            }
+            shape_shadow.set_position (game.shape.x * cell_size, game.shadow_y * cell_size);
+        }
+        else
+        {
+            if (shape_shadow != null)
+                shape_shadow.destroy ();
+            shape_shadow = null;
+        }
     }
 
     private void shape_dropped_cb ()
     {
         shape.animate (Clutter.AnimationMode.EASE_IN_QUAD, 60, "y", (float) game.shape.y * cell_size);
+        update_shadow ();
     }
 
     private void shape_rotated_cb ()
@@ -157,6 +192,7 @@ public class GameView : GtkClutter.Embed
             var actor = shape_blocks.lookup (block);
             actor.set_position (block.x * cell_size, block.y * cell_size);
         }
+        update_shadow ();
     }
 
     private void shape_landed_cb (int[] lines, List<Block> line_blocks)
@@ -181,6 +217,9 @@ public class GameView : GtkClutter.Embed
         /* Remove the moving shape */
         shape.destroy ();
         shape = null;
+        if (shape_shadow != null)
+            shape_shadow.destroy ();
+        shape_shadow = null;
         shape_blocks.remove_all ();
 
         /* Land the shape blocks */
@@ -261,6 +300,7 @@ public class GameView : GtkClutter.Embed
         }
         if (shape != null)
             shape.set_position (game.shape.x * cell_size, game.shape.y * cell_size);
+        update_shadow ();
 
         text_overlay.set_size (get_allocated_width (), get_allocated_height ());
         text_overlay.raise_top ();
diff --git a/quadrapassel/src/game.vala b/quadrapassel/src/game.vala
index d0a2d7b..d191ea2 100644
--- a/quadrapassel/src/game.vala
+++ b/quadrapassel/src/game.vala
@@ -209,7 +209,7 @@ public class Game : Object
 {
     /* Falling shape */
     public Shape? shape = null;
-
+    
     /* Next shape to be used */
     public Shape? next_shape = null;
 
@@ -257,6 +257,23 @@ public class Game : Object
         }
     }
 
+    /* The y co-ordinate of the shadow of the falling shape */
+    public int shadow_y
+    {
+        get
+        {
+            if (shape == null)
+                return 0;
+
+            var d = 0;
+            var g = copy ();
+            while (g.move_shape (0, 1, 0))
+                d++;
+
+            return shape.y + d;
+        }
+    }
+
     public bool game_over = false;
 
     public signal void started ();
diff --git a/quadrapassel/src/quadrapassel.vala b/quadrapassel/src/quadrapassel.vala
index a26ce58..9e98be6 100644
--- a/quadrapassel/src/quadrapassel.vala
+++ b/quadrapassel/src/quadrapassel.vala
@@ -36,7 +36,7 @@ public class Quadrapassel
     private Gtk.CheckButton do_preview_toggle;
     private Gtk.CheckButton difficult_blocks_toggle;
     private Gtk.CheckButton rotate_counter_clock_wise_toggle;
-    private Gtk.CheckButton use_target_toggle;
+    private Gtk.CheckButton show_shadow_toggle;
     private Gtk.CheckButton sound_toggle;
 
     private const Gtk.ActionEntry actions[] =
@@ -88,6 +88,7 @@ public class Quadrapassel
         view = new GameView ();
         view.theme = settings.get_string ("theme");
         view.mute = !settings.get_boolean ("sound");
+        view.show_shadow = settings.get_boolean ("show-shadow");
 
         preview = new Preview ();
         preview.theme = settings.get_string ("theme");
@@ -287,8 +288,9 @@ public class Quadrapassel
         rotate_counter_clock_wise_toggle.toggled.connect (set_rotate_counter_clock_wise);
         fvbox.pack_start (rotate_counter_clock_wise_toggle, false, false, 0);
 
-        use_target_toggle = new Gtk.CheckButton.with_mnemonic (_("Show _where the block will land"));
-        fvbox.pack_start (use_target_toggle, false, false, 0);
+        show_shadow_toggle = new Gtk.CheckButton.with_mnemonic (_("Show _where the block will land"));
+        show_shadow_toggle.toggled.connect (user_target_toggled_cb);
+        fvbox.pack_start (show_shadow_toggle, false, false, 0);
 
         frame.add (fvbox);
         vbox.pack_start (frame, false, false, 0);
@@ -398,6 +400,13 @@ public class Quadrapassel
         settings.set_boolean ("rotate-counter-clock-wise", rotate_counter_clock_wise_toggle.get_active ());
     }
 
+    private void user_target_toggled_cb ()
+    {
+        var show_shadow = show_shadow_toggle.get_active ();
+        settings.set_boolean ("show-shadow", show_shadow);
+        view.show_shadow = show_shadow;
+    }
+
     private void theme_combo_changed_cb (Gtk.ComboBox widget)
     {
         Gtk.TreeIter iter;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]