gtk-demo: Make losing games hurt

Use a more annoying sound for losses.
And use it for all games.
This commit is contained in:
Matthias Clasen 2022-09-09 15:36:31 -04:00
parent d7817e6fc6
commit 681ec04b85
3 changed files with 23 additions and 9 deletions

View File

@ -8,6 +8,7 @@
* to implement rather different interaction behavior to a typical list.
*/
#include "config.h"
#include <glib/gi18n.h>
#include <gtk/gtk.h>
@ -375,6 +376,23 @@ sweeper_game_init (SweeperGame *self)
sweeper_game_new_game (self, 8, 8, 10);
}
static void
celebrate (gboolean win)
{
char *path;
GtkMediaStream *stream;
if (win)
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "complete.oga", NULL);
else
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "suspend-error.oga", NULL);
stream = gtk_media_file_new_for_filename (path);
gtk_media_stream_set_volume (stream, 1.0);
gtk_media_stream_play (stream);
g_signal_connect (stream, "notify::ended", G_CALLBACK (g_object_unref), NULL);
g_free (path);
}
static void
sweeper_game_end (SweeperGame *self,
gboolean win)
@ -383,7 +401,9 @@ sweeper_game_end (SweeperGame *self,
{
self->playing = FALSE;
g_object_notify_by_pspec (G_OBJECT (self), game_properties[GAME_PROP_PLAYING]);
celebrate (win);
}
if (self->win != win)
{
self->win = win;

View File

@ -119,12 +119,6 @@ solitaire_peg_new (void)
/*** Helper for finding a win ***/
static void
ended (GObject *object)
{
g_object_unref (object);
}
static void
celebrate (gboolean win)
{
@ -134,12 +128,12 @@ celebrate (gboolean win)
if (win)
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "complete.oga", NULL);
else
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "dialog-error.oga", NULL);
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "suspend-error.oga", NULL);
stream = gtk_media_file_new_for_filename (path);
gtk_media_stream_set_volume (stream, 1.0);
gtk_media_stream_play (stream);
g_signal_connect (stream, "notify::ended", G_CALLBACK (ended), NULL);
g_signal_connect (stream, "notify::ended", G_CALLBACK (g_object_unref), NULL);
g_free (path);
}

View File

@ -40,7 +40,7 @@ celebrate (gboolean win)
if (win)
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "complete.oga", NULL);
else
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "dialog-error.oga", NULL);
path = g_build_filename (GTK_DATADIR, "sounds", "freedesktop", "stereo", "suspend-error.oga", NULL);
stream = gtk_media_file_new_for_filename (path);
gtk_media_stream_set_volume (stream, 1.0);
gtk_media_stream_play (stream);