00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/setup_audio.h"
00023
00024 #include "gui/ok_dialog.h"
00025
00026 #include "gui/widgets/checkbox.h"
00027 #include "gui/widgets/label.h"
00028 #include "gui/widgets/layouthelper.h"
00029 #include "gui/widgets/slider.h"
00030
00031 #include "configuration.h"
00032 #include "log.h"
00033 #include "sound.h"
00034
00035 #include "utils/gettext.h"
00036
00037 Setup_Audio::Setup_Audio():
00038 mMusicVolume((int)config.getValue("musicVolume", 60)),
00039 mSfxVolume((int)config.getValue("sfxVolume", 100)),
00040 mSoundEnabled(config.getValue("sound", 0)),
00041 mSoundCheckBox(new CheckBox(_("Sound"), mSoundEnabled)),
00042 mSfxSlider(new Slider(0, sound.getMaxVolume())),
00043 mMusicSlider(new Slider(0, sound.getMaxVolume()))
00044 {
00045 setName(_("Audio"));
00046 setDimension(gcn::Rectangle(0, 0, 250, 200));
00047
00048 gcn::Label *sfxLabel = new Label(_("Sfx volume"));
00049 gcn::Label *musicLabel = new Label(_("Music volume"));
00050
00051 mSfxSlider->setActionEventId("sfx");
00052 mMusicSlider->setActionEventId("music");
00053
00054 mSfxSlider->addActionListener(this);
00055 mMusicSlider->addActionListener(this);
00056
00057 mSoundCheckBox->setPosition(10, 10);
00058
00059 mSfxSlider->setValue(mSfxVolume);
00060 mMusicSlider->setValue(mMusicVolume);
00061
00062 mSfxSlider->setWidth(90);
00063 mMusicSlider->setWidth(90);
00064
00065
00066 LayoutHelper h(this);
00067 ContainerPlacer place = h.getPlacer(0, 0);
00068
00069 place(0, 0, mSoundCheckBox);
00070 place(0, 1, mSfxSlider);
00071 place(1, 1, sfxLabel);
00072 place(0, 2, mMusicSlider);
00073 place(1, 2, musicLabel);
00074
00075 setDimension(gcn::Rectangle(0, 0, 325, 280));
00076 }
00077
00078 void Setup_Audio::apply()
00079 {
00080 mSoundEnabled = mSoundCheckBox->isSelected();
00081 mSfxVolume = (int) config.getValue("sfxVolume", 100);
00082 mMusicVolume = (int) config.getValue("musicVolume", 60);
00083
00084 config.setValue("sound", mSoundEnabled);
00085
00086 if (mSoundEnabled)
00087 {
00088 try
00089 {
00090 sound.init();
00091 }
00092 catch (const char *err)
00093 {
00094 new OkDialog("Sound Engine", err);
00095 logger->log("Warning: %s", err);
00096 }
00097 }
00098 else
00099 {
00100 sound.close();
00101 }
00102 }
00103
00104 void Setup_Audio::cancel()
00105 {
00106 mSoundCheckBox->setSelected(mSoundEnabled);
00107
00108 sound.setSfxVolume(mSfxVolume);
00109 mSfxSlider->setValue(mSfxVolume);
00110
00111 sound.setMusicVolume(mMusicVolume);
00112 mMusicSlider->setValue(mMusicVolume);
00113
00114 config.setValue("sound", mSoundEnabled);
00115 config.setValue("sfxVolume", mSfxVolume);
00116 config.setValue("musicVolume", mMusicVolume);
00117 }
00118
00119 void Setup_Audio::action(const gcn::ActionEvent &event)
00120 {
00121 if (event.getId() == "sfx")
00122 {
00123 config.setValue("sfxVolume", (int) mSfxSlider->getValue());
00124 sound.setSfxVolume((int) mSfxSlider->getValue());
00125 }
00126 else if (event.getId() == "music")
00127 {
00128 config.setValue("musicVolume", (int) mMusicSlider->getValue());
00129 sound.setMusicVolume((int) mMusicSlider->getValue());
00130 }
00131 }