[gnome-nibbles] Add statusbar. Add countdown. Start game when countdown expires
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] Add statusbar. Add countdown. Start game when countdown expires
- Date: Mon, 26 Oct 2015 00:16:58 +0000 (UTC)
commit 954fddb71b4b5c0284be9b02e6c73c7fad6ab3ad
Author: Iulian Radu <iulian radu67 gmail com>
Date: Sun Jul 12 21:48:50 2015 +0300
Add statusbar. Add countdown. Start game when countdown expires
data/nibbles.css | 4 ++
data/nibbles.ui | 20 ++++++++-
src/gnome-nibbles.vala | 110 ++++++++++++++++++++++++++---------------------
src/nibbles-game.vala | 2 -
src/nibbles-view.vala | 1 -
5 files changed, 84 insertions(+), 53 deletions(-)
---
diff --git a/data/nibbles.css b/data/nibbles.css
index d941968..a4ddc70 100644
--- a/data/nibbles.css
+++ b/data/nibbles.css
@@ -14,3 +14,7 @@ GtkToggleButton.number-box {
font-size: 5em;
color: rgba(229, 229, 229, 1);
}
+GtkLabel.countdown {
+ font-size: 2em;
+ color: rgba(229, 229, 229, 1);
+}
diff --git a/data/nibbles.ui b/data/nibbles.ui
index 7377d2b..b2a155d 100644
--- a/data/nibbles.ui
+++ b/data/nibbles.ui
@@ -236,7 +236,25 @@
</child>
</object> <!-- End of main_stack -->
<packing>
- <property name="pack-type">end</property>
+ <property name="pack-type">start</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkBox" id="statusbar">
+ <property name="visible">False</property>
+ <!-- <property name="height-request">250</property> -->
+ <property name="halign">center</property>
+ <child>
+ <object class="GtkLabel" id="countdown">
+ <property name="visible">True</property>
+ <property name="label">5</property>
+ <property name="halign">center</property>
+ <style><class name="countdown"/></style>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="pack-type">start</property>
</packing>
</child>
</object> <!-- End of vbox -->
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index a82f3b2..2bfa16b 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -30,14 +30,16 @@ public class Nibbles : Gtk.Application
private Gtk.HeaderBar headerbar;
private Gtk.Stack main_stack;
private Games.GridFrame frame;
-
+ private Gtk.Box statusbar;
+ private Gtk.Label countdown;
private Gee.LinkedList<Gtk.ToggleButton> number_of_players_buttons;
private Gtk.Revealer next_button_revealer;
-
private NibblesView? view;
private NibblesGame? game = null;
+ private const int COUNTDOWN_TIME = 5;
+
private const ActionEntry action_entries[] =
{
{"start-game", start_game_cb},
@@ -107,9 +109,10 @@ public class Nibbles : Gtk.Application
if (settings.get_boolean ("window-is-maximized"))
window.maximize ();
- headerbar = builder.get_object ("headerbar") as Gtk.HeaderBar;
- main_stack = builder.get_object ("main_stack") as Gtk.Stack;
-
+ headerbar = (Gtk.HeaderBar) builder.get_object ("headerbar");
+ main_stack = (Gtk.Stack) builder.get_object ("main_stack");
+ statusbar = (Gtk.Box) builder.get_object ("statusbar");
+ countdown = (Gtk.Label) builder.get_object ("countdown");
number_of_players_buttons = new Gee.LinkedList<Gtk.ToggleButton> ();
for (int i = 0; i < 2; i++)
{
@@ -119,11 +122,43 @@ public class Nibbles : Gtk.Application
}
next_button_revealer = (Gtk.Revealer) builder.get_object ("next_button_revealer");
-
window.set_titlebar (headerbar);
add_window (window);
+ /* Load game */
+ game = new NibblesGame (settings);
+
+ view = new NibblesView (game);
+ view.show ();
+
+ frame = new Games.GridFrame (NibblesGame.WIDTH, NibblesGame.HEIGHT);
+ main_stack.add_named (frame, "frame");
+
+ frame.add (view);
+ frame.show ();
+ // frame.show_all ();
+
+ /* TODO Fix problem and remove this call
+ * For some reason tile_size gets set to 0 after calling
+ * frame.add (view). start_level stays the same
+ */
+ game.load_properties (settings);
+ game.current_level = game.start_level;
+ view.new_level (game.current_level);
+ view.configure_event.connect (configure_event_cb);
+
+ foreach (var worm in game.worms)
+ {
+ var actors = view.worm_actors.get (worm);
+ if (actors.get_stage () == null) {
+ view.stage.add_child (actors);
+ }
+ actors.show ();
+ }
+ game.load_worm_properties (worm_settings);
+
+ /* Check wether to display the first run screen */
var first_run = settings.get_boolean ("first-run");
if (first_run)
show_first_run_screen ();
@@ -183,6 +218,9 @@ public class Nibbles : Gtk.Application
ts_y--;
tile_size = int.min (ts_x, ts_y);
+ if (tile_size == 0 || game.tile_size == 0)
+ return true;
+
if (game.tile_size != tile_size)
{
view.stage.set_size (tile_size * NibblesGame.WIDTH, tile_size * NibblesGame.HEIGHT);
@@ -201,7 +239,22 @@ public class Nibbles : Gtk.Application
private void start_game_cb ()
{
settings.set_boolean ("first-run", false);
- start_game ();
+ game.add_worms ();
+ show_game_view ();
+
+ var seconds = COUNTDOWN_TIME;
+ Timeout.add (1000, () => {
+ countdown.set_label ("%d".printf (seconds));
+ if (seconds == 0)
+ {
+ countdown.hide ();
+ countdown.set_label ("GO!");
+ game.start ();
+ return Source.REMOVE;
+ }
+ seconds--;
+ return Source.CONTINUE;
+ });
}
private void show_first_run_screen ()
@@ -222,48 +275,7 @@ public class Nibbles : Gtk.Application
private void show_game_view ()
{
main_stack.set_visible_child_name ("frame");
- }
-
- private void start_game ()
- {
- if (game != null)
- {
- SignalHandler.disconnect_matched (game, SignalMatchType.DATA, 0, 0, null, null, this);
- }
-
- game = new NibblesGame (settings);
-
- view = new NibblesView (game);
- view.configure_event.connect (configure_event_cb);
-
- frame = new Games.GridFrame (NibblesGame.WIDTH, NibblesGame.HEIGHT);
- main_stack.add_named (frame, "frame");
-
- frame.add (view);
- frame.show_all ();
-
- /* TODO Fix problem and remove this call
- * For some reason tile_size gets set to 0 after calling
- * frame.add (view). start_level stays the same
- */
- game.load_properties (settings);
- game.current_level = game.start_level;
- view.new_level (game.current_level);
-
- foreach (var worm in game.worms)
- {
- var actors = view.worm_actors.get (worm);
- if (actors.get_stage () == null) {
- view.stage.add_child (actors);
- }
- actors.show ();
- }
- game.load_worm_properties (worm_settings);
-
- stderr.printf("[Debug] Showing game view\n");
- show_game_view ();
-
- game.start ();
+ statusbar.set_visible (true);
}
private void change_number_of_players_cb (Gtk.ToggleButton button)
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index d9aeeee..f761327 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -62,7 +62,6 @@ public class NibblesGame : Object
public bool fakes = false;
public signal void worm_moved (Worm worm);
-
public signal void bonus_applied (Worm worm);
public Gee.HashMap<Worm, WormProperties?> worm_props;
@@ -80,7 +79,6 @@ public class NibblesGame : Object
public void start ()
{
- add_worms ();
add_bonus (true);
var main_id = Timeout.add (GAMEDELAY * game_speed, main_loop_cb);
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index b9ef044..6834aef 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -372,7 +372,6 @@ public class NibblesView : GtkClutter.Embed
}
}
}
-
stage.add_child (level);
level.set_opacity (0);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]