[gnome-taquin] Add sound.



commit f4ac1cc08f75d75e20402da60b442976937581b2
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Fri Dec 26 03:37:12 2014 +0100

    Add sound.

 COPYING.sounds                    |   10 ++++++++++
 configure.ac                      |    2 ++
 data/Makefile.am                  |    7 +++++++
 data/gameover.ogg                 |  Bin 0 -> 8175 bytes
 data/gnome-taquin.6               |   14 +++++++++++++-
 data/org.gnome.taquin.gschema.xml |   15 ++++++++++-----
 data/sliding-1.ogg                |  Bin 0 -> 5536 bytes
 data/sliding-n.ogg                |  Bin 0 -> 7255 bytes
 data/taquin-menus.ui              |    6 ++++++
 src/Makefile.am                   |    3 +++
 src/config.vapi                   |    1 +
 src/taquin-main.vala              |   30 +++++++++++++++++++++++++++++-
 12 files changed, 81 insertions(+), 7 deletions(-)
---
diff --git a/COPYING.sounds b/COPYING.sounds
new file mode 100644
index 0000000..343e45c
--- /dev/null
+++ b/COPYING.sounds
@@ -0,0 +1,10 @@
+data/sliding-1.ogg
+data/sliding-n.ogg
+    distributed under GPL v. 3 (see COPYING)
+    originated from Wildfire Games’ data of 0 A.D. (under GPL v. 2 or later)
+    originally named “ui_button_click.ogg” and “ui_button_longclick.ogg”
+    see http://trac.wildfiregames.com/browser/ps/trunk/binaries/data/mods/mod/audio/interface/ui?order=name
+
+data/gameover.ogg
+    distributed under GPL v. 3 (see COPYING)
+    originated from GNOME games (under GPL v. 2 or later)
diff --git a/configure.ac b/configure.ac
index 99173cd..caa0434 100644
--- a/configure.ac
+++ b/configure.ac
@@ -20,11 +20,13 @@ dnl ###########################################################################
 GLIB_REQUIRED=2.40.0
 GTK_REQUIRED=3.15.0
 RSVG_REQUIRED=2.32.0
+CANBERRA_GTK_REQUIRED=0.26
 
 PKG_CHECK_MODULES(GNOME_TAQUIN, [
   glib-2.0 >= $GLIB_REQUIRED
   gtk+-3.0 >= $GTK_REQUIRED
   librsvg-2.0 >= $RSVG_REQUIRED
+  libcanberra-gtk3 >= $CANBERRA_GTK_REQUIRED
 ])
 
 AC_PATH_PROG([DESKTOP_FILE_VALIDATE], [desktop-file-validate], [/bin/true])
diff --git a/data/Makefile.am b/data/Makefile.am
index 001df01..4d112a3 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -9,6 +9,12 @@ dist_noinst_DATA = \
        schema-15.png \
        schema-16.png
 
+soundsdir = $(datadir)/gnome-taquin/sounds
+sounds_DATA = \
+       sliding-1.ogg \
+       sliding-n.ogg \
+       gameover.ogg
+
 desktopdir = $(datadir)/applications
 desktop_in_files = gnome-taquin.desktop.in
 desktop_DATA = $(desktop_in_files:.desktop.in=.desktop)
@@ -27,6 +33,7 @@ man_MANS = gnome-taquin.6
 EXTRA_DIST = \
        $(appstream_in_files) \
        $(desktop_in_files) \
+       $(sounds_DATA) \
        $(gsettings_SCHEMAS) \
        $(man_MANS)
 
diff --git a/data/gameover.ogg b/data/gameover.ogg
new file mode 100644
index 0000000..4858088
Binary files /dev/null and b/data/gameover.ogg differ
diff --git a/data/gnome-taquin.6 b/data/gnome-taquin.6
index 6240cf8..b162aa5 100644
--- a/data/gnome-taquin.6
+++ b/data/gnome-taquin.6
@@ -46,7 +46,19 @@ You should only use one of these options at the same time.
 .B \-s, \-\-size=<size>
 Sets the puzzle edges' size.
 .br
-It accepts value from 2 to 9; 2 is for debug only.
+The game is intended to be played in size 3 to 5.
+.br
+It accepts value from 2 to 9; 2 is for debug only,
+whereas 6 or more sizes are just not verified working.
+.PP
+.B \-\-mute
+.br
+.B \-\-unmute
+.RS 7
+Turn off/on the sound.
+.br
+If the two options are given, the game is muted.
+.RE
 .TP
 .B \-v, \-\-version
 Prints the program version and exits.
diff --git a/data/org.gnome.taquin.gschema.xml b/data/org.gnome.taquin.gschema.xml
index b9a6d0f..b11c631 100644
--- a/data/org.gnome.taquin.gschema.xml
+++ b/data/org.gnome.taquin.gschema.xml
@@ -8,17 +8,22 @@
     <key name="type" enum="org.gnome.taquin.GameType">
       <default>'fifteen'</default>
     </key>
-    <key name="theme" type="s">
-      <default>'cats'</default>
-      <summary>Name of the theme folder.</summary>
-      <description>Taquin has two default themes: 'cats' and 'numbers'.</description>
-    </key>
     <key name="size" type="i">
       <default>4</default>
       <range min="2" max="9"/>
       <summary>Number of tiles on each edge.</summary>
       <description>The game is tested and offers to select a size from 3 to 5. There is a 
human-understandable maximum value to avoid some bugs. Maximum size is 9 as the image files are randomly 
selected depending on the first character of their filename.</description>
     </key>
+    <key name="theme" type="s">
+      <default>'cats'</default>
+      <summary>Name of the theme folder.</summary>
+      <description>Taquin has two default themes: 'cats' and 'numbers'.</description>
+    </key>
+    <key name="sound" type="b">
+      <default>true</default>
+      <summary>Sound</summary>
+      <description>Whether or not to play event sounds.</description>
+    </key>
     <key name="window-width" type="i">
       <default>540</default>
       <summary>Width of the window in pixels.</summary>
diff --git a/data/sliding-1.ogg b/data/sliding-1.ogg
new file mode 100644
index 0000000..3037f82
Binary files /dev/null and b/data/sliding-1.ogg differ
diff --git a/data/sliding-n.ogg b/data/sliding-n.ogg
new file mode 100644
index 0000000..90604f4
Binary files /dev/null and b/data/sliding-n.ogg differ
diff --git a/data/taquin-menus.ui b/data/taquin-menus.ui
index c4b3e78..2bba404 100644
--- a/data/taquin-menus.ui
+++ b/data/taquin-menus.ui
@@ -4,6 +4,12 @@
   <menu id="app-menu">
     <section>
       <item>
+        <attribute name="label" translatable="yes">_Sound</attribute>
+        <attribute name="action">app.sound</attribute>
+      </item>
+    </section>
+    <section>
+      <item>
         <attribute name="label" translatable="yes">_Help</attribute>
         <attribute name="action">app.help</attribute>
       </item>
diff --git a/src/Makefile.am b/src/Makefile.am
index 698fc49..d5c139f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -13,6 +13,7 @@ gnome_taquin_CFLAGS = \
        -DVERSION=\"$(VERSION)\" \
        -DGETTEXT_PACKAGE=\"$(GETTEXT_PACKAGE)\" \
        -DDATA_DIRECTORY=\"$(datadir)/gnome-taquin\" \
+       -DSOUND_DIRECTORY=\"$(datadir)/gnome-taquin/sounds\" \
        -DLOCALEDIR=\"$(datadir)/locale\" \
        -w \
        $(GNOME_TAQUIN_CFLAGS)
@@ -21,6 +22,8 @@ gnome_taquin_VALAFLAGS = \
        --pkg posix \
        --pkg gtk+-3.0 \
        --pkg librsvg-2.0 \
+       --pkg libcanberra \
+       --pkg libcanberra-gtk \
        --target-glib 2.40
 
 gnome_taquin_LDADD = $(GNOME_TAQUIN_LIBS)
diff --git a/src/config.vapi b/src/config.vapi
index a18c12f..fe76ec0 100644
--- a/src/config.vapi
+++ b/src/config.vapi
@@ -21,4 +21,5 @@
 public const string VERSION;
 public const string GETTEXT_PACKAGE;
 public const string DATA_DIRECTORY;
+public const string SOUND_DIRECTORY;
 public const string LOCALEDIR;
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index f79a901..a4ac3fc 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -33,6 +33,7 @@ public class Taquin : Gtk.Application
     private bool type_changed = false;
     private bool size_changed = false;
     private bool theme_changed = false;
+    private static bool? sound = null;
 
     /* Widgets */
     private ApplicationWindow window;
@@ -54,7 +55,9 @@ public class Taquin : Gtk.Application
         /* { "no-gtk", 0, 0, OptionArg.NONE, null, N_("Begins a console game"), null}, TODO */
         { "fifteen", 0, 0, OptionArg.NONE, null, N_("Play the classical 1880s’ 15-puzzle"), null},
         { "sixteen", 0, 0, OptionArg.NONE, null, N_("Try this fun alternative 16-puzzle"), null},
-        { "size", 's', 0, OptionArg.INT, ref tmp_size, N_("Sets the puzzle edges’ size (2-9, 2 for debug 
only)"), null},
+        { "size", 's', 0, OptionArg.INT, ref tmp_size, N_("Sets the puzzle edges’ size (3-5, 2-9 for 
debug)"), null},
+        { "mute", 0, 0, OptionArg.NONE, null, N_("Turn off the sound"), null},
+        { "unmute", 0, 0, OptionArg.NONE, null, N_("Turn on the sound"), null},
         { "version", 'v', 0, OptionArg.NONE, null, N_("Print release version and exit"), null},
         { null }
     };
@@ -115,6 +118,11 @@ public class Taquin : Gtk.Application
         if (tmp_size != 0 && tmp_size < 2)
             tmp_size = 2;
 
+        if (options.contains ("unmute"))
+            sound = true;
+        if (options.contains ("mute"))
+            sound = false;
+
         if (options.contains ("fifteen"))
             tmp_type = "fifteen";
         else if (options.contains ("sixteen"))
@@ -132,6 +140,8 @@ public class Taquin : Gtk.Application
         StyleContext.add_provider_for_screen (Gdk.Screen.get_default (), css_provider, 
STYLE_PROVIDER_PRIORITY_APPLICATION);
 
         settings = new GLib.Settings ("org.gnome.taquin");
+        if (sound != null)
+            settings.set_boolean ("sound", sound);
         if (tmp_size > 1)
             settings.set_int ("size", tmp_size);
         if (tmp_type != null)
@@ -155,6 +165,7 @@ public class Taquin : Gtk.Application
         set_accels_for_action ("app.quit", {"<Primary>q"});
         set_accels_for_action ("win.new-game", {"<Primary>n"});
         set_accels_for_action ("win.undo", {"<Primary>z"});
+        add_action (settings.create_action ("sound"));
 
         headerbar = builder.get_object ("headerbar") as HeaderBar;
         back_button = builder.get_object ("back-button") as Button;
@@ -350,6 +361,7 @@ public class Taquin : Gtk.Application
     private void undo_cb ()
     {
         game.undo ();
+        play_sound ("sliding-1");
     }
 
     private void cannot_undo_more_cb ()
@@ -360,6 +372,7 @@ public class Taquin : Gtk.Application
     {
         headerbar.set_subtitle (null);
         undo_action.set_enabled (true);
+        play_sound ("sliding-1");
     }
     private void cannot_move_cb ()
     {
@@ -369,6 +382,7 @@ public class Taquin : Gtk.Application
     {
         headerbar.set_subtitle (_("Bravo! You finished the game!"));
         undo_action.set_enabled (false);
+        play_sound ("gameover");
     }
 
     /*\
@@ -427,4 +441,18 @@ public class Taquin : Gtk.Application
             warning ("Failed to load images: %s", e.message);
         }
     }
+
+    /*\
+    * * Sound
+    \*/
+
+    private void play_sound (string name)
+    {
+        if (!settings.get_boolean ("sound"))
+            return;
+
+        CanberraGtk.play_for_widget (view, 0,
+                                     Canberra.PROP_MEDIA_NAME, name,
+                                     Canberra.PROP_MEDIA_FILENAME, Path.build_filename (SOUND_DIRECTORY, 
"%s.ogg".printf (name)));
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]