ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

settingsmenu.cpp

Go to the documentation of this file.
00001 /* ResidualVM - A 3D game interpreter
00002  *
00003  * ResidualVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the AUTHORS
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #include "engines/stark/ui/menu/settingsmenu.h"
00024 #include "engines/stark/ui/cursor.h"
00025 #include "engines/stark/services/services.h"
00026 #include "engines/stark/services/userinterface.h"
00027 #include "engines/stark/services/staticprovider.h"
00028 
00029 #include "engines/stark/visual/image.h"
00030 
00031 #include "engines/stark/resources/sound.h"
00032 
00033 namespace Stark {
00034 
00035 const Color SettingsMenuScreen::_textColorHovered = Color(0x1E, 0x1E, 0x96);
00036 const Color SettingsMenuScreen::_textColorDefault = Color(0x00, 0x00, 0x00);
00037 const Color VolumeWidget::_textColorBgHovered = Color(0xFF, 0xFF, 0xFF);
00038 
00039 SettingsMenuScreen::SettingsMenuScreen(Gfx::Driver *gfx, Cursor *cursor) :
00040         StaticLocationScreen(gfx, cursor, "OptionLocation", Screen::kScreenSettingsMenu),
00041         _soundManager() {
00042 }
00043 
00044 SettingsMenuScreen::~SettingsMenuScreen() {
00045 }
00046 
00047 void SettingsMenuScreen::open() {
00048     StaticLocationScreen::open();
00049 
00050     _soundManager.load();
00051 
00052     _widgets.push_back(new StaticLocationWidget(
00053             // This is the background image
00054             "The Longest Journey",
00055             nullptr,
00056             nullptr));
00057     
00058     _widgets.push_back(new StaticLocationWidget(
00059             "Return",
00060             CLICK_HANDLER(SettingsMenuScreen, backHandler),
00061             nullptr));
00062     _widgets.back()->setupSounds(3, 4);
00063     
00064     _widgets.push_back(new StaticLocationWidget(
00065             "Back",
00066             CLICK_HANDLER(SettingsMenuScreen, backHandler),
00067             nullptr));
00068     _widgets.back()->setupSounds(3, 4);
00069     
00070     _widgets.push_back(new StaticLocationWidget(
00071             "GSettings",
00072             nullptr,
00073             nullptr));
00074     
00075     _widgets.push_back(new CheckboxWidget(
00076             "AprilHighRes",
00077             StarkSettings->getBoolSetting(Settings::kHighModel),
00078             CLICK_HANDLER(SettingsMenuScreen, flipSettingHandler<Settings::kHighModel>),
00079             MOVE_HANDLER(SettingsMenuScreen, textHandler<kHighRes>)));
00080     _widgets.back()->setupSounds(3, 4);
00081     
00082     _widgets.push_back(new StaticLocationWidget(
00083             "HighResHelp",
00084             nullptr,
00085             nullptr));
00086     _widgets.back()->setVisible(false);
00087     
00088     _widgets.push_back(new CheckboxWidget(
00089             "Subtitles",
00090             StarkSettings->getBoolSetting(Settings::kSubtitle),
00091             CLICK_HANDLER(SettingsMenuScreen, flipSettingHandler<Settings::kSubtitle>),
00092             MOVE_HANDLER(SettingsMenuScreen, textHandler<kSubtitles>)));
00093     _widgets.back()->setupSounds(3, 4);
00094     
00095     _widgets.push_back(new StaticLocationWidget(
00096             "SubtitleHelp",
00097             nullptr,
00098             nullptr));
00099     _widgets.back()->setVisible(false);
00100 
00101     _widgets.push_back(new CheckboxWidget(
00102             "SpecialFX",
00103             StarkSettings->getBoolSetting(Settings::kSpecialFX),
00104             CLICK_HANDLER(SettingsMenuScreen, flipSettingHandler<Settings::kSpecialFX>),
00105             MOVE_HANDLER(SettingsMenuScreen, textHandler<kSpecialFX>)));
00106     _widgets.back()->setupSounds(3, 4);
00107     
00108     _widgets.push_back(new StaticLocationWidget(
00109             "SpecialFXHelp",
00110             nullptr,
00111             nullptr));
00112     _widgets.back()->setVisible(false);
00113 
00114     _widgets.push_back(new CheckboxWidget(
00115             "Shadows",
00116             StarkSettings->getBoolSetting(Settings::kShadow),
00117             CLICK_HANDLER(SettingsMenuScreen, flipSettingHandler<Settings::kShadow>),
00118             MOVE_HANDLER(SettingsMenuScreen, textHandler<kShadows>)));
00119     _widgets.back()->setupSounds(3, 4);
00120     
00121     _widgets.push_back(new StaticLocationWidget(
00122             "ShadowsHelp",
00123             nullptr,
00124             nullptr));
00125     _widgets.back()->setVisible(false);
00126 
00127     _widgets.push_back(new CheckboxWidget(
00128             "HighResFMV",
00129             StarkSettings->getBoolSetting(Settings::kHighFMV),
00130             CLICK_HANDLER(SettingsMenuScreen, flipSettingHandler<Settings::kHighFMV>),
00131             MOVE_HANDLER(SettingsMenuScreen, textHandler<kHighResFMV>)));
00132     _widgets.back()->setupSounds(3, 4);
00133     _widgets.back()->setVisible(StarkSettings->hasLowResFMV());
00134     
00135     _widgets.push_back(new StaticLocationWidget(
00136             "FMVHelp",
00137             nullptr,
00138             nullptr));
00139     _widgets.back()->setVisible(false);
00140 
00141     _widgets.push_back(new StaticLocationWidget(
00142             "VSettings",
00143             nullptr,
00144             nullptr));
00145 
00146     _widgets.push_back(new VolumeWidget(
00147             "Voice",
00148             _cursor,
00149             _soundManager, 0,
00150             Settings::kVoice,
00151             MOVE_HANDLER(SettingsMenuScreen, textHandler<kVoice>)));
00152     
00153     _widgets.push_back(new StaticLocationWidget(
00154             "VoiceHelp",
00155             nullptr,
00156             nullptr));
00157     _widgets.back()->setVisible(false);
00158 
00159     _widgets.push_back(new VolumeWidget(
00160             "Music",
00161             _cursor,
00162             _soundManager, 2,
00163             Settings::kMusic,
00164             MOVE_HANDLER(SettingsMenuScreen, textHandler<kMusic>)));
00165     
00166     _widgets.push_back(new StaticLocationWidget(
00167             "MusicHelp",
00168             nullptr,
00169             nullptr));
00170     _widgets.back()->setVisible(false);
00171 
00172     _widgets.push_back(new VolumeWidget(
00173             "Sfx",
00174             _cursor,
00175             _soundManager, 1,
00176             Settings::kSfx,
00177             MOVE_HANDLER(SettingsMenuScreen, textHandler<kSfx>)));
00178     
00179     _widgets.push_back(new StaticLocationWidget(
00180             "SfxHelp",
00181             nullptr,
00182             nullptr));
00183     _widgets.back()->setVisible(false);
00184 
00185     _widgets.push_back(new CheckboxWidget(
00186             "AllowFF",
00187             StarkSettings->getBoolSetting(Settings::kTimeSkip),
00188             CLICK_HANDLER(SettingsMenuScreen, flipSettingHandler<Settings::kTimeSkip>),
00189             MOVE_HANDLER(SettingsMenuScreen, textHandler<kAllowFF>)));
00190     _widgets.back()->setupSounds(3, 4);
00191         
00192     _widgets.push_back(new StaticLocationWidget(
00193             "AllowFFHelp",
00194             nullptr,
00195             nullptr));
00196     _widgets.back()->setVisible(false);
00197 }
00198 
00199 void SettingsMenuScreen::close() {
00200     _soundManager.close();
00201     ConfMan.flushToDisk();
00202     StaticLocationScreen::close();
00203 }
00204 
00205 void SettingsMenuScreen::onGameLoop() {
00206     _soundManager.update();
00207 }
00208 
00209 void SettingsMenuScreen::handleMouseUp() {
00210     if (!_widgets.empty()) {
00211         _soundManager.endLoop();
00212         _widgets[kWidgetVoice]->onMouseUp();
00213         _widgets[kWidgetMusic]->onMouseUp();
00214         _widgets[kWidgetSfx]->onMouseUp();
00215     }
00216 }
00217 
00218 template<SettingsMenuScreen::HelpTextIndex N>
00219 void SettingsMenuScreen::textHandler(StaticLocationWidget &widget, const Common::Point &mousePos) {
00220     if (widget.isVisible()) {
00221         if (widget.isMouseInside(mousePos)) {
00222             widget.setTextColor(_textColorHovered);
00223             _widgets[N]->setVisible(true);
00224         } else {
00225             widget.setTextColor(_textColorDefault);
00226             _widgets[N]->setVisible(false);
00227         }
00228     }
00229 }
00230 
00231 template<Settings::BoolSettingIndex N>
00232 void SettingsMenuScreen::flipSettingHandler() {
00233     StarkSettings->flipSetting(N);
00234 }
00235 
00236 void SettingsMenuScreen::backHandler() {
00237     StarkUserInterface->backPrevScreen();
00238 }
00239 
00240 CheckboxWidget::CheckboxWidget(const char *renderEntryName, bool isChecked,
00241                                WidgetOnClickCallback *onClickCallback,
00242                                WidgetOnMouseMoveCallback *onMouseMoveCallback) :
00243         StaticLocationWidget(renderEntryName, onClickCallback, onMouseMoveCallback),
00244         _isChecked(isChecked) {
00245     // Load images
00246     _checkBoxImage[0] = StarkStaticProvider->getUIElement(StaticProvider::kCheckMark, 0);
00247     _checkBoxImage[1] = StarkStaticProvider->getUIElement(StaticProvider::kCheckMark, 1);
00248     _checkboxWidth = _checkBoxImage[0]->getWidth();
00249     _checkboxHeight = _checkBoxImage[0]->getHeight();
00250     _currentImage = _checkBoxImage[_isChecked];
00251 
00252     // Set positions
00253     Common::Point textPosition = getPosition();
00254     _position.x = textPosition.x - _checkboxWidth - 8;
00255     _position.y = textPosition.y - 4;
00256 }
00257 
00258 void CheckboxWidget::render() {
00259     StaticLocationWidget::render();
00260     _currentImage->render(_position, true);
00261 }
00262 
00263 bool CheckboxWidget::isMouseInside(const Common::Point &mousePos) const {
00264     return StaticLocationWidget::isMouseInside(mousePos) || isMouseInsideCheckbox(mousePos);
00265 }
00266 
00267 void CheckboxWidget::onClick() {
00268     StaticLocationWidget::onClick();
00269     _isChecked = !_isChecked;
00270     _currentImage = _checkBoxImage[_isChecked];
00271 }
00272 
00273 bool CheckboxWidget::isMouseInsideCheckbox(const Common::Point &mousePos) const {
00274     return mousePos.x >= _position.x && mousePos.x <= _position.x + _checkboxWidth &&
00275            mousePos.y >= _position.y && mousePos.y <= _position.y + _checkboxHeight;
00276 }
00277 
00278 VolumeWidget::VolumeWidget(const char *renderEntryName, Cursor *cursor,
00279                            TestSoundManager &soundManager, int soundIndex,
00280                            Settings::IntSettingIndex settingIndex,
00281                            WidgetOnMouseMoveCallback *onMouseMoveCallback) :
00282         StaticLocationWidget(renderEntryName, nullptr, onMouseMoveCallback),
00283         _cursor(cursor),
00284         _soundManager(soundManager),
00285         _soundIndex(soundIndex),
00286         _settingIndex(settingIndex),
00287         _isDragged(false) {
00288     // Load images
00289     _sliderImage = StarkStaticProvider->getUIElement(StaticProvider::kVolume, 0);
00290     _bgImage = StarkStaticProvider->getUIElement(StaticProvider::kVolume, 1);
00291     _bgWidth = _bgImage->getWidth();
00292     _bgHeight = _bgImage->getHeight();
00293     _sliderWidth = _sliderImage->getWidth();
00294 
00295     // Set positions
00296     _bgPosition.x = 313;
00297     _bgPosition.y = 303 + _settingIndex * 51;
00298     _sliderPosition.y = _bgPosition.y;
00299 
00300     _minX = _bgPosition.x;
00301     _maxX = _bgPosition.x + _bgWidth - _sliderWidth;
00302 }
00303 
00304 void VolumeWidget::render() {
00305     StaticLocationWidget::render();
00306 
00307     _sliderPosition.x = volumeToX(StarkSettings->getIntSetting(_settingIndex));
00308 
00309     _sliderImage->render(_sliderPosition, false);
00310     _bgImage->render(_bgPosition, false);
00311 }
00312 
00313 bool VolumeWidget::isMouseInside(const Common::Point &mousePos) const {
00314     return StaticLocationWidget::isMouseInside(mousePos) || isMouseInsideBg(mousePos);
00315 }
00316 
00317 void VolumeWidget::onClick() {
00318     if (isMouseInsideBg(_cursor->getMousePosition())) {
00319         _isDragged = true;
00320         _soundManager.play(_soundIndex);
00321     }
00322 }
00323 
00324 void VolumeWidget::onMouseMove(const Common::Point &mousePos) {
00325     if (isMouseInsideBg(mousePos)) {
00326         setTextColor(_textColorBgHovered);
00327     } else {
00328         StaticLocationWidget::onMouseMove(mousePos);
00329     }
00330 
00331     if (_isDragged) {
00332         int posX = mousePos.x - _sliderWidth / 2;
00333         if (posX < _minX) {
00334             posX = _minX;
00335         }
00336         if (posX > _maxX) {
00337             posX = _maxX;
00338         }
00339         StarkSettings->setIntSetting(_settingIndex, xToVolume(posX));
00340     }
00341 }
00342 
00343 void VolumeWidget::onMouseUp() {
00344     _isDragged = false;
00345 }
00346 
00347 bool VolumeWidget::isMouseInsideBg(const Common::Point &mousePos) const {
00348     return mousePos.x >= _bgPosition.x && mousePos.x <= _bgPosition.x + _bgWidth &&
00349            mousePos.y >= _bgPosition.y && mousePos.y <= _bgPosition.y + _bgHeight;
00350 }
00351 
00352 TestSoundManager::TestSoundManager() : 
00353         _currentSound(nullptr),
00354         _isLopping(false) {
00355     for (int i = 0; i < 3; ++i) {
00356         _sounds[i] = nullptr;
00357     }
00358 }
00359 
00360 void TestSoundManager::load() {
00361     for (int i = 0; i < 3; ++i) {
00362         _sounds[i] = StarkStaticProvider->getLocationSound(i);
00363         _sounds[i]->setLooping(false);
00364     }
00365 }
00366 
00367 void TestSoundManager::close() {
00368     stop();
00369     for (int i = 0; i < 3; ++i) {
00370         _sounds[i] = nullptr;
00371     }
00372 }
00373 
00374 void TestSoundManager::play(int index) {
00375     stop();
00376     _currentSound = _sounds[index];
00377     if (_currentSound) {
00378         _currentSound->play();
00379         _isLopping = true;
00380     }
00381 }
00382 
00383 void TestSoundManager::endLoop() {
00384     _isLopping = false;
00385 }
00386 
00387 void TestSoundManager::stop() {
00388     if (_currentSound) {
00389         _currentSound->stop();
00390         _currentSound = nullptr;
00391     }
00392     _isLopping = false;
00393 }
00394 
00395 void TestSoundManager::update() {
00396     if (_currentSound && !_currentSound->isPlaying()) {
00397         if (_isLopping) {
00398             _currentSound->play();
00399         } else {
00400             _currentSound->stop();
00401             _currentSound = nullptr;
00402         }
00403     }
00404 }
00405 
00406 } // End of namespace Stark


Generated on Sat Jul 13 2019 05:01:14 for ResidualVM by doxygen 1.7.1
curved edge   curved edge