[gbrainy] Add sound support
- From: Jordi Mas <jmas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gbrainy] Add sound support
- Date: Tue, 1 Jan 2013 20:28:42 +0000 (UTC)
commit 4f6acc42589e0cbedb09107780058219808f56f7
Author: Jordi Mas <jmas softcatala org>
Date: Tue Jan 1 21:30:57 2013 +0100
Add sound support
configure.ac | 3 +-
data/Makefile.am | 38 ++++++++++++--------
data/sounds/right.oga | Bin 0 -> 21073 bytes
data/sounds/wrong.oga | Bin 0 -> 12182 bytes
src/Clients/Classical/Dialogs/PreferencesDialog.cs | 3 ++
.../Classical/Dialogs/ui/PreferencesDialog.ui | 37 +++++++++++++------
src/Clients/Classical/gbrainy.cs | 9 +++++
src/Core/Main/Preferences.cs | 2 +
src/Core/Platform/Unix.cs | 14 +++++++
9 files changed, 79 insertions(+), 27 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 67bce28..3d5a4ab 100644
--- a/configure.ac
+++ b/configure.ac
@@ -89,11 +89,12 @@ dnl --- Required libraries
GTKSHARP_REQUIRED=2.10
MONO_REQUIRED=1.1.7
MONO_ADDINS=0.3
+CANBERRA_GTK_REQUIRED=0.26
PKG_CHECK_MODULES(GBRAINY_CORE, mono >= $MONO_REQUIRED)
-
PKG_CHECK_MODULES(GBRAINY, gtk-sharp-2.0 >= $GTKSHARP_REQUIRED)
+PKG_CHECK_MODULES(GBRAINY, libcanberra-gtk >= $CANBERRA_GTK_REQUIRED)
AC_SUBST(GBRAINY_LIBS)
AC_ARG_ENABLE(addins, AC_HELP_STRING([--disable-addins], [Disable mono-addins support]), , enable_addins="yes")
diff --git a/data/Makefile.am b/data/Makefile.am
index 547f89e..244ee78 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -8,7 +8,7 @@ analogiesdir = $(datadir)/games/gbrainy
themesdir = $(datadir)/games/gbrainy
hicolordir = $(datadir)/icons/hicolor
-images = $(datadir)/games/gbrainy
+datafiles = $(datadir)/games/gbrainy
man_MANS = gbrainy.6
@@ -61,6 +61,11 @@ themes_DATA = \
themes/classic_background.svg \
themes/notebook_background.svg
+sounds_files = \
+ sounds/right.oga \
+ sounds/wrong.oga
+
+
install-data-local:
@-$(mkinstalldirs) $(DESTDIR)$(hicolordir)/scalable/apps
$(INSTALL_DATA) $(srcdir)/app-graphics/gbrainy.svg $(DESTDIR)$(hicolordir)/scalable/apps/gbrainy.svg
@@ -70,18 +75,21 @@ install-data-local:
$(INSTALL_DATA) $(srcdir)/app-graphics/gbrainy.png $(DESTDIR)$(hicolordir)/32x32/apps/gbrainy.png
@-$(mkinstalldirs) $(DESTDIR)$(hicolordir)/48x48/apps
$(INSTALL_DATA) $(srcdir)/app-graphics/gbrainy48.png $(DESTDIR)$(hicolordir)/48x48/apps/gbrainy.png
- @-$(mkinstalldirs) $(DESTDIR)$(images)
- $(INSTALL_DATA) $(srcdir)/verbal_analogies.xml $(DESTDIR)$(images)/verbal_analogies.xml
- $(INSTALL_DATA) $(srcdir)/games.xml $(DESTDIR)$(images)/games.xml
- $(INSTALL_DATA) $(srcdir)/game-graphics/clock.svg $(DESTDIR)$(images)/clock.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/family.svg $(DESTDIR)$(images)/family.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/password.svg $(DESTDIR)$(images)/password.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/tennis.svg $(DESTDIR)$(images)/tennis.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/father_son.svg $(DESTDIR)$(images)/father_son.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/money.svg $(DESTDIR)$(images)/money.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/box.svg $(DESTDIR)$(images)/box.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/dartboard.svg $(DESTDIR)$(images)/dartboard.svg
- $(INSTALL_DATA) $(srcdir)/game-graphics/horses_men.svg $(DESTDIR)$(images)/horses_men.svg
+ @-$(mkinstalldirs) $(DESTDIR)$(datafiles)
+ $(INSTALL_DATA) $(srcdir)/verbal_analogies.xml $(DESTDIR)$(datafiles)/verbal_analogies.xml
+ $(INSTALL_DATA) $(srcdir)/games.xml $(DESTDIR)$(datafiles)/games.xml
+ $(INSTALL_DATA) $(srcdir)/game-graphics/clock.svg $(DESTDIR)$(datafiles)/clock.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/family.svg $(DESTDIR)$(datafiles)/family.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/password.svg $(DESTDIR)$(datafiles)/password.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/tennis.svg $(DESTDIR)$(datafiles)/tennis.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/father_son.svg $(DESTDIR)$(datafiles)/father_son.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/money.svg $(DESTDIR)$(datafiles)/money.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/box.svg $(DESTDIR)$(datafiles)/box.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/dartboard.svg $(DESTDIR)$(datafiles)/dartboard.svg
+ $(INSTALL_DATA) $(srcdir)/game-graphics/horses_men.svg $(DESTDIR)$(datafiles)/horses_men.svg
+ $(INSTALL_DATA) $(srcdir)/sounds/right.oga $(DESTDIR)$(datafiles)/right.oga
+ $(INSTALL_DATA) $(srcdir)/sounds/wrong.oga $(DESTDIR)$(datafiles)/wrong.oga
+
gtk_update_icon_cache = gtk-update-icon-cache -f -t $(datadir)/icons/hicolor
@@ -95,7 +103,7 @@ install-data-hook:
fi
uninstall-hook:
- rm -f $(DESTDIR)$(images)/verbal_analogies.xml
+ rm -f $(DESTDIR)$(datafiles)/verbal_analogies.xml
rm -f $(DESTDIR)$(hicolordir)/48x48/apps/gbrainy.png
rm -f $(DESTDIR)$(hicolordir)/32x32/apps/gbrainy.png
rm -f $(DESTDIR)$(hicolordir)/16x16/apps/gbrainy.png
@@ -106,4 +114,4 @@ noinst_DATA =
DISTCLEANFILES = $(desktop_files)
-EXTRA_DIST = $(pixmap_DATA) $(tango_icons) $(man_MANS) $(analogies_DATA) $(desktop_in_files) $(themes_DATA) gbrainy.pc.in
+EXTRA_DIST = $(pixmap_DATA) $(tango_icons) $(man_MANS) $(analogies_DATA) $(desktop_in_files) $(themes_DATA) $(sounds_files) gbrainy.pc.in
diff --git a/data/sounds/right.oga b/data/sounds/right.oga
new file mode 100644
index 0000000..7d34954
Binary files /dev/null and b/data/sounds/right.oga differ
diff --git a/data/sounds/wrong.oga b/data/sounds/wrong.oga
new file mode 100644
index 0000000..734cae7
Binary files /dev/null and b/data/sounds/wrong.oga differ
diff --git a/src/Clients/Classical/Dialogs/PreferencesDialog.cs b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
index 74709c5..58ddf03 100644
--- a/src/Clients/Classical/Dialogs/PreferencesDialog.cs
+++ b/src/Clients/Classical/Dialogs/PreferencesDialog.cs
@@ -39,6 +39,7 @@ namespace gbrainy.Clients.Classical.Dialogs
[GtkBeans.Builder.Object] Gtk.ComboBox themes_combobox;
[GtkBeans.Builder.Object] Gtk.CheckButton englishcheckbutton;
[GtkBeans.Builder.Object] Gtk.CheckButton loadextensionscheckbutton;
+ [GtkBeans.Builder.Object] Gtk.CheckButton usesoundscheckbutton;
const int COLUMN_VALUE = 1;
PlayerHistory history;
@@ -53,6 +54,7 @@ namespace gbrainy.Clients.Classical.Dialogs
colorblindcheckbutton.Active = Preferences.Get <bool> (Preferences.ColorBlindKey);
englishcheckbutton.Active = Preferences.Get <bool> (Preferences.EnglishKey);
loadextensionscheckbutton.Active = Preferences.Get <bool> (Preferences.LoadPlugginsKey);
+ usesoundscheckbutton.Active = Preferences.Get <bool> (Preferences.SoundsKey);
switch ((GameDifficulty) Preferences.Get <int> (Preferences.DifficultyKey)) {
case GameDifficulty.Easy:
@@ -133,6 +135,7 @@ namespace gbrainy.Clients.Classical.Dialogs
Preferences.Set <bool> (Preferences.ColorBlindKey, colorblindcheckbutton.Active);
Preferences.Set <bool> (Preferences.EnglishKey, englishcheckbutton.Active);
Preferences.Set <bool> (Preferences.LoadPlugginsKey, loadextensionscheckbutton.Active);
+ Preferences.Set <bool> (Preferences.SoundsKey, usesoundscheckbutton.Active);
TreeIter iter;
themes_combobox.GetActiveIter (out iter);
diff --git a/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui b/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui
index 99cb227..a3ebbc3 100644
--- a/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui
+++ b/src/Clients/Classical/Dialogs/ui/PreferencesDialog.ui
@@ -38,11 +38,11 @@
<child>
<object class="GtkButton" id="cancelbutton2">
<property name="label">gtk-cancel</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
</object>
<packing>
@@ -54,11 +54,11 @@
<child>
<object class="GtkButton" id="okbutton">
<property name="label">gtk-apply</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_stock">True</property>
<signal name="clicked" handler="OnOK" swapped="no"/>
</object>
@@ -98,10 +98,10 @@
<child>
<object class="GtkCheckButton" id="colorblindcheckbutton">
<property name="label" translatable="yes">Skip games that use colors (for colorblind users)</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
@@ -114,10 +114,10 @@
<child>
<object class="GtkCheckButton" id="englishcheckbutton">
<property name="label" translatable="yes">Force gbrainy to always use English language (ignore translations)</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -129,10 +129,10 @@
<child>
<object class="GtkCheckButton" id="loadextensionscheckbutton">
<property name="label" translatable="yes">Search and load extensions when starting</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="draw_indicator">True</property>
</object>
<packing>
@@ -142,6 +142,21 @@
</packing>
</child>
<child>
+ <object class="GtkCheckButton" id="usesoundscheckbutton">
+ <property name="label" translatable="yes">Enable sounds</property>
+ <property name="use_action_appearance">False</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ <property name="position">4</property>
+ </packing>
+ </child>
+ <child>
<object class="GtkHBox" id="hbox1">
<property name="visible">True</property>
<property name="can_focus">False</property>
@@ -176,7 +191,7 @@
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
- <property name="position">4</property>
+ <property name="position">5</property>
</packing>
</child>
</object>
@@ -209,10 +224,10 @@
<child>
<object class="GtkRadioButton" id="rb_easy">
<property name="label" translatable="yes">Easy</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
@@ -225,10 +240,10 @@
<child>
<object class="GtkRadioButton" id="rb_medium">
<property name="label" translatable="yes">Medium</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">rb_easy</property>
@@ -242,10 +257,10 @@
<child>
<object class="GtkRadioButton" id="rb_master">
<property name="label" translatable="yes">Master</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
<property name="group">rb_easy</property>
@@ -339,10 +354,10 @@
<child>
<object class="GtkCheckButton" id="prefcheckbutton">
<property name="label" translatable="yes">Show a countdown message</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<property name="draw_indicator">True</property>
</object>
@@ -482,11 +497,11 @@
<child>
<object class="GtkButton" id="clear_button">
<property name="label" translatable="yes">Delete Player's Game Session History</property>
+ <property name="use_action_appearance">False</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">False</property>
- <property name="use_action_appearance">False</property>
<property name="use_underline">True</property>
<signal name="clicked" handler="OnCleanHistory" swapped="no"/>
</object>
diff --git a/src/Clients/Classical/gbrainy.cs b/src/Clients/Classical/gbrainy.cs
index 7a79536..6d250be 100644
--- a/src/Clients/Classical/gbrainy.cs
+++ b/src/Clients/Classical/gbrainy.cs
@@ -425,9 +425,13 @@ namespace gbrainy.Clients.Classical
correct = session.ScoreGame (answer_entry.Text);
if (correct)
+ {
answer = Translations.GetString ("Congratulations.");
+ }
else
+ {
answer = Translations.GetString ("Incorrect answer.");
+ }
session.EnableTimer = false;
answer_entry.Text = String.Empty;
@@ -440,6 +444,11 @@ namespace gbrainy.Clients.Classical
ActiveInputControls (true);
next_button.GrabFocus ();
drawing_area.QueueDraw ();
+
+ if (Preferences.Get <bool> (Preferences.SoundsKey))
+ {
+ Unix.PlaySound(app_window.Handle, System.IO.Path.Combine(Defines.DATA_DIR, correct ? "right.oga" : "wrong.oga"));
+ }
}
void OnQuit (object sender, EventArgs args)
diff --git a/src/Core/Main/Preferences.cs b/src/Core/Main/Preferences.cs
index 6b30a0f..2322efb 100644
--- a/src/Core/Main/Preferences.cs
+++ b/src/Core/Main/Preferences.cs
@@ -43,6 +43,7 @@ namespace gbrainy.Core.Main
public const string EnglishKey = "English";
public const string EnglishVersionKey = "EnglishVersion";
public const string LoadPlugginsKey = "LoadExtensions";
+ public const string SoundsKey = "Sounds";
static Preferences ()
{
@@ -141,6 +142,7 @@ namespace gbrainy.Core.Main
defaults.Add (EnglishVersionKey, string.Empty);
defaults.Add (EnglishKey, false.ToString ());
defaults.Add (LoadPlugginsKey, false.ToString ());
+ defaults.Add (SoundsKey, true.ToString ());
}
public static void Load ()
diff --git a/src/Core/Platform/Unix.cs b/src/Core/Platform/Unix.cs
index a9f961c..043e713 100644
--- a/src/Core/Platform/Unix.cs
+++ b/src/Core/Platform/Unix.cs
@@ -42,6 +42,9 @@ namespace gbrainy.Core.Platform
[DllImport("libgtk-win32-2.0-0.dll")]
static extern unsafe bool gtk_show_uri(IntPtr screen, IntPtr uri, uint timestamp, out IntPtr error);
+ [DllImport ("libcanberra-gtk.so")]
+ static extern void ca_gtk_play_for_widget (IntPtr widget, uint id, string name1, string prop1, string name2, string prop2, IntPtr nil);
+
/* Taken from locale.h */
[StructLayout (LayoutKind.Sequential, Pack = 1, Size = 68)]
struct lconv
@@ -112,5 +115,16 @@ namespace gbrainy.Core.Platform
if (error != IntPtr.Zero) throw new GLib.GException (error);
return ret;
}
+
+ public static void PlaySound(IntPtr widget, string filename)
+ {
+ try {
+ ca_gtk_play_for_widget (widget, 0, "media.name", filename,
+ "media.filename", filename, IntPtr.Zero);
+ }
+ catch (Exception e) {
+ Console.WriteLine ("Unix.PlaySound. Error {0}", e);
+ }
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]