Introduce IGUIObject::PlaySound to unify 19 copies of the UI sound play following 9565c60a14
, refs #948.
Stops copying the CStrW each time a sound is played by using the reference GetSetting variant. Differential Revision: https://code.wildfiregames.com/D2209 This was SVN commit r22756.
This commit is contained in:
parent
659bf68cc7
commit
0e26503cc6
@ -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<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::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<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (!enabled)
|
||||
break;
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::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<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (!enabled)
|
||||
{
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::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<CStrW>::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<CStrW>::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<CStrW>::GetSetting(this, "sound_closed", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
}
|
||||
PlaySound("sound_closed");
|
||||
|
||||
m_Open = false;
|
||||
break;
|
||||
}
|
||||
|
@ -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<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (!enabled)
|
||||
{
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::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<int>::SetSetting(this, "selected", hovered);
|
||||
UpdateAutoScroll();
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::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<int>::SetSetting(this, "selected", selected);
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::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<int>::SetSetting(this, "selected", selected);
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
PlaySound("sound_selected");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<int>::SetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
ScriptEvent("selectioncolumnchange");
|
||||
|
||||
CStrW soundPath;
|
||||
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
|
||||
PlaySound("sound_selected");
|
||||
return;
|
||||
}
|
||||
xpos += width;
|
||||
|
@ -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<CStrW>::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<CStrW>::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<CStrW>::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<CStrW>::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<CStrW>::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<CStrW>::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<CStrW>::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<CStrW>::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty())
|
||||
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
|
||||
PlaySound("sound_released");
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -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<bool>::GetSetting(this, strGhost);
|
||||
}
|
||||
|
||||
void IGUIObject::PlaySound(const CStr& settingName) const
|
||||
{
|
||||
if (!g_SoundManager)
|
||||
return;
|
||||
|
||||
const CStrW& soundPath = GUI<CStrW>::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
|
||||
|
@ -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:
|
||||
//--------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user