[gnome-chess] Fix claim draw dialog appearing for moves through history



commit be944e49ccef33b356f2e9db765794d872932f9c
Author: Michael Catanzaro <mcatanzaro igalia com>
Date:   Tue Apr 24 12:09:20 2018 -0500

    Fix claim draw dialog appearing for moves through history
    
    Using the history viewer should not trigger the claim draw dialog. I
    noticed this because there's a big warning comment in game_turn_cb()
    saying to not use it for anything related to the game itself, yet here
    it was.
    
    Note I add one additional check here, to mave sure the game has not
    ended before telling the engine to move.
    
    Note also that this makes every move 0.1s slower than before... that
    seems fine.

 src/gnome-chess.vala |   28 ++++++++++++++++------------
 1 files changed, 16 insertions(+), 12 deletions(-)
---
diff --git a/src/gnome-chess.vala b/src/gnome-chess.vala
index 40ba64a..62b2dc4 100644
--- a/src/gnome-chess.vala
+++ b/src/gnome-chess.vala
@@ -874,12 +874,6 @@ Copyright © 2015–2016 Sahil Sareen""";
 
         if (game.clock != null)
             enable_window_action (PAUSE_RESUME_ACTION_NAME);
-
-        /* FIXME: This looks like the wrong place for this, as per the
-         * warning comment just above.
-         */
-        if (game.can_claim_draw ())
-            present_claim_draw_dialog ();
     }
 
     private void set_move_text (Gtk.TreeIter iter, ChessMove move)
@@ -1127,13 +1121,23 @@ Copyright © 2015–2016 Sahil Sareen""";
 
         view.queue_draw ();
 
-        if (opponent_engine != null)
-        {
-            opponent_engine.report_move (move);
+        /* Remaining work goes in a timeout to give the game widget a chance to
+         * redraw first, so the pieces are shown to move before displaying the
+         * claim draw dialog. */
+        Timeout.add(100, () => {
+            if (game.can_claim_draw ())
+                present_claim_draw_dialog ();
 
-            if (move.piece.color != opponent.color && !starting)
-                opponent_engine.move ();
-        }
+            if (opponent_engine != null)
+            {
+                opponent_engine.report_move (move);
+
+                if (move.piece.color != opponent.color && !starting && game.is_started)
+                    opponent_engine.move ();
+            }
+
+            return Source.REMOVE;
+        });
     }
 
     private void game_undo_cb (ChessGame game)


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