[lightsoff/wip/gtkview] More refactorings
- From: Robert Roth <robertroth src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [lightsoff/wip/gtkview] More refactorings
- Date: Mon, 16 Jul 2018 23:16:10 +0000 (UTC)
commit b60dd7d754fe1962daea0bcff29595a6b8827a2a
Author: Robert Roth <robert roth off gmail com>
Date: Tue Jul 17 02:15:06 2018 +0300
More refactorings
src/board-view-gtk.vala | 4 ++++
src/game-view-gtk.vala | 6 +++---
src/game-view.vala | 5 ++---
3 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/src/board-view-gtk.vala b/src/board-view-gtk.vala
index 0fce027..e3f5ed4 100644
--- a/src/board-view-gtk.vala
+++ b/src/board-view-gtk.vala
@@ -47,6 +47,7 @@ public class BoardViewGtk : Gtk.Grid, BoardView
}
set_focus_chain (focus_list);
_moves = 0;
+ show_all ();
}
// Pseudorandomly generates and sets the state of each light based on
@@ -57,6 +58,9 @@ public class BoardViewGtk : Gtk.Grid, BoardView
// Toggle a light and those in each cardinal direction around it.
public void toggle_light (int x, int y, bool clicked = true)
{
+ if (!playable)
+ return;
+
@foreach((light) => (light as Gtk.ToggleButton).toggled.disconnect (handle_toggle));
if (x>= size || y >= size || x < 0 || y < 0 )
diff --git a/src/game-view-gtk.vala b/src/game-view-gtk.vala
index b1cdbc7..eac83e6 100644
--- a/src/game-view-gtk.vala
+++ b/src/game-view-gtk.vala
@@ -31,6 +31,7 @@ public class GtkGameView : Gtk.Stack, GameView {
public void board_replaced (BoardViewGtk old_board, BoardViewGtk new_board)
{
@foreach((board) => { if (board != get_visible_child ()) remove(board);});
+ new_board.playable = true;
board_view = new_board;
disconnect(handlers.pop_head());
}
@@ -69,14 +70,13 @@ public class GtkGameView : Gtk.Stack, GameView {
{
var view = new BoardViewGtk ();
view.load_level (level);
- view.game_won.connect (() => GLib.Timeout.add (300, game_won_cb));
+ view.game_won.connect (() => game_won_cb());
view.light_toggled.connect (light_toggled_cb);
view.playable = false;
- view.show_all ();
return view;
}
- public BoardView get_board_view ()
+ public BoardView get_board_view ()
{
return board_view;
}
diff --git a/src/game-view.vala b/src/game-view.vala
index 4e7d945..882f24d 100644
--- a/src/game-view.vala
+++ b/src/game-view.vala
@@ -43,13 +43,12 @@ public interface GameView : GLib.Object {
// The player won the game; create a new board, update the level count,
// and transition between the two boards in a random direction.
- public bool game_won_cb ()
+ public void game_won_cb ()
{
if (is_transitioning ())
- return false;
+ return;
replace_board (get_board_view (), create_board_view (next_level (1)),
GameView.ReplaceStyle.SLIDE_NEXT);
- return false;
}
public void light_toggled_cb ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]