diff --git a/source/gui/CDropDown.cpp b/source/gui/CDropDown.cpp index e40c1e3066..b74e94c121 100644 --- a/source/gui/CDropDown.cpp +++ b/source/gui/CDropDown.cpp @@ -24,7 +24,6 @@ #include "lib/ogl.h" #include "lib/timer.h" #include "ps/CLogger.h" -#include "soundmanager/ISoundManager.h" CDropDown::CDropDown(CGUI& pGUI) : CList(pGUI), IGUIObject(pGUI), @@ -144,12 +143,8 @@ void CDropDown::HandleMessage(SGUIMessage& Message) { bool enabled; GUI::GetSetting(this, "enabled", enabled); - if (!enabled) - break; - - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (enabled) + PlaySound("sound_enter"); break; } @@ -159,12 +154,8 @@ void CDropDown::HandleMessage(SGUIMessage& Message) bool enabled; GUI::GetSetting(this, "enabled", enabled); - if (!enabled) - break; - - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (enabled) + PlaySound("sound_leave"); break; } @@ -176,9 +167,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message) GUI::GetSetting(this, "enabled", enabled); if (!enabled) { - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_disabled"); break; } @@ -195,10 +184,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message) // Start at the position of the selected item, if possible. GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_opened", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); - + PlaySound("sound_opened"); return; // overshadow } else @@ -210,11 +196,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message) { m_Open = false; GetScrollBar(0).SetZ(GetBufferedZ()); - - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_closed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); - + PlaySound("sound_closed"); return; // overshadow } @@ -269,11 +251,8 @@ void CDropDown::HandleMessage(SGUIMessage& Message) case GUIM_LOST_FOCUS: { if (m_Open) - { - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_closed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); - } + PlaySound("sound_closed"); + m_Open = false; break; } diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index 172ab546a3..1d18191b5b 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -24,8 +24,6 @@ #include "lib/external_libraries/libsdl.h" #include "ps/CLogger.h" #include "ps/Profile.h" -#include "soundmanager/ISoundManager.h" - CList::CList(CGUI& pGUI) : IGUIObject(pGUI), IGUITextOwner(pGUI), IGUIScrollBarOwner(pGUI), @@ -187,9 +185,7 @@ void CList::HandleMessage(SGUIMessage& Message) GUI::GetSetting(this, "enabled", enabled); if (!enabled) { - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_disabled"); break; } @@ -198,10 +194,7 @@ void CList::HandleMessage(SGUIMessage& Message) break; GUI::SetSetting(this, "selected", hovered); UpdateAutoScroll(); - - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_selected"); if (timer_Time() - m_LastItemClickTime < SELECT_DBLCLICK_RATE && hovered == m_PrevSelectedItem) this->SendEvent(GUIM_MOUSE_DBLCLICK_LEFT_ITEM, "mouseleftdoubleclickitem"); @@ -437,10 +430,7 @@ void CList::SelectNextElement() { ++selected; GUI::SetSetting(this, "selected", selected); - - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_selected"); } } @@ -452,10 +442,7 @@ void CList::SelectPrevElement() { --selected; GUI::SetSetting(this, "selected", selected); - - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_selected"); } } diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp index 62dd587da5..c3a7856cb0 100644 --- a/source/gui/COList.cpp +++ b/source/gui/COList.cpp @@ -22,7 +22,6 @@ #include "gui/CGUIColor.h" #include "i18n/L10n.h" #include "ps/CLogger.h" -#include "soundmanager/ISoundManager.h" const float SORT_SPRITE_DIM = 16.0f; const CPos COLUMN_SHIFT = CPos(0, 4); @@ -181,10 +180,7 @@ void COList::HandleMessage(SGUIMessage& Message) GUI::SetSetting(this, "selected_column_order", selectedColumnOrder); ScriptEvent("selectioncolumnchange"); - CStrW soundPath; - if (g_SoundManager && GUI::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); - + PlaySound("sound_selected"); return; } xpos += width; diff --git a/source/gui/IGUIButtonBehavior.cpp b/source/gui/IGUIButtonBehavior.cpp index 67c1cd8977..b89d67483b 100644 --- a/source/gui/IGUIButtonBehavior.cpp +++ b/source/gui/IGUIButtonBehavior.cpp @@ -20,7 +20,6 @@ #include "GUI.h" #include "ps/CLogger.h" -#include "soundmanager/ISoundManager.h" IGUIButtonBehavior::IGUIButtonBehavior(CGUI& pGUI) : IGUIObject(pGUI), m_Pressed(false) @@ -40,19 +39,13 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) switch (Message.type) { case GUIM_MOUSE_ENTER: - if (!enabled) - break; - - if (g_SoundManager && GUI::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (enabled) + PlaySound("sound_enter"); break; case GUIM_MOUSE_LEAVE: - if (!enabled) - break; - - if (g_SoundManager && GUI::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + if (enabled) + PlaySound("sound_leave"); break; case GUIM_MOUSE_DBLCLICK_LEFT: @@ -67,14 +60,11 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_PRESS_LEFT: if (!enabled) { - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_disabled"); break; } - // Button was clicked - if (g_SoundManager && GUI::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_pressed"); SendEvent(GUIM_PRESSED, "press"); m_Pressed = true; break; @@ -91,14 +81,12 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_PRESS_RIGHT: if (!enabled) { - if (g_SoundManager && GUI::GetSetting(this, "sound_disabled", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_disabled"); break; } // Button was right-clicked - if (g_SoundManager && GUI::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_pressed"); SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright"); m_PressedRight = true; break; @@ -110,8 +98,7 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) if (m_PressedRight) { m_PressedRight = false; - if (g_SoundManager && GUI::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_released"); } break; @@ -122,8 +109,7 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) if (m_Pressed) { m_Pressed = false; - if (g_SoundManager && GUI::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty()) - g_SoundManager->PlayAsUI(soundPath.c_str(), false); + PlaySound("sound_released"); } break; diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp index 4187e9ef5f..56f5806947 100644 --- a/source/gui/IGUIObject.cpp +++ b/source/gui/IGUIObject.cpp @@ -21,11 +21,11 @@ #include "gui/scripting/JSInterface_GUITypes.h" #include "gui/scripting/JSInterface_IGUIObject.h" - #include "ps/GameSetup/Config.h" #include "ps/CLogger.h" #include "ps/Profile.h" #include "scriptinterface/ScriptInterface.h" +#include "soundmanager/ISoundManager.h" IGUIObject::IGUIObject(CGUI& pGUI) : m_pGUI(pGUI), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime() @@ -439,6 +439,17 @@ bool IGUIObject::IsHiddenOrGhost() return IsHidden() || GUI::GetSetting(this, strGhost); } +void IGUIObject::PlaySound(const CStr& settingName) const +{ + if (!g_SoundManager) + return; + + const CStrW& soundPath = GUI::GetSetting(this, settingName); + + if (!soundPath.empty()) + g_SoundManager->PlayAsUI(soundPath.c_str(), false); +} + CStr IGUIObject::GetPresentableName() const { // __internal(), must be at least 13 letters to be able to be diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h index 645d12b840..ebb26b53ee 100644 --- a/source/gui/IGUIObject.h +++ b/source/gui/IGUIObject.h @@ -403,6 +403,11 @@ protected: */ void UpdateMouseOver(IGUIObject* const& pMouseOver); + /** + * Retrieves the configured sound filename from the given setting name and plays that once. + */ + void PlaySound(const CStr& settingName) const; + //@} private: //--------------------------------------------------------