Adds UI sounds for buttons, dropdowns, lists, and checkboxes, fixes #948

This was SVN commit r13521.
This commit is contained in:
historic_bruno 2013-07-01 04:15:09 +00:00
parent ef66f73a84
commit 9565c60a14
7 changed files with 156 additions and 12 deletions

View File

@ -212,6 +212,7 @@
textcolor="white"
text_align="center"
text_valign="center"
sound_pressed="audio/interface/ui/ui_button_click.ogg"
/>
<style name="StoneButton"
@ -223,6 +224,7 @@
textcolor="white"
text_align="center"
text_valign="center"
sound_pressed="audio/interface/ui/ui_button_click.ogg"
/>
<style name="StoneCrossBox"
@ -231,6 +233,7 @@
sprite2="StoneCheckBoxCross"
square_side="16"
textcolor="black"
sound_pressed="audio/interface/ui/ui_button_click.ogg"
/>
<style name="StoneInput"
@ -263,6 +266,10 @@
scrollbar="true"
scrollbar_style="wheatScrollBar"
sound_opened="audio/interface/ui/ui_button_click.ogg"
sound_closed="audio/interface/ui/ui_button_click.ogg"
sound_selected="audio/interface/ui/ui_button_click.ogg"
/>
<style name="StoneList"
@ -277,6 +284,7 @@
textcolor_selected="white"
text_align="left"
text_valign="center"
sound_selected="audio/interface/ui/ui_button_click.ogg"
/>
<style name="StoneExit"

View File

@ -191,6 +191,7 @@
sprite_over="snIconPortraitOver"
sprite_disabled="snIconPortraitDisabled"
tooltip_style="snToolTipBottom"
sound_pressed="audio/interface/ui/ui_button_click.ogg"
/>
<!-- ================================ ================================ -->

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,7 +20,7 @@ CButton
*/
#include "precompiled.h"
#include "GUI.h"
#include "CButton.h"
#include "lib/ogl.h"
@ -35,6 +35,11 @@ CButton::CButton()
AddSetting(GUIST_CGUIString, "caption");
AddSetting(GUIST_int, "cell_id");
AddSetting(GUIST_CStrW, "font");
AddSetting(GUIST_CStrW, "sound_disabled");
AddSetting(GUIST_CStrW, "sound_enter");
AddSetting(GUIST_CStrW, "sound_leave");
AddSetting(GUIST_CStrW, "sound_pressed");
AddSetting(GUIST_CStrW, "sound_released");
AddSetting(GUIST_CGUISpriteInstance, "sprite");
AddSetting(GUIST_CGUISpriteInstance, "sprite_over");
AddSetting(GUIST_CGUISpriteInstance, "sprite_pressed");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2009 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,11 +20,11 @@ CCheckBox
*/
#include "precompiled.h"
#include "GUI.h"
#include "CCheckBox.h"
#include "ps/Font.h"
#include "ps/CLogger.h"
#include "ps/Font.h"
//-------------------------------------------------------------------
@ -37,6 +37,11 @@ CCheckBox::CCheckBox()
AddSetting(GUIST_int, "cell_id");
AddSetting(GUIST_bool, "checked");
AddSetting(GUIST_CStrW, "font");
AddSetting(GUIST_CStrW, "sound_disabled");
AddSetting(GUIST_CStrW, "sound_enter");
AddSetting(GUIST_CStrW, "sound_leave");
AddSetting(GUIST_CStrW, "sound_pressed");
AddSetting(GUIST_CStrW, "sound_released");
AddSetting(GUIST_CGUISpriteInstance, "sprite");
AddSetting(GUIST_CGUISpriteInstance, "sprite_over");
AddSetting(GUIST_CGUISpriteInstance, "sprite_pressed");

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,11 +20,12 @@ CDropDown
*/
#include "precompiled.h"
#include "GUI.h"
#include "CDropDown.h"
#include "lib/ogl.h"
#include "lib/external_libraries/libsdl.h"
#include "lib/ogl.h"
#include "soundmanager/ISoundManager.h"
//-------------------------------------------------------------------
@ -36,6 +37,11 @@ CDropDown::CDropDown() : m_Open(false), m_HideScrollBar(false), m_ElementHighlig
AddSetting(GUIST_float, "dropdown_size");
AddSetting(GUIST_float, "dropdown_buffer");
// AddSetting(GUIST_CStrW, "font");
AddSetting(GUIST_CStrW, "sound_closed");
AddSetting(GUIST_CStrW, "sound_disabled");
AddSetting(GUIST_CStrW, "sound_enter");
AddSetting(GUIST_CStrW, "sound_leave");
AddSetting(GUIST_CStrW, "sound_opened");
// AddSetting(GUIST_CGUISpriteInstance, "sprite"); // Background that sits around the size
AddSetting(GUIST_CGUISpriteInstance, "sprite_list"); // Background of the drop down list
AddSetting(GUIST_CGUISpriteInstance, "sprite2"); // Button that sits to the right
@ -131,10 +137,31 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
break;
}
case GUIM_MOUSE_ENTER:
{
bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled);
if (enabled)
{
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
}
break;
}
case GUIM_MOUSE_LEAVE:
{
GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled);
if (enabled)
{
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
}
break;
}
@ -145,7 +172,12 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
bool enabled;
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);
break;
}
if (!m_Open)
{
@ -155,6 +187,11 @@ 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] );
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_opened", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
return; // overshadow
}
else
@ -166,6 +203,11 @@ 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);
return; // overshadow
}
@ -181,8 +223,16 @@ 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);
}
m_Open = false;
break;
}
case GUIM_LOAD:
SetupListRect();

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,12 +20,14 @@ CList
*/
#include "precompiled.h"
#include "GUI.h"
#include "CList.h"
#include "CGUIScrollBarVertical.h"
#include "ps/CLogger.h"
#include "lib/external_libraries/libsdl.h"
#include "ps/CLogger.h"
#include "soundmanager/ISoundManager.h"
//-------------------------------------------------------------------
@ -41,6 +43,8 @@ CList::CList() :
AddSetting(GUIST_CStrW, "font");
AddSetting(GUIST_bool, "scrollbar");
AddSetting(GUIST_CStr, "scrollbar_style");
AddSetting(GUIST_CStrW, "sound_disabled");
AddSetting(GUIST_CStrW, "sound_selected");
AddSetting(GUIST_CGUISpriteInstance, "sprite");
AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea");
AddSetting(GUIST_int, "cell_id");
@ -194,7 +198,12 @@ void CList::HandleMessage(SGUIMessage &Message)
bool enabled;
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);
break;
}
bool scrollbar;
CGUIList *pList;
@ -226,6 +235,10 @@ void CList::HandleMessage(SGUIMessage &Message)
{
GUI<int>::SetSetting(this, "selected", set);
UpdateAutoScroll();
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_selected", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
}
} break;
@ -455,6 +468,10 @@ 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);
}
}
@ -467,6 +484,10 @@ 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);
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@ -20,8 +20,10 @@ IGUIButtonBehavior
*/
#include "precompiled.h"
#include "GUI.h"
#include "soundmanager/ISoundManager.h"
//-------------------------------------------------------------------
// Constructor / Destructor
@ -39,13 +41,48 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
// TODO Gee: easier access functions
switch (Message.type)
{
case GUIM_MOUSE_ENTER:
{
bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled);
if (enabled)
{
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_enter", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
}
}
break;
case GUIM_MOUSE_LEAVE:
{
bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled);
if (enabled)
{
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_leave", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
}
}
break;
case GUIM_MOUSE_PRESS_LEFT:
{
bool enabled;
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);
break;
}
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
m_Pressed = true;
}
@ -77,6 +114,10 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright");
SendEvent(GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, "doublepressright");
}
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
}
}
break;
@ -87,7 +128,16 @@ void IGUIButtonBehavior::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);
break;
}
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_pressed", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
m_PressedRight = true;
}
@ -119,6 +169,10 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
SendEvent(GUIM_PRESSED, "press");
SendEvent(GUIM_DOUBLE_PRESSED, "doublepress");
}
CStrW soundPath;
if (g_SoundManager && GUI<CStrW>::GetSetting(this, "sound_released", soundPath) == PSRETURN_OK && !soundPath.empty())
g_SoundManager->PlayAsUI(soundPath.c_str(), false);
}
}
break;