[gnome-taquin] Some cleanings.



commit 02dec8626ba412c07933cc3e05c88b26f16c4b43
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jan 24 12:16:46 2019 +0100

    Some cleanings.

 src/game-window.vala | 32 ++++++++++++++++----------------
 src/taquin-game.vala |  6 ------
 src/taquin-main.vala | 21 ++++++---------------
 3 files changed, 22 insertions(+), 37 deletions(-)
---
diff --git a/src/game-window.vala b/src/game-window.vala
index 804074d..d0492db 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -116,7 +116,7 @@ private class GameWindow : BaseWindow, AdaptativeWidget
         return false;
     }
 
-    public void shutdown (GLib.Settings settings)
+    internal void shutdown (GLib.Settings settings)
     {
         settings.set_int ("window-width", window_width);
         settings.set_int ("window-height", window_height);
@@ -128,30 +128,30 @@ private class GameWindow : BaseWindow, AdaptativeWidget
     * * Some public calls
     \*/
 
-    public void cannot_undo_more ()
+    internal void cannot_move ()
     {
-        restart_action.set_enabled (false);
-        undo_action.set_enabled (false);
-        game_view.show_game_content (/* grab focus */ true);
+        /* Translators: notification, as a subtitle of the headerbar; on the 15-Puzzle game, if the user 
clicks a tile that cannot move */
+        show_notification (_("You can’t move this tile!"));
     }
 
-    public void set_moves_count (uint moves_count)
+    internal void move (uint moves_count)
     {
         headerbar.set_moves_count (ref moves_count);
         hide_notification ();
+        bool undo_possible = moves_count != 0;
+        restart_action.set_enabled (undo_possible);
+        undo_action.set_enabled (undo_possible);
+        if (!undo_possible)
+            game_view.show_game_content (/* grab focus */ true);
     }
 
-    public void set_subtitle (string? subtitle)
-    {
-        if (subtitle != null)
-            show_notification ((!) subtitle);
-    }
-
-    public void finish_game ()
+    internal void finish_game ()
     {
         game_finished = true;
         headerbar.new_game_button_grab_focus ();
         headerbar.save_best_score ();
+        /* Translators: notification, as a subtitle of the headerbar; on both games, if the user solves the 
puzzle */
+        show_notification (_("Bravo! You finished the game!"));
     }
 
     protected override bool escape_pressed ()
@@ -201,9 +201,9 @@ private class GameWindow : BaseWindow, AdaptativeWidget
     public signal void redo ();
     public signal void hint ();
 
-    public SimpleAction restart_action;
-    public SimpleAction    undo_action;
-    public SimpleAction    redo_action;
+    private SimpleAction restart_action;
+    private SimpleAction    undo_action;
+    private SimpleAction    redo_action;
 
     private bool back_action_disabled = true;
 
diff --git a/src/taquin-game.vala b/src/taquin-game.vala
index 4351c99..9e009f5 100644
--- a/src/taquin-game.vala
+++ b/src/taquin-game.vala
@@ -58,7 +58,6 @@ public class Game : Object
     public signal void move (bool x_axis, int number, int x_gap, int y_gap, uint moves_count, bool 
disable_animation);
     public signal void empty_tile ();
     public signal void cannot_move (int x, int y);
-    public signal void cannot_undo_more ();
 
     /*\
     * * Creation / exporting
@@ -303,9 +302,6 @@ public class Game : Object
 
         state = previous_state;
         previous_state = state == null ? null : ((!) state).previous;
-
-        if (state == null)
-            cannot_undo_more ();
     }
 
     public void restart ()
@@ -320,8 +316,6 @@ public class Game : Object
             state = previous_state;
             previous_state = state == null ? null : ((!) state).previous;
         }
-
-        cannot_undo_more ();
     }
 
     private void add_move (int x_gap, int y_gap)
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index fb8435c..2e0e685 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -239,13 +239,16 @@ private class Taquin : Gtk.Application, BaseApplication
     private void start_game ()
     {
         if (game != null)
+        {
             SignalHandler.disconnect_by_func ((!) game, null, this);
+            SignalHandler.disconnect_by_func ((!) game, null, window);
+        }
 
         GameType type = (GameType) settings.get_enum ("type");
         int size = settings.get_int ("size");
         game = new Game (type, size);
         view.game = (!) game;
-        window.set_moves_count (0);
+        window.move (0);
 
         string filename = "";
         var dirlist = theme_dirlist.copy ();
@@ -260,8 +263,7 @@ private class Taquin : Gtk.Application, BaseApplication
         view.realize ();        // TODO does that help?
 
         ((!) game).complete.connect (game_complete_cb);
-        ((!) game).cannot_move.connect (cannot_move_cb);
-        ((!) game).cannot_undo_more.connect (window.cannot_undo_more);
+        ((!) game).cannot_move.connect (window.cannot_move);
         ((!) game).move.connect (move_cb);
     }
 
@@ -289,24 +291,13 @@ private class Taquin : Gtk.Application, BaseApplication
 
     private void move_cb (bool x_axis, int number, int x_gap, int y_gap, uint moves_count, bool 
disable_animation)
     {
-        window.set_moves_count (moves_count);
-        window.set_subtitle (null);
-        window.restart_action.set_enabled (true);
-        window.undo_action.set_enabled (true);
+        window.move (moves_count);
         play_sound ("sliding-1");       // TODO sliding-n??
     }
 
-    private void cannot_move_cb ()
-    {
-        /* Translators: notification, as a subtitle of the headerbar; on the 15-Puzzle game, if the user 
clicks a tile that cannot move */
-        window.set_subtitle (_("You can’t move this tile!"));
-    }
-
     private void game_complete_cb ()
     {
         window.finish_game ();
-        /* Translators: notification, as a subtitle of the headerbar; on both games, if the user solves the 
puzzle */
-        window.set_subtitle (_("Bravo! You finished the game!"));
         play_sound ("gameover");
     }
 


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