From fec6e22cc92358b08d4e0f62e5db18119e5f2e6d Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 27 Jan 2008 15:30:53 +0000 Subject: - slightly refactored user settings handling - added user some settings handling for HoF svn-id: r30653 --- engines/kyra/gui_v1.cpp | 93 ----------------------------------------------- engines/kyra/kyra.cpp | 69 +++++++++++++++++++++++++++++++++++ engines/kyra/kyra.h | 17 +++++++++ engines/kyra/kyra_v1.cpp | 52 ++++++++++++++++++++++++++ engines/kyra/kyra_v1.h | 7 ---- engines/kyra/kyra_v2.cpp | 11 ++++++ engines/kyra/kyra_v2.h | 3 ++ engines/kyra/sound_v1.cpp | 8 ---- engines/kyra/text_v2.cpp | 6 +-- engines/kyra/timer_v2.cpp | 12 ++++++ 10 files changed, 167 insertions(+), 111 deletions(-) diff --git a/engines/kyra/gui_v1.cpp b/engines/kyra/gui_v1.cpp index d51f1e2fee..6c9b822955 100644 --- a/engines/kyra/gui_v1.cpp +++ b/engines/kyra/gui_v1.cpp @@ -37,99 +37,6 @@ namespace Kyra { -void KyraEngine_v1::registerDefaultSettings() { - // Most settings already have sensible defaults. This one, however, is - // specific to the Kyra engine. - ConfMan.registerDefault("walkspeed", 2); - ConfMan.registerDefault("cdaudio", (_flags.platform == Common::kPlatformFMTowns || _flags.platform == Common::kPlatformPC98)); -} - -void KyraEngine_v1::readSettings() { - int talkspeed = ConfMan.getInt("talkspeed"); - - // The default talk speed is 60. This should be mapped to "Normal". - - if (talkspeed == 0) - _configTextspeed = 3; // Clickable - if (talkspeed <= 50) - _configTextspeed = 0; // Slow - else if (talkspeed <= 150) - _configTextspeed = 1; // Normal - else - _configTextspeed = 2; // Fast - - _configWalkspeed = ConfMan.getInt("walkspeed"); - _configMusic = ConfMan.getBool("music_mute") ? 0 : ((ConfMan.getBool("cdaudio") && (_flags.platform == Common::kPlatformFMTowns || _flags.platform == Common::kPlatformPC98)) ? 2 : 1); - _configSounds = ConfMan.getBool("sfx_mute") ? 0 : 1; - - _sound->enableMusic(_configMusic); - _sound->enableSFX(_configSounds); - - bool speechMute = ConfMan.getBool("speech_mute"); - bool subtitles = ConfMan.getBool("subtitles"); - - if (!speechMute && subtitles) - _configVoice = 2; // Voice & Text - else if (!speechMute && !subtitles) - _configVoice = 1; // Voice only - else - _configVoice = 0; // Text only - - setWalkspeed(_configWalkspeed); -} - -void KyraEngine_v1::writeSettings() { - bool speechMute, subtitles; - int talkspeed; - - switch (_configTextspeed) { - case 0: // Slow - talkspeed = 1; - break; - case 1: // Normal - talkspeed = 60; - break; - case 2: // Fast - talkspeed = 255; - break; - default: // Clickable - talkspeed = 0; - break; - } - - ConfMan.setInt("talkspeed", talkspeed); - ConfMan.setInt("walkspeed", _configWalkspeed); - ConfMan.setBool("music_mute", _configMusic == 0); - ConfMan.setBool("cdaudio", _configMusic == 2); - ConfMan.setBool("sfx_mute", _configSounds == 0); - - switch (_configVoice) { - case 0: // Text only - speechMute = true; - subtitles = true; - break; - case 1: // Voice only - speechMute = false; - subtitles = false; - break; - default: // Voice & Text - speechMute = false; - subtitles = true; - break; - } - - if (!_configMusic) - _sound->beginFadeOut(); - - _sound->enableMusic(_configMusic); - _sound->enableSFX(_configSounds); - - ConfMan.setBool("speech_mute", speechMute); - ConfMan.setBool("subtitles", subtitles); - - ConfMan.flushToDisk(); -} - void KyraEngine_v1::initMainButtonList() { _haveScrollButtons = false; _buttonList = &_buttonData[0]; diff --git a/engines/kyra/kyra.cpp b/engines/kyra/kyra.cpp index d7dcab7da8..8ede5e21b0 100644 --- a/engines/kyra/kyra.cpp +++ b/engines/kyra/kyra.cpp @@ -230,6 +230,75 @@ void KyraEngine::delayWithTicks(int ticks) { delay(ticks * _tickLength); } +void KyraEngine::registerDefaultSettings() { + if (_flags.gameID != GI_KYRA3) + ConfMan.registerDefault("cdaudio", (_flags.platform == Common::kPlatformFMTowns || _flags.platform == Common::kPlatformPC98)); +} + +void KyraEngine::readSettings() { + _configWalkspeed = ConfMan.getInt("walkspeed"); + _configMusic = ConfMan.getBool("music_mute") ? 0 : ((ConfMan.getBool("cdaudio") && (_flags.platform == Common::kPlatformFMTowns || _flags.platform == Common::kPlatformPC98)) ? 2 : 1); + _configSounds = ConfMan.getBool("sfx_mute") ? 0 : 1; + + _sound->enableMusic(_configMusic); + _sound->enableSFX(_configSounds); + + bool speechMute = ConfMan.getBool("speech_mute"); + bool subtitles = ConfMan.getBool("subtitles"); + + if (!speechMute && subtitles) + _configVoice = 2; // Voice & Text + else if (!speechMute && !subtitles) + _configVoice = 1; // Voice only + else + _configVoice = 0; // Text only + + setWalkspeed(_configWalkspeed); +} + +void KyraEngine::writeSettings() { + bool speechMute, subtitles; + + ConfMan.setInt("walkspeed", _configWalkspeed); + ConfMan.setBool("music_mute", _configMusic == 0); + ConfMan.setBool("cdaudio", _configMusic == 2); + ConfMan.setBool("sfx_mute", _configSounds == 0); + + switch (_configVoice) { + case 0: // Text only + speechMute = true; + subtitles = true; + break; + case 1: // Voice only + speechMute = false; + subtitles = false; + break; + default: // Voice & Text + speechMute = false; + subtitles = true; + break; + } + + if (!_configMusic) + _sound->beginFadeOut(); + + _sound->enableMusic(_configMusic); + _sound->enableSFX(_configSounds); + + ConfMan.setBool("speech_mute", speechMute); + ConfMan.setBool("subtitles", subtitles); + + ConfMan.flushToDisk(); +} + +bool KyraEngine::speechEnabled() { + return _flags.isTalkie && (_configVoice == 1 || _configVoice == 2); +} + +bool KyraEngine::textEnabled() { + return !_flags.isTalkie || (_configVoice == 0 || _configVoice == 2); +} + } // End of namespace Kyra diff --git a/engines/kyra/kyra.h b/engines/kyra/kyra.h index 0e28539c13..7460a34e9c 100644 --- a/engines/kyra/kyra.h +++ b/engines/kyra/kyra.h @@ -147,11 +147,28 @@ protected: StaticResource *_staticres; TimerManager *_timer; ScriptHelper *_scriptInterpreter; + + // config specific + virtual void registerDefaultSettings(); + virtual void readSettings(); + virtual void writeSettings(); + + uint8 _configWalkspeed; + + int _configMusic; + bool _configSounds; + uint8 _configVoice; + + bool speechEnabled(); + bool textEnabled(); // game speed bool _skipFlag; uint16 _tickLength; uint16 _gameSpeed; + + // timer + virtual void setWalkspeed(uint8 speed) = 0; // detection GameFlags _flags; diff --git a/engines/kyra/kyra_v1.cpp b/engines/kyra/kyra_v1.cpp index 40feaed920..c835437cc5 100644 --- a/engines/kyra/kyra_v1.cpp +++ b/engines/kyra/kyra_v1.cpp @@ -1008,6 +1008,58 @@ void KyraEngine_v1::checkAmuletAnimFlags() { } } +#pragma mark - + +void KyraEngine_v1::registerDefaultSettings() { + KyraEngine::registerDefaultSettings(); + + // Most settings already have sensible defaults. This one, however, is + // specific to the Kyra engine. + ConfMan.registerDefault("walkspeed", 2); +} + +void KyraEngine_v1::readSettings() { + int talkspeed = ConfMan.getInt("talkspeed"); + + // The default talk speed is 60. This should be mapped to "Normal". + + if (talkspeed == 0) + _configTextspeed = 3; // Clickable + if (talkspeed <= 50) + _configTextspeed = 0; // Slow + else if (talkspeed <= 150) + _configTextspeed = 1; // Normal + else + _configTextspeed = 2; // Fast + + KyraEngine::readSettings(); +} + +void KyraEngine_v1::writeSettings() { + int talkspeed; + + switch (_configTextspeed) { + case 0: // Slow + talkspeed = 1; + break; + case 1: // Normal + talkspeed = 60; + break; + case 2: // Fast + talkspeed = 255; + break; + default: // Clickable + talkspeed = 0; + break; + } + + ConfMan.setInt("talkspeed", talkspeed); + + KyraEngine::writeSettings(); +} + +#pragma mark - + typedef Functor1Mem OpcodeV1; #define Opcode(x) OpcodeV1(this, &KyraEngine_v1::x) void KyraEngine_v1::setupOpcodeTable() { diff --git a/engines/kyra/kyra_v1.h b/engines/kyra/kyra_v1.h index 1cfb42ccf9..e9bba94b96 100644 --- a/engines/kyra/kyra_v1.h +++ b/engines/kyra/kyra_v1.h @@ -279,9 +279,6 @@ public: void snd_playWanderScoreViaMap(int command, int restart); virtual void snd_playVoiceFile(int id); void snd_voiceWaitForFinish(bool ingame = true); - - bool speechEnabled(); - bool textEnabled(); void saveGame(const char *fileName, const char *saveName); void loadGame(const char *fileName); @@ -594,10 +591,6 @@ protected: bool _fadeText; uint8 _configTextspeed; - uint8 _configWalkspeed; - int _configMusic; - bool _configSounds; - uint8 _configVoice; ScreenAnimator *_animator; SeqPlayer *_seq; diff --git a/engines/kyra/kyra_v2.cpp b/engines/kyra/kyra_v2.cpp index dedf81f979..7c6bb0429d 100644 --- a/engines/kyra/kyra_v2.cpp +++ b/engines/kyra/kyra_v2.cpp @@ -35,6 +35,7 @@ #include "kyra/debugger.h" #include "common/system.h" +#include "common/config-manager.h" namespace Kyra { @@ -1705,6 +1706,16 @@ void KyraEngine_v2::displayInvWsaLastFrame() { #pragma mark - +void KyraEngine_v2::registerDefaultSettings() { + KyraEngine::registerDefaultSettings(); + + // Most settings already have sensible defaults. This one, however, is + // specific to the Kyra engine. + ConfMan.registerDefault("walkspeed", 5); +} + +#pragma mark - + typedef Functor1Mem OpcodeV2; #define Opcode(x) OpcodeV2(this, &KyraEngine_v2::x) #define OpcodeUnImpl() OpcodeV2(this, 0) diff --git a/engines/kyra/kyra_v2.h b/engines/kyra/kyra_v2.h index db415aaffb..6436cec92f 100644 --- a/engines/kyra/kyra_v2.h +++ b/engines/kyra/kyra_v2.h @@ -272,6 +272,8 @@ protected: void runLoop(); void cleanup(); + void registerDefaultSettings(); + // TODO: get rid of all variables having pointers to the static resources if possible // i.e. let them directly use the _staticres functions void initStaticResource(); @@ -666,6 +668,7 @@ protected: void showIdleAnim(); void runIdleScript(int script); + void setWalkspeed(uint8 speed); // delay void delay(uint32 millis, bool updateGame = false, bool isMainLoop = false); diff --git a/engines/kyra/sound_v1.cpp b/engines/kyra/sound_v1.cpp index ae92821f16..ff345cf598 100644 --- a/engines/kyra/sound_v1.cpp +++ b/engines/kyra/sound_v1.cpp @@ -28,14 +28,6 @@ namespace Kyra { -bool KyraEngine_v1::speechEnabled() { - return _flags.isTalkie && (_configVoice == 1 || _configVoice == 2); -} - -bool KyraEngine_v1::textEnabled() { - return !_flags.isTalkie || (_configVoice == 0 || _configVoice == 2); -} - void KyraEngine_v1::snd_playSoundEffect(int track) { debugC(9, kDebugLevelMain | kDebugLevelSound, "KyraEngine_v1::snd_playSoundEffect(%d)", track); if ((_flags.platform == Common::kPlatformFMTowns || _flags.platform == Common::kPlatformPC98) && track == 49) { diff --git a/engines/kyra/text_v2.cpp b/engines/kyra/text_v2.cpp index a977c00507..e4c35c288f 100644 --- a/engines/kyra/text_v2.cpp +++ b/engines/kyra/text_v2.cpp @@ -212,14 +212,14 @@ void KyraEngine_v2::objectChatInit(const char *str, int object, int vocHigh, int _screen->hideMouse(); - if (1/*textEnabled()*/) { + if (textEnabled()) { objectChatPrintText(str, object); _chatEndTime = _system->getMillis() + chatCalcDuration(str) * _tickLength; } else { _chatEndTime = _system->getMillis(); } - if (1/*voiceEnabled()*/) { + if (speechEnabled()) { _chatVocHigh = vocHigh; _chatVocLow = vocLow; } else { @@ -318,7 +318,7 @@ void KyraEngine_v2::objectChatWaitToFinish() { } const uint32 curTime = _system->getMillis(); - if ((1/*textEnabled()*/ && curTime > endTime) || (1/*voiceEnabled()*/ && !snd_voiceIsPlaying()) || _skipFlag) { + if ((textEnabled() && curTime > endTime) || (speechEnabled() && !snd_voiceIsPlaying()) || _skipFlag) { _skipFlag = false; nextFrame = curTime; running = false; diff --git a/engines/kyra/timer_v2.cpp b/engines/kyra/timer_v2.cpp index ef0eb219d4..1b12db4e9f 100644 --- a/engines/kyra/timer_v2.cpp +++ b/engines/kyra/timer_v2.cpp @@ -100,4 +100,16 @@ void KyraEngine_v2::setTimer1DelaySecs(int secs) { _timer->setCountdown(1, secs * 60); } +void KyraEngine_v2::setWalkspeed(uint8 newSpeed) { + debugC(9, kDebugLevelMain | kDebugLevelTimer, "KyraEngine_v2::setWalkspeed(%i)", newSpeed); + + if (newSpeed < 5) + newSpeed = 3; + else + newSpeed = 5; + + _timer->setDelay(5, newSpeed); +} + + } // end of namespace Kyra -- cgit v1.2.3