diff options
-rw-r--r-- | engines/illusions/duckman/menusystem_duckman.cpp | 93 | ||||
-rw-r--r-- | engines/illusions/duckman/menusystem_duckman.h | 34 | ||||
-rw-r--r-- | engines/illusions/sound.cpp | 3 |
3 files changed, 94 insertions, 36 deletions
diff --git a/engines/illusions/duckman/menusystem_duckman.cpp b/engines/illusions/duckman/menusystem_duckman.cpp index 502a0ac865..b5af102bb9 100644 --- a/engines/illusions/duckman/menusystem_duckman.cpp +++ b/engines/illusions/duckman/menusystem_duckman.cpp @@ -107,7 +107,7 @@ BaseMenu *DuckmanMenuSystem::createLoadGameMenu() { return 0; // TODO } -MenuItem *DuckmanMenuSystem::createOptionsSliderMenuItem(const Common::String &text, SliderActionType type, BaseMenu *baseMenu) { +MenuItem *DuckmanMenuSystem::createOptionsSliderMenuItem(MenuActionUpdateSlider **action, const Common::String &text, SliderActionType type, BaseMenu *baseMenu) { int sliderValue = 0; Common::String sliderText = "{~~~~~~~~~~~~~~~~}"; switch (type) { @@ -120,9 +120,9 @@ MenuItem *DuckmanMenuSystem::createOptionsSliderMenuItem(const Common::String &t sliderText.setChar('|', sliderValue + 1); - MenuActionUpdateSlider *action = new MenuActionUpdateSlider(this, baseMenu, type, _vm); - MenuItem *menuItem = new MenuItem(text + sliderText, action); - action->setMenuItem(menuItem); + *action = new MenuActionUpdateSlider(this, baseMenu, type, _vm); + MenuItem *menuItem = new MenuItem(text + sliderText, *action); + (*action)->setMenuItem(menuItem); return menuItem; } @@ -131,12 +131,17 @@ BaseMenu *DuckmanMenuSystem::createOptionsMenu() { menu->addText(" GAME OPTIONS @@@@"); menu->addText("--------------------------------------"); - menu->addMenuItem(createOptionsSliderMenuItem("SFX Volume @@", SFX, menu)); - menu->addMenuItem(createOptionsSliderMenuItem("Music Volume @@@", MUSIC, menu)); - menu->addMenuItem(createOptionsSliderMenuItem("Speech Volume ", VOICE, menu)); - menu->addMenuItem(createOptionsSliderMenuItem("Text Duration @@@", TEXT_DURATION, menu)); + MenuActionUpdateSlider *sfxSlider; + MenuActionUpdateSlider *musicSlider; + MenuActionUpdateSlider *speechSlider; + MenuActionUpdateSlider *textDurationSlider; - menu->addMenuItem(new MenuItem("Restore Defaults", new MenuActionLeaveMenu(this))); + menu->addMenuItem(createOptionsSliderMenuItem(&sfxSlider, "SFX Volume @@", SFX, menu)); + menu->addMenuItem(createOptionsSliderMenuItem(&musicSlider, "Music Volume @@@", MUSIC, menu)); + menu->addMenuItem(createOptionsSliderMenuItem(&speechSlider, "Speech Volume ", VOICE, menu)); + menu->addMenuItem(createOptionsSliderMenuItem(&textDurationSlider, "Text Duration @@@", TEXT_DURATION, menu)); + + menu->addMenuItem(new MenuItem("Restore Defaults", new MenuActionResetOptionSliders(this, sfxSlider, musicSlider, speechSlider, textDurationSlider))); menu->addMenuItem(new MenuItem("Back", new MenuActionLeaveMenu(this))); return menu; @@ -315,32 +320,24 @@ void MenuActionInventoryAddRemove::execute() { MenuActionUpdateSlider::MenuActionUpdateSlider(BaseMenuSystem *menuSystem, BaseMenu *baseMenu, SliderActionType type, IllusionsEngine_Duckman *vm) : BaseMenuAction(menuSystem), menu(baseMenu), _type(type), _vm(vm) { - menuItem = NULL; + _menuItem = NULL; } void MenuActionUpdateSlider::execute() { - assert(menuItem); - Common::String text = menuItem->getText(); - Common::Point point = menuItem->getMouseClickPoint(); + assert(_menuItem); + Common::String text = _menuItem->getText(); + Common::Point point = _menuItem->getMouseClickPoint(); int offset = 0; _menuSystem->calcMenuItemTextPositionAtPoint(point, offset); - int newSliderValue = calcNewSliderValue(text, offset); + int newSliderValue = calcNewSliderValue(offset); debug(0, "item text: %s, (%d, %d), New slider value: %d", text.c_str(), point.x, point.y, newSliderValue); - menuItem->setText(text); - _menuSystem->redrawMenuText(menu); - - switch(_type) { - case SFX : _vm->_soundMan->setSfxVolume(newSliderValue * (255/15)); break; - case MUSIC : _vm->_soundMan->setMusicVolume(newSliderValue * (255/15)); break; - case VOICE : _vm->_soundMan->setSpeechVolume(newSliderValue * (255/15)); break; - case TEXT_DURATION : break; // TODO - default: break; - } + setSliderValue(newSliderValue); } -int MenuActionUpdateSlider::calcNewSliderValue(Common::String &text, int newOffset) { +int MenuActionUpdateSlider::calcNewSliderValue(int newOffset) { + Common::String text = _menuItem->getText(); int newSliderValue = 0; int start = 0; int end = 0; @@ -362,13 +359,51 @@ int MenuActionUpdateSlider::calcNewSliderValue(Common::String &text, int newOffs } else { newSliderValue = newOffset - (start + 1); } - - text.setChar('~', currentPosition); - text.setChar('|', start + 1 + newSliderValue); - return newSliderValue; } return currentPosition - start - 1; } +void MenuActionUpdateSlider::setSliderValue(uint8 newValue) { + int start = 0; + Common::String text = _menuItem->getText(); + for(int i = 0; i < text.size(); i++) { + switch (text[i]) { + case '{' : start = i; break; + case '|' : text.setChar('~', i); break; + default: break; + } + } + + text.setChar('|', start + newValue + 1); + + _menuItem->setText(text); + _menuSystem->redrawMenuText(menu); + + switch(_type) { + case SFX : _vm->_soundMan->setSfxVolume(newValue * (255/15)); break; + case MUSIC : _vm->_soundMan->setMusicVolume(newValue * (255/15)); break; + case VOICE : _vm->_soundMan->setSpeechVolume(newValue * (255/15)); break; + case TEXT_DURATION : break; // TODO + default: break; + } +} + +MenuActionResetOptionSliders::MenuActionResetOptionSliders(BaseMenuSystem *menuSystem, + MenuActionUpdateSlider *sfxSlider, + MenuActionUpdateSlider *musiclider, + MenuActionUpdateSlider *speechSlider, + MenuActionUpdateSlider *textDurationSlider) +: BaseMenuAction(menuSystem), _sfxSlider(sfxSlider), _musiclider(musiclider), + _speechSlider(speechSlider), _textDurationSlider(textDurationSlider) { + +} + +void MenuActionResetOptionSliders::execute() { + _sfxSlider->setSliderValue(11); + _musiclider->setSliderValue(11); + _speechSlider->setSliderValue(15); + _textDurationSlider->setSliderValue(0); +} + } // End of namespace Illusions diff --git a/engines/illusions/duckman/menusystem_duckman.h b/engines/illusions/duckman/menusystem_duckman.h index 3ebab4dea4..5b3cd55758 100644 --- a/engines/illusions/duckman/menusystem_duckman.h +++ b/engines/illusions/duckman/menusystem_duckman.h @@ -49,8 +49,9 @@ namespace Illusions { }; class IllusionsEngine_Duckman; +class MenuActionUpdateSlider; -class DuckmanMenuSystem : public BaseMenuSystem { + class DuckmanMenuSystem : public BaseMenuSystem { public: DuckmanMenuSystem(IllusionsEngine_Duckman *vm); ~DuckmanMenuSystem(); @@ -66,7 +67,6 @@ public://protected: BaseMenu *createMainMenu(); BaseMenu *createLoadGameMenu(); BaseMenu *createOptionsMenu(); - MenuItem *createOptionsSliderMenuItem(const Common::String &text, SliderActionType type, BaseMenu *baseMenu); BaseMenu *createPauseMenu(); BaseMenu *createQueryRestartMenu(); BaseMenu *createQueryQuitMenu(); @@ -80,7 +80,10 @@ public://protected: virtual void setGameState(int gameState); virtual void setMenuCursorNum(int cursorNum); virtual void playSoundEffect(int sfxId); -}; +private: + MenuItem *createOptionsSliderMenuItem(MenuActionUpdateSlider **action, const Common::String &text, + SliderActionType type, BaseMenu *baseMenu); + }; class MenuActionInventoryAddRemove : public BaseMenuAction { public: @@ -94,17 +97,34 @@ protected: class MenuActionUpdateSlider : public BaseMenuAction { public: MenuActionUpdateSlider(BaseMenuSystem *menuSystem, BaseMenu *baseMenu, SliderActionType type, IllusionsEngine_Duckman *vm); - void setMenuItem(MenuItem *newMmenuItem) { - menuItem = newMmenuItem; + void setMenuItem(MenuItem *menuItem) { + _menuItem = menuItem; } virtual void execute(); + void setSliderValue(uint8 newValue); protected: IllusionsEngine_Duckman *_vm; SliderActionType _type; - MenuItem *menuItem; + MenuItem *_menuItem; BaseMenu *menu; - int calcNewSliderValue(Common::String &text, int newOffset); + int calcNewSliderValue(int newOffset); +}; + +class MenuActionResetOptionSliders : public BaseMenuAction { +public: + MenuActionResetOptionSliders(BaseMenuSystem *menuSystem, + MenuActionUpdateSlider *sfxSlider, + MenuActionUpdateSlider *musiclider, + MenuActionUpdateSlider *speechSlider, + MenuActionUpdateSlider *textDurationSlider + ); + virtual void execute(); +protected: + MenuActionUpdateSlider *_sfxSlider; + MenuActionUpdateSlider *_musiclider; + MenuActionUpdateSlider *_speechSlider; + MenuActionUpdateSlider *_textDurationSlider; }; } // End of namespace Illusions diff --git a/engines/illusions/sound.cpp b/engines/illusions/sound.cpp index bbcf8ad75b..55bbf8661f 100644 --- a/engines/illusions/sound.cpp +++ b/engines/illusions/sound.cpp @@ -368,14 +368,17 @@ void SoundMan::fadeMidiMusic(int16 finalVolume, int16 duration) { void SoundMan::setMusicVolume(uint8 volume) { ConfMan.setInt("music_volume", volume); _midiPlayer->syncVolume(); + ConfMan.flushToDisk(); } void SoundMan::setSfxVolume(uint8 volume) { ConfMan.setInt("sfx_volume", volume); + ConfMan.flushToDisk(); } void SoundMan::setSpeechVolume(uint8 volume) { ConfMan.setInt("speech_volume", volume); + ConfMan.flushToDisk(); } uint8 SoundMan::calcAdjustedVolume(const Common::String &volumeConfigKey, uint8 volume) { |