[gnome-games] swell-foop: Fix clutter initialization and other bugs
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] swell-foop: Fix clutter initialization and other bugs
- Date: Sat, 10 Mar 2012 13:41:52 +0000 (UTC)
commit 1b01b52a43423f213fb78982f779774c6aab9823
Author: Robert Ancell <robert ancell canonical com>
Date: Sat Mar 10 16:22:57 2012 +1100
swell-foop: Fix clutter initialization and other bugs
swell-foop/data/Makefile.am | 10 ++++++++++
swell-foop/src/game-view.vala | 38 +++++++++++++++++++-------------------
swell-foop/src/game.vala | 7 +------
swell-foop/src/swell-foop.vala | 22 ++++++++--------------
4 files changed, 38 insertions(+), 39 deletions(-)
---
diff --git a/swell-foop/data/Makefile.am b/swell-foop/data/Makefile.am
index 16bfc69..29d2d0a 100644
--- a/swell-foop/data/Makefile.am
+++ b/swell-foop/data/Makefile.am
@@ -29,4 +29,14 @@ DISTCLEANFILES = \
@INTLTOOL_SCHEMAS_RULE@
+install-scorefiles-local:
+ -$(mkinstalldirs) $(DESTDIR)$(scoredir)
+ -for i in small normal large; do \
+ touch $(DESTDIR)$(scoredir)/swell-foop.$$i.scores; \
+ chown $(scores_user):$(scores_group) $(DESTDIR)$(scoredir)/swell-foop.$$i.scores; \
+ chmod 664 $(DESTDIR)$(scoredir)/swell-foop.$$i.scores; \
+ done
+
+install-data-local: install-scorefiles-local
+
-include $(top_srcdir)/git.mk
diff --git a/swell-foop/src/game-view.vala b/swell-foop/src/game-view.vala
index 3338835..7f0994a 100644
--- a/swell-foop/src/game-view.vala
+++ b/swell-foop/src/game-view.vala
@@ -8,7 +8,9 @@ public class GameView : Clutter.Group
{
/* A 2D array holding all tiles */
private TileActor[,] tiles;
- private ScoreActor score_text;
+
+ /* Group containing all the actors in the current game */
+ private Clutter.Group? game_actors = null;
/* Game being played */
private Game? _game = null;
@@ -17,6 +19,11 @@ public class GameView : Clutter.Group
get { return _game; }
set
{
+ if (game_actors != null)
+ game_actors.destroy ();
+ game_actors = new Clutter.Group ();
+ add_actor (game_actors);
+
/* Remove old tiles */
remove_tiles ();
@@ -32,12 +39,6 @@ public class GameView : Clutter.Group
width = tile_size * game.columns;
height = tile_size * game.rows;
-
- /* View size may change so we create the object score_text everytime with a new game */
- if (score_text != null)
- score_text.destroy ();
- score_text = new ScoreActor (width / 2.0, height / 2.0);
- add_actor (score_text);
}
}
@@ -118,7 +119,7 @@ public class GameView : Clutter.Group
tile.leave_event.connect (tile_left_cb);
tiles[x, y] = tile;
- add_actor (tile);
+ game_actors.add_actor (tile);
}
}
}
@@ -211,13 +212,19 @@ public class GameView : Clutter.Group
public void update_score_cb (int points_awarded)
{
if (is_zealous)
- score_text.animate_score (points_awarded);
+ {
+ var text = new ScoreActor (width / 2.0, height / 2.0);
+ game_actors.add_actor (text);
+ text.animate_score (points_awarded);
+ }
}
/* Show the final score when the game is over */
public void game_complete_cb ()
{
- score_text.animate_final_score (game.score);
+ var text = new ScoreActor (width / 2.0, height / 2.0);
+ game_actors.add_actor (text);
+ text.animate_final_score (game.score);
}
}
@@ -304,11 +311,6 @@ public class ScoreActor : Clutter.Group
this.y = (float) y;
}
- public void hide_score_cb ()
- {
- hide ();
- }
-
public void animate_score (int points)
{
if (points <= 0)
@@ -319,23 +321,21 @@ public class ScoreActor : Clutter.Group
/* The score will be shown repeatedly therefore we need to reset some important properties
* before the actual animation */
- show ();
opacity = 255;
depth = 0;
var a = animate (Clutter.AnimationMode.EASE_OUT_SINE, 600, "depth", 500.0, "opacity", 0);
- a.timeline.completed.connect (hide_score_cb);
+ a.timeline.completed.connect (() => { destroy (); });
}
public void animate_final_score (uint points)
{
label.set_font_name ("Bitstrem Vera Sans 50");
- label.set_markup ("<b>" + _ ("Game Over!") + "</b>\n" + points.to_string () + _ ("points"));
+ label.set_markup ("<b>" + _("Game Over!") + "</b>\n" + points.to_string () + _ ("points"));
label.set_line_alignment (Pango.Alignment.CENTER);
/* The score will be shown repeatedly therefore we need to reset some important properties
* before the actual animation */
- show ();
opacity = 255;
depth = 0;
diff --git a/swell-foop/src/game.vala b/swell-foop/src/game.vala
index 372a5a6..af2cd78 100644
--- a/swell-foop/src/game.vala
+++ b/swell-foop/src/game.vala
@@ -225,7 +225,7 @@ public class Game : Object
if (this.has_completed ())
{
if (this.has_won ())
- score += 1000;
+ increment_score (1000);
complete ();
}
@@ -282,9 +282,4 @@ public class Game : Object
update_score (points_awarded);
}
-
- public void update_score_category()
- {
- // TODO to be implemented
- }
}
diff --git a/swell-foop/src/swell-foop.vala b/swell-foop/src/swell-foop.vala
index 31aa6dc..785d4ce 100644
--- a/swell-foop/src/swell-foop.vala
+++ b/swell-foop/src/swell-foop.vala
@@ -122,7 +122,7 @@ public class SwellFoop : Gtk.Application
var status_alignment = new Gtk.Alignment (1.0f, 0.5f, 0.0f, 0.0f);
status_alignment.add (status_box);
- status_alignment.show();
+ status_alignment.show ();
var status_item = new Gtk.ToolItem ();
status_item.set_expand (true);
@@ -294,6 +294,7 @@ public class SwellFoop : Gtk.Application
public void set_zealous_animation (Gtk.CheckButton button)
{
settings.set_boolean ("zealous", button.active);
+ view.is_zealous = settings.get_boolean ("zealous");
}
[CCode (cname = "G_MODULE_EXPORT update_size", instance_pos = -1)]
@@ -416,6 +417,12 @@ public class SwellFoop : Gtk.Application
GnomeGamesSupport.scores_startup ();
+ if (GtkClutter.init (ref args) != Clutter.InitError.SUCCESS)
+ {
+ warning ("Failed to initialise Clutter");
+ return Posix.EXIT_FAILURE;
+ }
+
var context = new OptionContext ("");
context.add_group (Gtk.get_option_group (true));
@@ -435,19 +442,6 @@ public class SwellFoop : Gtk.Application
Gtk.Window.set_default_icon_name ("swellfoop");
- try
- {
- GtkClutter.init_with_args (ref args, "", new OptionEntry[0], null);
- }
- catch (Error e)
- {
- var dialog = new Gtk.MessageDialog (null, Gtk.DialogFlags.MODAL, Gtk.MessageType.ERROR, Gtk.ButtonsType.NONE, "Unable to initialize Clutter:\n%s", e.message);
- dialog.set_title (Environment.get_application_name ());
- dialog.run ();
- dialog.destroy ();
- return Posix.EXIT_FAILURE;
- }
-
var app = new SwellFoop ();
return app.run (args);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]