Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 8867ed39 authored by Yuri Chornoivan's avatar Yuri Chornoivan

Reenable sounds in Kolf

Differential Revision: https://phabricator.kde.org/D16978
parent 9f90efed
......@@ -25,8 +25,6 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
)
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 @@ target_link_libraries(kolfprivate
KF5::DBusAddons
KF5::KDELibs4Support
KF5::KIOCore
# Uncomment when sound is reenabled
# Phonon::phonon4qt5
KF5KDEGames
)
......
......@@ -125,7 +125,11 @@ void Ball::collisionDetect()
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;
......
......@@ -183,12 +183,6 @@ void CanvasItem::save(KConfigGroup *cfgGroup)
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();
......
......@@ -65,13 +65,10 @@ public:
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; }
......
......@@ -445,9 +445,18 @@ void StrokeCircle::paint (QPainter *p, const QStyleOptionGraphicsItem *, QWidget
/////////////////////////////////////////
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 @@ KolfGame::KolfGame(const Kolf::ItemFactory& factory, PlayerList *players, const
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 @@ KolfGame::KolfGame(const Kolf::ItemFactory& factory, PlayerList *players, const
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 @@ KolfGame::KolfGame(const Kolf::ItemFactory& factory, PlayerList *players, const
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 @@ KolfGame::~KolfGame()
}
delete cfg;
#ifdef SOUND
delete m_player;
#endif
}
void KolfGame::setModified(bool mod)
......@@ -1050,13 +1089,11 @@ void KolfGame::timeout()
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::emitMax()
void KolfGame::startBall(const Vector &velocity)
{
playSound("hit");
playSound(Sound::Hit);
emit inPlayStart();
putter->setVisible(false);
......@@ -2243,28 +2279,6 @@ void KolfGame::setSelectedItem(CanvasItem* citem)
}
}
#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;
......
......@@ -20,8 +20,6 @@
#ifndef GAME_H
#define GAME_H
//#define SOUND
#include <kolflib_export.h>
#include "ball.h"
......@@ -29,6 +27,7 @@
#include <QGraphicsView>
#include <KConfigGroup>
#include <KgSound>
class KolfGame;
class KGameRenderer;
......@@ -41,10 +40,6 @@ namespace Tagaro
{
class Board;
}
namespace Phonon
{
class MediaObject;
}
namespace Kolf
{
class ItemFactory;
......@@ -55,6 +50,17 @@ namespace Kolf
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 @@ public:
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 @@ public slots:
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 @@ private:
//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;
......
......@@ -193,7 +193,7 @@ bool Kolf::Puddle::collision(Ball* ball)
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);
......
......@@ -158,7 +158,7 @@ bool Kolf::BlackHole::collision(Ball* ball)
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 @@ bool Kolf::BlackHole::collision(Ball* ball)
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 @@ void Kolf::BlackHole::eject(Ball* ball, double speed)
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 @@ bool Kolf::Cup::collision(Ball* ball)
return true;
//place ball in hole
ball->setState(Holed);
playSound("holed");
game->playSound(Sound::Holed);
ball->setPos(pos());
ball->setVelocity(Vector());
return false;
......
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 )
......@@ -7,5 +7,5 @@ holed.wav
holeinone.wav
KReversi (kdegames/kreversi/sounds/reversi-won.wav)
puddle.wav, wall.wav
puddle.wav, wall.wav, woohoo.wav
Free sounds sites
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment