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

View File

@ -191,6 +191,7 @@
sprite_over="snIconPortraitOver" sprite_over="snIconPortraitOver"
sprite_disabled="snIconPortraitDisabled" sprite_disabled="snIconPortraitDisabled"
tooltip_style="snToolTipBottom" 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. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -20,7 +20,7 @@ CButton
*/ */
#include "precompiled.h" #include "precompiled.h"
#include "GUI.h"
#include "CButton.h" #include "CButton.h"
#include "lib/ogl.h" #include "lib/ogl.h"
@ -35,6 +35,11 @@ CButton::CButton()
AddSetting(GUIST_CGUIString, "caption"); AddSetting(GUIST_CGUIString, "caption");
AddSetting(GUIST_int, "cell_id"); AddSetting(GUIST_int, "cell_id");
AddSetting(GUIST_CStrW, "font"); 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");
AddSetting(GUIST_CGUISpriteInstance, "sprite_over"); AddSetting(GUIST_CGUISpriteInstance, "sprite_over");
AddSetting(GUIST_CGUISpriteInstance, "sprite_pressed"); 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. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -20,11 +20,11 @@ CCheckBox
*/ */
#include "precompiled.h" #include "precompiled.h"
#include "GUI.h"
#include "CCheckBox.h" #include "CCheckBox.h"
#include "ps/Font.h"
#include "ps/CLogger.h" #include "ps/CLogger.h"
#include "ps/Font.h"
//------------------------------------------------------------------- //-------------------------------------------------------------------
@ -37,6 +37,11 @@ CCheckBox::CCheckBox()
AddSetting(GUIST_int, "cell_id"); AddSetting(GUIST_int, "cell_id");
AddSetting(GUIST_bool, "checked"); AddSetting(GUIST_bool, "checked");
AddSetting(GUIST_CStrW, "font"); 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");
AddSetting(GUIST_CGUISpriteInstance, "sprite_over"); AddSetting(GUIST_CGUISpriteInstance, "sprite_over");
AddSetting(GUIST_CGUISpriteInstance, "sprite_pressed"); 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. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -20,11 +20,12 @@ CDropDown
*/ */
#include "precompiled.h" #include "precompiled.h"
#include "GUI.h"
#include "CDropDown.h" #include "CDropDown.h"
#include "lib/ogl.h"
#include "lib/external_libraries/libsdl.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_size");
AddSetting(GUIST_float, "dropdown_buffer"); AddSetting(GUIST_float, "dropdown_buffer");
// AddSetting(GUIST_CStrW, "font"); // 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"); // Background that sits around the size
AddSetting(GUIST_CGUISpriteInstance, "sprite_list"); // Background of the drop down list AddSetting(GUIST_CGUISpriteInstance, "sprite_list"); // Background of the drop down list
AddSetting(GUIST_CGUISpriteInstance, "sprite2"); // Button that sits to the right AddSetting(GUIST_CGUISpriteInstance, "sprite2"); // Button that sits to the right
@ -131,10 +137,31 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
break; 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: case GUIM_MOUSE_LEAVE:
{ {
GUI<int>::GetSetting(this, "selected", m_ElementHighlight); 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; break;
} }
@ -145,7 +172,12 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
bool enabled; bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled); GUI<bool>::GetSetting(this, "enabled", enabled);
if (!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; break;
}
if (!m_Open) if (!m_Open)
{ {
@ -155,6 +187,11 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
// Start at the position of the selected item, if possible. // Start at the position of the selected item, if possible.
GetScrollBar(0).SetPos( m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] ); 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 return; // overshadow
} }
else else
@ -166,6 +203,11 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
{ {
m_Open = false; m_Open = false;
GetScrollBar(0).SetZ(GetBufferedZ()); 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 return; // overshadow
} }
@ -181,8 +223,16 @@ void CDropDown::HandleMessage(SGUIMessage &Message)
} }
case GUIM_LOST_FOCUS: 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; m_Open = false;
break; break;
}
case GUIM_LOAD: case GUIM_LOAD:
SetupListRect(); 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. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -20,12 +20,14 @@ CList
*/ */
#include "precompiled.h" #include "precompiled.h"
#include "GUI.h"
#include "CList.h" #include "CList.h"
#include "CGUIScrollBarVertical.h" #include "CGUIScrollBarVertical.h"
#include "ps/CLogger.h"
#include "lib/external_libraries/libsdl.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_CStrW, "font");
AddSetting(GUIST_bool, "scrollbar"); AddSetting(GUIST_bool, "scrollbar");
AddSetting(GUIST_CStr, "scrollbar_style"); AddSetting(GUIST_CStr, "scrollbar_style");
AddSetting(GUIST_CStrW, "sound_disabled");
AddSetting(GUIST_CStrW, "sound_selected");
AddSetting(GUIST_CGUISpriteInstance, "sprite"); AddSetting(GUIST_CGUISpriteInstance, "sprite");
AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea"); AddSetting(GUIST_CGUISpriteInstance, "sprite_selectarea");
AddSetting(GUIST_int, "cell_id"); AddSetting(GUIST_int, "cell_id");
@ -194,7 +198,12 @@ void CList::HandleMessage(SGUIMessage &Message)
bool enabled; bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled); GUI<bool>::GetSetting(this, "enabled", enabled);
if (!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; break;
}
bool scrollbar; bool scrollbar;
CGUIList *pList; CGUIList *pList;
@ -226,6 +235,10 @@ void CList::HandleMessage(SGUIMessage &Message)
{ {
GUI<int>::SetSetting(this, "selected", set); GUI<int>::SetSetting(this, "selected", set);
UpdateAutoScroll(); 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; } break;
@ -455,6 +468,10 @@ void CList::SelectNextElement()
{ {
++selected; ++selected;
GUI<int>::SetSetting(this, "selected", 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; --selected;
GUI<int>::SetSetting(this, "selected", 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. * This file is part of 0 A.D.
* *
* 0 A.D. is free software: you can redistribute it and/or modify * 0 A.D. is free software: you can redistribute it and/or modify
@ -20,8 +20,10 @@ IGUIButtonBehavior
*/ */
#include "precompiled.h" #include "precompiled.h"
#include "GUI.h" #include "GUI.h"
#include "soundmanager/ISoundManager.h"
//------------------------------------------------------------------- //-------------------------------------------------------------------
// Constructor / Destructor // Constructor / Destructor
@ -39,13 +41,48 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
// TODO Gee: easier access functions // TODO Gee: easier access functions
switch (Message.type) 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: case GUIM_MOUSE_PRESS_LEFT:
{ {
bool enabled; bool enabled;
GUI<bool>::GetSetting(this, "enabled", enabled); GUI<bool>::GetSetting(this, "enabled", enabled);
if (!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; 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; m_Pressed = true;
} }
@ -77,6 +114,10 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright"); SendEvent(GUIM_PRESSED_MOUSE_RIGHT, "pressright");
SendEvent(GUIM_DOUBLE_PRESSED_MOUSE_RIGHT, "doublepressright"); 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; break;
@ -87,7 +128,16 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
GUI<bool>::GetSetting(this, "enabled", enabled); GUI<bool>::GetSetting(this, "enabled", enabled);
if (!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; 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; m_PressedRight = true;
} }
@ -119,6 +169,10 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage &Message)
SendEvent(GUIM_PRESSED, "press"); SendEvent(GUIM_PRESSED, "press");
SendEvent(GUIM_DOUBLE_PRESSED, "doublepress"); 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; break;