[gnome-games/swell-foop-vala: 1/2] swell-foop: Port to Vala
- From: Robert Ancell <rancell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/swell-foop-vala: 1/2] swell-foop: Port to Vala
- Date: Mon, 27 Feb 2012 04:46:25 +0000 (UTC)
commit c6b07c6de97f7f9fc0fbfc54474dd3941a5f9059
Author: Sophia Yu <sophia receiving gmail com>
Date: Sat Feb 25 20:27:10 2012 +1100
swell-foop: Port to Vala
swell-foop/data/swell-foop.ui | 12 +-
swell-foop/src/About.js | 32 ---
swell-foop/src/Board.js | 308 ----------------------
swell-foop/src/Light.js | 126 ---------
swell-foop/src/Makefile.am | 70 +++---
swell-foop/src/Path.js.in | 1 -
swell-foop/src/Score.js | 151 -----------
swell-foop/src/Settings.js | 157 -----------
swell-foop/src/ThemeLoader.js | 38 ---
swell-foop/src/board-view.vala | 566 ++++++++++++++++++++++++++++++++++++++++
swell-foop/src/main.js | 121 ---------
swell-foop/src/swell-foop.vala | 248 ++++++++++++++++++
12 files changed, 851 insertions(+), 979 deletions(-)
---
diff --git a/swell-foop/data/swell-foop.ui b/swell-foop/data/swell-foop.ui
index 2d36659..97c6597 100644
--- a/swell-foop/data/swell-foop.ui
+++ b/swell-foop/data/swell-foop.ui
@@ -2,7 +2,7 @@
<interface>
<requires lib="gtk+" version="2.14"/>
<object class="GtkWindow" id="game_window">
- <signal name="hide" handler="quit"/>
+ <signal name="hide" handler="quit_cb"/>
<property name="title" translatable="yes">Swell Foop</property>
<property name="icon_name">swell-foop</property>
<property name="resizable">False</property>
@@ -26,7 +26,7 @@
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="new_game_item">
- <signal name="activate" handler="new_game"/>
+ <signal name="activate" handler="new_game_cb"/>
<property name="label">games-new-game</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
@@ -46,7 +46,7 @@
</child>
<child>
<object class="GtkImageMenuItem" id="show_preferences_item">
- <signal name="activate" handler="show_settings"/>
+ <signal name="activate" handler="preferences_cb"/>
<property name="label">gtk-preferences</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
@@ -76,7 +76,7 @@
</child>
<child>
<object class="GtkImageMenuItem" id="quit_item">
- <signal name="activate" handler="quit"/>
+ <signal name="activate" handler="quit_cb"/>
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
@@ -98,7 +98,7 @@
<property name="visible">True</property>
<child>
<object class="GtkImageMenuItem" id="show_help_item">
- <signal name="activate" handler="show_help"/>
+ <signal name="activate" handler="help_cb"/>
<property name="label">games-contents</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
@@ -108,7 +108,7 @@
</child>
<child>
<object class="GtkImageMenuItem" id="show_about_item">
- <signal name="activate" handler="show_about"/>
+ <signal name="activate" handler="about_cb"/>
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="use_underline">True</property>
diff --git a/swell-foop/src/Makefile.am b/swell-foop/src/Makefile.am
index 41a9962..f237f1e 100644
--- a/swell-foop/src/Makefile.am
+++ b/swell-foop/src/Makefile.am
@@ -1,41 +1,33 @@
-swelldir=$(pkgdatadir)/swell-foop
-
-bin_SCRIPTS = swell-foop
-
-swell-foop: swell-foop.in Makefile
- $(AM_V_GEN) $(SED) -e "s|%pkglibdir%|$(pkglibdir)|" -e "s|%pkgdatadir%|$(pkgdatadir)|" $< > $@
- chmod +x $@
-
-swell_DATA = \
- About.js \
- Board.js \
- Light.js \
- main.js \
- Settings.js \
- Score.js \
- Path.js \
- ThemeLoader.js
-
-Path.js: Path.js.in
- $(AM_V_GEN) $(SED) -e "s|%pkgdatadir%|$(pkgdatadir)|" $< > $@
-
-EXTRA_DIST = \
- swell-foop.in \
- About.js \
- Board.js \
- Light.js \
- main.js \
- Settings.js \
- Score.js \
- Path.js.in \
- ThemeLoader.js
-
-CLEANFILES = \
- swell-foop \
- Path.js
-
-DISTCLEANFILES = \
- swell-foop \
- Path.js
+bin_PROGRAMS = swell-foop
+
+swell_foop_SOURCES = \
+ board-view.vala \
+ config.vapi \
+ swell-foop.vala
+
+swell_foop_VALAFLAGS = \
+ --pkg posix \
+ --pkg gmodule-2.0 \
+ --pkg clutter-gtk-1.0 \
+ --vapidir $(top_srcdir)/libgames-support \
+ --pkg GnomeGamesSupport-1.0
+
+swell_foop_CFLAGS = \
+ -I$(top_srcdir)/libgames-support \
+ -DVERSION=\"$(VERSION)\" \
+ -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
+ -DPKGDATADIR=\""$(pkgdatadir)/swell-foop"\" \
+ $(GHTREAD_CFLAGS) \
+ $(GMODULE_CFLAGS) \
+ $(GTK_CFLAGS) \
+ $(CLUTTER_GTK_CFLAGS)
+
+swell_foop_LDADD = \
+ $(top_builddir)/libgames-support/libgames-support.la \
+ $(GTHREAD_LIBS) \
+ $(GMODULE_LIBS) \
+ $(GTK_LIBS) \
+ $(CLUTTER_GTK_LIBS) \
+ $(INTLLIBS)
-include $(top_srcdir)/git.mk
diff --git a/swell-foop/src/board-view.vala b/swell-foop/src/board-view.vala
new file mode 100644
index 0000000..b7f86d1
--- /dev/null
+++ b/swell-foop/src/board-view.vala
@@ -0,0 +1,566 @@
+private class Light : Clutter.Group
+{
+ private Settings settings;
+ private Clutter.Actor on_actor;
+
+ public bool closed = false;
+ public int light_x;
+ public int light_y;
+ public int state;
+ public int tile_size = 50; // TODO make it changable in settings
+ public bool visited = false;
+
+ public Light ( Clutter.Texture on_texture )
+ {
+ settings = new Settings ("org.gnome.swell-foop");
+ on_actor = new Clutter.Clone (on_texture);
+ on_actor.set_size (tile_size, tile_size);
+ on_actor.set_scale_with_gravity (1.0, 1.0, Clutter.Gravity.CENTER);
+
+ opacity = 180;
+ reactive = true;
+
+ set_anchor_point(tile_size / 2, tile_size / 2);
+
+ add_actor(on_actor);
+ }
+
+ public void animate_out (Clutter.Timeline? timeline = null)
+ {
+ animate_with_timeline (Clutter.AnimationMode.LINEAR, timeline,
+ "scale-x", 2.0,
+ "scale-y", 2.0,
+ "opacity", 0
+ );
+
+ timeline.completed.connect (hide_light_cb);
+ }
+
+ public void animate_to (double new_x, double new_y, Clutter.Timeline timeline)
+ {
+ var anim_mode = settings.get_boolean("zealous") ?
+ Clutter.AnimationMode.EASE_OUT_BOUNCE :
+ Clutter.AnimationMode.EASE_OUT_QUAD;
+ animate_with_timeline (anim_mode, timeline, "x", new_x, "y", new_y);
+ }
+
+ public void close_tile (Clutter.Timeline timeline)
+ {
+ closed = true;
+ animate_out (timeline);
+ }
+
+ public void hide_light_cb ()
+ {
+ this.hide();
+ }
+}
+
+public class ScoreView : Clutter.Group
+{
+ private Clutter.Text label;
+
+ public ScoreView (double x, double y)
+ {
+ label = new Clutter.Text ();
+ label.set_color (Clutter.Color.from_string ("rgba(255, 255, 255, 255)"));
+
+ this.anchor_gravity = Clutter.Gravity.CENTER;
+ this.add_actor (label);
+ label.show ();
+
+ this.x = (float)x;
+ this.y = (float)y;
+ }
+
+ public void hide_score_cb (Clutter.Timeline timeline)
+ {
+ this.hide ();
+ }
+
+ public void animate_score (uint points)
+ {
+ if (points <= 0)
+ return;
+
+ label.set_font_name ("Bitstrem Vera Sans Bold 40");
+ label.set_text("+" + points.to_string());
+
+ var a = this.animate (Clutter.AnimationMode.EASE_OUT_SINE, 600,
+ "depth", 500.0,
+ "opacity", 0);
+
+ a.timeline.completed.connect (hide_score_cb);
+ }
+
+ 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_line_alignment (Pango.Alignment.CENTER);
+
+ this.scale_x = this.scale_y = 0.0;
+
+ var a = this.animate (Clutter.AnimationMode.EASE_OUT_ELASTIC, 2000,
+ scale_x: 1.0,
+ scale_y: 1.0,
+ opacity: 255
+ );
+ }
+}
+
+public struct Size {
+ public string name;
+ public int columns;
+ public int rows;
+}
+
+public class BoardView : Clutter.Group
+{
+ private Settings settings;
+ private Clutter.Texture blue_texture;
+ private Clutter.Texture green_texture;
+ private Clutter.Texture yellow_texture;
+ private Clutter.Texture red_texture;
+ private Clutter.Texture[] textures;
+ private Light[,] lights;
+ private bool animating = false;
+ private Clutter.Timeline anim_timeline;
+ private int rows = 8;
+ private int columns = 8;
+
+ public Size[] sizes;
+
+ /*if(colors < 2 || colors > 4)*/
+ /* colors = default_colors;*/
+ /**/
+ /*if(theme == null)*/
+ /* theme = themes[default_theme];*/
+
+ private uint current_score = 0;
+ private uint highscores;
+
+ public bool playable = true;
+
+ public signal void game_won ();
+
+ public BoardView ()
+ {
+ settings = new Settings ("org.gnome.swell-foop");
+ sizes = new Size[3];
+ sizes[0] = { _("Small"), 6, 5 };
+ sizes[1] = { _("Normal"), 15, 10 };
+ sizes[2] = { _("Large"), 20, 15 };
+
+ /*theme = themes[settings.get_string("theme")];*/
+
+ try
+ {
+ blue_texture = new Clutter.Texture.from_file (Path.build_filename (Config.PKGDATADIR,
+ "themes/shapesandcolors/blue.svg"));
+ green_texture = new Clutter.Texture.from_file (Path.build_filename (Config.PKGDATADIR,
+ "themes/shapesandcolors/green.svg"));
+ yellow_texture = new Clutter.Texture.from_file (Path.build_filename (Config.PKGDATADIR,
+ "themes/shapesandcolors/yellow.svg"));
+ red_texture = new Clutter.Texture.from_file (Path.build_filename (Config.PKGDATADIR,
+ "themes/shapesandcolors/red.svg"));
+ }
+ catch (Clutter.TextureError e)
+ {
+ warning ("Failed to load textures: %s", e.message);
+ }
+
+ blue_texture.hide ();
+ add_actor (blue_texture);
+ green_texture.hide ();
+ add_actor (green_texture);
+ yellow_texture.hide ();
+ add_actor (yellow_texture);
+ red_texture.hide ();
+ add_actor (red_texture);
+
+ textures = new Clutter.Texture [4];
+ textures[0] = blue_texture;
+ textures[1] = green_texture;
+ textures[2] = yellow_texture;
+ textures[3] = red_texture;
+
+ rows = sizes[settings.get_int("size")].rows;
+ columns = sizes[settings.get_int("size")].columns;
+
+ lights = new Light [rows, columns];
+
+ for (var x = 0; x < columns; x++)
+ {
+ for (var y = 0; y < rows; y++)
+ {
+ int state = (int)Math.floor (Random.next_double () * settings.get_int("colors"));
+ var l = new Light ( textures[state] );
+ l.state = state;
+ l.light_x = x;
+ l.light_y = y;
+
+ l.reactive = true;
+
+ float xx, yy;
+ xx = x * l.tile_size + l.tile_size / 2;
+ yy = ( rows - y - 1 ) * l.tile_size + l.tile_size / 2;
+ l.set_position (xx, yy);
+
+ l.button_release_event.connect (remove_region_cb);
+ l.enter_event.connect (light_entered_cb);
+ l.leave_event.connect (light_left_cb);
+
+ lights[y, x] = l;
+ add_actor (l);
+ }
+ }
+
+ this.width = lights[0, 0].tile_size * columns;
+ this.height = lights[0, 0].tile_size * rows;
+
+ /*score = new ScoreView (this.width/2.0, this.height/2.0); */
+ }
+
+ private void done_animating ()
+ {
+ animating = false;
+ }
+
+ private List<Light> _connected_lights (Light li)
+ {
+ var cl = new List<Light> ();
+
+ if (li.visited || li.closed) {
+ return cl;
+ }
+
+ var x = li.light_x;
+ var y = li.light_y;
+
+ li.visited = true;
+
+ cl.append (li);
+
+ var a = new List<Light> ();
+ var b = new List<Light> ();
+ var c = new List<Light> ();
+ var d = new List<Light> ();
+
+ if (lights[y+1, x] != null && (y+1) < rows && (li.state == lights[y+1, x].state))
+ a = _connected_lights (lights[y+1, x]);
+
+ if (lights[y-1, x] != null && (y-1) >= 0 && (li.state == lights[y-1, x].state))
+ b = _connected_lights (lights[y-1, x]);
+
+ if (lights[y, x+1] != null && (x+1) < columns && (li.state == lights[y, x+1].state))
+ c = _connected_lights (lights[y, x+1]);
+
+ if (lights[y, x-1] != null && (x-1) >= 0 && (li.state == lights[y, x-1].state))
+ d = _connected_lights (lights[y, x-1]);
+
+ cl.concat ((owned)a);
+ cl.concat ((owned)b);
+ cl.concat ((owned)c);
+ cl.concat ((owned)d);
+
+ return cl;
+ }
+
+ private List<Light> connected_lights (Light li)
+ {
+ for (int y = 0; y < rows; y++)
+ for (int x = 0; x < columns; x++)
+ if (lights[y, x] != null)
+ lights[y, x].visited = false;
+
+ return _connected_lights (li);
+ }
+
+ private List<Light> light_lights_from (Light li)
+ {
+ var cl = connected_lights (li);
+
+ if (cl.length () < 2) {
+ var e = new List<Light> ();
+ return e;
+ }
+
+ foreach (Light l in cl)
+ l.opacity = 255;
+
+ return cl;
+ }
+
+ private bool light_entered_cb (Clutter.Actor actor, Clutter.CrossingEvent event)
+ {
+ var l = (Light) actor;
+
+ var lights_lit = light_lights_from (l).length ();
+
+ /*var new_score = Score.calculate_score(lights_lit);*/
+ /*var score_string = _("No points");*/
+ /**/
+ /*if(new_score > 0)*/
+ /* score_string = Seed.sprintf(gettext.ngettext("%d point", "%d points", new_score), new_score);*/
+ /**/
+ /*main.message_label.label = score_string;*/
+ /*actor.opacity = 255;*/
+
+ return false;
+ }
+
+ private bool light_left_cb (Clutter.Actor actor, Clutter.CrossingEvent event)
+ {
+ var connected = connected_lights ((Light)actor);
+
+ foreach (Light l in connected)
+ if (!l.closed)
+ l.opacity = 180;
+
+ return false;
+ }
+
+ private bool remove_region_cb (Clutter.Actor actor, Clutter.ButtonEvent event)
+ {
+ if (animating)
+ return false;
+
+ var cl = connected_lights ((Light)actor);
+
+ if (cl.length () < 2)
+ return false;
+
+ /*main.message_label.label = "";*/
+
+ var close_timeline = new Clutter.Timeline (500);
+
+ foreach (Light l in cl)
+ l.close_tile (close_timeline);
+
+ close_timeline.start();
+
+ int real_x = 0;
+
+ animating = true;
+
+ anim_timeline = new Clutter.Timeline (500);
+
+ for (int x = 0; x < columns; x++)
+ {
+ var good_lights = new List<Light> ();
+ var bad_lights = new List<Light> ();
+ Light li;
+
+ for (int y = 0; y < rows; y++)
+ {
+ li = lights[y, x];
+
+ if (li == null)
+ break;
+
+ if (li.closed)
+ bad_lights.append (li);
+ else
+ good_lights.append (li);
+ }
+
+ good_lights.concat ((owned)bad_lights);
+
+ for (int y = 0; y < rows; y++)
+ {
+ lights[y, real_x] = good_lights.nth_data (y);
+ }
+
+ var empty_col = true;
+
+ for (int y = 0; y < rows; y++)
+ {
+ li = lights[y, real_x];
+ if (li == null)
+ break;
+
+ li.light_x = real_x;
+ li.light_y = y;
+
+ var new_x = real_x * li.tile_size + li.tile_size/2.0;
+ var new_y = (rows - y - 1) * li.tile_size + li.tile_size/2.0;
+
+ if (!li.closed && ((new_x != li.x) || (new_y != li.y)))
+ {
+ li.animate_to (new_x, new_y, anim_timeline);
+ }
+
+ if (!li.closed)
+ empty_col = false;
+ }
+
+ if (!empty_col)
+ real_x++;
+ }
+
+ anim_timeline.completed.connect (done_animating);
+ anim_timeline.start ();
+
+ for (; real_x < columns; real_x++)
+ for (int y = 0; y < rows; y++)
+ lights[y, real_x] = null;
+
+ increment_score (cl.length ());
+
+ if (this.has_completed ())
+ game_completed (this.has_won ());
+
+ cl = null;
+
+ return false;
+ }
+
+ public bool has_completed ()
+ {
+ for (int y = 0; y < rows; y++)
+ for (int x = 0; x < columns; x++)
+ {
+ var l = lights[y, x];
+ if (l != null && !l.closed && (connected_lights (l).length () > 1) ) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public bool has_won ()
+ {
+ for (int y = 0; y < rows; y++)
+ for (int x = 0; x < columns; x++)
+ {
+ var l = lights[y, x];
+ if (l != null && !l.closed) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ public bool board_left_cb ()
+ {
+ for (int y = 0; y < rows; y++)
+ for (int x = 0; x < columns; x++)
+ {
+ if (lights[y, x] != null) {
+ lights[y, x].visited = false;
+ lights[y, x].opacity = 180;
+ }
+ }
+
+ return false;
+ }
+
+ public void set_score (uint score)
+ {
+ current_score = score;
+ /*main.score_label.label = Seed.sprintf(_("Score: %d"), current_score);*/
+ }
+
+ public uint calculate_score (uint n_lights)
+ {
+ if (n_lights < 3)
+ return 0;
+
+ return (n_lights - 2) * (n_lights - 2);
+ }
+
+ public void increment_score (uint tiles)
+ {
+ var points_awarded = calculate_score (tiles);
+ var new_score = current_score;
+
+ if (settings.get_boolean("zealous"))
+ {
+ var score_text = new ScoreView (this.width/2.0, this.height/2.0 );
+ this.add_actor (score_text);
+ score_text.animate_score (points_awarded);
+ }
+
+ new_score += points_awarded;
+
+ set_score (new_score);
+ }
+
+ public void game_completed (bool won)
+ {
+ if (won)
+ set_score (current_score + 1000);
+
+ var final_score = new ScoreView (this.width/2.0, this.height/2.0);
+ this.add_actor (final_score);
+ final_score.animate_final_score (current_score);
+ }
+
+ public void new_game ()
+ {
+ remove_all();
+
+ add_actor (blue_texture);
+ green_texture.hide ();
+ add_actor (green_texture);
+ yellow_texture.hide ();
+ add_actor (yellow_texture);
+ red_texture.hide ();
+ add_actor (red_texture);
+
+ set_score (0);
+
+ rows = sizes[settings.get_int("size")].rows;
+ columns = sizes[settings.get_int("size")].columns;
+
+ lights = new Light [rows, columns];
+
+ for (var x = 0; x < columns; x++)
+ {
+ for (var y = 0; y < rows; y++)
+ {
+ int state = (int)Math.floor (Random.next_double () * settings.get_int("colors"));
+ var l = new Light ( textures[state] );
+ l.state = state;
+ l.light_x = x;
+ l.light_y = y;
+
+ l.reactive = true;
+
+ float xx, yy;
+ xx = x * l.tile_size + l.tile_size / 2;
+ yy = ( rows - y - 1 ) * l.tile_size + l.tile_size / 2;
+ l.set_position (xx, yy);
+
+ l.button_release_event.connect (remove_region_cb);
+ l.enter_event.connect (light_entered_cb);
+ l.leave_event.connect (light_left_cb);
+
+ lights[y, x] = l;
+ add_actor (l);
+ }
+ }
+
+ this.width = lights[0, 0].tile_size * columns;
+ this.height = lights[0, 0].tile_size * rows;
+ }
+
+ public void show_scores_dialog ()
+ {
+ /*var highscores_dialog = new GnomeGamesSupport.ScoresDialog.c_new(*/
+ /* main.window, highscores, _("Swell Foop Scores"));*/
+
+ /*highscores_dialog.set_category_description(_("Size:"));*/
+ /* */
+ /*highscores_dialog.run();*/
+ /*highscores_dialog.hide();*/
+ }
+
+ public void update_score_category()
+ {
+ /*highscores.set_category(Settings.sizes[Settings.size].name);*/
+ }
+}
diff --git a/swell-foop/src/swell-foop.vala b/swell-foop/src/swell-foop.vala
new file mode 100644
index 0000000..8fbf713
--- /dev/null
+++ b/swell-foop/src/swell-foop.vala
@@ -0,0 +1,248 @@
+public class SwellFoop
+{
+ private Settings settings;
+ private Gtk.Builder ui;
+ private Gtk.Window window;
+ private BoardView board_view;
+
+ private Gtk.Builder preferences_builder;
+ private Gtk.Dialog? preferences_dialog = null;
+
+ private SwellFoop () throws Error
+ {
+ settings = new Settings ("org.gnome.swell-foop");
+
+ ui = new Gtk.Builder();
+ try
+ {
+ ui.add_from_file (Path.build_filename (Config.PKGDATADIR, "swell-foop.ui"));
+ }
+ catch (Error e)
+ {
+ warning ("Could not load UI: %s", e.message);
+ }
+ ui.connect_signals (this);
+
+ window = (Gtk.Window) ui.get_object ("game_window");
+ window.hide.connect (Gtk.main_quit);
+
+ /*var box = (Gtk.Box) ui.get_object ("game_vbox");*/
+
+ var clutter_embed = (GtkClutter.Embed) ui.get_object("clutter");
+ clutter_embed.show ();
+ /*box.pack_start (clutter_embed, true, true);*/
+ /*var message_label = (Gtk.Label) ui.get_object("message_label");*/
+ /*var score_label = (Gtk.Label) ui.get_object("score_label");*/
+ /*box.pack_start (message_label, true, true);*/
+ /*box.pack_start (score_label, true, true);*/
+
+ var stage = (Clutter.Stage) clutter_embed.get_stage ();
+ /*stage.key_release_event.connect (key_release_event_cb);*/
+ stage.color = Clutter.Color.from_string ("#000000");
+
+ board_view = new BoardView ();
+ stage.add_actor (board_view);
+ board_view.show ();
+
+ stage.set_size (board_view.width, board_view.height);
+ clutter_embed.set_size_request ((int) stage.width, (int) stage.height);
+
+ clutter_embed.leave_notify_event.connect (board_view.board_left_cb);
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT preferences_cb", instance_pos = -1)]
+ public void preferences_cb (Gtk.Widget widget)
+ {
+ /*if (preferences_dialog != null)*/
+ /*{*/
+ /* preferences_dialog.present ();*/
+ /* return;*/
+ /*}*/
+
+ preferences_builder = new Gtk.Builder ();
+ try
+ {
+ preferences_builder.add_from_file (Path.build_filename (Config.PKGDATADIR, "preferences.ui", null));
+ }
+ catch (Error e)
+ {
+ warning ("Could not load preferences UI: %s", e.message);
+ }
+
+ preferences_dialog = (Gtk.Dialog) preferences_builder.get_object ("preferences");
+
+ var theme_combo = (Gtk.ComboBox) preferences_builder.get_object ("theme-selector");
+
+ var size_combo = (Gtk.ComboBoxText) preferences_builder.get_object ("size-selector");
+
+ for ( int i = 0; i < board_view.sizes.length; i++)
+ {
+ size_combo.append_text (board_view.sizes[i].name);
+ }
+
+ // Set current values
+ ((Gtk.ComboBoxText) preferences_builder.get_object ("size-selector")).set_active (settings.get_int ("size"));
+ ((Gtk.SpinButton) preferences_builder.get_object ("colors-spinner")).value = settings.get_int ("colors");
+ ((Gtk.CheckButton) preferences_builder.get_object ("zealous-checkbox")).active = settings.get_boolean ("zealous");
+
+ /*settings_dialog.set_transient_for(main.window);*/
+
+ preferences_builder.connect_signals (this);
+
+ preferences_dialog.present ();
+
+ preferences_dialog.run ();
+ preferences_dialog.destroy ();
+ /*var result = settings_dialog.run();*/
+ /**/
+ /*settings_dialog.destroy();*/
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT select_theme", instance_pos = -1)]
+ public void select_theme (Gtk.Widget widget)
+ {
+ /*new_theme = themes[selector.get_active_text()];*/
+
+ /*if(new_theme == theme)*/
+ /* return;*/
+ /**/
+ /*theme = new_theme;*/
+ /*ThemeLoader.load_theme(main.stage, theme);*/
+ /**/
+ /*settings.set_string("theme", selector.get_active_text()); */
+ /*Watcher.signal.theme_changed.emit();*/
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT set_zealous_animation", instance_pos = -1)]
+ public void set_zealous_animation (Gtk.CheckButton button)
+ {
+ settings.set_boolean("zealous", button.active);
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT update_size", instance_pos = -1)]
+ public void update_size (Gtk.ComboBoxText widget)
+ {
+ int new_size = widget.get_active();
+ /**/
+ /*if(new_size == size)*/
+ /* return;*/
+ /**/
+ /*size = new_size;*/
+ /**/
+ settings.set_int("size", new_size);
+ /*Watcher.signal.size_changed.emit();*/
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT update_colors", instance_pos = -1)]
+ public void update_colors (Gtk.SpinButton button)
+ {
+ int new_colors = (int) button.get_value();
+
+ /*if (new_colors == colors)*/
+ /* return;*/
+
+ /*colors = new_colors;*/
+
+ settings.set_int("colors", new_colors);
+ /*Watcher.signal.colors_changed.emit();*/
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT reset_defaults", instance_pos = -1)]
+ public void reset_defaults (Gtk.Widget widget)
+ {
+ /*print("Not yet implemented.");*/
+ }
+
+ public void show ()
+ {
+ window.show ();
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT new_game_cb", instance_pos = -1)]
+ public void new_game_cb (Gtk.Widget widget)
+ {
+ board_view.new_game();
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT quit_cb", instance_pos = -1)]
+ public void quit_cb (Gtk.Widget widget)
+ {
+ Gtk.main_quit ();
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT help_cb", instance_pos = -1)]
+ public void help_cb (Gtk.Widget widget)
+ {
+ /*GnomeGamesSupport.help_display (window, "swell-foop", null);*/
+ }
+
+ [CCode (cname = "G_MODULE_EXPORT about_cb", instance_pos = -1)]
+ public void about_cb (Gtk.Widget widget)
+ {
+ string[] authors =
+ {
+ "Tim Horton",
+ "Sophia Yu",
+ null
+ };
+
+ string[] artists =
+ {
+ "Tim Horton",
+ null
+ };
+
+ string[] documenters =
+ {
+ /* TODO add documenters */
+ null
+ };
+
+
+ Gtk.show_about_dialog (window,
+ "program-name", _("Swell Foop"),
+ "version", Config.VERSION,
+ "comments",
+ _("I want to play that game! You know, they all light-up and you click on them and they vanish!\n\nSwell Foop is a part of GNOME Games."),
+ "copyright", _("Copyright \xa9 2009 Tim Horton"),
+ "license", GnomeGamesSupport.get_license (_("Swell Foop")),
+ "wrap-license", true,
+ "authors", authors,
+ "artists", artists,
+ "documenters", documenters,
+ "translator-credits", _("translator-credits"),
+ "logo-icon-name", "gnome-swell-foop",
+ "website", "http://www.gnome.org/projects/gnome-games",
+ "website-label", _("GNOME Games web site"),
+ null);
+ }
+
+ public static int main (string[] args)
+ {
+ Environment.set_prgname ("swell-foop");
+
+ if (GtkClutter.init (ref args) != Clutter.InitError.SUCCESS)
+ {
+ warning ("Failed to initialise Clutter");
+ return Posix.EXIT_FAILURE;
+ }
+
+ GnomeGamesSupport.stock_init ();
+
+ SwellFoop app;
+ try
+ {
+ app = new SwellFoop ();
+ app.show ();
+ }
+ catch (Error e)
+ {
+ warning ("Failed to create application: %s", e.message);
+ return Posix.EXIT_FAILURE;
+ }
+
+ Gtk.main ();
+
+ return Posix.EXIT_SUCCESS;
+ }
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]