Cancel move if promotion type selector is closed

https://bugzilla.gnome.org/show_bug.cgi?id=742762
This commit is contained in:
Michael Catanzaro 2015-01-11 11:35:07 -06:00 committed by Sahil Sareen
parent 1f9239ec8c
commit ed9ffc4ba2
2 changed files with 6 additions and 7 deletions

View file

@ -77,7 +77,7 @@ public class ChessScene : Object
private double animation_time; private double animation_time;
public signal bool is_human (ChessPlayer player); public signal bool is_human (ChessPlayer player);
public signal PieceType choose_promotion_type (); public signal PieceType? choose_promotion_type ();
public signal void changed (); public signal void changed ();
public int selected_rank = -1; public int selected_rank = -1;
@ -229,7 +229,9 @@ public class ChessScene : Object
(rank == 0 || rank == 7)) (rank == 0 || rank == 7))
{ {
/* Prompt user for selecting promotion type */ /* Prompt user for selecting promotion type */
PieceType promotion_selection = choose_promotion_type (); PieceType? promotion_selection = choose_promotion_type ();
if (promotion_selection == null)
return;
game.current_player.move_with_coords (selected_rank, game.current_player.move_with_coords (selected_rank,
selected_file, rank, file, true, promotion_selection); selected_file, rank, file, true, promotion_selection);
selected_rank = selected_file = -1; selected_rank = selected_file = -1;

View file

@ -261,7 +261,7 @@ public class ChessApplication : Gtk.Application
window.show (); window.show ();
} }
public PieceType show_promotion_type_selector () public PieceType? show_promotion_type_selector ()
{ {
Gtk.Builder promotion_type_selector_builder; Gtk.Builder promotion_type_selector_builder;
@ -298,7 +298,7 @@ public class ChessApplication : Gtk.Application
promotion_type_selector_builder.connect_signals (this); promotion_type_selector_builder.connect_signals (this);
PieceType selection; PieceType? selection = null;
int choice = promotion_type_selector_dialog.run (); int choice = promotion_type_selector_dialog.run ();
switch (choice) switch (choice)
{ {
@ -314,9 +314,6 @@ public class ChessApplication : Gtk.Application
case PromotionTypeSelected.BISHOP: case PromotionTypeSelected.BISHOP:
selection = PieceType.BISHOP; selection = PieceType.BISHOP;
break; break;
default:
selection = PieceType.QUEEN;
break;
} }
promotion_type_selector_dialog.destroy (); promotion_type_selector_dialog.destroy ();