[swell-foop] Add a confirmation dialog when starting a new game



commit 7588c81072d72511254f8d331b64fba2dc718069
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Tue Feb 4 20:08:54 2014 -0600

    Add a confirmation dialog when starting a new game
    
    ...unless the game is already over, in which case we should start the
    next game without bothering the user.

 src/swell-foop.vala |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/src/swell-foop.vala b/src/swell-foop.vala
index a6527e9..30b0531 100644
--- a/src/swell-foop.vala
+++ b/src/swell-foop.vala
@@ -32,6 +32,8 @@ public class SwellFoop : Gtk.Application
 
     private Gtk.HeaderBar headerbar;
 
+    private bool game_in_progress = true;
+
     /* Store size options */
     public Size[] sizes;
 
@@ -202,6 +204,7 @@ public class SwellFoop : Gtk.Application
         var entry = new HistoryEntry (date, game.columns, game.rows, game.color_num, game.score);
         history.add (entry);
         history.save ();
+        game_in_progress = false;
     }
 
     protected override void shutdown ()
@@ -341,7 +344,10 @@ public class SwellFoop : Gtk.Application
 
     private void new_game_cb ()
     {
-        new_game ();
+        if (game_in_progress)
+            show_new_game_confirmation_dialog ();
+        else
+            new_game ();
     }
 
     private void scores_cb ()
@@ -407,9 +413,29 @@ public class SwellFoop : Gtk.Application
         stage.set_size (view.width, view.height);
         clutter_embed.set_size_request ( (int) stage.width, (int) stage.height);
 
+        game_in_progress = true;
+
         update_score_cb (0);
     }
 
+    private void show_new_game_confirmation_dialog ()
+    {
+        var dialog = new Gtk.MessageDialog.with_markup (window,
+                                                        Gtk.DialogFlags.MODAL,
+                                                        Gtk.MessageType.QUESTION,
+                                                        Gtk.ButtonsType.NONE,
+                                                        "<span weight=\"bold\" size=\"larger\">%s</span>",
+                                                        _("Abandon this game to start a new one?"));
+        dialog.add_button (_("_Cancel"), Gtk.ResponseType.CANCEL);
+        dialog.add_button (_("_New Game"), Gtk.ResponseType.YES);
+
+        var result = dialog.run ();
+        dialog.destroy ();
+
+        if (result == Gtk.ResponseType.YES)
+            new_game ();
+    }
+
     public static int main (string[] args)
     {
         Intl.setlocale (LocaleCategory.ALL, "");


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