GUI: U32: Improve u32 in all engine subsystems

- Common: add wordWrap function to ustr.cpp
- Bladerunner: Explicitly state we have a U32String in subs (same as Subtitles::loadOuttakeSubsText)
- Don't use translations for engine specific "put strings", because they might not support.
- SCI: Use const references for showScummVMDialog
- SCUMM:
-- Don't use translation in md5 warning. left comments with the translated version.
-- Remove some redundant headers in help.cpp
-- Don't use translation in handleSaveload when printing to console
-- Also, display success transaction correctly via u32::format
- TESTBED: Use fake constructor when setting label of button
- SKY: Correctly use translation when using SaveStateDescription
- ULTIMA: Don't use translations when display_string
- ENGINES:
-- GenerateUnknownGameReport correctly, with proper translations.
-- There was an error, where a function had been declared twice, in a header file. Correct this.
This commit is contained in:
aryanrawlani28 2020-07-21 04:24:04 +05:30 committed by Eugene Sandulenko
parent 68d01321d6
commit 12e4f871a3
25 changed files with 107 additions and 58 deletions

View File

@ -496,6 +496,44 @@ U32String operator+(const U32String &x, const U32String &y) {
return temp;
}
void U32String::wordWrap(const uint32 maxLength) {
if (_size < maxLength) {
return;
}
makeUnique();
const uint32 kNoSpace = 0xFFFFFFFF;
uint32 i = 0;
while (i < _size) {
uint32 lastSpace = kNoSpace;
uint32 x = 0;
while (i < _size && x <= maxLength) {
const char c = _str[i];
if (c == '\n') {
lastSpace = kNoSpace;
x = 0;
} else {
if (Common::isSpace(c)) {
lastSpace = i;
}
++x;
}
++i;
}
if (x > maxLength) {
if (lastSpace == kNoSpace) {
insertChar('\n', i - 1);
} else {
setChar('\n', lastSpace);
i = lastSpace + 1;
}
}
}
}
uint64 U32String::asUint64() const {
uint64 result = 0;
for (uint32 i = 0; i < _size; ++i) {

View File

@ -232,6 +232,8 @@ public:
/** Python-like method **/
String encode(CodePage page = kUtf8) const;
void wordWrap(const uint32 maxLength);
uint64 asUint64() const;
void trim();

View File

@ -270,7 +270,7 @@ void Subtitles::loadOuttakeSubsText(const Common::String &outtakesName, int fram
* Used for debug purposes mainly.
*/
void Subtitles::setGameSubsText(Common::String dbgQuote, bool forceShowWhenNoSpeech) {
_currentText = _useUTF8 ? Common::convertUtf8ToUtf32(dbgQuote) : Common::convertToU32String(dbgQuote.c_str());
_currentText = _useUTF8 ? Common::convertUtf8ToUtf32(dbgQuote) : Common::U32String(dbgQuote);
_forceShowWhenNoSpeech = forceShowWhenNoSpeech; // overrides not showing subtitles when no one is speaking
}

View File

@ -161,25 +161,26 @@ DetectedGames DetectionResults::listDetectedGames() const {
return _detectedGames;
}
Common::String DetectionResults::generateUnknownGameReport(bool translate, uint32 wordwrapAt) const {
Common::U32String DetectionResults::generateUnknownGameReport(bool translate, uint32 wordwrapAt) const {
return ::generateUnknownGameReport(_detectedGames, translate, false, wordwrapAt);
}
Common::String generateUnknownGameReport(const DetectedGames &detectedGames, bool translate, bool fullPath, uint32 wordwrapAt) {
Common::U32String generateUnknownGameReport(const DetectedGames &detectedGames, bool translate, bool fullPath, uint32 wordwrapAt) {
assert(!detectedGames.empty());
const char *reportStart = _s("The game in '%s' seems to be an unknown game variant.\n\n"
"Please report the following data to the ScummVM team at %s "
"along with the name of the game you tried to add and "
"its version, language, etc.:");
"Please report the following data to the ScummVM team at %s "
"along with the name of the game you tried to add and "
"its version, language, etc.:");
const char *reportEngineHeader = _s("Matched game IDs for the %s engine:");
Common::String report = Common::String::format(
translate ? Common::convertFromU32String(_(reportStart)).c_str() : reportStart,
Common::U32String report = Common::U32String::format(
translate ? _(reportStart) : Common::U32String(reportStart),
fullPath ? detectedGames[0].path.c_str() : detectedGames[0].shortPath.c_str(),
"https://bugs.scummvm.org/"
);
report += "\n";
report += Common::U32String("\n");
FilePropertiesMap matchedFiles;
@ -193,15 +194,15 @@ Common::String generateUnknownGameReport(const DetectedGames &detectedGames, boo
currentEngineId = game.engineId;
// If the engine is not the same as for the previous entry, print an engine line header
report += "\n";
report += Common::String::format(
translate ? Common::convertFromU32String(_(reportEngineHeader)).c_str() : reportEngineHeader,
report += Common::U32String("\n");
report += Common::U32String::format(
translate ? _(reportEngineHeader) : Common::U32String(reportEngineHeader),
game.engineId.c_str()
);
report += " ";
report += Common::U32String(" ");
} else {
report += ", ";
report += Common::U32String(", ");
}
// Add the gameId to the list of matched games for the engine
@ -219,17 +220,17 @@ Common::String generateUnknownGameReport(const DetectedGames &detectedGames, boo
report.wordWrap(wordwrapAt);
}
report += "\n\n";
report += Common::U32String("\n\n");
for (FilePropertiesMap::const_iterator file = matchedFiles.begin(); file != matchedFiles.end(); ++file)
report += Common::String::format(" {\"%s\", 0, \"%s\", %d},\n", file->_key.c_str(), file->_value.md5.c_str(), file->_value.size);
report += "\n";
report += Common::U32String("\n");
return report;
}
Common::String generateUnknownGameReport(const DetectedGame &detectedGame, bool translate, bool fullPath, uint32 wordwrapAt) {
Common::U32String generateUnknownGameReport(const DetectedGame &detectedGame, bool translate, bool fullPath, uint32 wordwrapAt) {
DetectedGames detectedGames;
detectedGames.push_back(detectedGame);

View File

@ -26,6 +26,7 @@
#include "common/array.h"
#include "common/hash-str.h"
#include "common/str.h"
#include "common/ustr.h"
#include "common/str-array.h"
#include "common/language.h"
#include "common/platform.h"
@ -233,7 +234,7 @@ public:
*
* @see ::generateUnknownGameReport
*/
Common::String generateUnknownGameReport(bool translate, uint32 wordwrapAt = 0) const;
Common::U32String generateUnknownGameReport(bool translate, uint32 wordwrapAt = 0) const;
private:
DetectedGames _detectedGames;
@ -248,7 +249,7 @@ private:
* of last component of the path is included
* @param wordwrapAt word wrap the text part of the report after a number of characters
*/
Common::String generateUnknownGameReport(const DetectedGames &detectedGames, bool translate, bool fullPath, uint32 wordwrapAt = 0);
Common::String generateUnknownGameReport(const DetectedGame &detectedGame, bool translate, bool fullPath, uint32 wordwrapAt = 0);
Common::U32String generateUnknownGameReport(const DetectedGames &detectedGames, bool translate, bool fullPath, uint32 wordwrapAt = 0);
Common::U32String generateUnknownGameReport(const DetectedGame &detectedGame, bool translate, bool fullPath, uint32 wordwrapAt = 0);
#endif

View File

@ -2811,7 +2811,7 @@ static int gsc_startup_code(Common::SeekableReadStream *game_stream, int restore
* Display a brief loading game message; here we have to use a timeout
* to ensure that the text is flushed to Glk.
*/
g_vm->glk_put_string(_("Loading game...\n").encode().c_str());
g_vm->glk_put_string("Loading game...\n");
if (g_vm->glk_gestalt(gestalt_Timer, 0)) {
event_t event;

View File

@ -593,8 +593,8 @@ bool VM::getWord(Common::String &line) {
_words.push_back(iw);
return true;
} else {
Common::U32String msg = Common::U32String::format(_("I don't know the word \"%s\".\n"), iw._text.c_str());
print(msg.encode());
Common::String msg = Common::String::format("I don't know the word \"%s\".\n", iw._text.c_str());
print(msg);
return false;
}
}

View File

@ -1330,7 +1330,7 @@ void ComprehendGame::read_input() {
// Empty line, so toggle picture window visibility
g_comprehend->toggleGraphics();
g_comprehend->print(Common::convertFromU32String(_("Picture window toggled\n")).c_str());
g_comprehend->print("Picture window toggled\n");
_updateFlags |= UPDATE_GRAPHICS;
update_graphics();

View File

@ -60,7 +60,7 @@ GlkAPI::GlkAPI(OSystem *syst, const GlkGameDescription &gameDesc) :
}
void GlkAPI::glk_exit(void) {
glk_put_string(_("[ press any key to exit ]").encode().c_str());
glk_put_string("[ press any key to exit ]");
_events->waitForPress();
// Trigger a ScumMVM shutdown of game

View File

@ -123,7 +123,7 @@ Common::Error ZCode::loadGameState(int slot) {
|| h_screen_cols != old_screen_cols))
erase_window(1);
} else {
error("%s", ("Error reading save file"));
error("Error reading save file");
}
return Common::kNoError;
@ -141,7 +141,7 @@ Common::Error ZCode::saveGameState(int slot, const Common::String &desc, bool is
bool success = q.save(*file, this, desc);
if (!success)
print_string(_("Error writing save file\n").encode().c_str());
print_string("Error writing save file\n");
return Common::kNoError;

View File

@ -70,7 +70,7 @@ static int16 adjustGraphColor(int16 color) {
return color;
}
int showScummVMDialog(const Common::U32String &message, Common::U32String altButton = Common::U32String(""), bool alignCenter = true) {
int showScummVMDialog(const Common::U32String &message, const Common::U32String &altButton = Common::U32String(""), bool alignCenter = true) {
Graphics::TextAlign alignment = alignCenter ? Graphics::kTextAlignCenter : Graphics::kTextAlignLeft;
GUI::MessageDialog dialog(message, _("OK"), altButton, alignment);
return dialog.runModal();

View File

@ -62,7 +62,7 @@
namespace Sci {
#ifdef ENABLE_SCI32
extern int showScummVMDialog(const Common::U32String& message, Common::U32String altButton = Common::U32String(""), bool alignCenter = true);
extern int showScummVMDialog(const Common::U32String& message, const Common::U32String &altButton = Common::U32String(""), bool alignCenter = true);
reg_t kBaseSetter32(EngineState *s, int argc, reg_t *argv) {
reg_t object = argv[0];

View File

@ -796,7 +796,7 @@ reg_t kPlatform(EngineState *s, int argc, reg_t *argv) {
return NULL_REG;
}
extern int showScummVMDialog(const Common::U32String& message, Common::U32String altButton = Common::U32String(""), bool alignCenter = true);
extern int showScummVMDialog(const Common::U32String &message, const Common::U32String &altButton = Common::U32String(""), bool alignCenter = true);
#ifdef ENABLE_SCI32
reg_t kPlatform32(EngineState *s, int argc, reg_t *argv) {

View File

@ -1239,7 +1239,7 @@ bool gamestate_save(EngineState *s, Common::WriteStream *fh, const Common::Strin
return true;
}
extern int showScummVMDialog(const Common::U32String& message, Common::U32String altButton = Common::U32String(""), bool alignCenter = true);
extern int showScummVMDialog(const Common::U32String& message, const Common::U32String &altButton = Common::U32String(""), bool alignCenter = true);
void gamestate_afterRestoreFixUp(EngineState *s, int savegameId) {
switch (g_sci->getGameId()) {

View File

@ -65,7 +65,7 @@ bool VideoPlayer::open(const Common::String &fileName) {
// KQ7 2.00b videos are compressed in 24bpp Cinepak, so cannot play on a
// system with no RGB support
if (_decoder->getPixelFormat().bytesPerPixel != 1) {
void showScummVMDialog(const Common::U32String &message, Common::U32String altButton = Common::U32String(""), bool alignCenter = true);
void showScummVMDialog(const Common::U32String &message, const Common::U32String &altButton = Common::U32String(""), bool alignCenter = true);
showScummVMDialog(Common::U32String::format(_("Cannot play back %dbpp video on a system with maximum color depth of 8bpp"), _decoder->getPixelFormat().bpp()));
_decoder->close();
return false;

View File

@ -813,7 +813,7 @@ void ResourceManager::addScriptChunkSources() {
#endif
}
extern int showScummVMDialog(const Common::U32String& message, Common::U32String altButton = Common::U32String(""), bool alignCenter = true);
extern int showScummVMDialog(const Common::U32String &essage, const Common::U32String &altButton = Common::U32String(""), bool alignCenter = true);
void ResourceManager::scanNewSources() {
_hasBadResources = false;

View File

@ -256,7 +256,7 @@ SciEngine::~SciEngine() {
g_sci = 0;
}
extern int showScummVMDialog(const Common::U32String& message, Common::U32String altButton = Common::U32String(""), bool alignCenter = true);
extern int showScummVMDialog(const Common::U32String &message, const Common::U32String &altButton = Common::U32String(""), bool alignCenter = true);
Common::Error SciEngine::run() {
_resMan = new ResourceManager();

View File

@ -1134,19 +1134,26 @@ Common::Error ScummMetaEngine::createInstance(OSystem *syst, Engine **engine) co
// unknown MD5, or with a medium debug level in case of a known MD5 (for
// debugging purposes).
if (!findInMD5Table(res.md5.c_str())) {
Common::U32String md5Warning;
Common::String md5Warning;
Common::String additionalInfo;
// Common::U32String md5WarningTranslated;
md5Warning = _("Your game version appears to be unknown. If this is *NOT* a fan-modified\n"
md5Warning = ("Your game version appears to be unknown. If this is *NOT* a fan-modified\n"
"version (in particular, not a fan-made translation), please, report the\n"
"following data to the ScummVM team along with the name of the game you tried\n"
"to add and its version, language, etc.:\n");
md5Warning += Common::String::format(" SCUMM gameid '%s', file '%s', MD5 '%s'\n\n",
// md5WarningTranslated = _(md5Warning);
additionalInfo = Common::String::format(" SCUMM gameid '%s', file '%s', MD5 '%s'\n\n",
res.game.gameid,
generateFilenameForDetection(res.fp.pattern, res.fp.genMethod, res.game.platform).c_str(),
res.md5.c_str());
g_system->logMessage(LogMessageType::kWarning, md5Warning.encode().c_str());
md5Warning += additionalInfo;
// md5WarningTranslated += additionalInfo;
g_system->logMessage(LogMessageType::kWarning, md5Warning.c_str());
} else {
debug(1, "Using MD5 '%s'", res.md5.c_str());
}

View File

@ -509,7 +509,7 @@ void ConfirmDialog::handleKeyDown(Common::KeyState state) {
#pragma mark -
ValueDisplayDialog::ValueDisplayDialog(const Common::U32String& label, int minVal, int maxVal,
ValueDisplayDialog::ValueDisplayDialog(const Common::U32String &label, int minVal, int maxVal,
int val, uint16 incKey, uint16 decKey)
: GUI::Dialog(0, 0, 0, 0),
_label(label), _min(minVal), _max(maxVal),

View File

@ -127,7 +127,7 @@ protected:
*/
class ValueDisplayDialog : public GUI::Dialog {
public:
ValueDisplayDialog(const Common::U32String& label, int minVal, int maxVal, int val, uint16 incKey, uint16 decKey);
ValueDisplayDialog(const Common::U32String &label, int minVal, int maxVal, int val, uint16 incKey, uint16 decKey);
void open() override;
void drawDialog(GUI::DrawLayer layerToDraw) override;

View File

@ -22,8 +22,6 @@
#include "common/str.h"
#include "common/ustr.h"
#include "common/util.h"
#include "scumm/help.h"

View File

@ -2444,7 +2444,7 @@ void ScummEngine::scummLoop_updateScummVars() {
void ScummEngine::scummLoop_handleSaveLoad() {
if (_saveLoadFlag) {
bool success;
Common::U32String errMsg("");
const char *errMsg = 0;
if (_game.version == 8 && _saveTemporaryState)
VAR(VAR_GAME_LOADED) = 0;
@ -2453,7 +2453,7 @@ void ScummEngine::scummLoop_handleSaveLoad() {
if (_saveLoadFlag == 1) {
success = saveState(_saveLoadSlot, _saveTemporaryState, filename);
if (!success)
errMsg = _("Failed to save game to file:\n\n%s");
errMsg = "Failed to save game to file:\n\n%s";
if (success && _saveTemporaryState && VAR_GAME_LOADED != 0xFF && _game.version <= 7)
VAR(VAR_GAME_LOADED) = 201;
@ -2463,20 +2463,19 @@ void ScummEngine::scummLoop_handleSaveLoad() {
} else {
success = loadState(_saveLoadSlot, _saveTemporaryState, filename);
if (!success)
errMsg = _("Failed to load saved game from file:\n\n%s");
errMsg = "Failed to load saved game from file:\n\n%s";
if (success && _saveTemporaryState && VAR_GAME_LOADED != 0xFF)
VAR(VAR_GAME_LOADED) = (_game.version == 8) ? 1 : 203;
}
if (!success) {
displayMessage(0, errMsg.encode().c_str(), filename.c_str());
displayMessage(0, errMsg, filename.c_str());
} else if (_saveLoadFlag == 1 && _saveLoadSlot != 0 && !_saveTemporaryState) {
// Display "Save successful" message, except for auto saves
char buf[256];
snprintf(buf, sizeof(buf), _("Successfully saved game in file:\n\n%s").encode().c_str(), filename.c_str());
Common::U32String buf = Common::U32String::format(_("Successfully saved game in file:\n\n%s"), filename.c_str());
GUI::TimedMessageDialog dialog(Common::U32String(buf), 1500);
GUI::TimedMessageDialog dialog(buf, 1500);
runDialog(dialog);
}
if (success && _saveLoadFlag != 1)
@ -2759,7 +2758,10 @@ bool ScummEngine::startManiac() {
eventMan->pushEvent(event);
return true;
} else {
displayMessage(0, "%s", _("Usually, Maniac Mansion would start now. But for that to work, the game files for Maniac Mansion have to be in the 'Maniac' directory inside the Tentacle game directory, and the game has to be added to ScummVM.").encode().c_str());
Common::U32String buf = Common::U32String::format(
_("Usually, Maniac Mansion would start now. But for that to work, the game files for Maniac Mansion have to be in the 'Maniac' directory \
inside the Tentacle game directory, and the game has to be added to ScummVM."));
GUI::MessageDialog dialog(buf);
return false;
}
}

View File

@ -313,7 +313,7 @@ SaveStateList SkyMetaEngine::listSaves(const char *target) const {
Common::InSaveFile *in = saveFileMan->openForLoading(*file);
if (in) {
saveList.push_back(SaveStateDescriptor(slotNum,
(slotNum == 0) ? _("Autosave").encode() : savenames[slotNum - 1]));
(slotNum == 0) ? _("Autosave") : Common::U32String(savenames[slotNum - 1])));
delete in;
}
}

View File

@ -76,32 +76,32 @@ void SoundSubsystemDialog::handleCommand(GUI::CommandSender *sender, uint32 cmd,
switch (cmd) {
case kPlayChannel1:
_buttonArray[0]->setLabel(Common::convertToU32String("Pause Channel #1"));
_buttonArray[0]->setLabel("Pause Channel #1");
_buttonArray[0]->setCmd(kPauseChannel1);
_mixer->pauseHandle(_h1, false);
break;
case kPlayChannel2:
_buttonArray[1]->setLabel(Common::convertToU32String("Pause Channel #2"));
_buttonArray[1]->setLabel("Pause Channel #2");
_buttonArray[1]->setCmd(kPauseChannel2);
_mixer->pauseHandle(_h2, false);
break;
case kPlayChannel3:
_buttonArray[2]->setLabel(Common::convertToU32String("Pause Channel #3"));
_buttonArray[2]->setLabel("Pause Channel #3");
_buttonArray[2]->setCmd(kPauseChannel3);
_mixer->pauseHandle(_h3, false);
break;
case kPauseChannel1:
_buttonArray[0]->setLabel(Common::convertToU32String("Play Channel #1"));
_buttonArray[0]->setLabel("Play Channel #1");
_buttonArray[0]->setCmd(kPlayChannel1);
_mixer->pauseHandle(_h1, true);
break;
case kPauseChannel2:
_buttonArray[1]->setLabel(Common::convertToU32String("Play Channel #2"));
_buttonArray[1]->setLabel("Play Channel #2");
_buttonArray[1]->setCmd(kPlayChannel2);
_mixer->pauseHandle(_h2, true);
break;
case kPauseChannel3:
_buttonArray[2]->setLabel(Common::convertToU32String("Play Channel #3"));
_buttonArray[2]->setLabel("Play Channel #3");
_buttonArray[2]->setCmd(kPlayChannel3);
_mixer->pauseHandle(_h3, true);
break;

View File

@ -321,7 +321,7 @@ Common::Error NuvieEngine::saveGameState(int slot, const Common::String &desc, b
// Display that the game was saved
MsgScroll *scroll = Game::get_game()->get_scroll();
scroll->display_string(_("\nGame Saved\n\n").encode().c_str());
scroll->display_string("\nGame Saved\n\n");
scroll->display_prompt();
}