[gnome-chess] Display a dialog if Claim Draw fails



commit 3c9ab4efdb5ce12fb266aa5b83a1d898f516221c
Author: Michael Catanzaro <mcatanzaro gnome org>
Date:   Sun Aug 11 15:17:49 2013 -0500

    Display a dialog if Claim Draw fails
    
    Previously there was no user feedback at all if Claim Draw was used at
    an incorrect time.  Instead, present a dialog explaining the usage of
    Claim Draw.  It also informs the user the number of repetitions of the
    current board state and presents the halfmove clock.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=703841

 src/chess-game.vala  |    2 +-
 src/gnome-chess.vala |   34 +++++++++++++++++++++++++++++++++-
 2 files changed, 34 insertions(+), 2 deletions(-)
---
diff --git a/src/chess-game.vala b/src/chess-game.vala
index 0e67111..82c348e 100644
--- a/src/chess-game.vala
+++ b/src/chess-game.vala
@@ -1538,7 +1538,7 @@ public class ChessGame
         return false;
     }
 
-    private int state_repeated_times (ChessState s1)
+    public int state_repeated_times (ChessState s1)
     {
         var count = 1;
 
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 433af5c..82eefb2 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -1169,7 +1169,39 @@ public class Application : Gtk.Application
     [CCode (cname = "G_MODULE_EXPORT claim_draw_cb", instance_pos = -1)]
     public void claim_draw_cb (Gtk.Widget widget)
     {
-        game.current_player.claim_draw ();
+        if (!game.current_player.claim_draw ())
+        {
+            var dialog = new Gtk.MessageDialog.with_markup (window,
+                                                            Gtk.DialogFlags.MODAL,
+                                                            Gtk.MessageType.INFO,
+                                                            Gtk.ButtonsType.CLOSE,
+                                                            "<span weight=\"bold\" 
size=\"larger\">%s</span>",
+                                                            _("You cannot currently claim a draw."));
+
+            var repetitions = game.state_repeated_times (game.current_state);
+            var moves = game.current_state.halfmove_clock / 2;
+
+            warn_if_fail (repetitions == 1 || repetitions == 2);
+
+            /* Dialog that appears when Claim Draw is used but a draw cannot be claimed */
+            dialog.format_secondary_text ("• " + (repetitions == 1 ?
+                                                      _("It is the first time this board position has 
occurred") :
+                                                      _("It is the second time this board position has 
occurred")) + "\n"
+                                            + "• " + ngettext ("%d move has passed without a capture or pawn 
advancement",
+                                                               "%d moves have passed without a capture or 
pawn advancement",
+                                                               moves) + "\n\n"
+                                            + _("You can claim a draw when either:") + "\n\n"
+                                            + "• " + _("Any board position has occurred three times") + "\n"
+                                            + "• " + _("50 moves have passed without a capture or pawn 
advancement") + "\n\n"
+                                            + _("(Board position is affected by the ability to castle or 
capture en passant.)") + "\n\n"
+                                            + _("The game is automatically a draw if:") + "\n\n"
+                                            + "• " + _("The current player cannot move (stalemate)") + "\n"
+                                            + "• " + _("Neither player can checkmate (insufficient 
material)"),
+                                          moves);
+
+            dialog.run ();
+            dialog.destroy ();
+        }
     }
 
     [CCode (cname = "G_MODULE_EXPORT undo_move_cb", instance_pos = -1)]


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