diff --git a/queen/cutaway.cpp b/queen/cutaway.cpp index 02d181574fe..bab72c2a4f0 100644 --- a/queen/cutaway.cpp +++ b/queen/cutaway.cpp @@ -1409,7 +1409,7 @@ int Cutaway::countSpaces(ObjectType type, const char *segment) { if (OBJECT_TYPE_TEXT_DISPLAY == type) tmp *= 3; - return (tmp * 2) / _logic->talkSpeed(); + return (tmp * 2) / (_logic->talkSpeed() / 3); } diff --git a/queen/journal.cpp b/queen/journal.cpp index f12b3ecadf2..28cfee89681 100644 --- a/queen/journal.cpp +++ b/queen/journal.cpp @@ -31,8 +31,8 @@ namespace Queen { -Journal::Journal(Logic *l, Graphics *g, Display *d, Sound *s, GameConfig *c) - : _logic(l), _graphics(g), _display(d), _sound(s), _cfg(c) { +Journal::Journal(Logic *l, Graphics *g, Display *d, Sound *s) + : _logic(l), _graphics(g), _display(d), _sound(s) { _savePath = g_engine->getSavePath(); _currentSavePage = 0; _currentSaveSlot = 0; @@ -44,7 +44,6 @@ void Journal::use() { BobSlot *joe = _graphics->bob(0); _prevJoeX = joe->x; _prevJoeY = joe->y; - debug(0, "Journal::prepare() - Joe.pos = (%d,%d)", _prevJoeX, _prevJoeY); _edit.enable = false; _mode = M_NORMAL; @@ -81,6 +80,8 @@ void Journal::use() { g_system->delay_msecs(20); } + _logic->writeOptionSettings(); + _graphics->textClear(0, GAME_SCREEN_HEIGHT - 1); _graphics->cameraBob(0); if (_quitCleanly) { @@ -172,9 +173,7 @@ void Journal::update() { void Journal::showBob(int bobNum, int16 x, int16 y, int frameNum) { BobSlot *bob = _graphics->bob(bobNum); - bob->active = true; - bob->x = x; - bob->y = y; + bob->curPos(x, y); bob->frameNum = JOURNAL_FRAMES + frameNum; } @@ -201,7 +200,6 @@ void Journal::findSaveDescriptions() { SaveFile *f = mgr->open_savefile(filename, _savePath, false); if (f) { f->read(_saveDescriptions[i], MAX_SAVE_DESC_LEN); - debug(0, "Journal::findSaveDescriptions() - %d %s desc=%s", i, filename, _saveDescriptions[i]); delete f; } } @@ -266,10 +264,7 @@ void Journal::handleNormalMode(int16 zoneNum, int x) { enterYesNoMode(zoneNum, TXT_GIVE_UP); } if (zoneNum == ZN_TEXT_SPEED) { - _cfg->talkSpeed = (x - 136) / 4; - if (_cfg->talkSpeed < 1) { - _cfg->talkSpeed = 1; - } + _logic->talkSpeed((x - 136) * 100 / 130); drawConfigPanel(); } else if (zoneNum == ZN_SFX_TOGGLE) { @@ -277,13 +272,7 @@ void Journal::handleNormalMode(int16 zoneNum, int x) { drawConfigPanel(); } else if (zoneNum == ZN_MUSIC_VOLUME) { - _cfg->musicVolume = (x - 136) * 100 / 130; - if (_cfg->musicVolume < 4) { - _cfg->musicVolume = 4; - } - else if (_cfg->musicVolume > 95) { - _cfg->musicVolume = 100; - } + // int val = (x - 136) * 100 / 130; // XXX alter_current_volume(); drawConfigPanel(); } @@ -311,22 +300,11 @@ void Journal::handleNormalMode(int16 zoneNum, int x) { } else if (zoneNum == ZN_VOICE_TOGGLE) { _sound->toggleSpeech(); - if (!_sound->speechOn()) { - // ensure text is always on when voice is off - _cfg->textToggle = true; - } drawConfigPanel(); } else if (zoneNum == ZN_TEXT_TOGGLE) { - // only allow change on CD-ROM version - if (_logic->resource()->JASVersion()[0] == 'C') { - _cfg->textToggle = !_cfg->textToggle; - if (!_sound->speechOn()) { - // ensure text is always on when voice is off - _cfg->textToggle = true; - } - drawConfigPanel(); - } + _logic->subtitles(!_logic->subtitles()); + drawConfigPanel(); } } @@ -494,13 +472,16 @@ void Journal::drawYesNoPanel(int titleNum) { void Journal::drawConfigPanel() { - drawSlideBar(_cfg->talkSpeed, 4, 1, BOB_TALK_SPEED, 136 - 4, 164, FRAME_BLUE_PIN); - drawSlideBar(_cfg->musicVolume, 130, 100, BOB_MUSIC_VOLUME, 136 - 4, 177, FRAME_GREEN_PIN); + _logic->checkOptionSettings(); - drawCheckBox(_sound->sfxOn(), BOB_SFX_TOGGLE, 221, 155, FRAME_CHECK_BOX); + drawSlideBar(_logic->talkSpeed(), 130, 100, BOB_TALK_SPEED, 136 - 4, 164, FRAME_BLUE_PIN); + // XXX music_volume + drawSlideBar(100, 130, 100, BOB_MUSIC_VOLUME, 136 - 4, 177, FRAME_GREEN_PIN); + + drawCheckBox(_sound->sfxOn(), BOB_SFX_TOGGLE, 221, 155, FRAME_CHECK_BOX); drawCheckBox(_sound->speechOn(), BOB_SPEECH_TOGGLE, 158, 155, FRAME_CHECK_BOX); - drawCheckBox(_cfg->textToggle, BOB_TEXT_TOGGLE, 125, 167, FRAME_CHECK_BOX); - drawCheckBox(_sound->musicOn(), BOB_MUSIC_TOGGLE, 125, 181, FRAME_CHECK_BOX); + drawCheckBox(_logic->subtitles(), BOB_TEXT_TOGGLE, 125, 167, FRAME_CHECK_BOX); + drawCheckBox(_sound->musicOn(), BOB_MUSIC_TOGGLE, 125, 181, FRAME_CHECK_BOX); } diff --git a/queen/journal.h b/queen/journal.h index 8432f7d6044..fbbf2528201 100644 --- a/queen/journal.h +++ b/queen/journal.h @@ -35,7 +35,7 @@ struct GameConfig; class Journal { public: - Journal(Logic *, Graphics *, Display *, Sound *, GameConfig *); + Journal(Logic *, Graphics *, Display *, Sound *); void use(); enum { @@ -184,7 +184,6 @@ private: Graphics *_graphics; Display *_display; Sound *_sound; - GameConfig *_cfg; const char *_savePath; }; diff --git a/queen/logic.cpp b/queen/logic.cpp index c8218ccc16d..be25550c01b 100644 --- a/queen/logic.cpp +++ b/queen/logic.cpp @@ -20,6 +20,7 @@ */ #include "stdafx.h" +#include "common/config-manager.h" #include "queen/logic.h" #include "queen/command.h" #include "queen/cutaway.h" @@ -181,7 +182,6 @@ Common::RandomSource Logic::randomizer; Logic::Logic(Resource *theResource, Graphics *graphics, Display *theDisplay, Input *input, Sound *sound) : _resource(theResource), _graphics(graphics), _display(theDisplay), _input(input), _sound(sound) { - _settings.talkSpeed = DEFAULT_TALK_SPEED; _jas = _resource->loadFile("QUEEN.JAS", 20); _joe.x = _joe.y = 0; _joe.scale = 100; @@ -381,12 +381,6 @@ void Logic::initialise() { for (i = 1; i <= _numAFile; i++) _aFile[i] = _resource->getJAS2Line(); - _settings.textToggle = true; - if (_resource->isFloppy()) - _sound->speechToggle(false); - else - _sound->speechToggle(true); - _cmd->clear(false); _scene = 0; memset(_gameState, 0, sizeof(_gameState)); @@ -2404,12 +2398,12 @@ bool Logic::gameSave(uint16 slot, const char *desc) { memcpy(ptr, buf, 32); ptr += 32; delete[] buf; - WRITE_BE_UINT16(ptr, _settings.talkSpeed); ptr += 2; - WRITE_BE_UINT16(ptr, _settings.musicVolume); ptr += 2; + WRITE_BE_UINT16(ptr, _talkSpeed); ptr += 2; + WRITE_BE_UINT16(ptr, 0 /*_settings.musicVolume*/); ptr += 2; WRITE_BE_UINT16(ptr, _sound->sfxOn() ? 1 : 0); ptr += 2; WRITE_BE_UINT16(ptr, _sound->speechOn() ? 1 : 0); ptr += 2; WRITE_BE_UINT16(ptr, _sound->musicOn() ? 1 : 0); ptr += 2; - WRITE_BE_UINT16(ptr, _settings.textToggle ? 1 : 0); ptr += 2; + WRITE_BE_UINT16(ptr, _subtitles ? 1 : 0); ptr += 2; for (i = 0; i < 4; i++) { WRITE_BE_UINT16(ptr, _inventoryItem[i]); ptr += 2; @@ -2471,12 +2465,13 @@ bool Logic::gameLoad(uint16 slot) { debug(3, "Loading game from slot %d", slot); ptr += 32; //skip description - _settings.talkSpeed = (int16)READ_BE_UINT16(ptr); ptr += 2; - _settings.musicVolume = (int16)READ_BE_UINT16(ptr); ptr += 2; + _talkSpeed = (int16)READ_BE_UINT16(ptr); ptr += 2; + /*_settings.musicVolume = (int16)READ_BE_UINT16(ptr);*/ ptr += 2; _sound->sfxToggle(READ_BE_UINT16(ptr) != 0); ptr += 2; _sound->speechToggle(READ_BE_UINT16(ptr) != 0); ptr += 2; _sound->musicToggle(READ_BE_UINT16(ptr) != 0); ptr += 2; - _settings.textToggle = READ_BE_UINT16(ptr) != 0; ptr += 2; + _subtitles = READ_BE_UINT16(ptr) != 0; ptr += 2; + ptr += 2 * 6; for (i = 0; i < 4; i++) { _inventoryItem[i] = (int16)READ_BE_UINT16(ptr); ptr += 2; @@ -2647,7 +2642,7 @@ void Logic::useJournal() { _cmd->clear(false); - Journal j(this, _graphics, _display, _sound, &_settings); + Journal j(this, _graphics, _display, _sound); j.use(); _walk->stopJoe(); @@ -2662,6 +2657,67 @@ void Logic::useJournal() { } +void Logic::registerDefaultSettings() { + + ConfMan.registerDefault("master_volume", 255); + ConfMan.registerDefault("music_mute", false); + ConfMan.registerDefault("sfx_mute", false); + ConfMan.registerDefault("talkspeed", DEFAULT_TALK_SPEED); + ConfMan.registerDefault("speech_mute", _resource->isFloppy()); + ConfMan.registerDefault("subtitles", true); +} + + +void Logic::checkOptionSettings() { + + // check talkspeed value + if (_talkSpeed < 4) { + _talkSpeed = 4; + } + else if (_talkSpeed > 95) { + _talkSpeed = 100; + } + + // XXX check master_volume value + + // only CD-ROM version has speech + if (_resource->JASVersion()[0] != 'C' && _sound->speechOn()) { + _sound->speechToggle(false); + } + + // ensure text is always on when voice is off + if (!_sound->speechOn()) { + _subtitles = true; + } +} + + +void Logic::readOptionSettings() { + + // XXX master_volume + _sound->musicToggle(!ConfMan.getBool("music_mute")); + _sound->sfxToggle(!ConfMan.getBool("sfx_mute")); + _talkSpeed = ConfMan.getInt("talkspeed"); + _sound->speechToggle(!ConfMan.getBool("speech_mute")); + _subtitles = ConfMan.getBool("subtitles"); + + checkOptionSettings(); +} + + +void Logic::writeOptionSettings() { + + // XXX master_volume + ConfMan.set("music_mute", !_sound->musicOn()); + ConfMan.set("sfx_mute", !_sound->sfxOn()); + ConfMan.set("talkspeed", _talkSpeed); + ConfMan.set("speech_mute", !_sound->speechOn()); + ConfMan.set("subtitles", _subtitles); + + ConfMan.flushToDisk(); +} + + void Logic::executeSpecialMove(uint16 sm) { // FIXME: for now, we initialise the various 'asm' procs here but, // in order to support the 'interview' mini-game', we will have to do diff --git a/queen/logic.h b/queen/logic.h index 52b8e396791..87143c48f46 100644 --- a/queen/logic.h +++ b/queen/logic.h @@ -41,13 +41,6 @@ struct ZoneSlot { Box box; }; -// FIXME: get rid of that and use ConfigurationManager -struct GameConfig { - int musicVolume; - bool textToggle; - int talkSpeed; -}; - /*! Each object/item in game has a state field. @@ -202,8 +195,6 @@ public: uint16 numFrames() const { return _numFrames; } - int talkSpeed() const { return _settings.talkSpeed; } - void zoneSet(uint16 screen, uint16 zone, uint16 x1, uint16 y1, uint16 x2, uint16 y2); void zoneSet(uint16 screen, uint16 zone, const Box& box); uint16 zoneIn(uint16 screen, uint16 x, uint16 y) const; @@ -300,6 +291,16 @@ public: void useJournal(); + int talkSpeed() const { return _talkSpeed; } + void talkSpeed(int speed) { _talkSpeed = speed; } + bool subtitles() const { return _subtitles; } + void subtitles(bool enable) { _subtitles = enable; } + + void registerDefaultSettings(); + void checkOptionSettings(); + void readOptionSettings(); + void writeOptionSettings(); + void executeSpecialMove(uint16 sm); void asmMakeJoeUseDress(); @@ -350,7 +351,7 @@ public: MAX_ZONES_NUMBER = 32, MAX_AREAS_NUMBER = 11, JOE_RESPONSE_MAX = 40, - DEFAULT_TALK_SPEED = 7, + DEFAULT_TALK_SPEED = 7 * 3, GAME_STATE_COUNT = 211, TALK_SELECTED_COUNT = 86 }; @@ -474,14 +475,16 @@ protected: //! Describe a string based animation (30 frames maximum, bob number must be < 17) AnimFrame _newAnim[17][30]; - GameConfig _settings; - //! Inventory items int16 _inventoryItem[4]; //! scene counter int _scene; + int _talkSpeed; + + bool _subtitles; + Resource *_resource; Graphics *_graphics; Debug *_dbg; diff --git a/queen/queen.cpp b/queen/queen.cpp index 074fc610b2f..f92abc80353 100644 --- a/queen/queen.cpp +++ b/queen/queen.cpp @@ -127,6 +127,9 @@ void QueenEngine::go() { initialise(); + _logic->registerDefaultSettings(); + _logic->readOptionSettings(); + _logic->oldRoom(0); _logic->newRoom(_logic->currentRoom()); diff --git a/queen/talk.cpp b/queen/talk.cpp index 94a9adde6a4..74f90f87519 100644 --- a/queen/talk.cpp +++ b/queen/talk.cpp @@ -677,6 +677,7 @@ exit: return personWalking; } +// cyx : there is a similar function in Cutaway, what about merging them ? int Talk::countSpaces(const char *segment) { int tmp = 0; @@ -686,7 +687,7 @@ int Talk::countSpaces(const char *segment) { if (tmp < 10) tmp = 10; - return (tmp * 2) / _logic->talkSpeed(); + return (tmp * 2) / (_logic->talkSpeed() / 3); } void Talk::headStringAnimation(const SpeechParameters *parameters, int bobNum, int bankNum) { diff --git a/queen/xref.txt b/queen/xref.txt index ec314c97615..33396becf7f 100644 --- a/queen/xref.txt +++ b/queen/xref.txt @@ -107,13 +107,13 @@ game_load() Logic::gameLoad() game_save() Logic::gameSave() - config_request -MUSICTOGGLE Sound::musicToggle -SFXTOGGLE Sound::sfxToggle -TALKSPD GameConfig::talkSpeed -TEXTTOGGLE GameConfig::textToggle -VersionStr Logic::language (add more functions if needed) -VOICETOGGLE Sound::speechToggle -VOLUME GameConfig::musicVolume +MUSICTOGGLE Sound::_musicToggle / ConfMan.("music_mute") +SFXTOGGLE Sound::_sfxToggle / ConfMan.("sfx_mute") +TALKSPD Logic::_talkSpeed / ConfMan.("talkspeed") +TEXTTOGGLE Logic::_subtitles / ConfMan.("subtitles") +VersionStr GameVersion::versionString +VOICETOGGLE Sound::_speechToggle / ConfMan.("speech_mute") +VOLUME ? / ConfMan.("master_volume") GRAPHICS