From c85d939d9b3f6c10288dc86ffa7811408e349657 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 28 Feb 2012 02:14:15 +0300 Subject: Add different sound effects for different events. Can be configured in audio tab in settings. --- src/gui/changeemaildialog.cpp | 3 ++- src/gui/changepassworddialog.cpp | 3 ++- src/gui/charcreatedialog.cpp | 4 ++-- src/gui/charselectdialog.cpp | 2 +- src/gui/confirmdialog.cpp | 2 +- src/gui/editserverdialog.cpp | 2 +- src/gui/okdialog.cpp | 10 +++++++- src/gui/okdialog.h | 11 +++++++-- src/gui/register.cpp | 2 +- src/gui/setup_audio.cpp | 50 ++++++++++++++++++++++++++++++++++++++++ src/gui/setup_audio.h | 5 ++++ src/gui/setup_keyboard.cpp | 2 +- src/gui/setup_theme.cpp | 4 ++-- src/gui/setup_video.cpp | 16 ++++++++----- src/gui/shopwindow.cpp | 2 +- src/gui/socialwindow.cpp | 6 ++--- src/gui/unregisterdialog.cpp | 3 ++- src/gui/widgets/chattab.cpp | 2 +- src/gui/widgets/setupitem.cpp | 40 ++++++++++++++++++++++++++++++-- src/gui/widgets/setupitem.h | 21 ++++++++++++++++- src/gui/widgets/sliderlist.h | 3 +++ 21 files changed, 164 insertions(+), 29 deletions(-) (limited to 'src/gui') diff --git a/src/gui/changeemaildialog.cpp b/src/gui/changeemaildialog.cpp index 518ed3da1..1a468d44f 100644 --- a/src/gui/changeemaildialog.cpp +++ b/src/gui/changeemaildialog.cpp @@ -154,7 +154,8 @@ void ChangeEmailDialog::action(const gcn::ActionEvent &event) else if (error == 2) mWrongDataNoticeListener->setTarget(this->mSecondEmailField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); if (dlg) dlg->addActionListener(mWrongDataNoticeListener); } diff --git a/src/gui/changepassworddialog.cpp b/src/gui/changepassworddialog.cpp index 8082b8d58..a58d8616b 100644 --- a/src/gui/changepassworddialog.cpp +++ b/src/gui/changepassworddialog.cpp @@ -144,7 +144,8 @@ void ChangePasswordDialog::action(const gcn::ActionEvent &event) else if (error == 3) mWrongDataNoticeListener->setTarget(this->mSecondPassField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 9f7436ad8..124476f1c 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -270,8 +270,8 @@ void CharCreateDialog::action(const gcn::ActionEvent &event) else { new OkDialog(_("Error"), - _("Your name needs to be at least 4 characters."), - true, this); + _("Your name needs to be at least 4 characters."), + DIALOG_ERROR, true, this); } } else if (id == "cancel") diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index d2b74a632..b1b8009a4 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -253,7 +253,7 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) } else { - new OkDialog(_("Error"), _("Incorrect password")); + new OkDialog(_("Error"), _("Incorrect password"), DIALOG_ERROR); } mDeleteIndex = -1; } diff --git a/src/gui/confirmdialog.cpp b/src/gui/confirmdialog.cpp index 22acf5116..b6645db3c 100644 --- a/src/gui/confirmdialog.cpp +++ b/src/gui/confirmdialog.cpp @@ -97,7 +97,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, } setVisible(true); yesButton->requestFocus(); - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundrequest"); } void ConfirmDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/editserverdialog.cpp b/src/gui/editserverdialog.cpp index 53e31c3c8..ca1afeaba 100644 --- a/src/gui/editserverdialog.cpp +++ b/src/gui/editserverdialog.cpp @@ -173,7 +173,7 @@ void EditServerDialog::action(const gcn::ActionEvent &event) { OkDialog *dlg = new OkDialog(_("Error"), _("Please at least type both the address and the port " - "of the server.")); + "of the server."), DIALOG_ERROR); dlg->addActionListener(this); } else diff --git a/src/gui/okdialog.cpp b/src/gui/okdialog.cpp index 4a3bdf731..fe22cf008 100644 --- a/src/gui/okdialog.cpp +++ b/src/gui/okdialog.cpp @@ -22,6 +22,8 @@ #include "gui/okdialog.h" +#include "sound.h" + #include "gui/gui.h" #include "gui/widgets/button.h" @@ -34,7 +36,8 @@ #include "debug.h" OkDialog::OkDialog(const std::string &title, const std::string &msg, - bool modal, bool showCenter, Window *parent): + int soundEvent, bool modal, bool showCenter, + Window *parent): Window(title, modal, parent, "ok.xml") { mTextBox = new TextBox; @@ -71,6 +74,11 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, centerHorisontally(); setVisible(true); okButton->requestFocus(); + + if (soundEvent == DIALOG_OK) + sound.playGuiSound("soundinfo"); + else if (soundEvent == DIALOG_ERROR) + sound.playGuiSound("sounderror"); } void OkDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/okdialog.h b/src/gui/okdialog.h index 5705be568..b6f17480b 100644 --- a/src/gui/okdialog.h +++ b/src/gui/okdialog.h @@ -31,6 +31,13 @@ class TextBox; +enum +{ + DIALOG_OK = 0, + DIALOG_ERROR, + DIALOG_SILENCE +}; + /** * An 'Ok' button dialog. * @@ -45,8 +52,8 @@ class OkDialog : public Window, public gcn::ActionListener * @see Window::Window */ OkDialog(const std::string &title, const std::string &msg, - bool modal = true, bool showCenter = true, - Window *parent = nullptr); + int soundEvent = DIALOG_OK, bool modal = true, + bool showCenter = true, Window *parent = nullptr); /** * Called when receiving actions from the widgets. diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 2122e0d6b..bf0cb299e 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -225,7 +225,7 @@ void RegisterDialog::action(const gcn::ActionEvent &event) mWrongDataNoticeListener->setTarget(this->mPasswordField); } - OkDialog *dlg = new OkDialog(_("Error"), errorMsg); + OkDialog *dlg = new OkDialog(_("Error"), errorMsg, DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 1f7db484c..a4c3110d9 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -25,9 +25,11 @@ #include "configuration.h" #include "sound.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/layouthelper.h" +#include "gui/widgets/namesmodel.h" #include "gui/widgets/scrollarea.h" #include "gui/widgets/setupitem.h" @@ -35,6 +37,19 @@ #include "debug.h" +class SoundsModel : public NamesModel +{ +public: + SoundsModel() + { + mNames.push_back(gettext("(no sound)")); + Theme::fillSoundsList(mNames); + } + + virtual ~SoundsModel() + { } +}; + Setup_Audio::Setup_Audio() { setName(_("Audio")); @@ -44,6 +59,10 @@ Setup_Audio::Setup_Audio() ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, mScroll, 10, 10); + mSoundModel = new SoundsModel(); + + new SetupItemLabel(_("Basic settings"), "", this); + new SetupItemCheckBox(_("Enable Audio"), "", "sound", this, "soundEvent"); new SetupItemCheckBox(_("Enable music"), "", @@ -61,6 +80,31 @@ Setup_Audio::Setup_Audio() new SetupItemSlider(_("Music volume"), "", "musicVolume", this, "musicVolumeEvent", 0, sound.getMaxVolume(), 150, true); + new SetupItemLabel(_("Sound effects"), "", this); + + new SetupItemSound(_("Information dialog sound"), "", + "soundinfo", this, "soundinfoEvent", mSoundModel); + + new SetupItemSound(_("Request dialog sound"), "", + "soundrequest", this, "soundrequestEvent", mSoundModel); + + new SetupItemSound(_("Whisper message sound"), "", + "soundwhisper", this, "soundwhisperEvent", mSoundModel); + + new SetupItemSound(_("Highlight message sound"), "", + "soundhighlight", this, "soundhighlightEvent", mSoundModel); + + new SetupItemSound(_("Global message sound"), "", + "soundglobal", this, "soundglobalEvent", mSoundModel); + + new SetupItemSound(_("Error message sound"), "", + "sounderror", this, "sounderrorEvent", mSoundModel); + + new SetupItemSound(_("Trade request sound"), "", + "soundtrade", this, "soundtradeEvent", mSoundModel); + + new SetupItemLabel(_("Other"), "", this); + new SetupItemCheckBox(_("Enable mumble voice chat"), "", "enableMumble", this, "enableMumbleEvent"); @@ -70,6 +114,12 @@ Setup_Audio::Setup_Audio() setDimension(gcn::Rectangle(0, 0, 550, 350)); } +Setup_Audio::~Setup_Audio() +{ + delete mSoundModel; + mSoundModel = nullptr; +} + void Setup_Audio::apply() { SetupTabScroll::apply(); diff --git a/src/gui/setup_audio.h b/src/gui/setup_audio.h index c08c49c7a..21b661bcb 100644 --- a/src/gui/setup_audio.h +++ b/src/gui/setup_audio.h @@ -34,7 +34,12 @@ class Setup_Audio : public SetupTabScroll public: Setup_Audio(); + ~Setup_Audio(); + void apply(); + + private: + gcn::ListModel *mSoundModel; }; #endif diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index bdd7c2083..ef024c5d9 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -131,7 +131,7 @@ void Setup_Keyboard::apply() if (keyboard.hasConflicts()) { new OkDialog(_("Key Conflict(s) Detected."), - keyboard.getBindError()); + keyboard.getBindError(), DIALOG_ERROR); } keyboard.setEnabled(true); keyboard.store(); diff --git a/src/gui/setup_theme.cpp b/src/gui/setup_theme.cpp index d3b9d0e3c..7386f496a 100644 --- a/src/gui/setup_theme.cpp +++ b/src/gui/setup_theme.cpp @@ -349,8 +349,8 @@ void Setup_Theme::apply() if (config.getValue("theme", config.getValue("selectedSkin", "")) != mTheme) { - new OkDialog(_("Theme Changed"), - _("Restart your client for the change to take effect.")); + new OkDialog(_("Theme Changed"), _("Restart your client for " + "the change to take effect.")); } config.setValue("selectedSkin", ""); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 6690f1452..24d42c83d 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -393,7 +393,7 @@ void Setup_Video::apply() else { new OkDialog(_("Switching to Full Screen"), - _("Restart needed for changes to take effect.")); + _("Restart needed for changes to take effect.")); } #endif config.setValue("screen", fullscreen); @@ -406,7 +406,7 @@ void Setup_Video::apply() // OpenGL can currently only be changed by restarting, notify user. new OkDialog(_("Changing to OpenGL"), - _("Applying change to OpenGL requires restart.")); + _("Applying change to OpenGL requires restart.")); } mFps = mFpsCheckBox->isSelected() ? @@ -498,13 +498,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) { #if defined(_WIN32) if (width < mainGraphics->mWidth || height < mainGraphics->mHeight) + { new OkDialog(_("Screen Resolution Changed"), - _("Restart your client for the change to take effect.") - + std::string("\n") + - _("Some windows may be moved to fit the lowered resolution.")); + _("Restart your client for the change to take effect.") + + std::string("\n") + _("Some windows may be moved to " + "fit the lowered resolution.")); + } else + { new OkDialog(_("Screen Resolution Changed"), - _("Restart your client for the change to take effect.")); + _("Restart your client for the change to take effect.")); + } #else Client::resize(width, height); #endif diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 1a27b8b0c..33ab32ca5 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -753,7 +753,7 @@ void ShopWindow::processRequest(std::string nick, std::string data, int mode) if (config.getBoolValue("autoShop")) { - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundtrade"); startTrade(); } else diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 287089790..f0ac9e128 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1630,13 +1630,13 @@ void SocialWindow::showPartyCreate() if (player_node->getParty()) { new OkDialog(_("Create Party"), - _("Cannot create party. You are already in a party"), - this); + _("Cannot create party. You are already in a party"), + DIALOG_ERROR, true, true, this); return; } mPartyCreateDialog = new TextDialog(_("Party Name"), - _("Choose your party's name."), this); + _("Choose your party's name."), this); mPartyCreateDialog->setActionEventId("create party"); mPartyCreateDialog->addActionListener(this); } diff --git a/src/gui/unregisterdialog.cpp b/src/gui/unregisterdialog.cpp index ca21263f1..9ba895ec8 100644 --- a/src/gui/unregisterdialog.cpp +++ b/src/gui/unregisterdialog.cpp @@ -134,7 +134,8 @@ void UnRegisterDialog::action(const gcn::ActionEvent &event) { mWrongDataNoticeListener->setTarget(this->mPasswordField); - OkDialog *dlg = new OkDialog(_("Error"), errorMsg.str()); + OkDialog *dlg = new OkDialog(_("Error"), + errorMsg.str(), DIALOG_ERROR); dlg->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 018e35030..53842e887 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -301,7 +301,7 @@ void ChatTab::chatLog(std::string line, Own own, && !Client::getInputFocused())))) { if (own != BY_SERVER) - sound.playGuiSfx("system/newmessage.ogg"); + sound.playGuiSound("soundwhisper"); } } } diff --git a/src/gui/widgets/setupitem.cpp b/src/gui/widgets/setupitem.cpp index 581002a58..9eedfd58d 100644 --- a/src/gui/widgets/setupitem.cpp +++ b/src/gui/widgets/setupitem.cpp @@ -23,6 +23,7 @@ #include "configuration.h" #include "main.h" #include "logger.h" +#include "sound.h" #include "gui/editdialog.h" #include "gui/gui.h" @@ -872,7 +873,7 @@ SetupItemSliderList::SetupItemSliderList(std::string text, mOnTheFly(onTheFly) { mValueType = VSTR; - createControls(); +// createControls(); } SetupItemSliderList::SetupItemSliderList(std::string text, @@ -892,7 +893,7 @@ SetupItemSliderList::SetupItemSliderList(std::string text, mOnTheFly(onTheFly) { mValueType = VSTR; - createControls(); +// createControls(); } SetupItemSliderList::~SetupItemSliderList() @@ -917,6 +918,8 @@ void SetupItemSliderList::createControls() mHorizont->add(mLabel, 5); mHorizont->add(mSlider); + addMoreControls(); + mParent->getContainer()->add2(mHorizont, true, 4); mParent->addControl(this); mParent->addActionListener(this); @@ -954,3 +957,36 @@ void SetupItemSliderList::apply(std::string eventName) fromWidget(); save(); } + +SetupItemSound::SetupItemSound(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + int width, bool onTheFly, bool mainConfig) : + SetupItemSliderList(text, description, keyName, parent, eventName, + model, width, onTheFly, mainConfig), + mButton(nullptr) +{ + createControls(); +} + +void SetupItemSound::addMoreControls() +{ + mButton = new Button(_("Play"), mEventName + "_PLAY", this); + mHorizont->add(mButton); +} + +void SetupItemSound::action(const gcn::ActionEvent &event) +{ + if (event.getId() == mEventName + "_PLAY") + { + if (mSlider->getSelected()) + { + sound.playGuiSfx(branding.getStringValue("systemsounds") + + mSlider->getSelectedString() + ".ogg"); + } + } + else + { + SetupItemSliderList::action(event); + } +} diff --git a/src/gui/widgets/setupitem.h b/src/gui/widgets/setupitem.h index f883a5b94..38dec929e 100644 --- a/src/gui/widgets/setupitem.h +++ b/src/gui/widgets/setupitem.h @@ -377,10 +377,12 @@ class SetupItemSliderList : public SetupItem void toWidget(); - void action(const gcn::ActionEvent &event); + virtual void action(const gcn::ActionEvent &event); void apply(std::string eventName); + virtual void addMoreControls() = 0; + protected: HorizontContainer *mHorizont; Label *mLabel; @@ -390,4 +392,21 @@ class SetupItemSliderList : public SetupItem bool mOnTheFly; }; +class SetupItemSound : public SetupItemSliderList +{ + public: + SetupItemSound(std::string text, std::string description, + std::string keyName, SetupTabScroll *parent, + std::string eventName, gcn::ListModel *model, + int width = 150, bool onTheFly = false, + bool mainConfig = true); + + void action(const gcn::ActionEvent &event); + + void addMoreControls(); + + protected: + Button *mButton; +}; + #endif diff --git a/src/gui/widgets/sliderlist.h b/src/gui/widgets/sliderlist.h index a7b1a564c..b2239834d 100644 --- a/src/gui/widgets/sliderlist.h +++ b/src/gui/widgets/sliderlist.h @@ -63,6 +63,9 @@ class SliderList : public Container, void adjustSize(); + int getSelected() + { return mSelectedIndex; } + protected: void updateLabel(); -- cgit v1.2.3-70-g09d2