[lightsoff/wip/gtkview] Refactored board replacement styles



commit 39a1d3edbada45323ed7b1492164f5bef3370b04
Author: Robert Roth <robert roth off gmail com>
Date:   Sun Jul 15 03:05:56 2018 +0300

    Refactored board replacement styles

 src/game-view-clutter.vala | 106 ++++++++++++++++++++++++++++-----------------
 src/game-view-gtk.vala     |  10 +++--
 src/game-view.vala         |  10 ++++-
 3 files changed, 81 insertions(+), 45 deletions(-)
---
diff --git a/src/game-view-clutter.vala b/src/game-view-clutter.vala
index 5f4f253..1a6ce63 100644
--- a/src/game-view-clutter.vala
+++ b/src/game-view-clutter.vala
@@ -134,26 +134,8 @@ public class ClutterGameView : Clutter.Group, GameView
 
         current_level++;
 
-        // Make sure the board transition is different than the previous.
-        var direction = 0;
-        var sign = 0;
-        do
-        {
-            direction = Random.int_range (0, 2); // x or y
-            sign = Random.boolean () ? 1 : -1; // left/right up/down
-        }
-        while (last_direction == direction && last_sign == sign);
-        last_direction = direction;
-        last_sign = sign;
-
         new_board_view = create_board_view (current_level);
-        board_group.add_child (new_board_view);
-
-        timeline = new Clutter.Timeline (1500);
-        new_board_view.slide_in (direction, sign, timeline);
-        board_view.slide_out (direction, sign, timeline);
-        timeline.completed.connect (transition_complete_cb);
-
+        replace_board (board_view, new_board_view, GameView.ReplaceStyle.SLIDE_NEXT);
         level_changed (current_level);
     }
 
@@ -174,32 +156,83 @@ public class ClutterGameView : Clutter.Group, GameView
         }
 
         new_board_view = create_board_view (current_level);
-        new_board_view.z_position = -250 * direction;
-        new_board_view.opacity = 0;
 
-        replace_board (board_view, new_board_view);
-
-        /* Fade into background or drop down */
-        board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
-                               "z_position", 250.0 * direction,
-                               "opacity", 0);
+        replace_board (board_view, new_board_view, 
+                       direction == 1 ? GameView.ReplaceStyle.SLIDE_FORWARD 
+                                      : GameView.ReplaceStyle.SLIDE_BACKWARD);
 
         level_changed (current_level);
     }
 
-    public void replace_board (BoardView old_board, BoardView new_board)
+    public void replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, bool 
fast = true)
     {
-        timeline = new Clutter.Timeline (500);
+        timeline = new Clutter.Timeline (fast ? 500 : 1500);
         board_group.add_child (new_board as Clutter.Group);
-
-        /* Bring into foreground and make visible */
-        (new_board as Clutter.Group).animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
+        int direction = 1;
+        switch (style)
+        {
+            case REFRESH: 
+                new_board_view.z_position = 250;
+                new_board_view.opacity = 0;
+                /* Fade into background or drop down */
+                board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
+                                       "z_position", 250.0 * -1,
+                                       "opacity", 0);
+                        /* Bring into foreground and make visible */
+                new_board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
+                               "opacity", 255,
+                               "z_position", 0.0);
+                break;
+            case SLIDE_NEXT:
+                // Make sure the board transition is different than the previous.
+                direction = 0;
+                var sign = 0;
+                do
+                {
+                    direction = Random.int_range (0, 2); // x or y
+                    sign = Random.boolean () ? 1 : -1; // left/right up/down
+                }
+                while (last_direction == direction && last_sign == sign);
+                last_direction = direction;
+                last_sign = sign;
+
+                timeline = new Clutter.Timeline (1500);
+                new_board_view.slide_in (direction, sign, timeline);
+                board_view.slide_out (direction, sign, timeline);
+                break;
+            case SLIDE_FORWARD: 
+                new_board_view.z_position = -250 * direction;
+                new_board_view.opacity = 0;
+                /* Fade into background or drop down */
+                board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
+                                       "z_position", 250.0 * direction,
+                                       "opacity", 0);
+                        /* Bring into foreground and make visible */
+                new_board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
+                               "opacity", 255,
+                               "z_position", 0.0);
+                break;
+            case SLIDE_BACKWARD: 
+                direction = -1;
+                new_board_view.z_position = -250 * direction;
+                new_board_view.opacity = 0;
+                /* Fade into background or drop down */
+                board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
+                                       "z_position", 250.0 * direction,
+                                       "opacity", 0);
+                        /* Bring into foreground and make visible */
+                new_board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
                                "opacity", 255,
                                "z_position", 0.0);
+                break;
+
+            default: break;
+        } 
 
         timeline.completed.connect (transition_complete_cb);
     }
 
+
     public void hide_cursor ()
     {
         setup_animation (key_cursor_view, Clutter.AnimationMode.EASE_OUT_SINE, 250);
@@ -252,15 +285,8 @@ public class ClutterGameView : Clutter.Group, GameView
         current_level = 1;
 
         new_board_view = create_board_view (current_level);
-        new_board_view.z_position = 250;
-        new_board_view.opacity = 0;
-
-        replace_board (board_view, new_board_view);
 
-        /* Fade into background or drop down */
-        board_view.animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
-                               "z_position", 250.0 * -1,
-                               "opacity", 0);
+        replace_board (board_view, new_board_view, GameView.ReplaceStyle.REFRESH);
 
         level_changed (current_level);
     }
diff --git a/src/game-view-gtk.vala b/src/game-view-gtk.vala
index f7403df..755e404 100644
--- a/src/game-view-gtk.vala
+++ b/src/game-view-gtk.vala
@@ -8,12 +8,14 @@ public class GtkGameView : Gtk.Frame, GameView {
     {
         current_level += direction;
         new_board_view = create_board_view (current_level);
-        replace_board (board_view, new_board_view);
+        replace_board (board_view, new_board_view, 
+                       direction == 1 ? GameView.ReplaceStyle.SLIDE_FORWARD 
+                                      : GameView.ReplaceStyle.SLIDE_BACKWARD);
         board_view = new_board_view;
         level_changed (current_level);
     }
 
-    public void replace_board (BoardView old_board, BoardView new_board)
+    public void replace_board (BoardView old_board, BoardView new_board, GameView.ReplaceStyle style, bool 
fast = true)
     {
         remove (old_board as Gtk.Widget);
         add (new_board as Gtk.Widget);
@@ -32,7 +34,7 @@ public class GtkGameView : Gtk.Frame, GameView {
     {
         current_level = 1;
         new_board_view = create_board_view (current_level);
-        replace_board (board_view, new_board_view);
+        replace_board (board_view, new_board_view, GameView.ReplaceStyle.REFRESH);
         board_view = new_board_view;
         level_changed (current_level);
     }
@@ -71,7 +73,7 @@ public class GtkGameView : Gtk.Frame, GameView {
         current_level++;
 
         new_board_view = create_board_view (current_level);
-        replace_board (board_view, new_board_view);
+        replace_board (board_view, new_board_view, GameView.ReplaceStyle.SLIDE_NEXT, false);
         board_view = new_board_view;
         level_changed (current_level);
     }
diff --git a/src/game-view.vala b/src/game-view.vala
index a8870c6..b8fb266 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -8,9 +8,17 @@
  * license.
  */
 public interface GameView : GLib.Object {
+
+    public enum ReplaceStyle {
+        REFRESH, // crossfade
+        SLIDE_FORWARD, // slide out-in
+        SLIDE_BACKWARD, // slide in-out
+        SLIDE_NEXT // slide over
+    }
+
     public abstract void swap_board (int direction);
 
-    public abstract void replace_board (BoardView board_biew, BoardView new_board_view);
+    public abstract void replace_board (BoardView board_biew, BoardView new_board_view, ReplaceStyle style, 
bool fast = true);
 
     public abstract void hide_cursor ();
     public abstract void activate_cursor ();


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