[gnome-nibbles] Add New Game button on header bar
- From: Iulian Radu <iulianradu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles] Add New Game button on header bar
- Date: Mon, 26 Oct 2015 00:18:49 +0000 (UTC)
commit 5b41887f1b729592ccaa988533355fa112a2e113
Author: Iulian Radu <iulian radu67 gmail com>
Date: Mon Aug 10 16:20:27 2015 +0300
Add New Game button on header bar
data/nibbles.ui | 11 ++++++++++-
src/gnome-nibbles.vala | 22 ++++++++++++++++------
src/nibbles-game.vala | 10 +++++++++-
src/nibbles-view.vala | 22 +++++++++++++++++-----
4 files changed, 52 insertions(+), 13 deletions(-)
---
diff --git a/data/nibbles.ui b/data/nibbles.ui
index fdd1269..f529fd0 100644
--- a/data/nibbles.ui
+++ b/data/nibbles.ui
@@ -1,8 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<object class="GtkHeaderBar" id="headerbar">
+ <property name="visible">True</property>
<property name="title" translatable="yes">Nibbles</property>
<property name="show-close-button">True</property>
+ <child>
+ <object class="GtkButton" id="new_game_button">
+ <property name="visible">False</property>
+ <property name="use-underline">True</property>
+ <property name="label" translatable="yes">_New Game</property>
+ <property name="action-name">app.show-new-game-screen</property>
+ </object>
+ </child>
</object>
<object class="GtkApplicationWindow" id="nibbles-window">
<property name="title" translatable="yes">Nibbles</property>
@@ -26,7 +35,7 @@
<property name="width-request">350</property>
<property name="height-request">350</property>
<child>
- <object class="GtkButton" id="new_game_button">
+ <object class="GtkButton">
<property name="visible">True</property>
<property name="use-underline">True</property>
<property name="label" translatable="yes">Let's _Play</property>
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 5fdd34d..5eec7e7 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -28,6 +28,7 @@ public class Nibbles : Gtk.Application
private Gtk.ApplicationWindow window;
private Gtk.HeaderBar headerbar;
+ private Gtk.Button new_game_button;
private Gtk.Stack main_stack;
private Gtk.Box game_box;
private Games.GridFrame frame;
@@ -40,7 +41,6 @@ public class Nibbles : Gtk.Application
/* Controls screen grids and pixbufs */
private Gtk.Box grids_box;
- private Gee.LinkedList<ControlsGrid> controls_grids;
private Gdk.Pixbuf arrow_pixbuf;
private Gdk.Pixbuf arrow_key_pixbuf;
@@ -126,6 +126,7 @@ public class Nibbles : Gtk.Application
window.maximize ();
headerbar = (Gtk.HeaderBar) builder.get_object ("headerbar");
+ new_game_button = (Gtk.Button) builder.get_object ("new_game_button");
main_stack = (Gtk.Stack) builder.get_object ("main_stack");
game_box = (Gtk.Box) builder.get_object ("game_box");
statusbar_stack = (Gtk.Stack) builder.get_object ("statusbar_stack");
@@ -151,6 +152,7 @@ public class Nibbles : Gtk.Application
view = new NibblesView (game);
view.configure_event.connect (configure_event_cb);
+ view.show ();
frame = new Games.GridFrame (NibblesGame.WIDTH, NibblesGame.HEIGHT);
game_box.pack_start (frame);
@@ -164,7 +166,6 @@ public class Nibbles : Gtk.Application
frame.show ();
/* Controls screen */
- controls_grids = new Gee.LinkedList<ControlsGrid> ();
arrow_pixbuf = view.load_pixmap_file ("arrow.svg", 5 * game.tile_size, 5 * game.tile_size);
arrow_key_pixbuf = view.load_pixmap_file ("arrow-key.svg", 5 * game.tile_size, 5 * game.tile_size);
@@ -175,7 +176,7 @@ public class Nibbles : Gtk.Application
else
show_new_game_screen_cb ();
- window.show_all ();
+ window.show ();
create_scores ();
}
@@ -262,6 +263,7 @@ public class Nibbles : Gtk.Application
view.create_name_labels ();
view.connect_worm_signals ();
+ stderr.printf("[Debug] Here4\n");
foreach (var worm in game.worms)
{
var color = game.worm_props.get (worm).color;
@@ -326,6 +328,10 @@ public class Nibbles : Gtk.Application
private void show_new_game_screen_cb ()
{
+ if (game.is_running)
+ game.stop ();
+
+ new_game_button.hide ();
main_stack.set_visible_child_name ("number_of_players");
}
@@ -345,21 +351,26 @@ public class Nibbles : Gtk.Application
game.create_worms ();
game.load_worm_properties (worm_settings);
+ stderr.printf("[Debug] worms size%d\n", game.worms.size);
+
+ foreach (var grid in grids_box.get_children ())
+ grid.destroy ();
+
foreach (var worm in game.worms)
{
if (worm.is_human)
{
var grid = new ControlsGrid (worm.id, game.worm_props.get (worm), arrow_pixbuf,
arrow_key_pixbuf);
grids_box.add (grid);
- controls_grids.add (grid);
}
}
-
+ stderr.printf("[Debug] Here3\n");
main_stack.set_visible_child_name ("controls");
}
private void show_game_view ()
{
+ new_game_button.show ();
main_stack.set_visible_child_name ("game_box");
}
@@ -407,7 +418,6 @@ public class Nibbles : Gtk.Application
scorecats.add (new Games.Scores.Category ("fast-fakes", "Fast with Fakes"));
scores_context.category_request.connect ((s, key) => {
-
foreach (var cat in scorecats)
{
if (key == cat.key)
diff --git a/src/nibbles-game.vala b/src/nibbles-game.vala
index 43fe8da..0065701 100644
--- a/src/nibbles-game.vala
+++ b/src/nibbles-game.vala
@@ -65,6 +65,8 @@ public class NibblesGame : Object
public int speed = 1;
+ public bool is_running = false;
+
public bool fakes = false;
private uint main_id = 0;
@@ -97,6 +99,7 @@ public class NibblesGame : Object
public void start ()
{
stderr.printf("[Debug] Game started\n");
+ is_running = true;
add_bonus (true);
main_id = Timeout.add (GAMEDELAY * speed, main_loop_cb);
@@ -106,8 +109,10 @@ public class NibblesGame : Object
Source.set_name_by_id (add_bonus_id, "[Nibbles] add_bonus_cb");
}
- private void stop ()
+ public void stop ()
{
+ is_running = false;
+
if (main_id != 0)
{
Source.remove (main_id);
@@ -174,6 +179,8 @@ public class NibblesGame : Object
public void create_worms ()
{
+ worms.clear ();
+
numworms = numai + numhumans;
for (int i = 0; i < numworms; i++)
{
@@ -490,6 +497,7 @@ public class NibblesGame : Object
public void load_worm_properties (Gee.ArrayList<Settings> worm_settings)
{
+ worm_props.clear ();
foreach (var worm in worms)
{
var properties = WormProperties ();
diff --git a/src/nibbles-view.vala b/src/nibbles-view.vala
index 216ae5c..6e0921a 100644
--- a/src/nibbles-view.vala
+++ b/src/nibbles-view.vala
@@ -100,6 +100,11 @@ public class NibblesView : GtkClutter.Embed
error (_("Nibbles couldn't find pixmap file: %s"), filename);
}
+
+ // foreach (var actor in worm_actors.values)
+ // {
+ // actor.destroy ();
+ // }
worm_actors.clear ();
bonus_actors.clear ();
game.boni.reset (game.numworms);
@@ -256,6 +261,13 @@ public class NibblesView : GtkClutter.Embed
int x_pos, y_pos;
GtkClutter.Texture tmp = null;
bool is_wall = true;
+
+ if (level != null)
+ {
+ level.remove_all_children ();
+ stage.remove_child (level);
+ }
+
level = new Clutter.Actor ();
/* Load wall_pixmaps onto the surface */
@@ -388,7 +400,7 @@ public class NibblesView : GtkClutter.Embed
name_labels.add (label);
}
- stage.add_child (name_labels);
+ level.add_child (name_labels);
}
public void connect_worm_signals ()
@@ -552,7 +564,7 @@ public class NibblesView : GtkClutter.Embed
actors.remove_all_children ();
- stage.add_child (group);
+ level.add_child (group);
group.save_easing_state ();
group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_QUAD);
@@ -594,7 +606,7 @@ public class NibblesView : GtkClutter.Embed
texture.set_size (game.tile_size, game.tile_size);
group.add_child (texture);
}
- stage.add_child (group);
+ level.add_child (group);
group.save_easing_state ();
group.set_easing_mode (Clutter.AnimationMode.EASE_OUT_EXPO);
@@ -626,7 +638,7 @@ public class NibblesView : GtkClutter.Embed
actor.set_position (bonus.x * game.tile_size, bonus.y * game.tile_size);
- stage.add_child (actor);
+ level.add_child (actor);
bonus_actors.set (bonus, actor);
}
@@ -636,7 +648,7 @@ public class NibblesView : GtkClutter.Embed
var bonus_actor = bonus_actors.get (bonus);
bonus_actors.unset (bonus);
bonus_actor.hide ();
- stage.remove_child (bonus_actor);
+ level.remove_child (bonus_actor);
}
public void bonus_applied_cb (Worm worm)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]