Mana
Loading...
Searching...
No Matches
setup_audio.cpp
Go to the documentation of this file.
1/*
2 * The Mana Client
3 * Copyright (C) 2004-2009 The Mana World Development Team
4 * Copyright (C) 2009-2012 The Mana Developers
5 *
6 * This file is part of The Mana Client.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22#include "gui/setup_audio.h"
23
24#include "configuration.h"
25#include "log.h"
26#include "sound.h"
27
28#include "gui/okdialog.h"
29
31#include "gui/widgets/label.h"
32#include "gui/widgets/layout.h"
33#include "gui/widgets/slider.h"
34
35#include "utils/gettext.h"
36
38 mMusicVolume(config.musicVolume),
39 mSfxVolume(config.sfxVolume),
40 mNotificationsVolume(config.notificationsVolume),
41 mSoundEnabled(config.sound),
42 mDownloadEnabled(config.downloadMusic),
43 mSoundCheckBox(new CheckBox(_("Sound"), mSoundEnabled)),
44 mDownloadMusicCheckBox(new CheckBox(_("Download music"), mDownloadEnabled)),
45 mSfxSlider(new Slider(0, sound.getMaxVolume())),
46 mNotificationsSlider(new Slider(0, sound.getMaxVolume())),
47 mMusicSlider(new Slider(0, sound.getMaxVolume()))
48{
49 setName(_("Audio"));
50
51 gcn::Label *sfxLabel = new Label(_("SFX volume"));
52 gcn::Label *notificationsLabel = new Label(_("Notifications volume"));
53 gcn::Label *musicLabel = new Label(_("Music volume"));
54
55 mSfxSlider->setActionEventId("sfx");
56 mNotificationsSlider->setActionEventId("notifications");
57 mMusicSlider->setActionEventId("music");
58
59 mSfxSlider->addActionListener(this);
60 mNotificationsSlider->addActionListener(this);
61 mMusicSlider->addActionListener(this);
62
63 mSoundCheckBox->setPosition(10, 10);
64
65 mSfxSlider->setValue(mSfxVolume);
67 mMusicSlider->setValue(mMusicVolume);
68
69 mSfxSlider->setWidth(90);
70 mNotificationsSlider->setWidth(90);
71 mMusicSlider->setWidth(90);
72
73 // Do the layout
74 place(0, 0, mSoundCheckBox);
76 place(1, 1, sfxLabel);
78 place(1, 2, notificationsLabel);
80 place(1, 3, musicLabel);
82}
83
85{
86 mSoundEnabled = mSoundCheckBox->isSelected();
91
93
94 // Display a message if user has selected to download music,
95 // And if downloadmusic is not already enabled
97 {
98 new OkDialog(_("Notice"),_("You may have to restart your client if you want to download new music"));
99 }
101
102 if (mSoundEnabled)
103 {
104 try
105 {
106 sound.init();
107 }
108 catch (const char *err)
109 {
110 new OkDialog(_("Sound Engine"), err);
111 Log::warn("%s", err);
112 }
113 }
114 else
115 {
116 sound.close();
117 }
118}
119
136
137void Setup_Audio::action(const gcn::ActionEvent &event)
138{
139 if (event.getId() == "sfx")
140 {
141 int volume = (int) mSfxSlider->getValue();
142 config.sfxVolume = volume;
143 sound.setSfxVolume(volume);
144 }
145 else if (event.getId() == "notifications")
146 {
147 int volume = (int) mNotificationsSlider->getValue();
150 }
151 else if (event.getId() == "music")
152 {
153 int volume = (int) mMusicSlider->getValue();
154 config.musicVolume = volume;
155 sound.setMusicVolume(volume);
156 }
157}
Check box widget.
Definition checkbox.h:32
LayoutCell & place(int x, int y, gcn::Widget *wg, int w=1, int h=1)
Adds a widget to the container and sets it at given cell.
Definition container.cpp:46
Label widget.
Definition label.h:34
LayoutCell & setVAlign(Alignment a)
Sets the vertical alignment of the cell content.
Definition layout.h:191
An 'Ok' button dialog.
Definition okdialog.h:34
void setName(const std::string &name)
Sets the name displayed on the tab.
Definition setuptab.h:54
gcn::Slider * mSfxSlider
Definition setup_audio.h:49
void action(const gcn::ActionEvent &event) override
int mNotificationsVolume
Definition setup_audio.h:43
void cancel() override
Called when the Cancel button is pressed in the setup window.
void apply() override
Called when the Apply button is pressed in the setup window.
gcn::Slider * mMusicSlider
Definition setup_audio.h:51
gcn::Slider * mNotificationsSlider
Definition setup_audio.h:50
gcn::CheckBox * mSoundCheckBox
Definition setup_audio.h:47
bool mSoundEnabled
Definition setup_audio.h:44
bool mDownloadEnabled
Definition setup_audio.h:45
gcn::CheckBox * mDownloadMusicCheckBox
Definition setup_audio.h:48
Slider widget.
Definition slider.h:32
void init()
Installs the sound engine.
Definition sound.cpp:61
void setMusicVolume(int volume)
Definition sound.cpp:139
void close()
Removes all sound functionalities.
Definition sound.cpp:296
void setSfxVolume(int volume)
Definition sound.cpp:147
void setNotificationsVolume(int volume)
Definition sound.cpp:158
Config config
Global settings (config.xml)
Definition client.cpp:97
Sound sound
Definition client.cpp:109
#define _(s)
Definition gettext.h:38
void warn(const char *log_text,...) LOG_PRINTF_ATTR
int sfxVolume
int notificationsVolume
int musicVolume
bool downloadMusic