sound themes
This commit is contained in:
parent
226a8cc017
commit
85aa866e02
22 changed files with 132 additions and 72 deletions
|
@ -640,12 +640,16 @@ SoundSettingsPage::SoundSettingsPage()
|
|||
soundEnabledCheckBox.setChecked(settingsCache->getSoundEnabled());
|
||||
connect(&soundEnabledCheckBox, SIGNAL(stateChanged(int)), settingsCache, SLOT(setSoundEnabled(int)));
|
||||
|
||||
soundPathEdit = new QLineEdit(settingsCache->getSoundPath());
|
||||
soundPathEdit->setReadOnly(true);
|
||||
QPushButton *soundPathClearButton = new QPushButton(deleteIcon, QString());
|
||||
connect(soundPathClearButton, SIGNAL(clicked()), this, SLOT(soundPathClearButtonClicked()));
|
||||
QPushButton *soundPathButton = new QPushButton("...");
|
||||
connect(soundPathButton, SIGNAL(clicked()), this, SLOT(soundPathButtonClicked()));
|
||||
QString themeName = settingsCache->getSoundThemeName();
|
||||
|
||||
QStringList themeDirs = soundEngine->getAvailableThemes().keys();
|
||||
for (int i = 0; i < themeDirs.size(); i++) {
|
||||
themeBox.addItem(themeDirs[i]);
|
||||
if (themeDirs[i] == themeName)
|
||||
themeBox.setCurrentIndex(i);
|
||||
}
|
||||
|
||||
connect(&themeBox, SIGNAL(currentIndexChanged(int)), this, SLOT(themeBoxChanged(int)));
|
||||
connect(&soundTestButton, SIGNAL(clicked()), soundEngine, SLOT(testSound()));
|
||||
|
||||
masterVolumeSlider = new QSlider(Qt::Horizontal);
|
||||
|
@ -657,8 +661,6 @@ SoundSettingsPage::SoundSettingsPage()
|
|||
connect(masterVolumeSlider, SIGNAL(sliderReleased()), soundEngine, SLOT(testSound()));
|
||||
connect(masterVolumeSlider, SIGNAL(valueChanged(int)), settingsCache, SLOT(setMasterVolume(int)));
|
||||
|
||||
|
||||
|
||||
masterVolumeSpinBox = new QSpinBox();
|
||||
masterVolumeSpinBox->setMinimum(0);
|
||||
masterVolumeSpinBox->setMaximum(100);
|
||||
|
@ -672,14 +674,12 @@ SoundSettingsPage::SoundSettingsPage()
|
|||
#endif
|
||||
|
||||
QGridLayout *soundGrid = new QGridLayout;
|
||||
soundGrid->addWidget(&soundEnabledCheckBox, 0, 0, 1, 4);
|
||||
soundGrid->addWidget(&soundEnabledCheckBox, 0, 0, 1, 3);
|
||||
soundGrid->addWidget(&masterVolumeLabel, 1, 0);
|
||||
soundGrid->addWidget(masterVolumeSlider, 1, 1);
|
||||
soundGrid->addWidget(masterVolumeSpinBox, 1, 2);
|
||||
soundGrid->addWidget(&soundPathLabel, 2, 0);
|
||||
soundGrid->addWidget(soundPathEdit, 2, 1);
|
||||
soundGrid->addWidget(soundPathClearButton, 2, 2);
|
||||
soundGrid->addWidget(soundPathButton, 2, 3);
|
||||
soundGrid->addWidget(&themeLabel, 2, 0);
|
||||
soundGrid->addWidget(&themeBox, 2, 1);
|
||||
soundGrid->addWidget(&soundTestButton, 3, 1);
|
||||
|
||||
soundGroupBox = new QGroupBox;
|
||||
|
@ -691,29 +691,20 @@ SoundSettingsPage::SoundSettingsPage()
|
|||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
void SoundSettingsPage::themeBoxChanged(int index)
|
||||
{
|
||||
QStringList themeDirs = soundEngine->getAvailableThemes().keys();
|
||||
if(index >= 0 && index < themeDirs.count())
|
||||
settingsCache->setSoundThemeName(themeDirs.at(index));
|
||||
}
|
||||
|
||||
void SoundSettingsPage::masterVolumeChanged(int value) {
|
||||
masterVolumeSlider->setToolTip(QString::number(value));
|
||||
}
|
||||
|
||||
void SoundSettingsPage::soundPathClearButtonClicked()
|
||||
{
|
||||
soundPathEdit->setText(QString());
|
||||
settingsCache->setSoundPath(QString());
|
||||
}
|
||||
|
||||
void SoundSettingsPage::soundPathButtonClicked()
|
||||
{
|
||||
QString path = QFileDialog::getExistingDirectory(this, tr("Choose path"));
|
||||
if (path.isEmpty())
|
||||
return;
|
||||
|
||||
soundPathEdit->setText(path);
|
||||
settingsCache->setSoundPath(path);
|
||||
}
|
||||
|
||||
void SoundSettingsPage::retranslateUi() {
|
||||
soundEnabledCheckBox.setText(tr("Enable &sounds"));
|
||||
soundPathLabel.setText(tr("Path to sounds directory:"));
|
||||
themeLabel.setText(tr("Current sounds theme:"));
|
||||
soundTestButton.setText(tr("Test system sound engine"));
|
||||
soundGroupBox->setTitle(tr("Sound settings"));
|
||||
#if QT_VERSION < 0x050000
|
||||
|
|
|
@ -174,20 +174,17 @@ public:
|
|||
SoundSettingsPage();
|
||||
void retranslateUi();
|
||||
private:
|
||||
QLabel themeLabel;
|
||||
QComboBox themeBox;
|
||||
QGroupBox *soundGroupBox;
|
||||
QPushButton soundTestButton;
|
||||
QCheckBox soundEnabledCheckBox;
|
||||
QLabel soundPathLabel;
|
||||
QLineEdit *soundPathEdit;
|
||||
QLabel masterVolumeLabel;
|
||||
QSlider *masterVolumeSlider;
|
||||
QSpinBox *masterVolumeSpinBox;
|
||||
signals:
|
||||
void soundPathChanged();
|
||||
private slots:
|
||||
void masterVolumeChanged(int value);
|
||||
void soundPathClearButtonClicked();
|
||||
void soundPathButtonClicked();
|
||||
void themeBoxChanged(int index);
|
||||
};
|
||||
|
||||
class DlgSettings : public QDialog {
|
||||
|
|
|
@ -191,20 +191,6 @@ int main(int argc, char *argv[])
|
|||
qDebug() << "Could not create " + dataDir + "/customsets folder.";
|
||||
}
|
||||
|
||||
if(settingsCache->getSoundPath().isEmpty() || !QDir(settingsCache->getSoundPath()).exists())
|
||||
{
|
||||
QDir tmpDir;
|
||||
|
||||
#ifdef Q_OS_MAC
|
||||
tmpDir = app.applicationDirPath() + "/../Resources/sounds";
|
||||
#elif defined(Q_OS_WIN)
|
||||
tmpDir = app.applicationDirPath() + "/sounds";
|
||||
#else // linux
|
||||
tmpDir = app.applicationDirPath() + "/../share/cockatrice/sounds/";
|
||||
#endif
|
||||
settingsCache->setSoundPath(tmpDir.canonicalPath());
|
||||
}
|
||||
|
||||
if (!settingsValid() || db->getLoadStatus() != Ok) {
|
||||
qDebug("main(): invalid settings or load status");
|
||||
DlgSettings dlgSettings;
|
||||
|
|
|
@ -137,7 +137,6 @@ SettingsCache::SettingsCache()
|
|||
setDeckPath(qApp->applicationDirPath() + "data/decks");
|
||||
setReplaysPath(qApp->applicationDirPath() +"data/replays");
|
||||
setPicsPath(qApp->applicationDirPath() + "data/pics");
|
||||
setSoundPath(qApp->applicationDirPath() +"data/sounds");
|
||||
#endif
|
||||
|
||||
notifyAboutUpdates = settings->value("personal/updatenotification", true).toBool();
|
||||
|
@ -198,7 +197,7 @@ SettingsCache::SettingsCache()
|
|||
zoneViewPileView = settings->value("zoneview/pileview", true).toBool();
|
||||
|
||||
soundEnabled = settings->value("sound/enabled", false).toBool();
|
||||
soundPath = settings->value("sound/path").toString();
|
||||
soundThemeName = settings->value("sound/theme").toString();
|
||||
|
||||
priceTagFeature = settings->value("deckeditor/pricetags", false).toBool();
|
||||
priceTagSource = settings->value("deckeditor/pricetagsource", 0).toInt();
|
||||
|
@ -482,11 +481,11 @@ void SettingsCache::setSoundEnabled(int _soundEnabled)
|
|||
emit soundEnabledChanged();
|
||||
}
|
||||
|
||||
void SettingsCache::setSoundPath(const QString &_soundPath)
|
||||
void SettingsCache::setSoundThemeName(const QString &_soundThemeName)
|
||||
{
|
||||
soundPath = _soundPath;
|
||||
settings->setValue("sound/path", soundPath);
|
||||
emit soundPathChanged();
|
||||
soundThemeName = _soundThemeName;
|
||||
settings->setValue("sound/theme", soundThemeName);
|
||||
emit soundThemeChanged();
|
||||
}
|
||||
|
||||
void SettingsCache::setPriceTagFeature(int _priceTagFeature)
|
||||
|
|
|
@ -39,7 +39,7 @@ signals:
|
|||
void invertVerticalCoordinateChanged();
|
||||
void minPlayersForMultiColumnLayoutChanged();
|
||||
void soundEnabledChanged();
|
||||
void soundPathChanged();
|
||||
void soundThemeChanged();
|
||||
void priceTagFeatureChanged(int enabled);
|
||||
void ignoreUnregisteredUsersChanged();
|
||||
void ignoreUnregisteredUserMessagesChanged();
|
||||
|
@ -81,7 +81,7 @@ private:
|
|||
bool chatHighlightForeground;
|
||||
bool zoneViewSortByName, zoneViewSortByType, zoneViewPileView;
|
||||
bool soundEnabled;
|
||||
QString soundPath;
|
||||
QString soundThemeName;
|
||||
bool priceTagFeature;
|
||||
int priceTagSource;
|
||||
bool ignoreUnregisteredUsers;
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
*/
|
||||
bool getZoneViewPileView() const { return zoneViewPileView; }
|
||||
bool getSoundEnabled() const { return soundEnabled; }
|
||||
QString getSoundPath() const { return soundPath; }
|
||||
QString getSoundThemeName() const { return soundThemeName; }
|
||||
bool getPriceTagFeature() const { return false; /* #859; priceTagFeature;*/ }
|
||||
int getPriceTagSource() const { return priceTagSource; }
|
||||
bool getIgnoreUnregisteredUsers() const { return ignoreUnregisteredUsers; }
|
||||
|
@ -223,7 +223,7 @@ public slots:
|
|||
void setZoneViewSortByType(int _zoneViewSortByType);
|
||||
void setZoneViewPileView(int _zoneViewPileView);
|
||||
void setSoundEnabled(int _soundEnabled);
|
||||
void setSoundPath(const QString &_soundPath);
|
||||
void setSoundThemeName(const QString &_soundThemeName);
|
||||
void setPriceTagFeature(int _priceTagFeature);
|
||||
void setPriceTagSource(int _priceTagSource);
|
||||
void setIgnoreUnregisteredUsers(int _ignoreUnregisteredUsers);
|
||||
|
|
|
@ -1,8 +1,17 @@
|
|||
#include "soundengine.h"
|
||||
#include "settingscache.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFileInfo>
|
||||
#include <QSound>
|
||||
#include <QLibraryInfo>
|
||||
#if QT_VERSION < 0x050000
|
||||
#include <QDesktopServices>
|
||||
#else
|
||||
#include <QStandardPaths>
|
||||
#endif
|
||||
|
||||
#define DEFAULT_THEME_NAME "Default"
|
||||
|
||||
/*
|
||||
fileNames = QStringList()
|
||||
|
@ -26,9 +35,12 @@
|
|||
SoundEngine::SoundEngine(QObject *parent)
|
||||
: QObject(parent), enabled(false)
|
||||
{
|
||||
ensureThemeDirectoryExists();
|
||||
connect(settingsCache, SIGNAL(soundThemeChanged()), this, SLOT(themeChangedSlot()));
|
||||
connect(settingsCache, SIGNAL(soundEnabledChanged()), this, SLOT(soundEnabledChanged()));
|
||||
|
||||
soundEnabledChanged();
|
||||
themeChangedSlot();
|
||||
}
|
||||
|
||||
void SoundEngine::soundEnabledChanged()
|
||||
|
@ -59,7 +71,7 @@ void SoundEngine::playSound(QString fileName)
|
|||
if(!enabled)
|
||||
return;
|
||||
|
||||
QFileInfo fi(settingsCache->getSoundPath() + "/" + fileName + ".wav");
|
||||
QFileInfo fi("sounds:/" + fileName + ".wav");
|
||||
qDebug() << "playing" << fi.absoluteFilePath();
|
||||
if(!fi.exists())
|
||||
return;
|
||||
|
@ -70,4 +82,66 @@ void SoundEngine::playSound(QString fileName)
|
|||
void SoundEngine::testSound()
|
||||
{
|
||||
playSound(TEST_SOUND_FILENAME);
|
||||
}
|
||||
|
||||
void SoundEngine::ensureThemeDirectoryExists()
|
||||
{
|
||||
if(settingsCache->getSoundThemeName().isEmpty() ||
|
||||
!getAvailableThemes().contains(settingsCache->getSoundThemeName()))
|
||||
{
|
||||
qDebug() << "Sounds theme name not set, setting default value";
|
||||
settingsCache->setSoundThemeName(DEFAULT_THEME_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
QStringMap & SoundEngine::getAvailableThemes()
|
||||
{
|
||||
QDir dir;
|
||||
availableThemes.clear();
|
||||
|
||||
// load themes from user profile dir
|
||||
dir =
|
||||
#ifdef PORTABLE_BUILD
|
||||
qApp->applicationDirPath() +
|
||||
#elif QT_VERSION < 0x050000
|
||||
QDesktopServices::storageLocation(QDesktopServices::DataLocation) +
|
||||
#else
|
||||
QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() +
|
||||
#endif
|
||||
"/sounds";
|
||||
|
||||
foreach(QString themeName, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name))
|
||||
{
|
||||
if(!availableThemes.contains(themeName))
|
||||
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
|
||||
}
|
||||
|
||||
// load themes from cockatrice system dir
|
||||
#ifdef Q_OS_MAC
|
||||
dir = qApp->applicationDirPath() + "/../Resources/sounds";
|
||||
#elif defined(Q_OS_WIN)
|
||||
dir = qApp->applicationDirPath() + "/sounds";
|
||||
#else // linux
|
||||
dir = qApp->applicationDirPath() + "/../share/cockatrice/sounds";
|
||||
#endif
|
||||
foreach(QString themeName, dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot, QDir::Name))
|
||||
{
|
||||
if(!availableThemes.contains(themeName))
|
||||
availableThemes.insert(themeName, dir.absoluteFilePath(themeName));
|
||||
}
|
||||
|
||||
return availableThemes;
|
||||
}
|
||||
|
||||
void SoundEngine::themeChangedSlot()
|
||||
{
|
||||
QString themeName = settingsCache->getSoundThemeName();
|
||||
qDebug() << "Sound theme changed:" << themeName;
|
||||
|
||||
QDir dir = getAvailableThemes().value(themeName);
|
||||
|
||||
// resources
|
||||
QStringList resources;
|
||||
resources << dir.absolutePath();
|
||||
QDir::setSearchPaths("sounds", resources);
|
||||
}
|
|
@ -2,16 +2,26 @@
|
|||
#define SOUNDENGINE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QMap>
|
||||
#include <QDir>
|
||||
#include <QString>
|
||||
|
||||
typedef QMap<QString, QString> QStringMap;
|
||||
|
||||
class SoundEngine : public QObject {
|
||||
Q_OBJECT
|
||||
private:
|
||||
bool enabled;
|
||||
private slots:
|
||||
void soundEnabledChanged();
|
||||
public:
|
||||
SoundEngine(QObject *parent = 0);
|
||||
void playSound(QString fileName);
|
||||
QStringMap &getAvailableThemes();
|
||||
private:
|
||||
bool enabled;
|
||||
QStringMap availableThemes;
|
||||
protected:
|
||||
void ensureThemeDirectoryExists();
|
||||
private slots:
|
||||
void soundEnabledChanged();
|
||||
void themeChangedSlot();
|
||||
public slots:
|
||||
void testSound();
|
||||
};
|
||||
|
|
|
@ -1,16 +1,19 @@
|
|||
# CMakeLists for sounds/ directory
|
||||
# CMakeLists for sounds directory
|
||||
#
|
||||
# Installs default sound files
|
||||
# add sounds subfolders
|
||||
|
||||
FILE(GLOB sounds "${CMAKE_CURRENT_SOURCE_DIR}/*.wav")
|
||||
SET(defsounds
|
||||
Default
|
||||
Legacy
|
||||
)
|
||||
|
||||
if(UNIX)
|
||||
if(APPLE)
|
||||
INSTALL(FILES ${sounds} DESTINATION cockatrice.app/Contents/Resources/sounds/)
|
||||
INSTALL(DIRECTORY ${defsounds} DESTINATION cockatrice.app/Contents/Resources/sounds/)
|
||||
else()
|
||||
# Assume linux
|
||||
INSTALL(FILES ${sounds} DESTINATION share/cockatrice/sounds/)
|
||||
INSTALL(DIRECTORY ${defsounds} DESTINATION share/cockatrice/sounds/)
|
||||
endif()
|
||||
elseif(WIN32)
|
||||
INSTALL(FILES ${sounds} DESTINATION sounds/)
|
||||
endif()
|
||||
INSTALL(DIRECTORY ${defsounds} DESTINATION sounds/)
|
||||
endif()
|
||||
|
|
BIN
sounds/Legacy/all_mention.wav
Normal file
BIN
sounds/Legacy/all_mention.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/chat_mention.wav
Normal file
BIN
sounds/Legacy/chat_mention.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/draw_step.wav
Normal file
BIN
sounds/Legacy/draw_step.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/play_card.wav
Normal file
BIN
sounds/Legacy/play_card.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/player_join.wav
Normal file
BIN
sounds/Legacy/player_join.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/private_message.wav
Normal file
BIN
sounds/Legacy/private_message.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/shuffle.wav
Normal file
BIN
sounds/Legacy/shuffle.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/tap_card.wav
Normal file
BIN
sounds/Legacy/tap_card.wav
Normal file
Binary file not shown.
BIN
sounds/Legacy/untap_card.wav
Normal file
BIN
sounds/Legacy/untap_card.wav
Normal file
Binary file not shown.
Loading…
Reference in a new issue