From 53c5487abe80dc1c407b4e58dbb41a9a1a8fb335 Mon Sep 17 00:00:00 2001 From: mniip Date: Tue, 24 Mar 2020 12:00:47 +0300 Subject: [PATCH] Refactor stuff for i18n --- src/client/GameSave.cpp | 160 ++++++++++++++--------------- src/gui/game/GameController.cpp | 98 +++++++++--------- src/gui/game/GameView.cpp | 173 +++++++++++++++++--------------- src/lua/LegacyLuaAPI.cpp | 8 +- src/lua/LuaScriptHelper.h | 2 +- src/lua/LuaScriptInterface.cpp | 92 ++++++++--------- src/lua/TPTSTypes.h | 2 +- 7 files changed, 272 insertions(+), 263 deletions(-) diff --git a/src/client/GameSave.cpp b/src/client/GameSave.cpp index 3bc055752..94fcdbbfc 100644 --- a/src/client/GameSave.cpp +++ b/src/client/GameSave.cpp @@ -212,18 +212,18 @@ void GameSave::read(char * data, int dataSize) else if(data[0] == 'O' && data[1] == 'P' && data[2] == 'S') { if (data[3] != '1') - throw ParseException(ParseException::WrongVersion, "Save format from newer version"); + throw ParseException(ParseException::WrongVersion, "Save format from newer version"_i18n); readOPS(data, dataSize); } else { std::cerr << "Got Magic number '" << data[0] << data[1] << data[2] << "'" << std::endl; - throw ParseException(ParseException::Corrupt, "Invalid save format"); + throw ParseException(ParseException::Corrupt, "Invalid save format"_i18n); } } else { - throw ParseException(ParseException::Corrupt, "No data"); + throw ParseException(ParseException::Corrupt, "No data"_i18n); } } @@ -601,11 +601,11 @@ void GameSave::readOPS(char * data, int dataLength) //Incompatible cell size if (inputData[5] != CELL) - throw ParseException(ParseException::InvalidDimensions, "Incorrect CELL size"); + throw ParseException(ParseException::InvalidDimensions, "Incorrect CELL size"_i18n); //Too large/off screen if (blockX+blockW > XRES/CELL || blockY+blockH > YRES/CELL) - throw ParseException(ParseException::InvalidDimensions, "Save too large"); + throw ParseException(ParseException::InvalidDimensions, "Save too large"_i18n); setSize(blockW, blockH); @@ -617,11 +617,11 @@ void GameSave::readOPS(char * data, int dataLength) //Check for overflows, don't load saves larger than 200MB unsigned int toAlloc = bsonDataLen+1; if (toAlloc > 209715200 || !toAlloc) - throw ParseException(ParseException::InvalidDimensions, "Save data too large, refusing"); + throw ParseException(ParseException::InvalidDimensions, "Save data too large, refusing"_i18n); bsonData = (unsigned char*)malloc(toAlloc); if (!bsonData) - throw ParseException(ParseException::InternalError, "Unable to allocate memory"); + throw ParseException(ParseException::InternalError, "Unable to allocate memory"_i18n); //Make sure bsonData is null terminated, since all string functions need null terminated strings //(bson_iterator_key returns a pointer into bsonData, which is then used with strcmp) @@ -630,10 +630,11 @@ void GameSave::readOPS(char * data, int dataLength) int bz2ret; if ((bz2ret = BZ2_bzBuffToBuffDecompress((char*)bsonData, &bsonDataLen, (char*)(inputData+12), inputDataLen-12, 0, 0)) != BZ_OK) { - throw ParseException(ParseException::Corrupt, String::Build("Unable to decompress (ret ", bz2ret, ")")); + auto decompress = i18nMulti("Unable to decompress (", ")"); + throw ParseException(ParseException::Corrupt, String::Build(decompress[0], bz2ret, decompress[1])); } - set_bson_err_handler([](const char* err) { throw ParseException(ParseException::Corrupt, "BSON error when parsing save: " + ByteString(err).FromUtf8()); }); + set_bson_err_handler([](const char* err) { throw ParseException(ParseException::Corrupt, "BSON error when parsing save: "_i18n + ByteString(err).FromUtf8()); }); bson_init_data_size(&b, (char*)bsonData, bsonDataLen); bson_iterator_init(&iter, &b); @@ -674,7 +675,7 @@ void GameSave::readOPS(char * data, int dataLength) bson_iterator signiter; bson_iterator_subiterator(&subiter, &signiter); - sign tempSign("", 0, 0, sign::Left); + sign tempSign(""_ascii, 0, 0, sign::Left); while (bson_iterator_next(&signiter)) { if (!strcmp(bson_iterator_key(&signiter), "text") && bson_iterator_type(&signiter) == BSON_STRING) @@ -682,13 +683,13 @@ void GameSave::readOPS(char * data, int dataLength) tempSign.text = format::CleanString(ByteString(bson_iterator_string(&signiter)).FromUtf8(), true, true, true).Substr(0, 45); if (majorVersion < 94 || (majorVersion == 94 && minorVersion < 2)) { - if (tempSign.text == "{t}") + if (tempSign.text == "{t}"_ascii) { - tempSign.text = "Temp: {t}"; + tempSign.text = "Temp: {t}"_ascii; } - else if (tempSign.text == "{p}") + else if (tempSign.text == "{p}"_ascii) { - tempSign.text = "Pressure: {p}"; + tempSign.text = "Pressure: {p}"_ascii; } } } @@ -825,7 +826,7 @@ void GameSave::readOPS(char * data, int dataLength) if (major > SAVE_VERSION || (major == SAVE_VERSION && minor > MINOR_VERSION)) #endif { - String errorMessage = String::Build("Save from a newer version: Requires version ", major, ".", minor); + String errorMessage = String::Build("Save from a newer version: Requires version "_i18n, major, "."_ascii, minor); throw ParseException(ParseException::WrongVersion, errorMessage); } #if defined(SNAPSHOT) || defined(DEBUG) @@ -861,7 +862,7 @@ void GameSave::readOPS(char * data, int dataLength) { unsigned int j = 0; if (blockW * blockH > wallDataLen) - throw ParseException(ParseException::Corrupt, "Not enough wall data"); + throw ParseException(ParseException::Corrupt, "Not enough wall data"_i18n); for (unsigned int x = 0; x < blockW; x++) { for (unsigned int y = 0; y < blockH; y++) @@ -924,7 +925,7 @@ void GameSave::readOPS(char * data, int dataLength) unsigned int j = 0; unsigned char i, i2; if (blockW * blockH > pressDataLen) - throw ParseException(ParseException::Corrupt, "Not enough pressure data"); + throw ParseException(ParseException::Corrupt, "Not enough pressure data"_i18n); for (unsigned int x = 0; x < blockW; x++) { for (unsigned int y = 0; y < blockH; y++) @@ -943,7 +944,7 @@ void GameSave::readOPS(char * data, int dataLength) unsigned int j = 0; unsigned char i, i2; if (blockW * blockH > vxDataLen) - throw ParseException(ParseException::Corrupt, "Not enough vx data"); + throw ParseException(ParseException::Corrupt, "Not enough vx data"_i18n); for (unsigned int x = 0; x < blockW; x++) { for (unsigned int y = 0; y < blockH; y++) @@ -961,7 +962,7 @@ void GameSave::readOPS(char * data, int dataLength) unsigned int j = 0; unsigned char i, i2; if (blockW * blockH > vyDataLen) - throw ParseException(ParseException::Corrupt, "Not enough vy data"); + throw ParseException(ParseException::Corrupt, "Not enough vy data"_i18n); for (unsigned int x = 0; x < blockW; x++) { for (unsigned int y = 0; y < blockH; y++) @@ -978,7 +979,7 @@ void GameSave::readOPS(char * data, int dataLength) { unsigned int i = 0, tempTemp; if (blockW * blockH > ambientDataLen) - throw ParseException(ParseException::Corrupt, "Not enough ambient heat data"); + throw ParseException(ParseException::Corrupt, "Not enough ambient heat data"_i18n); for (unsigned int x = 0; x < blockW; x++) { for (unsigned int y = 0; y < blockH; y++) @@ -997,7 +998,7 @@ void GameSave::readOPS(char * data, int dataLength) int newIndex = 0, fieldDescriptor, tempTemp; int posCount, posTotal, partsPosDataIndex = 0; if (fullW * fullH * 3 > partsPosDataLen) - throw ParseException(ParseException::Corrupt, "Not enough particle position data"); + throw ParseException(ParseException::Corrupt, "Not enough particle position data"_i18n); partsCount = 0; @@ -1019,16 +1020,16 @@ void GameSave::readOPS(char * data, int dataLength) particlesCount = newIndex+1; //i+3 because we have 4 bytes of required fields (type (1), descriptor (2), temp (1)) if (i+3 >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer"_i18n); x = saved_x + fullX; y = saved_y + fullY; fieldDescriptor = partsData[i+1]; fieldDescriptor |= partsData[i+2] << 8; if (x >= fullW || y >= fullH) - throw ParseException(ParseException::Corrupt, "Particle out of range"); + throw ParseException(ParseException::Corrupt, "Particle out of range"_i18n); if (newIndex < 0 || newIndex >= NPART) - throw ParseException(ParseException::Corrupt, "Too many particles"); + throw ParseException(ParseException::Corrupt, "Too many particles"_i18n); //Clear the particle, ready for our new properties memset(&(particles[newIndex]), 0, sizeof(Particle)); @@ -1062,14 +1063,14 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x02) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading life"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading life"_i18n); particles[newIndex].life = partsData[i++]; //i++; //Read 2nd byte if(fieldDescriptor & 0x04) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading life"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading life"_i18n); particles[newIndex].life |= (((unsigned)partsData[i++]) << 8); } } @@ -1078,19 +1079,19 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x08) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp"_i18n); particles[newIndex].tmp = partsData[i++]; //Read 2nd byte if(fieldDescriptor & 0x10) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp"_i18n); particles[newIndex].tmp |= (((unsigned)partsData[i++]) << 8); //Read 3rd and 4th bytes if(fieldDescriptor & 0x1000) { if (i+1 >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp"_i18n); particles[newIndex].tmp |= (((unsigned)partsData[i++]) << 24); particles[newIndex].tmp |= (((unsigned)partsData[i++]) << 16); } @@ -1101,13 +1102,13 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x20) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading ctype"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading ctype"_i18n); particles[newIndex].ctype = partsData[i++]; //Read additional bytes if(fieldDescriptor & 0x200) { if (i+2 >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading ctype"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading ctype"_i18n); particles[newIndex].ctype |= (((unsigned)partsData[i++]) << 24); particles[newIndex].ctype |= (((unsigned)partsData[i++]) << 16); particles[newIndex].ctype |= (((unsigned)partsData[i++]) << 8); @@ -1118,7 +1119,7 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x40) { if (i+3 >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading deco"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading deco"_i18n); particles[newIndex].dcolour = (((unsigned)partsData[i++]) << 24); particles[newIndex].dcolour |= (((unsigned)partsData[i++]) << 16); particles[newIndex].dcolour |= (((unsigned)partsData[i++]) << 8); @@ -1129,7 +1130,7 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x80) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading vx"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading vx"_i18n); particles[newIndex].vx = (partsData[i++]-127.0f)/16.0f; } @@ -1137,7 +1138,7 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x100) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading vy"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading vy"_i18n); particles[newIndex].vy = (partsData[i++]-127.0f)/16.0f; } @@ -1145,12 +1146,12 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x400) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp2"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp2"_i18n); particles[newIndex].tmp2 = partsData[i++]; if(fieldDescriptor & 0x800) { if (i >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp2"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading tmp2"_i18n); particles[newIndex].tmp2 |= (((unsigned)partsData[i++]) << 8); } } @@ -1159,7 +1160,7 @@ void GameSave::readOPS(char * data, int dataLength) if(fieldDescriptor & 0x2000) { if (i+3 >= partsDataLen) - throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading pavg"); + throw ParseException(ParseException::Corrupt, "Ran past particle data buffer while loading pavg"_i18n); int pavg; pavg = partsData[i++]; pavg |= (((unsigned)partsData[i++]) << 8); @@ -1307,7 +1308,7 @@ void GameSave::readOPS(char * data, int dataLength) } if (i != partsDataLen) - throw ParseException(ParseException::Corrupt, "Didn't reach end of particle data buffer"); + throw ParseException(ParseException::Corrupt, "Didn't reach end of particle data buffer"_i18n); } if (soapLinkData) @@ -1357,7 +1358,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) std::vector tempSigns; char tempSignText[255]; - sign tempSign("", 0, 0, sign::Left); + sign tempSign(""_ascii, 0, 0, sign::Left); //Gol data used to read older saves std::vector goltype = LoadGOLTypes(); @@ -1369,14 +1370,14 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) //This creates a problem for old clients, that display and "corrupt" error instead of a "newer version" error if (dataLength<16) - throw ParseException(ParseException::Corrupt, "No save data"); + throw ParseException(ParseException::Corrupt, "No save data"_i18n); if (!(saveData[2]==0x43 && saveData[1]==0x75 && saveData[0]==0x66) && !(saveData[2]==0x76 && saveData[1]==0x53 && saveData[0]==0x50)) - throw ParseException(ParseException::Corrupt, "Unknown format"); + throw ParseException(ParseException::Corrupt, "Unknown format"_i18n); if (saveData[2]==0x76 && saveData[1]==0x53 && saveData[0]==0x50) { new_format = 1; } if (saveData[4]>SAVE_VERSION) - throw ParseException(ParseException::WrongVersion, "Save from newer version"); + throw ParseException(ParseException::WrongVersion, "Save from newer version"_i18n); ver = saveData[4]; majorVersion = saveData[4]; minorVersion = 0; @@ -1418,25 +1419,25 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) by0 = 0; if (saveData[5]!=CELL || bx0+bw>XRES/CELL || by0+bh>YRES/CELL) - throw ParseException(ParseException::InvalidDimensions, "Save too large"); + throw ParseException(ParseException::InvalidDimensions, "Save too large"_i18n); int size = (unsigned)saveData[8]; size |= ((unsigned)saveData[9])<<8; size |= ((unsigned)saveData[10])<<16; size |= ((unsigned)saveData[11])<<24; if (size > 209715200 || !size) - throw ParseException(ParseException::InvalidDimensions, "Save data too large"); + throw ParseException(ParseException::InvalidDimensions, "Save data too large"_i18n); auto dataPtr = std::unique_ptr(new unsigned char[size]); unsigned char *data = dataPtr.get(); if (!data) - throw ParseException(ParseException::Corrupt, "Cannot allocate memory"); + throw ParseException(ParseException::Corrupt, "Cannot allocate memory"_i18n); setSize(bw, bh); int bzStatus = 0; if ((bzStatus = BZ2_bzBuffToBuffDecompress((char *)data, (unsigned *)&size, (char *)(saveData+12), dataLength-12, 0, 0))) - throw ParseException(ParseException::Corrupt, String::Build("Cannot decompress: ", bzStatus)); + throw ParseException(ParseException::Corrupt, String::Build("Cannot decompress: "_i18n, bzStatus)); dataLength = size; #ifdef DEBUG @@ -1444,7 +1445,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) #endif if (dataLength < bw*bh) - throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)"); + throw ParseException(ParseException::Corrupt, "Save data corrupt (missing data)"_i18n); // normalize coordinates x0 = bx0*CELL; @@ -1461,7 +1462,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) int *particleIDMap = particleIDMapPtr.get(); std::fill(&particleIDMap[0], &particleIDMap[XRES*YRES], 0); if (!particleIDMap) - throw ParseException(ParseException::Corrupt, "Cannot allocate memory"); + throw ParseException(ParseException::Corrupt, "Cannot allocate memory"_i18n); // load the required air state for (y=by0; y=44 && data[(y-by0)*bw+(x-bx0)]==O_WL_FAN)) { if (p >= dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); fanVelX[y][x] = (data[p++]-127.0f)/64.0f; } for (y=by0; y=44 && data[(y-by0)*bw+(x-bx0)]==O_WL_FAN)) { if (p >= dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); fanVelY[y][x] = (data[p++]-127.0f)/64.0f; } @@ -1574,10 +1575,10 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) for (x=x0; x= dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); j=data[p++]; if (j >= PT_NUM) { - j = PT_DUST;//throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + j = PT_DUST;//throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (j) { @@ -1608,7 +1609,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) { i--; if (p+1 >= dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); if (i < NPART) { particles[i].vx = (data[p++]-127.0f)/16.0f; @@ -1625,7 +1626,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) { if (ver>=44) { if (p >= dataLength) { - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (i <= NPART) { ttv = (data[p++])<<8; @@ -1636,7 +1637,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) } } else { if (p >= dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); if (i <= NPART) particles[i-1].life = data[p++]*4; else @@ -1651,7 +1652,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) if (i) { if (p >= dataLength) { - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (i <= NPART) { ttv = (data[p++])<<8; @@ -1681,7 +1682,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) if (i && (ty==PT_PBCN || (ty==PT_TRON && ver>=77))) { if (p >= dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); if (i <= NPART) particles[i-1].tmp2 = data[p++]; else @@ -1697,7 +1698,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) { if (ver>=49) { if (p >= dataLength) { - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (i <= NPART) { particles[i-1].dcolour = data[p++]<<24; @@ -1715,7 +1716,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) { if (ver>=49) { if (p >= dataLength) { - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (i <= NPART) { particles[i-1].dcolour |= data[p++]<<16; @@ -1733,7 +1734,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) { if (ver>=49) { if (p >= dataLength) { - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (i <= NPART) { particles[i-1].dcolour |= data[p++]<<8; @@ -1751,7 +1752,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) { if (ver>=49) { if (p >= dataLength) { - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (i <= NPART) { particles[i-1].dcolour |= data[p++]; @@ -1771,7 +1772,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) { if (p >= dataLength) { - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); } if (i <= NPART) { @@ -1813,7 +1814,7 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) if (i && (ty==PT_CLNE || (ty==PT_PCLN && ver>=43) || (ty==PT_BCLN && ver>=44) || (ty==PT_SPRK && ver>=21) || (ty==PT_LAVA && ver>=34) || (ty==PT_PIPE && ver>=43) || (ty==PT_LIFE && ver>=51) || (ty==PT_PBCN && ver>=52) || (ty==PT_WIRE && ver>=55) || (ty==PT_STOR && ver>=59) || (ty==PT_CONV && ver>=60))) { if (p >= dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); if (i <= NPART) particles[i-1].ctype = data[p++]; else @@ -1955,13 +1956,13 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) } if (p >= dataLength) - throw ParseException(ParseException::Corrupt, "Ran past data buffer"); + throw ParseException(ParseException::Corrupt, "Ran past data buffer"_i18n); j = data[p++]; for (i=0; i dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); x = data[p++]; x |= ((unsigned)data[p++])<<8; tempSign.x = x+x0; @@ -1972,19 +1973,19 @@ void GameSave::readPSv(char * saveDataChar, int dataLength) tempSign.ju = (sign::Justification)x; x = data[p++]; if (p+x > dataLength) - throw ParseException(ParseException::Corrupt, "Not enough data at line " MTOS(__LINE__) " in " MTOS(__FILE__)); + throw ParseException(ParseException::Corrupt, "Not enough data at "_i18n + ByteString(MTOS(__FILE__) ":" MTOS(__LINE__)).FromUtf8()); if(x>254) x = 254; memcpy(tempSignText, data+p, x); tempSignText[x] = 0; tempSign.text = format::CleanString(ByteString(tempSignText).FromUtf8(), true, true, true).Substr(0, 45); - if (tempSign.text == "{t}") + if (tempSign.text == "{t}"_ascii) { - tempSign.text = "Temp: {t}"; + tempSign.text = "Temp: {t}"_ascii; } - else if (tempSign.text == "{p}") + else if (tempSign.text == "{p}"_ascii) { - tempSign.text = "Pressure: {p}"; + tempSign.text = "Pressure: {p}"_ascii; } tempSigns.push_back(tempSign); p += x; @@ -2045,7 +2046,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) auto ambientData = std::unique_ptr(new unsigned char[blockWidth*blockHeight*2]); std::fill(&ambientData[0], &ambientData[blockWidth*blockHeight*2], 0); if (!wallData || !fanData || !pressData || !vxData || !vyData || !ambientData) - throw BuildException("Save error, out of memory (blockmaps)"); + throw BuildException("Save error, out of memory (blockmaps)"_i18n); unsigned int wallDataLen = blockWidth*blockHeight, fanDataLen = 0, pressDataLen = 0, vxDataLen = 0, vyDataLen = 0, ambientDataLen = 0; for (x = blockX; x < blockX+blockW; x++) @@ -2107,7 +2108,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) auto partsPosCount = std::unique_ptr(new unsigned[fullW*fullH]); auto partsPosLink = std::unique_ptr(new unsigned[NPART]); if (!partsPosFirstMap || !partsPosLastMap || !partsPosCount || !partsPosLink) - throw BuildException("Save error, out of memory (partmaps)"); + throw BuildException("Save error, out of memory (partmaps)"_i18n); std::fill(&partsPosFirstMap[0], &partsPosFirstMap[fullW*fullH], 0); std::fill(&partsPosLastMap[0], &partsPosLastMap[fullW*fullH], 0); std::fill(&partsPosCount[0], &partsPosCount[fullW*fullH], 0); @@ -2142,7 +2143,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) auto partsPosData = std::unique_ptr(new unsigned char[fullW*fullH*3]); unsigned int partsPosDataLen = 0; if (!partsPosData) - throw BuildException("Save error, out of memory (partposdata)"); + throw BuildException("Save error, out of memory (partposdata)"_i18n); for (y=0;y(new unsigned[NPART]); unsigned int partsCount = 0; if (!partsData || !partsSaveIndex) - throw BuildException("Save error, out of memory (partsdata)"); + throw BuildException("Save error, out of memory (partsdata)"_i18n); std::fill(&partsSaveIndex[0], &partsSaveIndex[NPART], 0); for (y=0;y(soapLinkData); //Iterate through particles in the same order that they were saved @@ -2484,7 +2485,7 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) // Use unique_ptr with a custom deleter to ensure that bson_destroy is called even when an exception is thrown std::unique_ptr b_ptr(&b, bson_deleter); - set_bson_err_handler([](const char* err) { throw BuildException("BSON error when parsing save: " + ByteString(err).FromUtf8()); }); + set_bson_err_handler([](const char* err) { throw BuildException("BSON error when parsing save: "_i18n + ByteString(err).FromUtf8()); }); bson_init(&b); bson_append_start_object(&b, "origin"); bson_append_int(&b, "majorVersion", SAVE_VERSION); @@ -2605,13 +2606,13 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) bson_append_finish_object(&b); } if (bson_finish(&b) == BSON_ERROR) - throw BuildException("Error building bson data"); + throw BuildException("Error building bson data"_i18n); unsigned char *finalData = (unsigned char*)bson_data(&b); unsigned int finalDataLen = bson_size(&b); auto outputData = std::unique_ptr(new unsigned char[finalDataLen*2+12]); if (!outputData) - throw BuildException(String::Build("Save error, out of memory (finalData): ", finalDataLen*2+12)); + throw BuildException(String::Build("Save error, out of memory (finalData): "_i18n, finalDataLen*2+12)); outputData[0] = 'O'; outputData[1] = 'P'; @@ -2629,7 +2630,8 @@ char * GameSave::serialiseOPS(unsigned int & dataLength) unsigned int compressedSize = finalDataLen*2, bz2ret; if ((bz2ret = BZ2_bzBuffToBuffCompress((char*)(outputData.get()+12), &compressedSize, (char*)finalData, bson_size(&b), 9, 0, 0)) != BZ_OK) { - throw BuildException(String::Build("Save error, could not compress (ret ", bz2ret, ")")); + auto compress = i18nMulti("Save error, could not compress (", ")"); + throw BuildException(String::Build(compress[0], bz2ret, compress[1])); } #ifdef DEBUG diff --git a/src/gui/game/GameController.cpp b/src/gui/game/GameController.cpp index 77c515206..91d088b20 100644 --- a/src/gui/game/GameController.cpp +++ b/src/gui/game/GameController.cpp @@ -295,20 +295,20 @@ void GameController::PlaceSave(ui::Point position) void GameController::Install() { #if defined(MACOSX) - new InformationMessage("No installation necessary", "You don't need to install The Powder Toy on OS X", false); + new InformationMessage("No installation necessary"_i18n, "You don't need to install The Powder Toy on OS X"_i18n, false); #elif defined(WIN) || defined(LIN) - new ConfirmPrompt("Install The Powder Toy", "Do you wish to install The Powder Toy on this computer?\nThis allows you to open save files and saves directly from the website.", { [] { + new ConfirmPrompt("Install The Powder Toy"_i18n, "Do you wish to install The Powder Toy on this computer?\nThis allows you to open save files and saves directly from the website."_i18n, { [] { if (Client::Ref().DoInstallation()) { - new InformationMessage("Success", "Installation completed", false); + new InformationMessage("Success"_i18n, "Installation completed"_i18n, false); } else { - new ErrorMessage("Could not install", "The installation did not complete due to an error"); + new ErrorMessage("Could not install"_i18n, "The installation did not complete due to an error"_i18n); } } }); #else - new ErrorMessage("Cannot install", "You cannot install The Powder Toy on this platform"); + new ErrorMessage("Cannot install"_i18n, "You cannot install The Powder Toy on this platform"_i18n); #endif } @@ -519,12 +519,12 @@ ByteString GameController::StampRegion(ui::Point point1, ui::Point point2) ByteString stampName = Client::Ref().AddStamp(newSave); delete newSave; if (stampName.length() == 0) - new ErrorMessage("Could not create stamp", "Error serializing save file"); + new ErrorMessage("Could not create stamp"_i18n, "Error serializing save file"_i18n); return stampName; } else { - new ErrorMessage("Could not create stamp", "Error generating save file"); + new ErrorMessage("Could not create stamp"_i18n, "Error generating save file"_i18n); return ""; } } @@ -840,13 +840,13 @@ void GameController::SwitchGravity() switch (gameModel->GetSimulation()->gravityMode) { case 0: - gameModel->SetInfoTip("Gravity: Vertical"); + gameModel->SetInfoTip("Gravity: Vertical"_i18n); break; case 1: - gameModel->SetInfoTip("Gravity: Off"); + gameModel->SetInfoTip("Gravity: Off"_i18n); break; case 2: - gameModel->SetInfoTip("Gravity: Radial"); + gameModel->SetInfoTip("Gravity: Radial"_i18n); break; } } @@ -858,19 +858,19 @@ void GameController::SwitchAir() switch (gameModel->GetSimulation()->air->airMode) { case 0: - gameModel->SetInfoTip("Air: On"); + gameModel->SetInfoTip("Air: On"_i18n); break; case 1: - gameModel->SetInfoTip("Air: Pressure Off"); + gameModel->SetInfoTip("Air: Pressure Off"_i18n); break; case 2: - gameModel->SetInfoTip("Air: Velocity Off"); + gameModel->SetInfoTip("Air: Velocity Off"_i18n); break; case 3: - gameModel->SetInfoTip("Air: Off"); + gameModel->SetInfoTip("Air: Off"_i18n); break; case 4: - gameModel->SetInfoTip("Air: No Update"); + gameModel->SetInfoTip("Air: No Update"_i18n); break; } } @@ -1164,7 +1164,7 @@ void GameController::OpenSearch(String searchText) } catch(GameModelException & ex) { - new ErrorMessage("Cannot open save", ByteString(ex.what()).FromUtf8()); + new ErrorMessage("Cannot open save"_i18n, ByteString(ex.what()).FromUtf8()); } } }); @@ -1179,7 +1179,7 @@ void GameController::OpenLocalSaveWindow(bool asCurrent) GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour()); if(!gameSave) { - new ErrorMessage("Error", "Unable to build save."); + new ErrorMessage("Error"_i18n, "Unable to build save."_i18n); } else { @@ -1213,11 +1213,11 @@ void GameController::OpenLocalSaveWindow(bool asCurrent) Client::Ref().MakeDirectory(LOCAL_SAVE_DIR); std::vector saveData = gameSave->Serialise(); if (saveData.size() == 0) - new ErrorMessage("Error", "Unable to serialize game data."); + new ErrorMessage("Error"_i18n, "Unable to serialize game data."_i18n); else if (Client::Ref().WriteFile(saveData, gameModel->GetSaveFile()->GetName())) - new ErrorMessage("Error", "Unable to write save file."); + new ErrorMessage("Error"_i18n, "Unable to write save file."_i18n); else - gameModel->SetInfoTip("Saved Successfully"); + gameModel->SetInfoTip("Saved Successfully"_i18n); } } } @@ -1244,7 +1244,7 @@ void GameController::OpenSaveDone() } catch(GameModelException & ex) { - new ErrorMessage("Cannot open save", ByteString(ex.what()).FromUtf8()); + new ErrorMessage("Cannot open save"_i18n, ByteString(ex.what()).FromUtf8()); } } } @@ -1326,7 +1326,7 @@ void GameController::OpenTags() } else { - new ErrorMessage("Error", "No save open"); + new ErrorMessage("Error"_i18n, "No save open"_i18n); } } @@ -1337,7 +1337,7 @@ void GameController::OpenStamps() if (file) { if (file->GetError().length()) - new ErrorMessage("Error loading stamp", file->GetError()); + new ErrorMessage("Error loading stamp"_i18n, file->GetError()); else if (localBrowser->GetMoveToFront()) Client::Ref().MoveStampToFront(file->GetDisplayName().ToUtf8()); LoadStamp(file->GetGameSave()); @@ -1385,7 +1385,7 @@ void GameController::OpenSaveWindow() GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour()); if(!gameSave) { - new ErrorMessage("Error", "Unable to build save."); + new ErrorMessage("Error"_i18n, "Unable to build save."_i18n); } else { @@ -1403,7 +1403,7 @@ void GameController::OpenSaveWindow() } else { - SaveInfo tempSave(0, 0, 0, 0, 0, gameModel->GetUser().Username, ""); + SaveInfo tempSave(0, 0, 0, 0, 0, gameModel->GetUser().Username, ""_ascii); tempSave.SetGameSave(gameSave); new ServerSaveActivity(tempSave, [this](SaveInfo &save) { save.SetVote(1); @@ -1415,7 +1415,7 @@ void GameController::OpenSaveWindow() } else { - new ErrorMessage("Error", "You need to login to upload saves."); + new ErrorMessage("Error"_i18n, "You need to login to upload saves."_i18n); } } @@ -1427,7 +1427,7 @@ void GameController::SaveAsCurrent() GameSave * gameSave = sim->Save(gameModel->GetIncludePressure() != gameView->ShiftBehaviour()); if(!gameSave) { - new ErrorMessage("Error", "Unable to build save."); + new ErrorMessage("Error"_i18n, "Unable to build save."_i18n); } else { @@ -1441,7 +1441,7 @@ void GameController::SaveAsCurrent() } else { - SaveInfo tempSave(0, 0, 0, 0, 0, gameModel->GetUser().Username, ""); + SaveInfo tempSave(0, 0, 0, 0, 0, gameModel->GetUser().Username, ""_ascii); tempSave.SetGameSave(gameSave); new ServerSaveActivity(tempSave, true, [this](SaveInfo &save) { LoadSave(&save); }); } @@ -1453,7 +1453,7 @@ void GameController::SaveAsCurrent() } else { - new ErrorMessage("Error", "You need to login to upload saves."); + new ErrorMessage("Error"_i18n, "You need to login to upload saves."_i18n); } } @@ -1473,7 +1473,7 @@ void GameController::Vote(int direction) } catch(GameModelException & ex) { - new ErrorMessage("Error while voting", ByteString(ex.what()).FromUtf8()); + new ErrorMessage("Error while voting"_i18n, ByteString(ex.what()).FromUtf8()); } } } @@ -1498,7 +1498,7 @@ String GameController::ElementResolve(int type, int ctype) { return gameModel->GetSimulation()->ElementResolve(type, ctype); } - return ""; + return ""_ascii; } String GameController::BasicParticleInfo(Particle const &sample_part) @@ -1507,7 +1507,7 @@ String GameController::BasicParticleInfo(Particle const &sample_part) { return gameModel->GetSimulation()->BasicParticleInfo(sample_part); } - return ""; + return ""_ascii; } void GameController::ReloadSim() @@ -1584,37 +1584,37 @@ void GameController::NotifyUpdateAvailable(Client * sender) UpdateInfo info = Client::Ref().GetUpdateInfo(); StringBuilder updateMessage; #ifndef MACOSX - updateMessage << "Are you sure you want to run the updater? Please save any changes before updating.\n\nCurrent version:\n "; + updateMessage << "Are you sure you want to run the updater? Please save any changes before updating.\n\nCurrent version:\n "_i18n; #else - updateMessage << "Click \"Continue\" to download the latest version from our website.\n\nCurrent version:\n "; + updateMessage << "Click \"Continue\" to download the latest version from our website.\n\nCurrent version:\n "_i18n; #endif #ifdef SNAPSHOT - updateMessage << "Snapshot " << SNAPSHOT_ID; + updateMessage << "Snapshot "_i18n << SNAPSHOT_ID; #elif MOD_ID > 0 - updateMessage << "Mod version " << SNAPSHOT_ID; + updateMessage << "Mod version "_i18n << SNAPSHOT_ID; #elif defined(BETA) - updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Beta, Build " << BUILD_NUM; + updateMessage << SAVE_VERSION << '.' << MINOR_VERSION << " Beta, Build "_i18n << BUILD_NUM; #else - updateMessage << SAVE_VERSION << "." << MINOR_VERSION << " Stable, Build " << BUILD_NUM; + updateMessage << SAVE_VERSION << '.' << MINOR_VERSION << " Stable, Build "_i18n << BUILD_NUM; #endif - updateMessage << "\nNew version:\n "; + updateMessage << "\nNew version:\n "_i18n; if (info.Type == UpdateInfo::Beta) - updateMessage << info.Major << "." << info.Minor << " Beta, Build " << info.Build; + updateMessage << info.Major << '.' << info.Minor << " Beta, Build "_i18n << info.Build; else if (info.Type == UpdateInfo::Snapshot) #if MOD_ID > 0 - updateMessage << "Mod version " << info.Time; + updateMessage << "Mod version "_i18n << info.Time; #else - updateMessage << "Snapshot " << info.Time; + updateMessage << "Snapshot "_i18n << info.Time; #endif else if(info.Type == UpdateInfo::Stable) - updateMessage << info.Major << "." << info.Minor << " Stable, Build " << info.Build; + updateMessage << info.Major << '.' << info.Minor << " Stable, Build "_i18n << info.Build; if (info.Changelog.length()) - updateMessage << "\n\nChangelog:\n" << info.Changelog; + updateMessage << "\n\nChangelog:\n"_i18n << info.Changelog; - new ConfirmPrompt("Run Updater", updateMessage.Build(), { [this] { c->RunUpdater(); } }); + new ConfirmPrompt("Run Updater"_i18n, updateMessage.Build(), { [this] { c->RunUpdater(); } }); } }; @@ -1622,16 +1622,16 @@ void GameController::NotifyUpdateAvailable(Client * sender) { case UpdateInfo::Snapshot: #if MOD_ID > 0 - gameModel->AddNotification(new UpdateNotification(this, "A new mod update is available - click here to update")); + gameModel->AddNotification(new UpdateNotification(this, "A new mod update is available - click here to update"_i18n)); #else - gameModel->AddNotification(new UpdateNotification(this, "A new snapshot is available - click here to update")); + gameModel->AddNotification(new UpdateNotification(this, "A new snapshot is available - click here to update"_i18n)); #endif break; case UpdateInfo::Stable: - gameModel->AddNotification(new UpdateNotification(this, "A new version is available - click here to update")); + gameModel->AddNotification(new UpdateNotification(this, "A new version is available - click here to update"_i18n)); break; case UpdateInfo::Beta: - gameModel->AddNotification(new UpdateNotification(this, "A new beta is available - click here to update")); + gameModel->AddNotification(new UpdateNotification(this, "A new beta is available - click here to update"_i18n)); break; } } diff --git a/src/gui/game/GameView.cpp b/src/gui/game/GameView.cpp index fe1e5417f..89a4eccdf 100644 --- a/src/gui/game/GameView.cpp +++ b/src/gui/game/GameView.cpp @@ -181,13 +181,13 @@ GameView::GameView(): lastMenu(-1), toolTipPresence(0), - toolTip(""), + toolTip(""_ascii), isToolTipFadingIn(false), toolTipPosition(-1, -1), infoTipPresence(0), - infoTip(""), + infoTip(""_ascii), buttonTipShow(0), - buttonTip(""), + buttonTip(""_ascii), isButtonTipFadingIn(false), introText(2048), introTextMessage(ByteString(introTextData).FromUtf8()), @@ -217,14 +217,14 @@ GameView::GameView(): int currentX = 1; //Set up UI - scrollBar = new ui::Button(ui::Point(0,YRES+21), ui::Point(XRES, 2), ""); + scrollBar = new ui::Button(ui::Point(0,YRES+21), ui::Point(XRES, 2), ""_ascii); scrollBar->Appearance.BorderHover = ui::Colour(200, 200, 200); scrollBar->Appearance.BorderActive = ui::Colour(200, 200, 200); scrollBar->Appearance.HorizontalAlign = ui::Appearance::AlignCentre; scrollBar->Appearance.VerticalAlign = ui::Appearance::AlignMiddle; AddComponent(scrollBar); - searchButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(17, 15), "", "Find & open a simulation. Hold Ctrl to load offline saves."); //Open + searchButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(17, 15), ""_ascii, "Find & open a simulation. Hold Ctrl to load offline saves."_i18n); //Open searchButton->SetIcon(IconOpen); currentX+=18; searchButton->SetTogglable(false); @@ -232,18 +232,18 @@ GameView::GameView(): if (CtrlBehaviour()) c->OpenLocalBrowse(); else - c->OpenSearch(""); + c->OpenSearch(""_ascii); } }); AddComponent(searchButton); - reloadButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(17, 15), "", "Reload the simulation"); + reloadButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(17, 15), ""_ascii, "Reload the simulation"_i18n); reloadButton->SetIcon(IconReload); reloadButton->Appearance.Margin.Left+=2; currentX+=18; reloadButton->SetActionCallback({ [this] { c->ReloadSim(); }, [this] { c->OpenSavePreview(); } }); AddComponent(reloadButton); - saveSimulationButton = new SplitButton(ui::Point(currentX, Size.Y-16), ui::Point(150, 15), "[untitled simulation]", "", "", 19); + saveSimulationButton = new SplitButton(ui::Point(currentX, Size.Y-16), ui::Point(150, 15), "[untitled simulation]"_i18n, ""_ascii, ""_ascii, 19); saveSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; saveSimulationButton->SetIcon(IconSave); currentX+=151; @@ -264,7 +264,7 @@ GameView::GameView(): SetSaveButtonTooltips(); AddComponent(saveSimulationButton); - upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(39, 15), "", "Like this save"); + upVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(39, 15), ""_ascii, "Like this save"_i18n); upVoteButton->SetIcon(IconVoteUp); upVoteButton->Appearance.Margin.Top+=2; upVoteButton->Appearance.Margin.Left+=2; @@ -272,7 +272,7 @@ GameView::GameView(): upVoteButton->SetActionCallback({ [this] { c->Vote(1); } }); AddComponent(upVoteButton); - downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(15, 15), "", "Dislike this save"); + downVoteButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(15, 15), ""_ascii, "Dislike this save"_i18n); downVoteButton->SetIcon(IconVoteDown); downVoteButton->Appearance.Margin.Bottom+=2; downVoteButton->Appearance.Margin.Left+=2; @@ -280,20 +280,20 @@ GameView::GameView(): downVoteButton->SetActionCallback({ [this] { c->Vote(-1); } }); AddComponent(downVoteButton); - tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(227, 15), "[no tags set]", "Add simulation tags"); + tagSimulationButton = new ui::Button(ui::Point(currentX, Size.Y-16), ui::Point(227, 15), "[no tags set]"_i18n, "Add simulation tags"_i18n); tagSimulationButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; tagSimulationButton->SetIcon(IconTag); //currentX+=252; tagSimulationButton->SetActionCallback({ [this] { c->OpenTags(); } }); AddComponent(tagSimulationButton); - clearSimButton = new ui::Button(ui::Point(Size.X-159, Size.Y-16), ui::Point(17, 15), "", "Erase everything"); + clearSimButton = new ui::Button(ui::Point(Size.X-159, Size.Y-16), ui::Point(17, 15), ""_ascii, "Erase everything"_i18n); clearSimButton->SetIcon(IconNew); clearSimButton->Appearance.Margin.Left+=2; clearSimButton->SetActionCallback({ [this] { c->ClearSim(); } }); AddComponent(clearSimButton); - loginButton = new SplitButton(ui::Point(Size.X-141, Size.Y-16), ui::Point(92, 15), "[sign in]", "Sign into simulation server", "Edit Profile", 19); + loginButton = new SplitButton(ui::Point(Size.X-141, Size.Y-16), ui::Point(92, 15), "[sign in]"_i18n, "Sign into simulation server"_i18n, "Edit Profile"_i18n, 19); loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft; loginButton->SetIcon(IconLogin); loginButton->SetSplitActionCallback({ @@ -302,30 +302,30 @@ GameView::GameView(): }); AddComponent(loginButton); - simulationOptionButton = new ui::Button(ui::Point(Size.X-48, Size.Y-16), ui::Point(15, 15), "", "Simulation options"); + simulationOptionButton = new ui::Button(ui::Point(Size.X-48, Size.Y-16), ui::Point(15, 15), ""_ascii, "Simulation options"_i18n); simulationOptionButton->SetIcon(IconSimulationSettings); simulationOptionButton->Appearance.Margin.Left+=2; simulationOptionButton->SetActionCallback({ [this] { c->OpenOptions(); } }); AddComponent(simulationOptionButton); - displayModeButton = new ui::Button(ui::Point(Size.X-32, Size.Y-16), ui::Point(15, 15), "", "Renderer options"); + displayModeButton = new ui::Button(ui::Point(Size.X-32, Size.Y-16), ui::Point(15, 15), ""_ascii, "Renderer options"_i18n); displayModeButton->SetIcon(IconRenderSettings); displayModeButton->Appearance.Margin.Left+=2; displayModeButton->SetActionCallback({ [this] { c->OpenRenderOptions(); } }); AddComponent(displayModeButton); - pauseButton = new ui::Button(ui::Point(Size.X-16, Size.Y-16), ui::Point(15, 15), "", "Pause/Resume the simulation"); //Pause + pauseButton = new ui::Button(ui::Point(Size.X-16, Size.Y-16), ui::Point(15, 15), ""_ascii, "Pause/Resume the simulation"_i18n); //Pause pauseButton->SetIcon(IconPause); pauseButton->SetTogglable(true); pauseButton->SetActionCallback({ [this] { c->SetPaused(pauseButton->GetToggleState()); } }); AddComponent(pauseButton); - ui::Button * tempButton = new ui::Button(ui::Point(WINDOWW-16, WINDOWH-32), ui::Point(15, 15), 0xE065, "Search for elements"); + ui::Button * tempButton = new ui::Button(ui::Point(WINDOWW-16, WINDOWH-32), ui::Point(15, 15), 0xE065, "Search for elements"_i18n); tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2); tempButton->SetActionCallback({ [this] { c->OpenElementSearch(); } }); AddComponent(tempButton); - colourPicker = new ui::Button(ui::Point((XRES/2)-8, YRES+1), ui::Point(16, 16), "", "Pick Colour"); + colourPicker = new ui::Button(ui::Point((XRES/2)-8, YRES+1), ui::Point(16, 16), ""_ascii, "Pick Colour"_i18n); colourPicker->SetActionCallback({ [this] { c->OpenColourPicker(); } }); } @@ -412,11 +412,11 @@ void GameView::NotifyMenuListChanged(GameModel * sender) { if (menuList[i]->GetVisible()) { - String tempString = ""; + String tempString = ""_ascii; tempString += menuList[i]->GetIcon(); String description = menuList[i]->GetDescription(); if (i == SC_FAVORITES && !Favorite::Ref().AnyFavorites()) - description += " (Use ctrl+shift+click to toggle the favorite status of an element)"; + description += " (Use ctrl+shift+click to toggle the favorite status of an element)"_i18n; auto *tempButton = new MenuButton(ui::Point(WINDOWW-16, currentY), ui::Point(15, 15), tempString, description); tempButton->Appearance.Margin = ui::Border(0, 2, 3, 2); tempButton->menuID = i; @@ -570,7 +570,7 @@ void GameView::NotifyToolListChanged(GameModel * sender) tempTexture = ((DecorationTool*)tool)->GetIcon(tool->GetToolID(), 26, 14); if(tempTexture) - tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", tool->GetIdentifier(), tool->GetDescription()); + tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), ""_ascii, tool->GetIdentifier(), tool->GetDescription()); else tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), tool->GetName(), tool->GetIdentifier(), tool->GetDescription()); @@ -685,7 +685,7 @@ void GameView::NotifyColourPresetsChanged(GameModel * sender) int i = 0; for(std::vector::iterator iter = colours.begin(), end = colours.end(); iter != end; ++iter) { - ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), "", "", "Decoration Presets."); + ToolButton * tempButton = new ToolButton(ui::Point(currentX, YRES+1), ui::Point(30, 18), ""_ascii, "", "Decoration Presets."_i18n); tempButton->Appearance.BackgroundInactive = *iter; tempButton->SetActionCallback({ [this, i, tempButton] { c->SetActiveColourPreset(i); @@ -738,15 +738,15 @@ void GameView::NotifyUserChanged(GameModel * sender) { if(!sender->GetUser().UserID) { - loginButton->SetText("[sign in]"); + loginButton->SetText("[sign in]"_i18n); loginButton->SetShowSplit(false); - loginButton->SetRightToolTip("Sign in to simulation server"); + loginButton->SetRightToolTip("Sign in to simulation server"_i18n); } else { loginButton->SetText(sender->GetUser().Username.FromUtf8()); loginButton->SetShowSplit(true); - loginButton->SetRightToolTip("Edit profile"); + loginButton->SetRightToolTip("Edit profile"_i18n); } // saveSimulationButtonEnabled = sender->GetUser().ID; saveSimulationButtonEnabled = true; @@ -817,19 +817,19 @@ void GameView::NotifySaveChanged(GameModel * sender) for (std::list::const_iterator iter = tags.begin(), begin = tags.begin(), end = tags.end(); iter != end; iter++) { if (iter != begin) - tagsStream << " "; + tagsStream << " "_ascii; tagsStream << iter->FromUtf8(); } tagSimulationButton->SetText(tagsStream.Build()); } else { - tagSimulationButton->SetText("[no tags set]"); + tagSimulationButton->SetText("[no tags set]"_i18n); } } else { - tagSimulationButton->SetText("[no tags set]"); + tagSimulationButton->SetText("[no tags set]"_i18n); } currentSaveType = 1; int saveID = sender->GetSave()->GetID(); @@ -851,13 +851,13 @@ void GameView::NotifySaveChanged(GameModel * sender) downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100); tagSimulationButton->Enabled = false; - tagSimulationButton->SetText("[no tags set]"); + tagSimulationButton->SetText("[no tags set]"_i18n); currentSaveType = 2; } else { saveSimulationButton->SetShowSplit(false); - saveSimulationButton->SetText("[untitled simulation]"); + saveSimulationButton->SetText("[untitled simulation]"_i18n); reloadButton->Enabled = false; upVoteButton->Enabled = false; upVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); @@ -866,7 +866,7 @@ void GameView::NotifySaveChanged(GameModel * sender) downVoteButton->Appearance.BackgroundDisabled = (ui::Colour(0, 0, 0)); downVoteButton->Appearance.BorderDisabled = ui::Colour(100, 100, 100), tagSimulationButton->Enabled = false; - tagSimulationButton->SetText("[no tags set]"); + tagSimulationButton->SetText("[no tags set]"_i18n); currentSaveType = 0; } saveSimulationButton->Enabled = (saveSimulationButtonEnabled && saveReuploadAllowed) || ctrlBehaviour; @@ -893,7 +893,7 @@ int GameView::Record(bool record) else if (!recording) { // block so that the return value is correct - bool record = ConfirmPrompt::Blocking("Recording", "You're about to start recording all drawn frames. This will use a load of disk space."); + bool record = ConfirmPrompt::Blocking("Recording"_i18n, "You're about to start recording all drawn frames. This will use a load of disk space."_i18n); if (record) { time_t startTime = time(NULL); @@ -1207,7 +1207,7 @@ void GameView::BeginStampSelection() selectMode = SelectStamp; selectPoint1 = selectPoint2 = ui::Point(-1, -1); isMouseDown = false; - buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to create a stamp (right click = cancel)"; + buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to create a stamp (right click = cancel)"_i18n; buttonTipShow = 120; } @@ -1312,7 +1312,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, || Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin) && ctrl) { ByteString authorString = Client::Ref().GetAuthorInfo().toStyledString(); - new InformationMessage("Save authorship info", authorString.FromUtf8(), true); + new InformationMessage("Save authorship info"_i18n, authorString.FromUtf8(), true); } break; case SDL_SCANCODE_R: @@ -1404,7 +1404,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, selectMode = SelectCopy; selectPoint1 = selectPoint2 = ui::Point(-1, -1); isMouseDown = false; - buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy (right click = cancel)"; + buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy (right click = cancel)"_i18n; buttonTipShow = 120; } break; @@ -1414,7 +1414,7 @@ void GameView::OnKeyPress(int key, int scan, bool repeat, bool shift, bool ctrl, selectMode = SelectCut; selectPoint1 = selectPoint2 = ui::Point(-1, -1); isMouseDown = false; - buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy then cut (right click = cancel)"; + buttonTip = "\x0F\xEF\xEF\020Click-and-drag to specify an area to copy then cut (right click = cancel)"_i18n; buttonTipShow = 120; } break; @@ -1528,7 +1528,7 @@ void GameView::OnFileDrop(ByteString filename) { if (!(filename.EndsWith(".cps") || filename.EndsWith(".stm"))) { - new ErrorMessage("Error loading save", "Dropped file is not a TPT save file (.cps or .stm format)"); + new ErrorMessage("Error loading save"_i18n, "Dropped file is not a TPT save file (.cps or .stm format)"_i18n); return; } @@ -1537,7 +1537,7 @@ void GameView::OnFileDrop(ByteString filename) return; if (saveFile->GetError().length()) { - new ErrorMessage("Error loading save", "Dropped save file could not be loaded: " + saveFile->GetError()); + new ErrorMessage("Error loading save"_i18n, "Dropped save file could not be loaded: "_i18n + saveFile->GetError()); return; } c->LoadSaveFile(saveFile); @@ -1588,13 +1588,16 @@ void GameView::OnTick(float dt) switch (si.second) { case sign::Type::Save: - tooltip << "Go to save ID:" << str.Substr(3, si.first - 3); + tooltip << "Go to save ID:"_i18n << str.Substr(3, si.first - 3); break; case sign::Type::Thread: - tooltip << "Open forum thread " << str.Substr(3, si.first - 3) << " in browser"; - break; + { + auto openThread = i18nMulti("Open forum thread ", " in browser"); + tooltip << openThread[0] << str.Substr(3, si.first - 3) << openThread[1]; + break; + } case sign::Type::Search: - tooltip << "Search for " << str.Substr(3, si.first - 3); + tooltip << "Search for "_i18n << str.Substr(3, si.first - 3); break; default: break; } @@ -1855,7 +1858,7 @@ void GameView::enableCtrlBehaviour() searchButton->Appearance.BackgroundInactive = searchButton->Appearance.BackgroundHover = ui::Colour(255, 255, 255); searchButton->Appearance.TextInactive = searchButton->Appearance.TextHover = ui::Colour(0, 0, 0); - searchButton->SetToolTip("Open a simulation from your hard drive."); + searchButton->SetToolTip("Open a simulation from your hard drive."_i18n); if (currentSaveType == 2) saveSimulationButton->SetShowSplit(true); } @@ -1879,7 +1882,7 @@ void GameView::disableCtrlBehaviour() searchButton->Appearance.BackgroundInactive = ui::Colour(0, 0, 0); searchButton->Appearance.BackgroundHover = ui::Colour(20, 20, 20); searchButton->Appearance.TextInactive = searchButton->Appearance.TextHover = ui::Colour(255, 255, 255); - searchButton->SetToolTip("Find & open a simulation. Hold Ctrl to load offline saves."); + searchButton->SetToolTip("Find & open a simulation. Hold Ctrl to load offline saves."_i18n); if (currentSaveType == 2) saveSimulationButton->SetShowSplit(false); } @@ -1915,13 +1918,13 @@ void GameView::UpdateToolStrength() void GameView::SetSaveButtonTooltips() { if (!Client::Ref().GetAuthUser().UserID) - saveSimulationButton->SetToolTips("Overwrite the open simulation on your hard drive.", "Save the simulation to your hard drive. Login to save online."); + saveSimulationButton->SetToolTips("Overwrite the open simulation on your hard drive."_i18n, "Save the simulation to your hard drive. Login to save online."_i18n); else if (ctrlBehaviour) - saveSimulationButton->SetToolTips("Overwrite the open simulation on your hard drive.", "Save the simulation to your hard drive."); + saveSimulationButton->SetToolTips("Overwrite the open simulation on your hard drive."_i18n, "Save the simulation to your hard drive."_i18n); else if (saveSimulationButton->GetShowSplit()) - saveSimulationButton->SetToolTips("Re-upload the current simulation", "Modify simulation properties"); + saveSimulationButton->SetToolTips("Re-upload the current simulation"_i18n, "Modify simulation properties"_i18n); else - saveSimulationButton->SetToolTips("Re-upload the current simulation", "Upload a new simulation. Hold Ctrl to save offline."); + saveSimulationButton->SetToolTips("Re-upload the current simulation"_i18n, "Upload a new simulation. Hold Ctrl to save offline."_i18n); } void GameView::OnDraw() @@ -2096,7 +2099,8 @@ void GameView::OnDraw() if (recording) { - String sampleInfo = String::Build("#", screenshotIndex, " ", String(0xE00E), " REC"); + auto rec = i18nMulti("#", " ", " REC"); + String sampleInfo = String::Build(rec[0], screenshotIndex, rec[1], String(0xE00E), rec[2]); int textWidth = Graphics::textwidth(sampleInfo); g->fillrect(XRES-20-textWidth, 12, textWidth+8, 15, 0, 0, 0, 255*0.5); @@ -2125,17 +2129,17 @@ void GameView::OnDraw() { if (type == PT_LAVA && c->IsValidElement(ctype)) { - sampleInfo << "Molten " << c->ElementResolve(ctype, -1); + sampleInfo << "Molten "_i18n << c->ElementResolve(ctype, -1); } else if ((type == PT_PIPE || type == PT_PPIP) && c->IsValidElement(ctype)) { if (ctype == PT_LAVA && c->IsValidElement((int)sample.particle.pavg[1])) { - sampleInfo << c->ElementResolve(type, -1) << " with molten " << c->ElementResolve((int)sample.particle.pavg[1], -1); + sampleInfo << c->ElementResolve(type, -1) << " with molten "_i18n << c->ElementResolve((int)sample.particle.pavg[1], -1); } else { - sampleInfo << c->ElementResolve(type, -1) << " with " << c->ElementResolve(ctype, (int)sample.particle.pavg[1]); + sampleInfo << c->ElementResolve(type, -1) << " with "_i18n << c->ElementResolve(ctype, (int)sample.particle.pavg[1]); } } else if (type == PT_LIFE) @@ -2145,27 +2149,27 @@ void GameView::OnDraw() else if (type == PT_FILT) { sampleInfo << c->ElementResolve(type, ctype); - String filtModes[] = {"set colour", "AND", "OR", "subtract colour", "red shift", "blue shift", "no effect", "XOR", "NOT", "old QRTZ scattering", "variable red shift", "variable blue shift"}; + auto filtModes = i18nMulti("set colour", "AND", "OR", "subtract colour", "red shift", "blue shift", "no effect", "XOR", "NOT", "old QRTZ scattering", "variable red shift", "variable blue shift"); if (sample.particle.tmp>=0 && sample.particle.tmp<=11) - sampleInfo << " (" << filtModes[sample.particle.tmp] << ")"; + sampleInfo << " ("_ascii << filtModes[sample.particle.tmp] << ")"_ascii; else - sampleInfo << " (unknown mode)"; + sampleInfo << " (unknown mode)"_i18n; } else { sampleInfo << c->ElementResolve(type, ctype); if (wavelengthGfx) - sampleInfo << " (" << ctype << ")"; + sampleInfo << " ("_ascii << ctype << ")"_ascii; // Some elements store extra LIFE info in upper bits of ctype, instead of tmp/tmp2 else if (type == PT_CRAY || type == PT_DRAY || type == PT_CONV) - sampleInfo << " (" << c->ElementResolve(TYP(ctype), ID(ctype)) << ")"; + sampleInfo << " ("_ascii << c->ElementResolve(TYP(ctype), ID(ctype)) << ")"_ascii; else if (c->IsValidElement(ctype)) - sampleInfo << " (" << c->ElementResolve(ctype, -1) << ")"; + sampleInfo << " ("_ascii << c->ElementResolve(ctype, -1) << ")"_ascii; else - sampleInfo << " ()"; + sampleInfo << " ()"_ascii; } - sampleInfo << ", Temp: " << (sample.particle.temp - 273.15f) << " C"; - sampleInfo << ", Life: " << sample.particle.life; + sampleInfo << ", Temp: "_i18n << (sample.particle.temp - 273.15f) << " C"_i18n; + sampleInfo << ", Life: "_i18n << sample.particle.life; if (sample.particle.type != PT_RFRG && sample.particle.type != PT_RFGL) { if (sample.particle.type == PT_CONV) @@ -2173,40 +2177,40 @@ void GameView::OnDraw() String elemName = c->ElementResolve( TYP(sample.particle.tmp), ID(sample.particle.tmp)); - if (elemName == "") - sampleInfo << ", Tmp: " << sample.particle.tmp; + if (elemName == ""_ascii) + sampleInfo << ", Tmp: "_i18n << sample.particle.tmp; else - sampleInfo << ", Tmp: " << elemName; + sampleInfo << ", Tmp: "_i18n << elemName; } else - sampleInfo << ", Tmp: " << sample.particle.tmp; + sampleInfo << ", Tmp: "_i18n << sample.particle.tmp; } // only elements that use .tmp2 show it in the debug HUD if (type == PT_CRAY || type == PT_DRAY || type == PT_EXOT || type == PT_LIGH || type == PT_SOAP || type == PT_TRON || type == PT_VIBR || type == PT_VIRS || type == PT_WARP || type == PT_LCRY || type == PT_CBNW || type == PT_TSNS || type == PT_DTEC || type == PT_LSNS || type == PT_PSTN || type == PT_LDTC) - sampleInfo << ", Tmp2: " << sample.particle.tmp2; + sampleInfo << ", Tmp2: "_i18n << sample.particle.tmp2; - sampleInfo << ", Pressure: " << sample.AirPressure; + sampleInfo << ", Pressure: "_i18n << sample.AirPressure; } else { sampleInfo << c->BasicParticleInfo(sample.particle); - sampleInfo << ", Temp: " << sample.particle.temp - 273.15f << " C"; - sampleInfo << ", Pressure: " << sample.AirPressure; + sampleInfo << ", Temp: "_i18n << sample.particle.temp - 273.15f << " C"_i18n; + sampleInfo << ", Pressure: "_i18n << sample.AirPressure; } } else if (sample.WallType) { sampleInfo << c->WallName(sample.WallType); - sampleInfo << ", Pressure: " << sample.AirPressure; + sampleInfo << ", Pressure: "_i18n << sample.AirPressure; } else if (sample.isMouseInSim) { - sampleInfo << "Empty, Pressure: " << sample.AirPressure; + sampleInfo << "Empty, Pressure: "_i18n << sample.AirPressure; } else { - sampleInfo << "Empty"; + sampleInfo << "Empty"_i18n; } int textWidth = Graphics::textwidth(sampleInfo.Build()); @@ -2256,15 +2260,15 @@ void GameView::OnDraw() sampleInfo << Format::Precision(2); if (type) - sampleInfo << "#" << sample.ParticleID << ", "; + sampleInfo << "#"_ascii << sample.ParticleID << ", "_ascii; - sampleInfo << "X:" << sample.PositionX << " Y:" << sample.PositionY; + sampleInfo << "X:"_ascii << sample.PositionX << " Y:"_ascii << sample.PositionY; if (sample.Gravity) - sampleInfo << ", GX: " << sample.GravityVelocityX << " GY: " << sample.GravityVelocityY; + sampleInfo << ", GX: "_ascii << sample.GravityVelocityX << " GY: "_ascii << sample.GravityVelocityY; if (c->GetAHeatEnable()) - sampleInfo << ", AHeat: " << sample.AirTemperature - 273.15f << " C"; + sampleInfo << ", AHeat: "_i18n << sample.AirTemperature - 273.15f << " C"_i18n; textWidth = Graphics::textwidth(sampleInfo.Build()); g->fillrect(XRES-20-textWidth, 27, textWidth+8, 14, 0, 0, 0, alpha*0.5f); @@ -2276,23 +2280,26 @@ void GameView::OnDraw() { //FPS and some version info StringBuilder fpsInfo; - fpsInfo << Format::Precision(2) << "FPS: " << ui::Engine::Ref().GetFps(); + fpsInfo << Format::Precision(2) << "FPS: "_i18n << ui::Engine::Ref().GetFps(); if (showDebug) { if (ren->findingElement) - fpsInfo << " Parts: " << ren->foundElements << "/" << sample.NumParts; + fpsInfo << " Parts: "_i18n << ren->foundElements << "/"_ascii << sample.NumParts; else - fpsInfo << " Parts: " << sample.NumParts; + fpsInfo << " Parts: "_i18n << sample.NumParts; } if (c->GetReplaceModeFlags()&REPLACE_MODE) - fpsInfo << " [REPLACE MODE]"; + fpsInfo << " [REPLACE MODE]"_i18n; if (c->GetReplaceModeFlags()&SPECIFIC_DELETE) - fpsInfo << " [SPECIFIC DELETE]"; + fpsInfo << " [SPECIFIC DELETE]"_i18n; if (ren && ren->GetGridSize()) - fpsInfo << " [GRID: " << ren->GetGridSize() << "]"; + { + auto grid = i18nMulti("[GRID: ", "]"); + fpsInfo << grid[0] << ren->GetGridSize() << grid[1]; + } if (ren && ren->findingElement) - fpsInfo << " [FIND]"; + fpsInfo << " [FIND]"_i18n; int textWidth = Graphics::textwidth(fpsInfo.Build()); int alpha = 255-introText*5; diff --git a/src/lua/LegacyLuaAPI.cpp b/src/lua/LegacyLuaAPI.cpp index b73f3674f..9307d95c5 100644 --- a/src/lua/LegacyLuaAPI.cpp +++ b/src/lua/LegacyLuaAPI.cpp @@ -286,10 +286,10 @@ void luacon_hook(lua_State * l, lua_Debug * ar) } } -String luacon_geterror() +ByteString luacon_geterror() { luaL_tostring(luacon_ci->l, -1); - String err = ByteString(luaL_optstring(luacon_ci->l, -1, "failed to execute")).FromUtf8(); + ByteString err = luaL_optstring(luacon_ci->l, -1, "failed to execute"); lua_pop(luacon_ci->l, 1); return err; } @@ -331,7 +331,7 @@ int luacon_elementReplacement(UPDATE_FUNC_ARGS) lua_pushinteger(luacon_ci->l, nt); callret = lua_pcall(luacon_ci->l, 5, 1, 0); if (callret) - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, luacon_geterror().FromUtf8()); if(lua_isboolean(luacon_ci->l, -1)){ retval = lua_toboolean(luacon_ci->l, -1); } @@ -391,7 +391,7 @@ int luacon_graphicsReplacement(GRAPHICS_FUNC_ARGS, int i) callret = lua_pcall(luacon_ci->l, 4, 10, 0); if (callret) { - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, luacon_geterror().FromUtf8()); lua_pop(luacon_ci->l, 1); } else diff --git a/src/lua/LuaScriptHelper.h b/src/lua/LuaScriptHelper.h index 73fbf334d..8987ab741 100644 --- a/src/lua/LuaScriptHelper.h +++ b/src/lua/LuaScriptHelper.h @@ -37,7 +37,7 @@ extern LuaSmartRef *tptPart; void luaopen_eventcompat(lua_State *l); void luacon_hook(lua_State *L, lua_Debug *ar); int luacon_eval(const char *command); -String luacon_geterror(); +ByteString luacon_geterror(); void luacon_close(); void initLegacyProps(); int luacon_partsread(lua_State* l); diff --git a/src/lua/LuaScriptInterface.cpp b/src/lua/LuaScriptInterface.cpp index 9851cc7ea..4cb1fa21e 100644 --- a/src/lua/LuaScriptInterface.cpp +++ b/src/lua/LuaScriptInterface.cpp @@ -221,7 +221,7 @@ LuaScriptInterface::LuaScriptInterface(GameController * c, GameModel * m): luacon_currentCommand = ¤tCommand; luacon_lastError = &lastError; - lastCode = ""; + lastCode = ""_ascii; //Replace print function with our screen logging thingy lua_pushcfunction(l, luatpt_log); @@ -370,9 +370,9 @@ void LuaScriptInterface::Init() { lua_State *l = luacon_ci->l; if(luaL_loadfile(l, "autorun.lua") || lua_pcall(l, 0, 0, 0)) - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, luacon_geterror().FromUtf8()); else - luacon_ci->Log(CommandInterface::LogWarning, "Loaded autorun.lua"); + luacon_ci->Log(CommandInterface::LogWarning, "Loaded autorun.lua"_i18n); } } @@ -2703,7 +2703,7 @@ void luaCreateWrapper(ELEMENT_CREATE_FUNC_ARGS) lua_pushinteger(luacon_ci->l, v); if (lua_pcall(luacon_ci->l, 5, 0, 0)) { - luacon_ci->Log(CommandInterface::LogError, "In create func: " + luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, "In create func: "_ascii + luacon_geterror().FromUtf8()); lua_pop(luacon_ci->l, 1); } } @@ -2721,7 +2721,7 @@ bool luaCreateAllowedWrapper(ELEMENT_CREATE_ALLOWED_FUNC_ARGS) lua_pushinteger(luacon_ci->l, t); if (lua_pcall(luacon_ci->l, 4, 1, 0)) { - luacon_ci->Log(CommandInterface::LogError, "In create allowed: " + luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, "In create allowed: "_ascii + luacon_geterror().FromUtf8()); lua_pop(luacon_ci->l, 1); } else @@ -2746,7 +2746,7 @@ void luaChangeTypeWrapper(ELEMENT_CHANGETYPE_FUNC_ARGS) lua_pushinteger(luacon_ci->l, to); if (lua_pcall(luacon_ci->l, 5, 0, 0)) { - luacon_ci->Log(CommandInterface::LogError, "In change type: " + luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, "In change type: "_ascii + luacon_geterror().FromUtf8()); lua_pop(luacon_ci->l, 1); } } @@ -2763,7 +2763,7 @@ static bool luaCtypeDrawWrapper(CTYPEDRAW_FUNC_ARGS) lua_pushinteger(luacon_ci->l, v); if (lua_pcall(luacon_ci->l, 3, 1, 0)) { - luacon_ci->Log(CommandInterface::LogError, luacon_geterror()); + luacon_ci->Log(CommandInterface::LogError, luacon_geterror().FromUtf8()); lua_pop(luacon_ci->l, 1); } else @@ -3916,7 +3916,7 @@ int LuaScriptInterface::Command(String command) { if (command[0] == '!') { - lastError = ""; + lastError = ""_ascii; int ret = legacy->Command(command.Substr(1)); lastError = legacy->GetLastError(); return ret; @@ -3924,13 +3924,13 @@ int LuaScriptInterface::Command(String command) else { int level = lua_gettop(l), ret = -1; - String text = ""; - lastError = ""; + String text = ""_ascii; + lastError = ""_ascii; currentCommand = true; if (lastCode.length()) - lastCode += "\n"; + lastCode += "\n"_ascii; lastCode += command; - ByteString tmp = ("return " + lastCode).ToUtf8(); + ByteString tmp = ("return "_ascii + lastCode).ToUtf8(); ui::Engine::Ref().LastTick(Platform::GetTime()); luaL_loadbuffer(l, tmp.c_str(), tmp.length(), "@console"); if (lua_type(l, -1) != LUA_TFUNCTION) @@ -3941,26 +3941,26 @@ int LuaScriptInterface::Command(String command) } if (lua_type(l, -1) != LUA_TFUNCTION) { - lastError = luacon_geterror(); - String err = lastError; + ByteString err = luacon_geterror(); + lastError = err.FromUtf8(); if (err.Contains("near ''")) //the idea stolen from lua-5.1.5/lua.c - lastError = "..."; + lastError = "..."_ascii; else - lastCode = ""; + lastCode = ""_ascii; } else { - lastCode = ""; + lastCode = ""_ascii; ret = lua_pcall(l, 0, LUA_MULTRET, 0); if (ret) - lastError = luacon_geterror(); + lastError = luacon_geterror().FromUtf8(); else { for (level++;level<=lua_gettop(l);level++) { luaL_tostring(l, level); if (text.length()) - text += ", " + ByteString(luaL_optstring(l, -1, "")).FromUtf8(); + text += ", "_ascii + ByteString(luaL_optstring(l, -1, "")).FromUtf8(); else text = ByteString(luaL_optstring(l, -1, "")).FromUtf8(); lua_pop(l, 1); @@ -3968,7 +3968,7 @@ int LuaScriptInterface::Command(String command) if (text.length()) { if (lastError.length()) - lastError += "; " + text; + lastError += "; "_ascii + text; else lastError = text; } @@ -4003,7 +4003,7 @@ String highlight(String command) { StringBuilder result; int pos = 0; - String::value_type const*raw = command.c_str(); + String::value_type const *raw = command.c_str(); String::value_type c; while ((c = raw[pos])) { @@ -4011,16 +4011,16 @@ String highlight(String command) { int len = 0; String::value_type w; - String::value_type const* wstart = raw+pos; + String::value_type const *wstart = raw + pos; while((w = wstart[len]) && ((w >= 'A' && w <= 'Z') || (w >= 'a' && w <= 'z') || (w >= '0' && w <= '9') || w == '_')) len++; -#define CMP(X) (String(wstart, len) == X) +#define CMP(X) (String(wstart, len) == X##_ascii) if(CMP("and") || CMP("break") || CMP("do") || CMP("else") || CMP("elseif") || CMP("end") || CMP("for") || CMP("function") || CMP("if") || CMP("in") || CMP("local") || CMP("not") || CMP("or") || CMP("repeat") || CMP("return") || CMP("then") || CMP("until") || CMP("while")) - result << "\x0F\xB5\x89\x01" << String(wstart, len) << "\bw"; + result << "\x0F\xB5\x89\x01"_ascii << String(wstart, len) << "\bw"_ascii; else if(CMP("false") || CMP("nil") || CMP("true")) - result << "\x0F\xCB\x4B\x16" << String(wstart, len) << "\bw"; + result << "\x0F\xCB\x4B\x16"_ascii << String(wstart, len) << "\bw"_ascii; else - result << "\x0F\x2A\xA1\x98" << String(wstart, len) << "\bw"; + result << "\x0F\x2A\xA1\x98"_ascii << String(wstart, len) << "\bw"_ascii; #undef CMP pos += len; } @@ -4030,17 +4030,17 @@ String highlight(String command) { int len = 2; String::value_type w; - String::value_type const* wstart = raw+pos; + String::value_type const *wstart = raw + pos; while((w = wstart[len]) && ((w >= '0' && w <= '9') || (w >= 'A' && w <= 'F') || (w >= 'a' && w <= 'f'))) len++; - result << "\x0F\xD3\x36\x82" << String(wstart, len) << "\bw"; + result << "\x0F\xD3\x36\x82"_ascii << String(wstart, len) << "\bw"_ascii; pos += len; } else { int len = 0; String::value_type w; - String::value_type const* wstart = raw+pos; + String::value_type const *wstart = raw + pos; bool seendot = false; while((w = wstart[len]) && ((w >= '0' && w <= '9') || w == '.')) { @@ -4062,7 +4062,7 @@ String highlight(String command) while((w = wstart[len]) && (w >= '0' && w <= '9')) len++; } - result << "\x0F\xD3\x36\x82" << String(wstart, len) << "\bw"; + result << "\x0F\xD3\x36\x82"_ascii << String(wstart, len) << "\bw"_ascii; pos += len; } } @@ -4072,7 +4072,7 @@ String highlight(String command) { int len = 1, eqs=0; String::value_type w; - String::value_type const* wstart = raw + pos; + String::value_type const *wstart = raw + pos; while((w = wstart[len]) && (w == '=')) { eqs++; @@ -4083,25 +4083,25 @@ String highlight(String command) if(w == ']') { int nlen = 1; - String::value_type const* cstart = wstart + len; + String::value_type const *cstart = wstart + len; while((w = cstart[nlen]) && (w == '=')) nlen++; - if(w == ']' && nlen == eqs+1) + if(w == ']' && nlen == eqs + 1) { - len += nlen+1; + len += nlen + 1; break; } } len++; } - result << "\x0F\xDC\x32\x2F" << String(wstart, len) << "\bw"; + result << "\x0F\xDC\x32\x2F"_ascii << String(wstart, len) << "\bw"_ascii; pos += len; } else { int len = 1; String::value_type w; - String::value_type const* wstart = raw+pos; + String::value_type const *wstart = raw + pos; while((w = wstart[len]) && (w != c)) { if(w == '\\' && wstart[len + 1]) @@ -4110,7 +4110,7 @@ String highlight(String command) } if(w == c) len++; - result << "\x0F\xDC\x32\x2F" << String(wstart, len) << "\bw"; + result << "\x0F\xDC\x32\x2F"_ascii << String(wstart, len) << "\bw"_ascii; pos += len; } } @@ -4120,7 +4120,7 @@ String highlight(String command) { int len = 3, eqs = 0; String::value_type w; - String::value_type const* wstart = raw + pos; + String::value_type const *wstart = raw + pos; while((w = wstart[len]) && (w == '=')) { eqs++; @@ -4131,39 +4131,39 @@ String highlight(String command) if(w == ']') { int nlen = 1; - String::value_type const* cstart = wstart + len; + String::value_type const *cstart = wstart + len; while((w = cstart[nlen]) && (w == '=')) nlen++; if(w == ']' && nlen == eqs + 1) { - len += nlen+1; + len += nlen + 1; break; } } len++; } - result << "\x0F\x85\x99\x01" << String(wstart, len) << "\bw"; + result << "\x0F\x85\x99\x01"_ascii << String(wstart, len) << "\bw"_ascii; pos += len; } else { int len = 2; String::value_type w; - String::value_type const* wstart = raw + pos; + String::value_type const *wstart = raw + pos; while((w = wstart[len]) && (w != '\n')) len++; - result << "\x0F\x85\x99\x01" << String(wstart, len) << "\bw"; + result << "\x0F\x85\x99\x01"_ascii << String(wstart, len) << "\bw"_ascii; pos += len; } } else if(c == '{' || c == '}') { - result << "\x0F\xCB\x4B\x16" << c << "\bw"; + result << "\x0F\xCB\x4B\x16"_ascii << c << "\bw"_ascii; pos++; } else if(c == '.' && raw[pos + 1] == '.' && raw[pos + 2] == '.') { - result << "\x0F\x2A\xA1\x98...\bw"; + result << "\x0F\x2A\xA1\x98...\bw"_ascii; pos += 3; } else @@ -4179,7 +4179,7 @@ String LuaScriptInterface::FormatCommand(String command) { if(command.size() && command[0] == '!') { - return "!"+legacy->FormatCommand(command.Substr(1)); + return "!"_ascii + legacy->FormatCommand(command.Substr(1)); } else return highlight(command); diff --git a/src/lua/TPTSTypes.h b/src/lua/TPTSTypes.h index a0d5b6018..0d3566e33 100644 --- a/src/lua/TPTSTypes.h +++ b/src/lua/TPTSTypes.h @@ -84,7 +84,7 @@ public: class InvalidConversionException: public GeneralException { - static auto getErrorMsg() { return i18nMulti("Invalid conversion from ", " to "); } + static std::array getErrorMsg() { return i18nMulti("Invalid conversion from ", " to "); } public: InvalidConversionException(ValueType from_, ValueType to_): GeneralException(getErrorMsg()[0] + AnyType::TypeName(from_).FromAscii() + getErrorMsg()[1] + AnyType::TypeName(to_).FromAscii()) {