[gnome-tetravex] Warning will be shown prior to selecting new board size if the game is in progress.



commit 720385a0f829b3ccb5a5975f962b813be92d10b0
Author: amishas157 <amishas157 gmail com>
Date:   Wed Sep 10 22:18:54 2014 +0530

    Warning will be shown prior to selecting new board size if the game is in progress.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=736238

 src/gnome-tetravex.vala |   17 +++++++++++++++++
 src/puzzle-view.vala    |   19 +++++++++++++++++++
 2 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 1c8e9f0..76d3add 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -417,6 +417,23 @@ public class Tetravex : Gtk.Application
 
         if (size == settings.get_int (KEY_GRID_SIZE))
             return;
+        if (view.game_in_progress)
+        {
+            var dialog = new Gtk.MessageDialog (window,
+                                                Gtk.DialogFlags.MODAL,
+                                                Gtk.MessageType.QUESTION,
+                                                Gtk.ButtonsType.NONE,
+                                                _("Are you sure you want to start a new game with a 
different board size?"));
+            dialog.add_buttons (_("_Keep Playing"), Gtk.ResponseType.REJECT,
+                                _("_Start New Game"), Gtk.ResponseType.ACCEPT,
+                                null);
+
+            var response = dialog.run ();
+            dialog.destroy ();
+
+            if (response != Gtk.ResponseType.ACCEPT)
+                return;
+        }
         settings.set_int (KEY_GRID_SIZE, size);
         game_size = (int) size;
         action.set_state (value);
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 7f98895..002b379 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -104,6 +104,25 @@ public class PuzzleView : Gtk.DrawingArea
         animation_timer = new Timer ();
         animation_timer.start ();
     }
+
+    public bool game_in_progress
+    {
+        get
+        {
+            if (puzzle.is_solved)
+                return false;
+
+            for (uint y = 0; y < puzzle.size; y++)
+            {
+                for (uint x = puzzle.size; x < puzzle.size * 2; x++)
+                {
+                    if (puzzle.get_tile (x, y) == null)
+                        return true;
+                }
+            }
+            return false;
+        }
+    }
     
     private void redraw_tile (TileImage image)
     {


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