[gnome-tetravex] Confirm new game action when playing.



commit 5a47afe6f81b837138a7fc09fae498b8627525a8
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Sep 20 20:46:36 2019 +0200

    Confirm new game action when playing.
    
    Fixes #16.

 src/gnome-tetravex.vala | 31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index a7b3099..d8ed49b 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -419,6 +419,28 @@ private class Tetravex : Gtk.Application
 
     private void new_game_cb ()
     {
+        if (view.game_in_progress)
+        {
+            MessageDialog dialog = new MessageDialog (window,
+                                                      DialogFlags.MODAL,
+                                                      MessageType.QUESTION,
+                                                      ButtonsType.NONE,
+        /* Translators: popup dialog main text; appearing when user clicks "New Game" from the hamburger 
menu, while a game is started; possible answers are "Keep playing"/"Start New Game" */
+                                                      _("Are you sure you want to start a new game with same 
board size?"));
+
+        /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user clicks "New Game" from the hamburger menu; other possible answer is "_Start New Game" */
+            dialog.add_buttons (_("_Keep Playing"),   ResponseType.REJECT,
+
+        /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user clicks "New Game" from the hamburger menu; other possible answer is "_Keep Playing" */
+                                _("_Start New Game"), ResponseType.ACCEPT,
+                                null);
+
+            int response = dialog.run ();
+            dialog.destroy ();
+
+            if (response != ResponseType.ACCEPT)
+                return;
+        }
         new_game ();
     }
 
@@ -449,7 +471,6 @@ private class Tetravex : Gtk.Application
         /* Translators: popup dialog main text; appearing when user clicks the "Give up" button in the 
bottom bar; possible answers are "Keep playing"/"Give up" */
                                                   _("Are you sure you want to give up and view the 
solution?"));
 
-
         /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user clicks the "Give up" button in the bottom bar; other possible answer is "_Give Up" */
         dialog.add_buttons (_("_Keep Playing"), ResponseType.REJECT,
 
@@ -480,7 +501,9 @@ private class Tetravex : Gtk.Application
 
     private void size_changed (SimpleAction action, Variant variant)
     {
-        int size = ((string) variant)[0] - '0'; // FIXME that... is... horrible
+        int size = int.parse (variant.get_string ());
+        if (size < 2 || size > 6)
+            assert_not_reached ();
 
         if (size == settings.get_int (KEY_GRID_SIZE))
             return;
@@ -493,10 +516,10 @@ private class Tetravex : Gtk.Application
         /* Translators: popup dialog main text; appearing when user changes size from the hamburger menu 
submenu, while a game is started; possible answers are "Keep playing"/"Start New Game" */
                                                       _("Are you sure you want to start a new game with a 
different board size?"));
 
-        /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user clicks the "Give up" button in the bottom bar; other possible answer is "_Start New Game" */
+        /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user changes size from the hamburger menu submenu, while a game is started; other possible answer is 
"_Start New Game" */
             dialog.add_buttons (_("_Keep Playing"),   ResponseType.REJECT,
 
-        /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user clicks the "Give up" button in the bottom bar; other possible answer is "_Keep Playing" */
+        /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing 
when user changes size from the hamburger menu submenu, while a game is started; other possible answer is 
"_Keep Playing" */
                                 _("_Start New Game"), ResponseType.ACCEPT,
                                 null);
 


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