[lightsoff/wip/gtkview] Moved swapin and swapout from board to game view



commit a6a2c3a797e972588a4fe16f5a7fff2b6b7597d1
Author: Robert Roth <robert roth off gmail com>
Date:   Sun Jul 15 01:56:42 2018 +0300

    Moved swapin and swapout from board to game view

 src/board-view-clutter.vala | 17 -----------------
 src/board-view-gtk.vala     |  8 --------
 src/game-view-clutter.vala  | 38 ++++++++++++++++++++++++++------------
 src/game-view-gtk.vala      | 18 ++++++++++--------
 src/game-view.vala          |  3 +++
 5 files changed, 39 insertions(+), 45 deletions(-)
---
diff --git a/src/board-view-clutter.vala b/src/board-view-clutter.vala
index 89a780c..eb5b504 100644
--- a/src/board-view-clutter.vala
+++ b/src/board-view-clutter.vala
@@ -141,23 +141,6 @@ public class BoardViewClutter : Clutter.Group, BoardView
                                "y", sign * (1 - direction) * height);
     }
 
-    public void swap_in (float direction, Clutter.Timeline timeline)
-    {
-        /* Bring into foreground and make visible */
-        animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
-                               "opacity", 255,
-                               "z_position", 0.0);
-
-    }
-
-    public void swap_out (float direction, Clutter.Timeline timeline)
-    {
-        /* Fade into background or drop down */
-        animate_with_timeline (Clutter.AnimationMode.EASE_IN_SINE, timeline,
-                               "z_position", 250.0 * direction,
-                               "opacity", 0);
-    }
-
     private void light_button_press_cb (Clutter.TapAction tap, Clutter.Actor actor)
     {
         int x, y;
diff --git a/src/board-view-gtk.vala b/src/board-view-gtk.vala
index 56d6f55..f2f7437 100644
--- a/src/board-view-gtk.vala
+++ b/src/board-view-gtk.vala
@@ -54,14 +54,6 @@ public class BoardViewGtk : Gtk.Grid, BoardView
     {
     }
 
-    public void swap_in (float direction, Clutter.Timeline timeline)
-    {
-    }
-
-    public void swap_out (float direction, Clutter.Timeline timeline)
-    {
-    }
-
     public void light_toggled_cb (Gtk.ToggleButton source)
     {
         int xl, yl;
diff --git a/src/game-view-clutter.vala b/src/game-view-clutter.vala
index 19cfb99..2a5f0bb 100644
--- a/src/game-view-clutter.vala
+++ b/src/game-view-clutter.vala
@@ -173,20 +173,34 @@ public class ClutterGameView : Clutter.Group, GameView
             return;
         }
 
-        timeline = new Clutter.Timeline (500);
-
         new_board_view = create_board_view (current_level);
-        board_group.add_child (new_board_view);
         new_board_view.z_position = -250 * direction;
         new_board_view.opacity = 0;
 
-        new_board_view.swap_in (direction, timeline);
-        board_view.swap_out (direction, timeline);
-        timeline.completed.connect (transition_complete_cb);
+        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);
 
         level_changed (current_level);
     }
 
+    public void replace_board (BoardView old_board, BoardView new_board)
+    {
+        timeline = new Clutter.Timeline (500);
+        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,
+                               "opacity", 255,
+                               "z_position", 0.0);
+
+        timeline.completed.connect (transition_complete_cb);
+    }
+
+
     public void hide_cursor ()
     {
         setup_animation (key_cursor_view, Clutter.AnimationMode.EASE_OUT_SINE, 250);
@@ -238,16 +252,16 @@ public class ClutterGameView : Clutter.Group, GameView
 
         current_level = 1;
 
-        timeline = new Clutter.Timeline (500);
-
         new_board_view = create_board_view (current_level);
-        board_group.add_child (new_board_view);
         new_board_view.z_position = 250;
         new_board_view.opacity = 0;
 
-        new_board_view.swap_in (-1, timeline);
-        board_view.swap_out (-1, timeline);
-        timeline.completed.connect (transition_complete_cb);
+        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);
 
         level_changed (current_level);
     }
diff --git a/src/game-view-gtk.vala b/src/game-view-gtk.vala
index b6bce8e..2fdcfcb 100644
--- a/src/game-view-gtk.vala
+++ b/src/game-view-gtk.vala
@@ -8,11 +8,17 @@ public class GtkGameView : Gtk.Frame, GameView {
     {
         current_level += direction;
         new_board_view = create_board_view (current_level);
-        remove (board_view);
-        add (new_board_view);
+        replace_board (board_view, new_board_view);
         board_view = new_board_view;
         level_changed (current_level);
     }
+
+    public void replace_board (BoardView old_board, BoardView new_board)
+    {
+        @foreach ((widget) => remove (widget));
+        add (new_board as Gtk.Widget);
+    }
+
     public void hide_cursor ()
     {
     }
@@ -26,10 +32,8 @@ public class GtkGameView : Gtk.Frame, GameView {
     {
         current_level = 1;
         new_board_view = create_board_view (current_level);
-        remove (board_view);
-        add (new_board_view);
+        replace_board (board_view, new_board_view);
         board_view = new_board_view;
-
         level_changed (current_level);
     }
 
@@ -67,10 +71,8 @@ public class GtkGameView : Gtk.Frame, GameView {
         current_level++;
 
         new_board_view = create_board_view (current_level);
-        remove (board_view);
-        add (new_board_view);
+        replace_board (board_view, new_board_view);
         board_view = new_board_view;
-
         level_changed (current_level);
     }
 
diff --git a/src/game-view.vala b/src/game-view.vala
index 2bbd956..a8870c6 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -9,6 +9,9 @@
  */
 public interface GameView : GLib.Object {
     public abstract void swap_board (int direction);
+
+    public abstract void replace_board (BoardView board_biew, BoardView new_board_view);
+
     public abstract void hide_cursor ();
     public abstract void activate_cursor ();
     public abstract void move_cursor (int x, int y);


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