xoreos  0.0.5
sound.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/configman.h"
26 
27 #include "src/sound/sound.h"
28 
32 
35 
36 namespace Engines {
37 
38 namespace NWN {
39 
40 OptionsSoundMenu::OptionsSoundMenu(bool isMain, ::Engines::Console *console) : GUI(console) {
41  load("options_sound");
42 
43  if (isMain) {
44  WidgetPanel *backdrop = new WidgetPanel(*this, "PNL_MAINMENU", "pnl_mainmenu");
45  backdrop->setPosition(0.0f, 0.0f, 100.0f);
46  addWidget(backdrop);
47  }
48 
49  std::list<Widget *> speakerGroup;
50  speakerGroup.push_back(getWidget("71Speakers"));
51  speakerGroup.push_back(getWidget("51Speakers"));
52  speakerGroup.push_back(getWidget("2Speakers"));
53  speakerGroup.push_back(getWidget("4Speakers"));
54  speakerGroup.push_back(getWidget("Surround"));
55  speakerGroup.push_back(getWidget("Headphones"));
56  declareGroup(speakerGroup);
57 
58  // TODO: Sound settings
59  Widget *soundEAX = getWidget("EAXCheckbox");
60  if (soundEAX)
61  soundEAX->setDisabled(true);
62  Widget *soundHardware = getWidget("HardwareBox");
63  if (soundHardware)
64  soundHardware->setDisabled(true);
65  Widget *sound71Speakers = getWidget("71Speakers");
66  if (sound71Speakers)
67  sound71Speakers->setDisabled(true);
68  Widget *sound51Speakers = getWidget("51Speakers");
69  if (sound51Speakers)
70  sound51Speakers->setDisabled(true);
71  Widget *sound4Speakers = getWidget("4Speakers");
72  if (sound4Speakers)
73  sound4Speakers->setDisabled(true);
74  Widget *sound2Speakers = getWidget("2Speakers");
75  if (sound2Speakers)
76  sound2Speakers->setDisabled(true);
77  Widget *soundSurround = getWidget("Surround");
78  if (soundSurround)
79  soundSurround->setDisabled(true);
80  Widget *soundHeadphones = getWidget("Headphones");
81  if (soundHeadphones)
82  soundHeadphones->setDisabled(true);
83 
84  _advanced.reset(new OptionsSoundAdvancedMenu(isMain, _console));
85 }
86 
88  _volMusic = ConfigMan.getDouble("volume_music", 1.0);
89  _volSFX = ConfigMan.getDouble("volume_sfx" , 1.0);
90  _volVoice = ConfigMan.getDouble("volume_voice", 1.0);
91  _volVideo = ConfigMan.getDouble("volume_video", 1.0);
92 
94  updateVolume(_volSFX , Sound::kSoundTypeSFX , "SoundFXLabel");
96 
97  getSlider("MusicSlider" , true)->setState(_volMusic * 20);
98  getSlider("SoundFXSlider", true)->setState(_volSFX * 20);
99  getSlider("VoicesSlider" , true)->setState(_volVoice * 20);
100 
101  GUI::show();
102 }
103 
105 }
106 
108  if (widget.getTag() == "MusicSlider") {
109  dynamic_cast<WidgetSlider &>(widget).setSteps(20);
110  return;
111  }
112 
113  if (widget.getTag() == "VoicesSlider") {
114  dynamic_cast<WidgetSlider &>(widget).setSteps(20);
115  return;
116  }
117 
118  if (widget.getTag() == "SoundFXSlider") {
119  dynamic_cast<WidgetSlider &>(widget).setSteps(20);
120  return;
121  }
122 }
123 
125  if ((widget.getTag() == "CancelButton") ||
126  (widget.getTag() == "XButton")) {
127 
128  revertChanges();
129  _returnCode = 1;
130  return;
131  }
132 
133  if (widget.getTag() == "OkButton") {
134 
135  adoptChanges();
136  _returnCode = 2;
137  return;
138  }
139 
140  if (widget.getTag() == "AdvSoundBtn") {
141  sub(*_advanced);
142  return;
143  }
144 
145  if (widget.getTag() == "MusicSlider") {
146  _volMusic = dynamic_cast<WidgetSlider &>(widget).getState() / 20.0f;
148  return;
149  }
150 
151  if (widget.getTag() == "VoicesSlider") {
152  _volVoice = dynamic_cast<WidgetSlider &>(widget).getState() / 20.0f;
154  return;
155  }
156 
157  if (widget.getTag() == "SoundFXSlider") {
158  _volSFX = _volVideo = dynamic_cast<WidgetSlider &>(widget).getState() / 20.0f;
159  updateVolume(_volSFX , Sound::kSoundTypeSFX , "SoundFXLabel");
161  return;
162  }
163 }
164 
166  const Common::UString &label) {
167 
168  SoundMan.setTypeGain(type, volume);
169 
170  if (!label.empty())
171  getLabel(label, true)->setText(Common::UString::format("%.0f%%", volume * 100.0f));
172 }
173 
175  ConfigMan.setDouble("volume_music", _volMusic, true);
176  ConfigMan.setDouble("volume_sfx" , _volSFX , true);
177  ConfigMan.setDouble("volume_voice", _volVoice, true);
178  ConfigMan.setDouble("volume_video", _volVideo, true);
179 }
180 
182  SoundMan.setTypeGain(Sound::kSoundTypeMusic, ConfigMan.getDouble("volume_music", 1.0));
183  SoundMan.setTypeGain(Sound::kSoundTypeSFX , ConfigMan.getDouble("volume_sfx" , 1.0));
184  SoundMan.setTypeGain(Sound::kSoundTypeVoice, ConfigMan.getDouble("volume_voice", 1.0));
185  SoundMan.setTypeGain(Sound::kSoundTypeVideo, ConfigMan.getDouble("volume_video", 1.0));
186 }
187 
188 } // End of namespace NWN
189 
190 } // End of namespace Engines
A NWN panel widget.
Definition: panel.h:41
Widget * getWidget(const Common::UString &tag, bool vital=false)
Return a widget in the GUI.
Definition: gui.cpp:314
The NWN advanced sound options menu.
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
A NWN slider widget.
The global config manager.
void updateVolume(double volume, Sound::SoundType type, const Common::UString &label)
Definition: sound.cpp:165
A NWN slider widget.
Definition: slider.h:41
virtual void setDisabled(bool disabled)
Disable/Enable the widget.
Definition: widget.cpp:154
Console * _console
Definition: gui.h:70
void declareGroup(const std::list< Widget *> &group)
Put these widgets together into a group.
Definition: gui.cpp:340
virtual void show()
Show the GUI.
Definition: gui.cpp:62
WidgetLabel * getLabel(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:270
static UString format(const char *s,...) GCC_PRINTF(1
Print formatted data into an UString object, similar to sprintf().
Definition: ustring.cpp:718
#define ConfigMan
Shortcut for accessing the config manager.
Definition: configman.h:176
A NWN GUI.
Definition: gui.h:54
const Common::UString & getTag() const
Get the widget&#39;s tag.
Definition: widget.cpp:45
WidgetSlider * getSlider(const Common::UString &tag, bool vital=false)
Definition: gui.cpp:282
uint32 sub(GUI &gui, uint32 startCode=kStartCodeNone, bool showSelf=true, bool hideSelf=true)
Open up a sub GUI.
Definition: gui.cpp:349
void load(const Common::UString &resref)
Definition: gui.cpp:77
The global sound manager, handling all sound output.
bool empty() const
Is the string empty?
Definition: ustring.cpp:245
The NWN advanced sound options menu.
Definition: soundadv.h:35
Video/Movie.
Definition: types.h:47
#define SoundMan
Shortcut for accessing the sound manager.
Definition: sound.h:293
void show()
Show the GUI.
Definition: sound.cpp:87
The NWN sound options menu.
Voice/Speech.
Definition: types.h:46
OptionsSoundMenu(bool isMain=false, ::Engines::Console *console=0)
Definition: sound.cpp:40
A widget in a GUI.
Definition: widget.h:40
void setPosition(float x, float y, float z)
Set the widget&#39;s position.
Definition: modelwidget.cpp:71
SoundType
The type of a sound.
Definition: types.h:43
void setState(int state)
Definition: slider.cpp:69
Sound effect.
Definition: types.h:45
void addWidget(Widget *widget)
Add a widget.
Definition: gui.cpp:250
void initWidget(Widget &widget)
Definition: sound.cpp:107
Common::ScopedPtr< GUI > _advanced
Definition: sound.h:51
A NWN panel widget.
A NWN label widget.
void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: sound.cpp:124
void setText(const Common::UString &text)
Definition: label.cpp:67