1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 * This file contains configuration functionality
22 */
23
24 //#define USE_3FLAGS 1
25
26 #include "tinsel/config.h"
27 #include "tinsel/dw.h"
28 #include "tinsel/sound.h"
29 #include "tinsel/music.h"
30
31 #include "common/file.h"
32 #include "common/config-manager.h"
33
34 #include "audio/mixer.h"
35
36 namespace Tinsel {
37
Config(TinselEngine * vm)38 Config::Config(TinselEngine *vm) : _vm(vm) {
39 _dclickSpeed = DOUBLE_CLICK_TIME;
40 _musicVolume = Audio::Mixer::kMaxChannelVolume;
41 _soundVolume = Audio::Mixer::kMaxChannelVolume;
42 _voiceVolume = Audio::Mixer::kMaxChannelVolume;
43 _textSpeed = DEFTEXTSPEED;
44 _useSubtitles = false;
45 _swapButtons = false;
46 _language = TXT_ENGLISH;
47 _isAmericanEnglishVersion = false;
48 }
49
50
51 /**
52 * Write settings to config manager and flush the config file to disk.
53 */
writeToDisk()54 void Config::writeToDisk() {
55 ConfMan.setInt("dclick_speed", _dclickSpeed);
56 ConfMan.setInt("music_volume", _musicVolume);
57 ConfMan.setInt("sfx_volume", _soundVolume);
58 ConfMan.setInt("speech_volume", _voiceVolume);
59 ConfMan.setInt("talkspeed", (_textSpeed * 255) / 100);
60 ConfMan.setBool("subtitles", _useSubtitles);
61 //ConfMan.setBool("swap_buttons", _swapButtons ? 1 : 0);
62
63 // Store language for multilingual versions
64 if ((_vm->getFeatures() & GF_USE_3FLAGS) || (_vm->getFeatures() & GF_USE_4FLAGS) || (_vm->getFeatures() & GF_USE_5FLAGS)) {
65 Common::Language lang;
66 switch (_language) {
67 case TXT_FRENCH:
68 lang = Common::FR_FRA;
69 break;
70 case TXT_GERMAN:
71 lang = Common::DE_DEU;
72 break;
73 case TXT_SPANISH:
74 lang = Common::ES_ESP;
75 break;
76 case TXT_ITALIAN:
77 lang = Common::IT_ITA;
78 break;
79 case TXT_US:
80 lang = Common::EN_USA;
81 break;
82 default:
83 lang = Common::EN_ANY;
84 }
85
86 ConfMan.set("language", Common::getLanguageCode(lang));
87 }
88
89 // Write to disk
90 ConfMan.flushToDisk();
91 }
92
93 /**
94 * Read configuration settings from the config file into memory
95 */
readFromDisk()96 void Config::readFromDisk() {
97 if (ConfMan.hasKey("dclick_speed"))
98 _dclickSpeed = ConfMan.getInt("dclick_speed");
99
100 // HACK/FIXME:
101 // We need to clip the volumes from [0, 256] to [0, 255]
102 // here, since for example Tinsel's internal options dialog
103 // and also the midi playback code rely on the volumes to be
104 // in [0, 255]
105 _musicVolume = CLIP(ConfMan.getInt("music_volume"), 0, 255);
106 _soundVolume = CLIP(ConfMan.getInt("sfx_volume"), 0, 255);
107 _voiceVolume = CLIP(ConfMan.getInt("speech_volume"), 0, 255);
108
109 if (ConfMan.hasKey("talkspeed"))
110 _textSpeed = (ConfMan.getInt("talkspeed") * 100) / 255;
111 if (ConfMan.hasKey("subtitles"))
112 _useSubtitles = ConfMan.getBool("subtitles");
113
114 // FIXME: If JAPAN is set, subtitles are forced OFF in the original engine
115
116 //_swapButtons = ConfMan.getBool("swap_buttons") == 1 ? true : false;
117 //ConfigData.language = language; // not necessary, as language has been set in the launcher
118 //ConfigData._isAmericanEnglishVersion = _isAmericanEnglishVersion; // EN_USA / EN_GRB
119
120 // Set language - we'll be clever here and use the ScummVM language setting
121 _language = TXT_ENGLISH;
122 Common::Language lang = _vm->getLanguage();
123 if (lang == Common::UNK_LANG && ConfMan.hasKey("language"))
124 lang = Common::parseLanguage(ConfMan.get("language")); // For multi-lingual versions, fall back to user settings
125 switch (lang) {
126 case Common::FR_FRA:
127 _language = TXT_FRENCH;
128 break;
129 case Common::DE_DEU:
130 _language = TXT_GERMAN;
131 break;
132 case Common::ES_ESP:
133 _language = TXT_SPANISH;
134 break;
135 case Common::IT_ITA:
136 _language = TXT_ITALIAN;
137 break;
138 case Common::EN_USA:
139 _language = TXT_US;
140 break;
141 default:
142 _language = TXT_ENGLISH;
143 }
144
145 if (lang == Common::JA_JPN) {
146 // TODO: Add support for JAPAN version
147 } else if (lang == Common::HE_ISR) {
148 // TODO: Add support for HEBREW version
149
150 // The Hebrew version appears to the software as being English
151 // but it needs to have subtitles on...
152 _language = TXT_ENGLISH;
153 _useSubtitles = true;
154 } else if (_vm->getFeatures() & GF_USE_3FLAGS) {
155 // 3 FLAGS version supports French, German, Spanish
156 // Fall back to German if necessary
157 if (_language != TXT_FRENCH && _language != TXT_GERMAN && _language != TXT_SPANISH) {
158 _language = TXT_GERMAN;
159 _useSubtitles = true;
160 }
161 } else if (_vm->getFeatures() & GF_USE_4FLAGS) {
162 // 4 FLAGS version supports French, German, Spanish, Italian
163 // Fall back to German if necessary
164 if (_language != TXT_FRENCH && _language != TXT_GERMAN &&
165 _language != TXT_SPANISH && _language != TXT_ITALIAN) {
166 _language = TXT_GERMAN;
167 _useSubtitles = true;
168 }
169 }
170 }
171
isJapanMode()172 bool isJapanMode() {
173 #ifdef JAPAN
174 return true;
175 #else
176 return false;
177 #endif
178 }
179
180 } // End of namespace Tinsel
181