summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS4
-rw-r--r--Doxyfile (renamed from docs/SOURCE/Doxyfile)6
-rw-r--r--data/CMakeLists.txt1
-rw-r--r--data/sfx/CMakeLists.txt1
-rw-r--r--data/sfx/system/CMakeLists.txt5
-rw-r--r--data/sfx/system/newmessage.oggbin0 -> 8194 bytes
-rw-r--r--src/client.cpp3
-rw-r--r--src/client.h9
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/gui/customserverdialog.cpp11
-rw-r--r--src/gui/equipmentwindow.cpp2
-rw-r--r--src/gui/equipmentwindow.h2
-rw-r--r--src/gui/gui.cpp3
-rw-r--r--src/gui/serverdialog.cpp16
-rw-r--r--src/gui/setup_audio.cpp32
-rw-r--r--src/gui/setup_audio.h18
-rw-r--r--src/gui/truetypefont.cpp4
-rw-r--r--src/gui/widgets/chattab.cpp23
-rw-r--r--src/gui/widgets/chattab.h9
-rw-r--r--src/gui/widgets/whispertab.h3
-rw-r--r--src/map.cpp6
-rw-r--r--src/map.h6
-rw-r--r--src/net/serverinfo.h12
-rw-r--r--src/properties.h4
-rw-r--r--src/resources/beinginfo.cpp2
-rw-r--r--src/resources/iteminfo.cpp2
-rw-r--r--src/resources/soundeffect.cpp4
-rw-r--r--src/resources/soundeffect.h3
-rw-r--r--src/resources/userpalette.cpp2
-rw-r--r--src/sound.cpp29
-rw-r--r--src/sound.h9
-rw-r--r--src/utils/stringutils.cpp8
-rw-r--r--src/utils/stringutils.h6
33 files changed, 181 insertions, 65 deletions
diff --git a/AUTHORS b/AUTHORS
index 18b9b653..1a3761e2 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -78,3 +78,7 @@ Jean-Francois Lampron <sull.kf gmail.com>
Rodney Dawes <dobey novell.com>
Ultramichy
Zuzanna K. Filutowska <platyna users.sourceforge.net>
+
+== Sound files ==
+
+data/sfx/system/newmessage.ogg (Psi-IM, GPL)
diff --git a/docs/SOURCE/Doxyfile b/Doxyfile
index 5b5f30f9..f0c02a46 100644
--- a/docs/SOURCE/Doxyfile
+++ b/Doxyfile
@@ -30,7 +30,7 @@ PROJECT_NUMBER =
# If a relative path is entered, it will be relative to the location
# where doxygen was started. If left blank the current directory will be used.
-OUTPUT_DIRECTORY =
+OUTPUT_DIRECTORY = docs/SOURCE
# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
# 4096 sub-directories (in 2 levels) under the output directory of each output
@@ -406,7 +406,7 @@ WARN_FORMAT = "$file:$line: $text"
# and error messages should be written. If left blank the output is written
# to stderr.
-WARN_LOGFILE = "warnings.log"
+WARN_LOGFILE = "docs/SOURCE/warnings.log"
#---------------------------------------------------------------------------
# configuration options related to the input files
@@ -417,7 +417,7 @@ WARN_LOGFILE = "warnings.log"
# directories like "/usr/src/myproject". Separate the files or directories
# with spaces.
-INPUT = "../../src"
+INPUT = "src"
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt
index 4aa0cdd5..e5dd528c 100644
--- a/data/CMakeLists.txt
+++ b/data/CMakeLists.txt
@@ -4,3 +4,4 @@ ADD_SUBDIRECTORY(fonts)
ADD_SUBDIRECTORY(graphics)
ADD_SUBDIRECTORY(help)
ADD_SUBDIRECTORY(icons)
+ADD_SUBDIRECTORY(sfx)
diff --git a/data/sfx/CMakeLists.txt b/data/sfx/CMakeLists.txt
new file mode 100644
index 00000000..e006c71f
--- /dev/null
+++ b/data/sfx/CMakeLists.txt
@@ -0,0 +1 @@
+ADD_SUBDIRECTORY(system)
diff --git a/data/sfx/system/CMakeLists.txt b/data/sfx/system/CMakeLists.txt
new file mode 100644
index 00000000..b19c3e06
--- /dev/null
+++ b/data/sfx/system/CMakeLists.txt
@@ -0,0 +1,5 @@
+SET(FILES
+ newmessage.ogg
+ )
+
+INSTALL(FILES ${FILES} DESTINATION ${DATA_DIR}/sfx/system)
diff --git a/data/sfx/system/newmessage.ogg b/data/sfx/system/newmessage.ogg
new file mode 100644
index 00000000..69b996f7
--- /dev/null
+++ b/data/sfx/system/newmessage.ogg
Binary files differ
diff --git a/src/client.cpp b/src/client.cpp
index 5a9cc726..28affce6 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -380,6 +380,7 @@ Client::Client(const Options &options):
sound.init();
sound.setSfxVolume(config.getIntValue("sfxVolume"));
+ sound.setNotificationsVolume(config.getIntValue("notificationsVolume"));
sound.setMusicVolume(config.getIntValue("musicVolume"));
}
catch (const char *err)
@@ -541,7 +542,7 @@ int Client::exec()
lastTickTime = tick_time;
// Update the screen when application is active, delay otherwise.
- if (SDL_GetAppState() & SDL_APPACTIVE)
+ if (isActive())
{
frame_count++;
gui->draw();
diff --git a/src/client.h b/src/client.h
index 2ee6764c..4ad5562d 100644
--- a/src/client.h
+++ b/src/client.h
@@ -214,6 +214,15 @@ public:
*/
void videoResized(int width, int height);
+ static bool isActive()
+ { return SDL_GetAppState() & SDL_APPACTIVE; }
+
+ static bool hasInputFocus()
+ { return SDL_GetAppState() & SDL_APPINPUTFOCUS; }
+
+ static bool hasMouseFocus()
+ { return SDL_GetAppState() & SDL_APPMOUSEFOCUS; }
+
private:
void initRootDir();
void initHomeDir();
diff --git a/src/defaults.cpp b/src/defaults.cpp
index fea7c435..6c75797d 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -85,6 +85,7 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "hwaccel", false);
AddDEF(configData, "sound", false);
AddDEF(configData, "sfxVolume", 100);
+ AddDEF(configData, "notificationsVolume", 100);
AddDEF(configData, "musicVolume", 60);
AddDEF(configData, "remember", false);
AddDEF(configData, "username", "");
diff --git a/src/gui/customserverdialog.cpp b/src/gui/customserverdialog.cpp
index 9d56a3ce..e0d25928 100644
--- a/src/gui/customserverdialog.cpp
+++ b/src/gui/customserverdialog.cpp
@@ -161,12 +161,10 @@ void CustomServerDialog::action(const gcn::ActionEvent &event)
if (event.getId() == "addServer")
{
// Check the given information
- if (mServerAddressField->getText().empty()
- || mPortField->getText().empty())
+ if (mServerAddressField->getText().empty())
{
OkDialog *dlg = new OkDialog(_("Error"),
- _("Please at least type both the address and the port "
- "of the server."));
+ _("Please type in at least the address of the server."));
dlg->addActionListener(this);
}
else
@@ -178,7 +176,6 @@ void CustomServerDialog::action(const gcn::ActionEvent &event)
serverInfo.name = mNameField->getText();
serverInfo.description = mDescriptionField->getText();
serverInfo.hostname = mServerAddressField->getText();
- serverInfo.port = (short) atoi(mPortField->getText().c_str());
#ifdef MANASERV_SUPPORT
switch (mTypeField->getSelected())
{
@@ -194,6 +191,10 @@ void CustomServerDialog::action(const gcn::ActionEvent &event)
#else
serverInfo.type = ServerInfo::TMWATHENA;
#endif
+ if (mPortField->getText().empty())
+ serverInfo.port = ServerInfo::defaultPortForServerType(serverInfo.type);
+ else
+ serverInfo.port = (short) atoi(mPortField->getText().c_str());
// Tell the server has to be saved
serverInfo.save = true;
diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp
index 4aa76c2f..85a4c766 100644
--- a/src/gui/equipmentwindow.cpp
+++ b/src/gui/equipmentwindow.cpp
@@ -197,7 +197,7 @@ Item *EquipmentWindow::getItem(int x, int y) const
return 0;
}
-const std::string EquipmentWindow::getSlotName(int x, int y) const
+std::string EquipmentWindow::getSlotName(int x, int y) const
{
for (int i = 0; i < mBoxesNumber; ++i)
{
diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h
index 0f1d19fa..29814dc5 100644
--- a/src/gui/equipmentwindow.h
+++ b/src/gui/equipmentwindow.h
@@ -93,7 +93,7 @@ class EquipmentWindow : public Window, public gcn::ActionListener
void mouseMoved(gcn::MouseEvent &event);
Item *getItem(int x, int y) const;
- const std::string getSlotName(int x, int y) const;
+ std::string getSlotName(int x, int y) const;
void setSelected(int index);
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 2f24d009..78fc42fb 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -29,6 +29,7 @@
#include "gui/widgets/window.h"
#include "gui/widgets/windowcontainer.h"
+#include "client.h"
#include "configuration.h"
#include "eventlistener.h"
#include "graphics.h"
@@ -204,7 +205,7 @@ void Gui::draw()
int mouseX, mouseY;
Uint8 button = SDL_GetMouseState(&mouseX, &mouseY);
- if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS || button & SDL_BUTTON(1))
+ if ((Client::hasMouseFocus() || button & SDL_BUTTON(1))
&& mCustomCursor
&& mMouseCursorAlpha > 0.0f)
{
diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp
index 49de7f38..9802224b 100644
--- a/src/gui/serverdialog.cpp
+++ b/src/gui/serverdialog.cpp
@@ -69,18 +69,6 @@ static std::string serverTypeToString(ServerInfo::Type type)
}
}
-static unsigned short defaultPortForServerType(ServerInfo::Type type)
-{
- switch (type)
- {
- default:
- case ServerInfo::TMWATHENA:
- return 6901;
- case ServerInfo::MANASERV:
- return 9601;
- }
-}
-
ServersListModel::ServersListModel(ServerInfos *servers, ServerDialog *parent):
mServers(servers),
mVersionStrings(servers->size(), VersionString(0, "")),
@@ -510,7 +498,7 @@ void ServerDialog::loadServers()
if (server.port == 0)
{
// If no port is given, use the default for the given type
- server.port = defaultPortForServerType(server.type);
+ server.port = ServerInfo::defaultPortForServerType(server.type);
}
}
else if (xmlStrEqual(subNode->name, BAD_CAST "description"))
@@ -563,7 +551,7 @@ void ServerDialog::loadCustomServers()
server.hostname = config.getValue(hostNameKey, "");
server.type = ServerInfo::parseType(config.getValue(typeKey, ""));
- const int defaultPort = defaultPortForServerType(server.type);
+ const int defaultPort = ServerInfo::defaultPortForServerType(server.type);
server.port = (unsigned short) config.getValue(portKey, defaultPort);
server.description = config.getValue(descriptionKey, "");
diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp
index c43210d0..69ee3dc3 100644
--- a/src/gui/setup_audio.cpp
+++ b/src/gui/setup_audio.cpp
@@ -37,31 +37,38 @@
Setup_Audio::Setup_Audio():
mMusicVolume(config.getIntValue("musicVolume")),
mSfxVolume(config.getIntValue("sfxVolume")),
+ mNotificationsVolume(config.getIntValue("notificationsVolume")),
mSoundEnabled(config.getBoolValue("sound")),
mDownloadEnabled(config.getBoolValue("download-music")),
mSoundCheckBox(new CheckBox(_("Sound"), mSoundEnabled)),
mDownloadMusicCheckBox(new CheckBox(_("Download music"), mDownloadEnabled)),
mSfxSlider(new Slider(0, sound.getMaxVolume())),
+ mNotificationsSlider(new Slider(0, sound.getMaxVolume())),
mMusicSlider(new Slider(0, sound.getMaxVolume()))
{
setName(_("Audio"));
setDimension(gcn::Rectangle(0, 0, 250, 200));
gcn::Label *sfxLabel = new Label(_("Sfx volume"));
+ gcn::Label *notificationsLabel = new Label(_("Notifications volume"));
gcn::Label *musicLabel = new Label(_("Music volume"));
mSfxSlider->setActionEventId("sfx");
+ mNotificationsSlider->setActionEventId("notifications");
mMusicSlider->setActionEventId("music");
mSfxSlider->addActionListener(this);
+ mNotificationsSlider->addActionListener(this);
mMusicSlider->addActionListener(this);
mSoundCheckBox->setPosition(10, 10);
mSfxSlider->setValue(mSfxVolume);
+ mNotificationsSlider->setValue(mNotificationsVolume);
mMusicSlider->setValue(mMusicVolume);
mSfxSlider->setWidth(90);
+ mNotificationsSlider->setWidth(90);
mMusicSlider->setWidth(90);
// Do the layout
@@ -71,9 +78,11 @@ Setup_Audio::Setup_Audio():
place(0, 0, mSoundCheckBox);
place(0, 1, mSfxSlider);
place(1, 1, sfxLabel);
- place(0, 2, mMusicSlider);
- place(1, 2, musicLabel);
- place(0, 3, mDownloadMusicCheckBox);
+ place(0, 2, mNotificationsSlider);
+ place(1, 2, notificationsLabel);
+ place(0, 3, mMusicSlider);
+ place(1, 3, musicLabel);
+ place(0, 4, mDownloadMusicCheckBox);
setDimension(gcn::Rectangle(0, 0, 370, 280));
}
@@ -83,6 +92,7 @@ void Setup_Audio::apply()
mSoundEnabled = mSoundCheckBox->isSelected();
mDownloadEnabled = mDownloadMusicCheckBox->isSelected();
mSfxVolume = config.getIntValue("sfxVolume");
+ mNotificationsVolume = config.getIntValue("sfxVolume");
mMusicVolume = config.getIntValue("musicVolume");
config.setValue("sound", mSoundEnabled);
@@ -134,12 +144,20 @@ void Setup_Audio::action(const gcn::ActionEvent &event)
{
if (event.getId() == "sfx")
{
- config.setValue("sfxVolume", (int) mSfxSlider->getValue());
- sound.setSfxVolume((int) mSfxSlider->getValue());
+ int volume = (int) mSfxSlider->getValue();
+ config.setValue("sfxVolume", volume);
+ sound.setSfxVolume(volume);
+ }
+ else if (event.getId() == "notifications")
+ {
+ int volume = (int) mNotificationsSlider->getValue();
+ config.setValue("notificationsVolume", volume);
+ sound.setNotificationsVolume(volume);
}
else if (event.getId() == "music")
{
- config.setValue("musicVolume", (int) mMusicSlider->getValue());
- sound.setMusicVolume((int) mMusicSlider->getValue());
+ int volume = (int) mMusicSlider->getValue();
+ config.setValue("musicVolume", volume);
+ sound.setMusicVolume(volume);
}
}
diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h
index 5477eaad..ac81bdb7 100644
--- a/src/gui/setup_audio.h
+++ b/src/gui/setup_audio.h
@@ -39,11 +39,17 @@ class Setup_Audio : public SetupTab, public gcn::ActionListener
void action(const gcn::ActionEvent &event);
private:
- int mMusicVolume, mSfxVolume;
- bool mSoundEnabled, mDownloadEnabled;
-
- gcn::CheckBox *mSoundCheckBox, *mDownloadMusicCheckBox;
- gcn::Slider *mSfxSlider, *mMusicSlider;
+ int mMusicVolume;
+ int mSfxVolume;
+ int mNotificationsVolume;
+ bool mSoundEnabled;
+ bool mDownloadEnabled;
+
+ gcn::CheckBox *mSoundCheckBox;
+ gcn::CheckBox *mDownloadMusicCheckBox;
+ gcn::Slider *mSfxSlider;
+ gcn::Slider *mNotificationsSlider;
+ gcn::Slider *mMusicSlider;
};
-#endif
+#endif // GUI_SETUP_AUDIO_H
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp
index 5f85ea68..620ba191 100644
--- a/src/gui/truetypefont.cpp
+++ b/src/gui/truetypefont.cpp
@@ -57,7 +57,7 @@ class TextChunk
sdlCol.r = color.r;
sdlCol.g = color.g;
- const char* str = getSafeUtf8String(text);
+ const char *str = getSafeUtf8String(text);
SDL_Surface *surface = TTF_RenderUTF8_Blended(
font, str, sdlCol);
delete[] str;
@@ -179,7 +179,7 @@ int TrueTypeFont::getWidth(const std::string &text) const
}
int w, h;
- const char* str = getSafeUtf8String(text);
+ const char *str = getSafeUtf8String(text);
TTF_SizeUTF8(mFont, str, &w, &h);
delete[] str;
return w;
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index 8642be69..1979ecbd 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -23,9 +23,11 @@
#include "actorspritemanager.h"
#include "chatlogger.h"
+#include "client.h"
#include "commandhandler.h"
#include "configuration.h"
#include "localplayer.h"
+#include "sound.h"
#include "gui/gui.h"
#include "gui/recorder.h"
@@ -237,10 +239,20 @@ void ChatTab::chatLog(std::string line, Own own, bool ignoreRecord)
}
mScrollArea->logic();
+
chatWindow->mRecorder->record(line.substr(3));
- if (this != getTabbedArea()->getSelectedTab() &&
- own != BY_PLAYER)
- setFlash(true);
+
+ if (own != BY_PLAYER)
+ {
+ bool currentTab = getTabbedArea()->getSelectedTab() == this;
+
+ if (!currentTab)
+ setFlash(true);
+
+ if (!(currentTab && Client::hasInputFocus()) && own != BY_SERVER)
+ if (checkNotify(own))
+ sound.playNotification("system/newmessage.ogg");
+ }
}
void ChatTab::chatLog(const std::string &nick, const std::string &msg)
@@ -318,6 +330,11 @@ void ChatTab::handleCommand(const std::string &msg)
commandHandler->handleCommand(msg, this);
}
+bool ChatTab::checkNotify(Own own) const
+{
+ return own == ACT_WHISPER;
+}
+
void ChatTab::getAutoCompleteList(std::vector<std::string> &names) const
{
actorSpriteManager->getPlayerNPCNameLister()->getAutoCompleteList(names);
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index 3796c37b..200ad55a 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -115,6 +115,15 @@ class ChatTab : public Tab, public AutoCompleteLister, public EventListener
virtual void handleCommand(const std::string &msg);
/**
+ * Returns whether a notify sound may be played for the given type of
+ * message. By default, only returns true for inline whispers.
+ *
+ * Is never called for server-messages or when the window has focus
+ * and this is the current tab.
+ */
+ virtual bool checkNotify(Own own) const;
+
+ /**
* Adapts the text format to the current gui opacity,
* for better readability.
*/
diff --git a/src/gui/widgets/whispertab.h b/src/gui/widgets/whispertab.h
index e88d084b..a0dcfc14 100644
--- a/src/gui/widgets/whispertab.h
+++ b/src/gui/widgets/whispertab.h
@@ -57,6 +57,9 @@ class WhisperTab : public ChatTab
void handleCommand(const std::string &msg);
+ bool checkNotify(Own) const
+ { return true; }
+
private:
std::string mNick;
};
diff --git a/src/map.cpp b/src/map.cpp
index 8c748bbc..fa3d9a4c 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -644,12 +644,12 @@ void Map::removeActor(Actors::iterator iterator)
mActors.erase(iterator);
}
-const std::string Map::getMusicFile() const
+std::string Map::getMusicFile() const
{
return getProperty("music");
}
-const std::string Map::getName() const
+std::string Map::getName() const
{
if (hasProperty("name"))
return getProperty("name");
@@ -657,7 +657,7 @@ const std::string Map::getName() const
return getProperty("mapname");
}
-const std::string Map::getFilename() const
+std::string Map::getFilename() const
{
std::string fileName = getProperty("_filename");
int lastSlash = fileName.rfind("/") + 1;
diff --git a/src/map.h b/src/map.h
index 8bd47b45..b7917275 100644
--- a/src/map.h
+++ b/src/map.h
@@ -275,13 +275,13 @@ class Map : public Properties
*/
Vector getTileCenter(int x, int y);
- const std::string getMusicFile() const;
- const std::string getName() const;
+ std::string getMusicFile() const;
+ std::string getName() const;
/**
* Gives the map id based on filepath (ex: 009-1)
*/
- const std::string getFilename() const;
+ std::string getFilename() const;
/**
* Check the current position against surrounding blocking tiles, and
diff --git a/src/net/serverinfo.h b/src/net/serverinfo.h
index e709bed0..8e2ee5b0 100644
--- a/src/net/serverinfo.h
+++ b/src/net/serverinfo.h
@@ -108,6 +108,18 @@ public:
return MANASERV;
return UNKNOWN;
}
+
+ static unsigned short defaultPortForServerType(Type type)
+ {
+ switch (type)
+ {
+ default:
+ case ServerInfo::TMWATHENA:
+ return 6901;
+ case ServerInfo::MANASERV:
+ return 9601;
+ }
+ }
};
typedef std::deque<ServerInfo> ServerInfos;
diff --git a/src/properties.h b/src/properties.h
index b6ef5d80..59318b80 100644
--- a/src/properties.h
+++ b/src/properties.h
@@ -42,8 +42,8 @@ class Properties
* @return the value of the given property or the given default when it
* doesn't exist.
*/
- const std::string getProperty(const std::string &name,
- const std::string &def = "") const
+ std::string getProperty(const std::string &name,
+ const std::string &def = "") const
{
PropertyMap::const_iterator i = mProperties.find(name);
return (i != mProperties.end()) ? i->second : def;
diff --git a/src/resources/beinginfo.cpp b/src/resources/beinginfo.cpp
index 8683e7bc..5a277770 100644
--- a/src/resources/beinginfo.cpp
+++ b/src/resources/beinginfo.cpp
@@ -84,7 +84,7 @@ void BeingInfo::addSound(SoundEvent event, const std::string &filename)
const std::string &BeingInfo::getSound(SoundEvent event) const
{
- static std::string empty("");
+ static const std::string empty;
SoundEvents::const_iterator i = mSounds.find(event);
return (i == mSounds.end()) ? empty :
diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp
index 22be274a..3583bb27 100644
--- a/src/resources/iteminfo.cpp
+++ b/src/resources/iteminfo.cpp
@@ -33,7 +33,7 @@ const std::string &ItemInfo::getSprite(Gender gender) const
}
else
{
- static const std::string empty = "";
+ static const std::string empty;
std::map<int, std::string>::const_iterator i =
mAnimationFiles.find(gender);
diff --git a/src/resources/soundeffect.cpp b/src/resources/soundeffect.cpp
index 91ee1fde..d1b0227b 100644
--- a/src/resources/soundeffect.cpp
+++ b/src/resources/soundeffect.cpp
@@ -44,9 +44,9 @@ Resource *SoundEffect::load(SDL_RWops *rw)
}
}
-bool SoundEffect::play(int loops, int volume)
+bool SoundEffect::play(int loops, int volume, int channel)
{
Mix_VolumeChunk(mChunk, volume);
- return Mix_PlayChannel(-1, mChunk, loops) != -1;
+ return Mix_PlayChannel(channel, mChunk, loops) != -1;
}
diff --git a/src/resources/soundeffect.h b/src/resources/soundeffect.h
index dee8f551..decc60a0 100644
--- a/src/resources/soundeffect.h
+++ b/src/resources/soundeffect.h
@@ -53,11 +53,12 @@ class SoundEffect : public Resource
*
* @param loops Number of times to repeat the playback.
* @param volume Sample playback volume.
+ * @param channel Sample playback channel.
*
* @return <code>true</code> if the playback started properly
* <code>false</code> otherwise.
*/
- virtual bool play(int loops, int volume);
+ bool play(int loops, int volume, int channel = -1);
protected:
SoundEffect(Mix_Chunk *soundEffect): mChunk(soundEffect) {}
diff --git a/src/resources/userpalette.cpp b/src/resources/userpalette.cpp
index 12ea3f8d..073f5b03 100644
--- a/src/resources/userpalette.cpp
+++ b/src/resources/userpalette.cpp
@@ -32,7 +32,7 @@
#include <math.h>
-const std::string ColorTypeNames[] = {
+static const std::string ColorTypeNames[] = {
"ColorBeing",
"ColorPlayer",
"ColorSelf",
diff --git a/src/sound.cpp b/src/sound.cpp
index e8348a40..1af1f136 100644
--- a/src/sound.cpp
+++ b/src/sound.cpp
@@ -31,6 +31,10 @@
#include "resources/resourcemanager.h"
#include "resources/soundeffect.h"
+enum {
+ CHANNEL_NOTIFICATIONS = 0
+};
+
/**
* This will be set to true, when a music can be freed after a fade out
* Currently used by fadeOutCallBack()
@@ -49,6 +53,7 @@ static void fadeOutCallBack()
Sound::Sound():
mInstalled(false),
mSfxVolume(100),
+ mNotificationsVolume(100),
mMusicVolume(60),
mMusic(NULL)
{
@@ -90,8 +95,10 @@ void Sound::init()
}
Mix_AllocateChannels(16);
+ Mix_ReserveChannels(1); // reserve one channel for notification sounds
Mix_VolumeMusic(mMusicVolume);
Mix_Volume(-1, mSfxVolume);
+ Mix_Volume(CHANNEL_NOTIFICATIONS, mNotificationsVolume);
info();
@@ -154,7 +161,18 @@ void Sound::setSfxVolume(int volume)
mSfxVolume = volume;
if (mInstalled)
+ {
Mix_Volume(-1, mSfxVolume);
+ Mix_Volume(CHANNEL_NOTIFICATIONS, mNotificationsVolume);
+ }
+}
+
+void Sound::setNotificationsVolume(int volume)
+{
+ mNotificationsVolume = volume;
+
+ if (mInstalled)
+ Mix_Volume(CHANNEL_NOTIFICATIONS, mNotificationsVolume);
}
static Music *loadMusic(const std::string &fileName)
@@ -281,6 +299,17 @@ void Sound::playSfx(const std::string &path, int x, int y)
}
}
+void Sound::playNotification(const std::string &path)
+{
+ const std::string fullPath = paths.getValue("sfx", "sfx/") + path;
+
+ ResourceManager *resman = ResourceManager::getInstance();
+ if (SoundEffect *sample = resman->getSoundEffect(fullPath))
+ {
+ sample->play(0, 128, CHANNEL_NOTIFICATIONS);
+ }
+}
+
void Sound::close()
{
if (!mInstalled)
diff --git a/src/sound.h b/src/sound.h
index dd368f84..180bca62 100644
--- a/src/sound.h
+++ b/src/sound.h
@@ -92,6 +92,7 @@ class Sound
void setMusicVolume(int volume);
void setSfxVolume(int volume);
+ void setNotificationsVolume(int volume);
/**
* Plays a sound at the specified location.
@@ -103,6 +104,13 @@ class Sound
void playSfx(const std::string &path, int x = 0, int y = 0);
/**
+ * Plays a sound on the notification channel.
+ *
+ * @param path The resource path to the sound file.
+ */
+ void playNotification(const std::string &path);
+
+ /**
* The sound logic.
* Currently used to check whether the music file can be freed after
* a fade out, and whether new music has to be played.
@@ -125,6 +133,7 @@ class Sound
bool mInstalled;
int mSfxVolume;
+ int mNotificationsVolume;
int mMusicVolume;
std::string mCurrentMusicFile;
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 5a51ef66..4f27d41b 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -157,8 +157,8 @@ bool isWordSeparator(char chr)
return (chr == ' ' || chr == ',' || chr == '.' || chr == '"');
}
-const std::string findSameSubstring(const std::string &str1,
- const std::string &str2)
+std::string findSameSubstring(const std::string &str1,
+ const std::string &str2)
{
int minLength = str1.length() > str2.length() ? str2.length() : str1.length();
for (int f = 0; f < minLength; f ++)
@@ -171,9 +171,9 @@ const std::string findSameSubstring(const std::string &str1,
return str1.substr(0, minLength);
}
-const char* getSafeUtf8String(std::string text)
+const char *getSafeUtf8String(const std::string &text)
{
- char* buf = new char[text.size() + UTF8_MAX_SIZE];
+ char *buf = new char[text.size() + UTF8_MAX_SIZE];
memcpy(buf, text.c_str(), text.size());
memset(buf + text.size(), 0, UTF8_MAX_SIZE);
return buf;
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index 74365491..b83bc580 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -125,10 +125,10 @@ int compareStrI(const std::string &a, const std::string &b);
*/
bool isWordSeparator(char chr);
-const std::string findSameSubstring(const std::string &str1,
- const std::string &str2);
+std::string findSameSubstring(const std::string &str1,
+ const std::string &str2);
-const char* getSafeUtf8String(std::string text);
+const char *getSafeUtf8String(const std::string &text);
/**
* Returns a bool value depending on the given string value.