scummvm/engines/sludge/language.cpp

126 lines
3.3 KiB
C++
Raw Normal View History

/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/debug.h"
2017-07-18 17:25:00 +02:00
#include "sludge/fileset.h"
2017-06-05 19:10:47 +02:00
#include "sludge/language.h"
2017-12-19 22:15:55 +01:00
#include "sludge/moreio.h"
#include "sludge/newfatal.h"
2017-06-05 19:10:47 +02:00
#include "sludge/sludge.h"
#include "sludge/version.h"
2017-05-26 21:25:11 +02:00
namespace Sludge {
LanguageManager::LanguageManager() {
init();
}
2017-07-18 17:25:00 +02:00
LanguageManager::~LanguageManager() {
kill();
}
void LanguageManager::init() {
_languageID = 0;
_languageIdx = -1;
_numLanguages = 0;
_languageTable = nullptr;
_languageNames = nullptr;
}
void LanguageManager::kill() {
2017-07-18 17:25:00 +02:00
if (_languageTable) {
delete []_languageTable;
_languageTable = nullptr;
2017-07-18 17:25:00 +02:00
}
if (_languageNames) {
delete []_languageNames;
_languageNames = nullptr;
2017-07-18 17:25:00 +02:00
}
}
void LanguageManager::createTable(Common::File *fp) {
2017-07-18 17:25:00 +02:00
// get number of languages
_numLanguages =
(gameVersion >= VERSION(1, 3)) ? (fp->readByte()) : 0;
2017-08-02 16:35:09 +02:00
debugC(2, kSludgeDebugDataLoad, "numLanguages : %c", _numLanguages);
2017-07-18 17:25:00 +02:00
// make language table
_languageTable = new uint[_numLanguages + 1];
if (!checkNew(_languageTable))
2017-05-29 08:02:59 +02:00
return;
2017-07-18 17:25:00 +02:00
_languageNames = new Common::String[_numLanguages + 1];
if (!checkNew(_languageNames))
2017-05-29 08:02:59 +02:00
return;
2017-07-18 17:25:00 +02:00
for (uint i = 0; i <= _numLanguages; i++) {
_languageTable[i] = i ? fp->readUint16BE() : 0;
2017-08-02 16:35:09 +02:00
debugC(2, kSludgeDebugDataLoad, "languageTable %i: %i", i, _languageTable[i]);
2017-07-18 17:25:00 +02:00
_languageNames[i].clear();
if (gameVersion >= VERSION(2, 0)) {
2017-07-18 17:25:00 +02:00
if (_numLanguages) {
_languageNames[i] = readString(fp);
2017-08-02 16:35:09 +02:00
debugC(2, kSludgeDebugDataLoad, "languageName %i: %s\n", i, _languageNames[i].c_str());
}
}
}
}
2017-07-18 17:25:00 +02:00
void LanguageManager::setLanguageID(uint id) {
_languageID = id;
// get index of language
setLanguageIndex(getLanguageForFileB());
}
2017-07-18 17:25:00 +02:00
int LanguageManager::getLanguageForFileB() {
int indexNum = -1;
for (uint i = 0; i <= _numLanguages; i++) {
if (_languageTable[i] == _languageID)
2017-05-29 08:02:59 +02:00
indexNum = i;
}
return indexNum;
}
2017-05-26 21:25:11 +02:00
2017-07-18 17:25:00 +02:00
void LanguageManager::saveLanguageSetting(Common::WriteStream *writeStream) {
writeStream->writeByte(_numLanguages);
}
void LanguageManager::loadLanguageSetting(Common::SeekableReadStream *readStream) {
uint languageIdx = readStream->readByte();
setLanguageIndex(languageIdx);
}
void LanguageManager::setLanguageIndex(int idx) {
if (idx < 0)
fatal("Can't find the translation data specified!");
if (idx != _languageIdx) {
// Load the saved language!
_languageIdx = idx;
// Now set file indices properly to the chosen language.
2017-07-18 19:03:45 +02:00
g_sludge->_resMan->setFileIndices(_numLanguages, _languageIdx);
2017-07-18 17:25:00 +02:00
}
}
2017-05-26 21:25:11 +02:00
} // End of namespace Sludge