[gnome-nibbles/arnaudb/fix-bugs-3-36: 3/3] Fix pause bug.



commit 2cb4a2dedca91c34d0c27ef4c6ffa882b385a3b9
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jun 10 17:47:59 2020 +0200

    Fix pause bug.
    
    Else pausing is saved after a game restart.

 src/gnome-nibbles.vala | 20 ++++++++++++++++++--
 src/nibbles-game.vala  |  1 +
 2 files changed, 19 insertions(+), 2 deletions(-)
---
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 02e99cb..6e78a69 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -362,6 +362,8 @@ public class Nibbles : Gtk.Application
     {
         settings.set_boolean ("first-run", false);
 
+        if (game.is_paused)
+            set_pause_button_label (/* paused */ false);
         game.reset ();
 
         view.new_level (game.current_level);
@@ -452,17 +454,31 @@ public class Nibbles : Gtk.Application
             if (game.is_running)
             {
                 game.pause ();
-                pause_button.set_label (_("_Resume"));
+                set_pause_button_label (/* paused */ true);
             }
             else
             {
                 game.unpause ();
-                pause_button.set_label (_("_Pause"));
+                set_pause_button_label (/* paused */ false);
                 view.grab_focus ();
             }
         }
     }
 
+    private void set_pause_button_label (bool paused)
+    {
+        if (paused)
+        {
+            /* Translators: label of the Pause button, when the game is paused */
+            pause_button.set_label (_("_Resume"));
+        }
+        else
+        {
+            /* Translators: label of the Pause button, when the game is running */
+            pause_button.set_label (_("_Pause"));
+        }
+    }
+
     /*\
     * * Settings changed events
     \*/
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 7ded550..0e50d0d 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -145,6 +145,7 @@ public class NibblesGame : Object
     public void reset ()
     {
         current_level = start_level;
+        is_paused = false;
     }
 
     private void end ()


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