diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,8 +25,6 @@ ) find_package(KF5KDEGames 4.9.0 REQUIRED) -# Uncomment when sound is reenabled -# find_package(Phonon4Qt5 CONFIG REQUIRED) include(FeatureSummary) include(ECMAddAppIcon) @@ -129,8 +127,6 @@ KF5::DBusAddons KF5::KDELibs4Support KF5::KIOCore -# Uncomment when sound is reenabled -# Phonon::phonon4qt5 KF5KDEGames ) diff --git a/ball.cpp b/ball.cpp --- a/ball.cpp +++ b/ball.cpp @@ -125,7 +125,11 @@ foreach (QGraphicsItem* item, items) { if (item->data(0) == Rtti_NoCollision || item->data(0) == Rtti_Putter) + { + if (item->data(0) == Rtti_NoCollision) + game->playSound(Sound::Wall); continue; + } if (!isVisible() || state == Holed) return; diff --git a/canvasitem.h b/canvasitem.h --- a/canvasitem.h +++ b/canvasitem.h @@ -65,13 +65,10 @@ void setId(int newId) { m_id = newId; } int curId() const { return m_id; } - ///Play a sound (e.g. playSound("wall") plays kdedir/share/apps/kolf/sounds/wall.wav). Optionally, specify \a vol to be between 0-1, for no sound to full volume, respectively. - void playSound(const QString &file, double vol = 1); - ///Called on ball's collision. Return if terrain collidingItems should be processed. virtual bool collision(Ball *ball) { Q_UNUSED(ball) return false; } - ///Reimplement if you want extra items to have access to the game object. playSound() relies on having this. + ///Reimplement if you want extra items to have access to the game object. virtual void setGame(KolfGame *game) { this->game = game; } QString name() const { return m_name; } diff --git a/canvasitem.cpp b/canvasitem.cpp --- a/canvasitem.cpp +++ b/canvasitem.cpp @@ -183,12 +183,6 @@ cfgGroup->writeEntry("dummykey", true); } -void CanvasItem::playSound(const QString &file, double vol) -{ - if (game) - game->playSound(file, vol); -} - void CanvasItem::editModeChanged(bool editing) { Kolf::Overlay* overlay = this->overlay(); diff --git a/game.h b/game.h --- a/game.h +++ b/game.h @@ -20,8 +20,6 @@ #ifndef GAME_H #define GAME_H -//#define SOUND - #include #include "ball.h" @@ -29,6 +27,7 @@ #include #include +#include class KolfGame; class KGameRenderer; @@ -41,10 +40,6 @@ { class Board; } -namespace Phonon -{ - class MediaObject; -} namespace Kolf { class ItemFactory; @@ -55,6 +50,17 @@ enum Direction { D_Left, D_Right, Forwards, Backwards }; enum Amount { Amount_Less, Amount_Normal, Amount_More }; +enum class Sound { + BlackHole, + BlackHoleEject, + BlackHolePutIn, + Hit, + Holed, + HoleINone, + Puddle, + Wall, + WooHoo +}; class BallStateInfo { @@ -268,6 +274,7 @@ static void scoresFromSaved(KConfig*, PlayerList &players); static void courseInfo(CourseInfo &info, const QString &filename); + void playSound(Sound soundType); public slots: void pause(); @@ -284,7 +291,6 @@ void firstHole(); void lastHole(); void randHole(); - void playSound(const QString &file, float vol = 1); void showInfoDlg(bool = false); void resetHole(); void clearHole(); @@ -412,11 +418,16 @@ //For intro banner Tagaro::SpriteObjectItem *banner; -#ifdef SOUND - Phonon::MediaObject *m_player; -#endif + KgSound m_soundBlackHole; + KgSound m_soundBlackHoleEject; + KgSound m_soundBlackHolePutIn; + KgSound m_soundHit; + KgSound m_soundHoled; + KgSound m_soundHoleINone; + KgSound m_soundPuddle; + KgSound m_soundWall; + KgSound m_soundWooHoo; bool m_sound; - QString soundDir; bool m_ignoreEvents; diff --git a/game.cpp b/game.cpp --- a/game.cpp +++ b/game.cpp @@ -445,9 +445,18 @@ ///////////////////////////////////////// KolfGame::KolfGame(const Kolf::ItemFactory& factory, PlayerList *players, const QString &filename, QWidget *parent) -: QGraphicsView(parent) -, m_factory(factory) -, holeInfo(g_world) +: QGraphicsView(parent), + m_factory(factory), + m_soundBlackHole(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/blackhole.wav")), + m_soundBlackHoleEject(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/blackholeeject.wav")), + m_soundBlackHolePutIn(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/blackholeputin.wav")), + m_soundHit(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/hit.wav")), + m_soundHoled(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/holed.wav")), + m_soundHoleINone(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/holeinone.wav")), + m_soundPuddle(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/puddle.wav")), + m_soundWall(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/wall.wav")), + m_soundWooHoo(QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds/woohoo.wav")), + holeInfo(g_world) { setRenderHint(QPainter::Antialiasing); // for mouse control @@ -473,7 +482,6 @@ lastDelId = -1; m_showInfo = false; ballStateList.canUndo = false; - soundDir = QStandardPaths::locate(QStandardPaths::AppDataLocation, "sounds", QStandardPaths::LocateDirectory); dontAddStroke = false; addingNewHole = false; scoreboardHoles = 0; @@ -486,10 +494,6 @@ recalcHighestHole = false; banner = 0; -#ifdef SOUND - m_player = Phonon::createPlayer(Phonon::GameCategory); -#endif - holeInfo.setGame(this); holeInfo.setAuthor(i18n("Course Author")); holeInfo.setName(i18n("Course Name")); @@ -602,6 +606,44 @@ putterTimerMsec = 20; } +void KolfGame::playSound(Sound soundType) +{ + if (m_sound) { + switch (soundType) { + case Sound::BlackHole: + m_soundBlackHole.start(); + break; + case Sound::BlackHoleEject: + m_soundBlackHoleEject.start(); + break; + case Sound::BlackHolePutIn: + m_soundBlackHolePutIn.start(); + break; + case Sound::Hit: + m_soundHit.start(); + break; + case Sound::Holed: + m_soundHoled.start(); + break; + case Sound::HoleINone: + m_soundHoleINone.start(); + break; + case Sound::Puddle: + m_soundPuddle.start(); + break; + case Sound::Wall: + m_soundWall.start(); + break; + case Sound::WooHoo: + m_soundWooHoo.start(); + break; + default: + qWarning() << "There was a request to play an unknown sound."; + break; + } + } +} + void KolfGame::startFirstHole(int hole) { if (curHole > 0) // if there was saved game, sync scoreboard @@ -645,9 +687,6 @@ } delete cfg; -#ifdef SOUND - delete m_player; -#endif } void KolfGame::setModified(bool mod) @@ -1050,13 +1089,11 @@ if (curScore == 1) { - playSound("holeinone"); + playSound(Sound::HoleINone); } else if (curScore <= holeInfo.par()) { - // I don't have a sound!! - // *sob* - // playSound("woohoo"); + playSound(Sound::WooHoo); } (*curPlayer).ball()->setZValue((*curPlayer).ball()->zValue() + .1 - (.1)/(curScore)); @@ -1493,8 +1530,7 @@ void KolfGame::startBall(const Vector &velocity) { - playSound("hit"); - + playSound(Sound::Hit); emit inPlayStart(); putter->setVisible(false); @@ -2243,28 +2279,6 @@ } } -#ifdef SOUND -void KolfGame::playSound(const QString& file, float vol) -{ - if (m_sound) - { - QString resFile = soundDir + '/' + file + QString::fromLatin1(".wav"); - - // not needed when all of the files are in the distribution - //if (!QFile::exists(resFile)) - //return; - if (vol > 1) - vol = 1; - m_player->setCurrentSource(resFile); - m_player->play(); - } -} -#else //SOUND -void KolfGame::playSound( const QString&, float ) -{ -} -#endif //SOUND - void HoleInfo::borderWallsChanged(bool yes) { m_borderWalls = yes; diff --git a/landscape.cpp b/landscape.cpp --- a/landscape.cpp +++ b/landscape.cpp @@ -193,7 +193,7 @@ if (!contains(ball->pos() - pos())) return true; //ball is visible and has reached the puddle - playSound("puddle"); + game->playSound(Sound::Puddle); ball->setAddStroke(ball->addStroke() + 1); ball->setPlaceOnGround(true); ball->setVisible(false); diff --git a/objects.cpp b/objects.cpp --- a/objects.cpp +++ b/objects.cpp @@ -158,7 +158,7 @@ if (m_runs > 10 && game && game->isInPlay()) return true; - playSound("blackholeputin"); + game->playSound(Sound::BlackHolePutIn); const double diff = m_maxSpeed - m_minSpeed; const double newSpeed = m_minSpeed + speed / 3.75 * diff; @@ -174,7 +174,7 @@ connect(timer, SIGNAL(eject(Ball*,double)), this, SLOT(eject(Ball*,double))); connect(timer, SIGNAL(halfway()), this, SLOT(halfway())); - playSound("blackhole"); + game->playSound(Sound::BlackHole); return false; } @@ -204,12 +204,12 @@ m_runs++; - playSound("blackholeeject"); + game->playSound(Sound::BlackHoleEject); } void Kolf::BlackHole::halfway() { - playSound("blackhole"); + game->playSound(Sound::BlackHole); } void Kolf::BlackHole::load(KConfigGroup* cfgGroup) @@ -348,7 +348,7 @@ return true; //place ball in hole ball->setState(Holed); - playSound("holed"); + game->playSound(Sound::Holed); ball->setPos(pos()); ball->setVelocity(Vector()); return false; diff --git a/sounds/CMakeLists.txt b/sounds/CMakeLists.txt --- a/sounds/CMakeLists.txt +++ b/sounds/CMakeLists.txt @@ -1 +1 @@ -install( FILES wall.wav puddle.wav holeinone.wav holed.wav blackhole.wav blackholeputin.wav blackholeeject.wav hit.wav DESTINATION ${KDE_INSTALL_DATADIR}/kolf/sounds ) +install( FILES wall.wav puddle.wav holeinone.wav holed.wav blackhole.wav blackholeputin.wav blackholeeject.wav hit.wav woohoo.wav DESTINATION ${KDE_INSTALL_DATADIR}/kolf/sounds ) diff --git a/sounds/FROM b/sounds/FROM --- a/sounds/FROM +++ b/sounds/FROM @@ -7,5 +7,5 @@ holeinone.wav KReversi (kdegames/kreversi/sounds/reversi-won.wav) -puddle.wav, wall.wav +puddle.wav, wall.wav, woohoo.wav Free sounds sites diff --git a/sounds/woohoo.wav b/sounds/woohoo.wav new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@