CStringTable: Make use of size_t
Plays nicer with standard containers. While we're at it, we can use std::move where applicable.
This commit is contained in:
parent
f71ef1e615
commit
09f5163184
|
@ -589,11 +589,13 @@ void GenerateAssetNames(CGameProject *pProj)
|
||||||
|
|
||||||
for (TResourceIterator<EResourceType::StringTable> It(pStore); It; ++It)
|
for (TResourceIterator<EResourceType::StringTable> It(pStore); It; ++It)
|
||||||
{
|
{
|
||||||
if (It->IsNamed()) continue;
|
if (It->IsNamed())
|
||||||
CStringTable *pString = (CStringTable*) It->Load();
|
continue;
|
||||||
|
|
||||||
|
auto *pString = static_cast<CStringTable*>(It->Load());
|
||||||
TString String;
|
TString String;
|
||||||
|
|
||||||
for (uint32 iStr = 0; iStr < pString->NumStrings() && String.IsEmpty(); iStr++)
|
for (size_t iStr = 0; iStr < pString->NumStrings() && String.IsEmpty(); iStr++)
|
||||||
String = CStringTable::StripFormatting(pString->GetString(ELanguage::English, iStr)).Trimmed();
|
String = CStringTable::StripFormatting(pString->GetString(ELanguage::English, iStr)).Trimmed();
|
||||||
|
|
||||||
if (!String.IsEmpty())
|
if (!String.IsEmpty())
|
||||||
|
|
|
@ -4,34 +4,34 @@
|
||||||
|
|
||||||
void CStringCooker::WritePrimeDemoSTRG(IOutputStream& STRG)
|
void CStringCooker::WritePrimeDemoSTRG(IOutputStream& STRG)
|
||||||
{
|
{
|
||||||
uint StartOffset = STRG.Tell();
|
const uint32 StartOffset = STRG.Tell();
|
||||||
uint NumStrings = mpStringTable->NumStrings();
|
const size_t NumStrings = mpStringTable->NumStrings();
|
||||||
|
|
||||||
// Start writing the file...
|
// Start writing the file...
|
||||||
STRG.WriteLong(0); // Dummy file size
|
STRG.WriteLong(0); // Dummy file size
|
||||||
uint TableStart = STRG.Tell();
|
const uint32 TableStart = STRG.Tell();
|
||||||
STRG.WriteLong(NumStrings);
|
STRG.WriteLong(NumStrings);
|
||||||
|
|
||||||
// Dummy string offsets
|
// Dummy string offsets
|
||||||
for (uint StringIdx = 0; StringIdx < NumStrings; StringIdx++)
|
for (size_t StringIdx = 0; StringIdx < NumStrings; StringIdx++)
|
||||||
STRG.WriteLong(0);
|
STRG.WriteLong(0);
|
||||||
|
|
||||||
// Write strings
|
// Write strings
|
||||||
std::vector<uint> StringOffsets(NumStrings);
|
std::vector<uint32> StringOffsets(NumStrings);
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < NumStrings; StringIdx++)
|
for (size_t StringIdx = 0; StringIdx < NumStrings; StringIdx++)
|
||||||
{
|
{
|
||||||
StringOffsets[StringIdx] = STRG.Tell() - TableStart;
|
StringOffsets[StringIdx] = STRG.Tell() - TableStart;
|
||||||
STRG.Write16String(mpStringTable->GetString(ELanguage::English, StringIdx).ToUTF16());
|
STRG.Write16String(mpStringTable->GetString(ELanguage::English, StringIdx).ToUTF16());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill in offsets
|
// Fill in offsets
|
||||||
uint FileSize = STRG.Tell() - StartOffset;
|
const uint32 FileSize = STRG.Tell() - StartOffset;
|
||||||
STRG.GoTo(StartOffset);
|
STRG.GoTo(StartOffset);
|
||||||
STRG.WriteLong(FileSize);
|
STRG.WriteLong(FileSize);
|
||||||
STRG.Skip(4);
|
STRG.Skip(4);
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < NumStrings; StringIdx++)
|
for (size_t StringIdx = 0; StringIdx < NumStrings; StringIdx++)
|
||||||
STRG.WriteLong(StringOffsets[StringIdx]);
|
STRG.WriteLong(StringOffsets[StringIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,16 +40,16 @@ void CStringCooker::WritePrimeSTRG(IOutputStream& STRG)
|
||||||
// Magic/Version
|
// Magic/Version
|
||||||
STRG.WriteLong(0x87654321);
|
STRG.WriteLong(0x87654321);
|
||||||
STRG.WriteLong(mpStringTable->Game() >= EGame::EchoesDemo ? 1 : 0);
|
STRG.WriteLong(mpStringTable->Game() >= EGame::EchoesDemo ? 1 : 0);
|
||||||
STRG.WriteLong( mpStringTable->NumLanguages() );
|
STRG.WriteLong(static_cast<int>(mpStringTable->NumLanguages()));
|
||||||
STRG.WriteLong( mpStringTable->NumStrings() );
|
STRG.WriteLong(static_cast<int>(mpStringTable->NumStrings()));
|
||||||
|
|
||||||
// Language info
|
// Language info
|
||||||
uint LanguagesStart = STRG.Tell();
|
const uint LanguagesStart = STRG.Tell();
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t i = 0; i < mpStringTable->NumLanguages(); i++)
|
||||||
{
|
{
|
||||||
const CStringTable::SLanguageData& kLanguage = mpStringTable->mLanguages[LanguageIdx];
|
const CStringTable::SLanguageData& kLanguage = mpStringTable->mLanguages[i];
|
||||||
STRG.WriteLong( (uint) kLanguage.Language );
|
STRG.WriteLong(static_cast<int>(kLanguage.Language));
|
||||||
STRG.WriteLong(0); // Dummy offset
|
STRG.WriteLong(0); // Dummy offset
|
||||||
|
|
||||||
if (mpStringTable->Game() >= EGame::EchoesDemo)
|
if (mpStringTable->Game() >= EGame::EchoesDemo)
|
||||||
|
@ -65,15 +65,15 @@ void CStringCooker::WritePrimeSTRG(IOutputStream& STRG)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strings
|
// Strings
|
||||||
uint StringDataStart = STRG.Tell();
|
const uint32 StringDataStart = STRG.Tell();
|
||||||
std::vector<uint> LanguageOffsets( mpStringTable->NumLanguages() );
|
std::vector<uint32> LanguageOffsets(mpStringTable->NumLanguages());
|
||||||
std::vector<uint> LanguageSizes( mpStringTable->NumLanguages() );
|
std::vector<uint32> LanguageSizes(mpStringTable->NumLanguages());
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
const CStringTable::SLanguageData& kLanguage = mpStringTable->mLanguages[LanguageIdx];
|
const CStringTable::SLanguageData& kLanguage = mpStringTable->mLanguages[LanguageIdx];
|
||||||
|
|
||||||
uint LanguageStart = STRG.Tell();
|
const uint32 LanguageStart = STRG.Tell();
|
||||||
LanguageOffsets[LanguageIdx] = LanguageStart - StringDataStart;
|
LanguageOffsets[LanguageIdx] = LanguageStart - StringDataStart;
|
||||||
|
|
||||||
if (mpStringTable->Game() == EGame::Prime)
|
if (mpStringTable->Game() == EGame::Prime)
|
||||||
|
@ -82,24 +82,24 @@ void CStringCooker::WritePrimeSTRG(IOutputStream& STRG)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill dummy string offsets
|
// Fill dummy string offsets
|
||||||
uint StringOffsetBase = STRG.Tell();
|
const uint32 StringOffsetBase = STRG.Tell();
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
||||||
{
|
{
|
||||||
STRG.WriteLong(0);
|
STRG.WriteLong(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write strings
|
// Write strings
|
||||||
std::vector<uint> StringOffsets( mpStringTable->NumStrings() );
|
std::vector<uint32> StringOffsets(mpStringTable->NumStrings());
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
for (size_t i = 0; i < mpStringTable->NumStrings(); i++)
|
||||||
{
|
{
|
||||||
StringOffsets[StringIdx] = STRG.Tell() - StringOffsetBase;
|
StringOffsets[i] = STRG.Tell() - StringOffsetBase;
|
||||||
STRG.Write16String( kLanguage.Strings[StringIdx].String.ToUTF16() );
|
STRG.Write16String(kLanguage.Strings[i].String.ToUTF16());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Go back and fill in size/offsets
|
// Go back and fill in size/offsets
|
||||||
uint LanguageEnd = STRG.Tell();
|
const uint32 LanguageEnd = STRG.Tell();
|
||||||
LanguageSizes[LanguageIdx] = LanguageEnd - StringOffsetBase;
|
LanguageSizes[LanguageIdx] = LanguageEnd - StringOffsetBase;
|
||||||
STRG.GoTo(LanguageStart);
|
STRG.GoTo(LanguageStart);
|
||||||
|
|
||||||
|
@ -108,27 +108,27 @@ void CStringCooker::WritePrimeSTRG(IOutputStream& STRG)
|
||||||
STRG.WriteLong(LanguageSizes[LanguageIdx]);
|
STRG.WriteLong(LanguageSizes[LanguageIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
for (size_t i = 0; i < mpStringTable->NumStrings(); i++)
|
||||||
{
|
{
|
||||||
STRG.WriteLong( StringOffsets[StringIdx] );
|
STRG.WriteLong(StringOffsets[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
STRG.GoTo(LanguageEnd);
|
STRG.GoTo(LanguageEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint STRGEnd = STRG.Tell();
|
const uint32 STRGEnd = STRG.Tell();
|
||||||
|
|
||||||
// Fill in missing language data
|
// Fill in missing language data
|
||||||
STRG.GoTo(LanguagesStart);
|
STRG.GoTo(LanguagesStart);
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t i = 0; i < mpStringTable->NumLanguages(); i++)
|
||||||
{
|
{
|
||||||
STRG.Skip(4); // Skip language ID
|
STRG.Skip(4); // Skip language ID
|
||||||
STRG.WriteLong( LanguageOffsets[LanguageIdx] );
|
STRG.WriteLong(LanguageOffsets[i]);
|
||||||
|
|
||||||
if (mpStringTable->Game() >= EGame::EchoesDemo)
|
if (mpStringTable->Game() >= EGame::EchoesDemo)
|
||||||
{
|
{
|
||||||
STRG.WriteLong( LanguageSizes[LanguageIdx] );
|
STRG.WriteLong(LanguageSizes[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,12 +153,12 @@ void CStringCooker::WriteCorruptionSTRG(IOutputStream& STRG)
|
||||||
{
|
{
|
||||||
ELanguage Language;
|
ELanguage Language;
|
||||||
std::vector<uint> StringOffsets;
|
std::vector<uint> StringOffsets;
|
||||||
uint TotalSize;
|
uint32 TotalSize;
|
||||||
};
|
};
|
||||||
std::vector<SCookedLanguageData> CookedLanguageData( mpStringTable->NumLanguages() );
|
std::vector<SCookedLanguageData> CookedLanguageData( mpStringTable->NumLanguages() );
|
||||||
int EnglishIdx = -1;
|
size_t EnglishIdx = UINT32_MAX;
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
const CStringTable::SLanguageData& kLanguageData = mpStringTable->mLanguages[LanguageIdx];
|
const CStringTable::SLanguageData& kLanguageData = mpStringTable->mLanguages[LanguageIdx];
|
||||||
|
|
||||||
|
@ -169,34 +169,34 @@ void CStringCooker::WriteCorruptionSTRG(IOutputStream& STRG)
|
||||||
|
|
||||||
if (CookedData.Language == ELanguage::English)
|
if (CookedData.Language == ELanguage::English)
|
||||||
{
|
{
|
||||||
EnglishIdx = (int) LanguageIdx;
|
EnglishIdx = LanguageIdx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Language IDs
|
// Language IDs
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
STRG.WriteLong( (uint) CookedLanguageData[LanguageIdx].Language );
|
STRG.WriteLong(static_cast<int>(CookedLanguageData[LanguageIdx].Language));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Language Info
|
// Language Info
|
||||||
uint LanguageInfoStart = STRG.Tell();
|
const uint32 LanguageInfoStart = STRG.Tell();
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
// Fill language size/offsets with dummy data...
|
// Fill language size/offsets with dummy data...
|
||||||
STRG.WriteLong(0);
|
STRG.WriteLong(0);
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
||||||
STRG.WriteLong(0);
|
STRG.WriteLong(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strings
|
// Strings
|
||||||
uint StringsStart = STRG.Tell();
|
const uint32 StringsStart = STRG.Tell();
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
||||||
{
|
{
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
const CStringTable::SLanguageData& kLanguageData = mpStringTable->mLanguages[LanguageIdx];
|
const CStringTable::SLanguageData& kLanguageData = mpStringTable->mLanguages[LanguageIdx];
|
||||||
const CStringTable::SStringData& kStringData = kLanguageData.Strings[StringIdx];
|
const CStringTable::SStringData& kStringData = kLanguageData.Strings[StringIdx];
|
||||||
|
@ -219,17 +219,17 @@ void CStringCooker::WriteCorruptionSTRG(IOutputStream& STRG)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint STRGEnd = STRG.Tell();
|
const uint32 STRGEnd = STRG.Tell();
|
||||||
|
|
||||||
// Fill in missing language data
|
// Fill in missing language data
|
||||||
STRG.GoTo(LanguageInfoStart);
|
STRG.GoTo(LanguageInfoStart);
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
const SCookedLanguageData& kCookedData = CookedLanguageData[LanguageIdx];
|
const SCookedLanguageData& kCookedData = CookedLanguageData[LanguageIdx];
|
||||||
STRG.WriteLong(kCookedData.TotalSize);
|
STRG.WriteLong(kCookedData.TotalSize);
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
for (size_t StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
||||||
STRG.WriteLong(kCookedData.StringOffsets[StringIdx]);
|
STRG.WriteLong(kCookedData.StringOffsets[StringIdx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,13 +241,13 @@ void CStringCooker::WriteNameTable(IOutputStream& STRG)
|
||||||
// Build a list of name entries to put in the map
|
// Build a list of name entries to put in the map
|
||||||
struct SNameEntry
|
struct SNameEntry
|
||||||
{
|
{
|
||||||
uint Offset;
|
uint32 Offset;
|
||||||
uint Index;
|
uint32 Index;
|
||||||
TString Name;
|
TString Name;
|
||||||
};
|
};
|
||||||
std::vector<SNameEntry> NameEntries;
|
std::vector<SNameEntry> NameEntries;
|
||||||
|
|
||||||
for (uint StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
for (uint32 StringIdx = 0; StringIdx < mpStringTable->NumStrings(); StringIdx++)
|
||||||
{
|
{
|
||||||
SNameEntry Entry;
|
SNameEntry Entry;
|
||||||
Entry.Offset = 0;
|
Entry.Offset = 0;
|
||||||
|
@ -256,46 +256,46 @@ void CStringCooker::WriteNameTable(IOutputStream& STRG)
|
||||||
|
|
||||||
if (!Entry.Name.IsEmpty())
|
if (!Entry.Name.IsEmpty())
|
||||||
{
|
{
|
||||||
NameEntries.push_back(Entry);
|
NameEntries.push_back(std::move(Entry));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::stable_sort( NameEntries.begin(), NameEntries.end(), [](const SNameEntry& kLHS, const SNameEntry& kRHS) -> bool {
|
std::stable_sort(NameEntries.begin(), NameEntries.end(), [](const SNameEntry& kLHS, const SNameEntry& kRHS) {
|
||||||
return kLHS.Name < kRHS.Name;
|
return kLHS.Name < kRHS.Name;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Write out name entries
|
// Write out name entries
|
||||||
uint NameTableStart = STRG.Tell();
|
const uint32 NameTableStart = STRG.Tell();
|
||||||
STRG.WriteLong(NameEntries.size());
|
STRG.WriteLong(NameEntries.size());
|
||||||
STRG.WriteLong(0); // Dummy name table size
|
STRG.WriteLong(0); // Dummy name table size
|
||||||
uint NameTableOffsetsStart = STRG.Tell();
|
const uint32 NameTableOffsetsStart = STRG.Tell();
|
||||||
|
|
||||||
for (uint NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++)
|
for (size_t NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++)
|
||||||
{
|
{
|
||||||
STRG.WriteLong(0); // Dummy name offset
|
STRG.WriteLong(0); // Dummy name offset
|
||||||
STRG.WriteLong(NameEntries[NameIdx].Index);
|
STRG.WriteLong(NameEntries[NameIdx].Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write out names
|
// Write out names
|
||||||
std::vector<uint> NameOffsets( NameEntries.size() );
|
std::vector<uint32> NameOffsets(NameEntries.size());
|
||||||
|
|
||||||
for (uint NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++)
|
for (size_t NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++)
|
||||||
{
|
{
|
||||||
NameOffsets[NameIdx] = STRG.Tell() - NameTableOffsetsStart;
|
NameOffsets[NameIdx] = STRG.Tell() - NameTableOffsetsStart;
|
||||||
STRG.WriteString(NameEntries[NameIdx].Name);
|
STRG.WriteString(NameEntries[NameIdx].Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fill out sizes and offsets
|
// Fill out sizes and offsets
|
||||||
uint NameTableEnd = STRG.Tell();
|
const uint32 NameTableEnd = STRG.Tell();
|
||||||
uint NameTableSize = NameTableEnd - NameTableOffsetsStart;
|
const uint32 NameTableSize = NameTableEnd - NameTableOffsetsStart;
|
||||||
|
|
||||||
STRG.GoTo(NameTableStart);
|
STRG.GoTo(NameTableStart);
|
||||||
STRG.Skip(4);
|
STRG.Skip(4);
|
||||||
STRG.WriteLong(NameTableSize);
|
STRG.WriteLong(NameTableSize);
|
||||||
|
|
||||||
for (uint NameIdx = 0; NameIdx < NameEntries.size(); NameIdx++)
|
for (const uint32 offset : NameOffsets)
|
||||||
{
|
{
|
||||||
STRG.WriteLong( NameOffsets[NameIdx] );
|
STRG.WriteLong(offset);
|
||||||
STRG.Skip(4);
|
STRG.Skip(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,11 +77,11 @@ static std::pair<const ELanguage*, size_t> GetSupportedLanguages(EGame Game, ERe
|
||||||
// Utility function - retrieve the index of a given language
|
// Utility function - retrieve the index of a given language
|
||||||
static int FindLanguageIndex(const CStringTable* pkInTable, ELanguage InLanguage)
|
static int FindLanguageIndex(const CStringTable* pkInTable, ELanguage InLanguage)
|
||||||
{
|
{
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < pkInTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < pkInTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
if (pkInTable->LanguageByIndex(LanguageIdx) == InLanguage)
|
if (pkInTable->LanguageByIndex(LanguageIdx) == InLanguage)
|
||||||
{
|
{
|
||||||
return LanguageIdx;
|
return static_cast<int>(LanguageIdx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,36 +89,35 @@ static int FindLanguageIndex(const CStringTable* pkInTable, ELanguage InLanguage
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Returns a string given a language/index pair */
|
/** Returns a string given a language/index pair */
|
||||||
TString CStringTable::GetString(ELanguage Language, uint StringIndex) const
|
TString CStringTable::GetString(ELanguage Language, size_t StringIndex) const
|
||||||
{
|
{
|
||||||
int LanguageIdx = FindLanguageIndex(this, Language);
|
const int LanguageIdx = FindLanguageIndex(this, Language);
|
||||||
|
|
||||||
if (LanguageIdx >= 0 && mLanguages[LanguageIdx].Strings.size() > StringIndex)
|
if (LanguageIdx >= 0 && mLanguages[LanguageIdx].Strings.size() > StringIndex)
|
||||||
{
|
{
|
||||||
return mLanguages[LanguageIdx].Strings[StringIndex].String;
|
return mLanguages[LanguageIdx].Strings[StringIndex].String;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/** Updates a string for a given language */
|
/** Updates a string for a given language */
|
||||||
void CStringTable::SetString(ELanguage Language, uint StringIndex, const TString& kNewString)
|
void CStringTable::SetString(ELanguage Language, size_t StringIndex, TString kNewString)
|
||||||
{
|
{
|
||||||
int LanguageIdx = FindLanguageIndex(this, Language);
|
const int LanguageIdx = FindLanguageIndex(this, Language);
|
||||||
int EnglishIdx = FindLanguageIndex(this, ELanguage::English);
|
const int EnglishIdx = FindLanguageIndex(this, ELanguage::English);
|
||||||
|
|
||||||
if (LanguageIdx >= 0 && mLanguages[LanguageIdx].Strings.size() > StringIndex)
|
if (LanguageIdx >= 0 && mLanguages[LanguageIdx].Strings.size() > StringIndex)
|
||||||
{
|
{
|
||||||
mLanguages[LanguageIdx].Strings[StringIndex].String = kNewString;
|
auto& string = mLanguages[LanguageIdx].Strings[StringIndex];
|
||||||
mLanguages[LanguageIdx].Strings[StringIndex].IsLocalized =
|
|
||||||
(LanguageIdx == EnglishIdx || kNewString != mLanguages[EnglishIdx].Strings[StringIndex].String);
|
string.IsLocalized = LanguageIdx == EnglishIdx || kNewString != mLanguages[EnglishIdx].Strings[StringIndex].String;
|
||||||
|
string.String = std::move(kNewString);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Updates a string name */
|
/** Updates a string name */
|
||||||
void CStringTable::SetStringName(uint StringIndex, const TString& kNewName)
|
void CStringTable::SetStringName(size_t StringIndex, TString kNewName)
|
||||||
{
|
{
|
||||||
// Sanity check - make sure the string index is valid
|
// Sanity check - make sure the string index is valid
|
||||||
ASSERT(NumStrings() > StringIndex);
|
ASSERT(NumStrings() > StringIndex);
|
||||||
|
@ -129,7 +128,7 @@ void CStringTable::SetStringName(uint StringIndex, const TString& kNewName)
|
||||||
mStringNames.resize(StringIndex + 1);
|
mStringNames.resize(StringIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
mStringNames[StringIndex] = kNewName;
|
mStringNames[StringIndex] = std::move(kNewName);
|
||||||
|
|
||||||
// Strip empty string names
|
// Strip empty string names
|
||||||
while (mStringNames.back().IsEmpty())
|
while (mStringNames.back().IsEmpty())
|
||||||
|
@ -137,7 +136,7 @@ void CStringTable::SetStringName(uint StringIndex, const TString& kNewName)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Move string to another position in the table */
|
/** Move string to another position in the table */
|
||||||
void CStringTable::MoveString(uint StringIndex, uint NewIndex)
|
void CStringTable::MoveString(size_t StringIndex, size_t NewIndex)
|
||||||
{
|
{
|
||||||
ASSERT(NumStrings() > StringIndex);
|
ASSERT(NumStrings() > StringIndex);
|
||||||
ASSERT(NumStrings() > NewIndex);
|
ASSERT(NumStrings() > NewIndex);
|
||||||
|
@ -146,28 +145,27 @@ void CStringTable::MoveString(uint StringIndex, uint NewIndex)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Update string data
|
// Update string data
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mLanguages.size(); LanguageIdx++)
|
for (SLanguageData& Language : mLanguages)
|
||||||
{
|
{
|
||||||
SLanguageData& Language = mLanguages[LanguageIdx];
|
|
||||||
SStringData String = Language.Strings[StringIndex];
|
SStringData String = Language.Strings[StringIndex];
|
||||||
|
|
||||||
if (NewIndex > StringIndex)
|
if (NewIndex > StringIndex)
|
||||||
{
|
{
|
||||||
for (uint i=StringIndex; i<NewIndex; i++)
|
for (size_t i = StringIndex; i < NewIndex; i++)
|
||||||
Language.Strings[i] = Language.Strings[i + 1];
|
Language.Strings[i] = Language.Strings[i + 1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (uint i=StringIndex; i>NewIndex; i--)
|
for (size_t i = StringIndex; i > NewIndex; i--)
|
||||||
Language.Strings[i] = Language.Strings[i - 1];
|
Language.Strings[i] = Language.Strings[i - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
Language.Strings[NewIndex] = String;
|
Language.Strings[NewIndex] = std::move(String);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update string name
|
// Update string name
|
||||||
uint MinIndex = Math::Min(StringIndex, NewIndex);
|
const size_t MinIndex = std::min(StringIndex, NewIndex);
|
||||||
uint MaxIndex = Math::Max(StringIndex, NewIndex);
|
const size_t MaxIndex = std::max(StringIndex, NewIndex);
|
||||||
|
|
||||||
if (MinIndex < mStringNames.size())
|
if (MinIndex < mStringNames.size())
|
||||||
{
|
{
|
||||||
|
@ -180,15 +178,15 @@ void CStringTable::MoveString(uint StringIndex, uint NewIndex)
|
||||||
|
|
||||||
if (NewIndex > StringIndex)
|
if (NewIndex > StringIndex)
|
||||||
{
|
{
|
||||||
for (uint i=StringIndex; i<NewIndex; i++)
|
for (size_t i = StringIndex; i < NewIndex; i++)
|
||||||
mStringNames[i] = mStringNames[i + 1];
|
mStringNames[i] = mStringNames[i + 1];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (uint i=StringIndex; i>NewIndex; i--)
|
for (size_t i = StringIndex; i > NewIndex; i--)
|
||||||
mStringNames[i] = mStringNames[i - 1];
|
mStringNames[i] = mStringNames[i - 1];
|
||||||
}
|
}
|
||||||
mStringNames[NewIndex] = Name;
|
mStringNames[NewIndex] = std::move(Name);
|
||||||
|
|
||||||
// Strip empty string names
|
// Strip empty string names
|
||||||
while (mStringNames.back().IsEmpty())
|
while (mStringNames.back().IsEmpty())
|
||||||
|
@ -197,7 +195,7 @@ void CStringTable::MoveString(uint StringIndex, uint NewIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a new string to the table */
|
/** Add a new string to the table */
|
||||||
void CStringTable::AddString(uint AtIndex)
|
void CStringTable::AddString(size_t AtIndex)
|
||||||
{
|
{
|
||||||
if (AtIndex < NumStrings())
|
if (AtIndex < NumStrings())
|
||||||
{
|
{
|
||||||
|
@ -207,26 +205,26 @@ void CStringTable::AddString(uint AtIndex)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
AtIndex = NumStrings();
|
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mLanguages.size(); LanguageIdx++)
|
|
||||||
{
|
{
|
||||||
SLanguageData& Language = mLanguages[LanguageIdx];
|
AtIndex = NumStrings();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SLanguageData& Language : mLanguages)
|
||||||
|
{
|
||||||
Language.Strings.insert(Language.Strings.begin() + AtIndex, 1, SStringData());
|
Language.Strings.insert(Language.Strings.begin() + AtIndex, 1, SStringData());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Remove a string from the table */
|
/** Remove a string from the table */
|
||||||
void CStringTable::RemoveString(uint StringIndex)
|
void CStringTable::RemoveString(size_t StringIndex)
|
||||||
{
|
{
|
||||||
ASSERT(StringIndex < NumStrings());
|
ASSERT(StringIndex < NumStrings());
|
||||||
|
|
||||||
if (mStringNames.size() > StringIndex)
|
if (mStringNames.size() > StringIndex)
|
||||||
mStringNames.erase(mStringNames.begin() + StringIndex);
|
mStringNames.erase(mStringNames.begin() + StringIndex);
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mLanguages.size(); LanguageIdx++)
|
for (SLanguageData& Language : mLanguages)
|
||||||
{
|
{
|
||||||
SLanguageData& Language = mLanguages[LanguageIdx];
|
|
||||||
Language.Strings.erase(Language.Strings.begin() + StringIndex);
|
Language.Strings.erase(Language.Strings.begin() + StringIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -235,7 +233,7 @@ void CStringTable::RemoveString(uint StringIndex)
|
||||||
void CStringTable::InitializeNewResource()
|
void CStringTable::InitializeNewResource()
|
||||||
{
|
{
|
||||||
// Initialize data for whatever languages are supported by our game/region
|
// Initialize data for whatever languages are supported by our game/region
|
||||||
ERegion Region = ( Entry() && Entry()->Project() ? Entry()->Project()->Region() : ERegion::NTSC );
|
const ERegion Region = ( Entry() && Entry()->Project() ? Entry()->Project()->Region() : ERegion::NTSC );
|
||||||
const auto [data, dataSize] = GetSupportedLanguages(Game(), Region);
|
const auto [data, dataSize] = GetSupportedLanguages(Game(), Region);
|
||||||
mLanguages.resize(dataSize);
|
mLanguages.resize(dataSize);
|
||||||
|
|
||||||
|
@ -276,13 +274,15 @@ std::unique_ptr<CDependencyTree> CStringTable::BuildDependencyTree() const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get tag name and parameters
|
// Get tag name and parameters
|
||||||
int NameEnd = kString.IndexOf('=', TagIdx);
|
const int NameEnd = kString.IndexOf('=', TagIdx);
|
||||||
int TagEnd = kString.IndexOf(';', TagIdx);
|
const int TagEnd = kString.IndexOf(';', TagIdx);
|
||||||
if (NameEnd == -1 || TagEnd == -1) continue;
|
if (NameEnd == -1 || TagEnd == -1)
|
||||||
|
continue;
|
||||||
|
|
||||||
TString TagName = kString.SubString(TagIdx + 1, NameEnd - TagIdx - 1);
|
const TString TagName = kString.SubString(TagIdx + 1, NameEnd - TagIdx - 1);
|
||||||
TString ParamString = kString.SubString(NameEnd + 1, TagEnd - NameEnd - 1);
|
TString ParamString = kString.SubString(NameEnd + 1, TagEnd - NameEnd - 1);
|
||||||
if (ParamString.IsEmpty()) continue;
|
if (ParamString.IsEmpty())
|
||||||
|
continue;
|
||||||
|
|
||||||
// Font
|
// Font
|
||||||
if (TagName == "font")
|
if (TagName == "font")
|
||||||
|
@ -297,7 +297,6 @@ std::unique_ptr<CDependencyTree> CStringTable::BuildDependencyTree() const
|
||||||
ASSERT(ParamString.Size() == IDLength * 2);
|
ASSERT(ParamString.Size() == IDLength * 2);
|
||||||
pTree->AddDependency(CAssetID::FromString(ParamString));
|
pTree->AddDependency(CAssetID::FromString(ParamString));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Image
|
// Image
|
||||||
else if (TagName == "image")
|
else if (TagName == "image")
|
||||||
{
|
{
|
||||||
|
@ -307,20 +306,25 @@ std::unique_ptr<CDependencyTree> CStringTable::BuildDependencyTree() const
|
||||||
uint TexturesStart = 0;
|
uint TexturesStart = 0;
|
||||||
|
|
||||||
if (ImageType == "A")
|
if (ImageType == "A")
|
||||||
|
{
|
||||||
TexturesStart = 2;
|
TexturesStart = 2;
|
||||||
|
}
|
||||||
else if (ImageType == "SI")
|
else if (ImageType == "SI")
|
||||||
|
{
|
||||||
TexturesStart = 3;
|
TexturesStart = 3;
|
||||||
|
}
|
||||||
else if (ImageType == "SA")
|
else if (ImageType == "SA")
|
||||||
|
{
|
||||||
TexturesStart = 4;
|
TexturesStart = 4;
|
||||||
|
}
|
||||||
else if (ImageType == "B")
|
else if (ImageType == "B")
|
||||||
|
{
|
||||||
TexturesStart = 2;
|
TexturesStart = 2;
|
||||||
|
}
|
||||||
else if (ImageType.IsHexString(false, static_cast<int>(IDLength) * 2))
|
else if (ImageType.IsHexString(false, static_cast<int>(IDLength) * 2))
|
||||||
|
{
|
||||||
TexturesStart = 0;
|
TexturesStart = 0;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errorf("Unrecognized image type: %s", *ImageType);
|
errorf("Unrecognized image type: %s", *ImageType);
|
||||||
|
@ -330,7 +334,7 @@ std::unique_ptr<CDependencyTree> CStringTable::BuildDependencyTree() const
|
||||||
// Load texture IDs
|
// Load texture IDs
|
||||||
TStringList::iterator Iter = Params.begin();
|
TStringList::iterator Iter = Params.begin();
|
||||||
|
|
||||||
for (uint ParamIdx = 0; ParamIdx < Params.size(); ParamIdx++, Iter++)
|
for (uint ParamIdx = 0; ParamIdx < Params.size(); ParamIdx++, ++Iter)
|
||||||
{
|
{
|
||||||
if (ParamIdx >= TexturesStart)
|
if (ParamIdx >= TexturesStart)
|
||||||
{
|
{
|
||||||
|
@ -365,8 +369,9 @@ TString CStringTable::StripFormatting(const TString& kInString)
|
||||||
if (Out[CharIdx] == '&')
|
if (Out[CharIdx] == '&')
|
||||||
{
|
{
|
||||||
if (TagStart == -1)
|
if (TagStart == -1)
|
||||||
|
{
|
||||||
TagStart = CharIdx;
|
TagStart = CharIdx;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Out.Remove(TagStart, 1);
|
Out.Remove(TagStart, 1);
|
||||||
|
@ -374,11 +379,10 @@ TString CStringTable::StripFormatting(const TString& kInString)
|
||||||
CharIdx--;
|
CharIdx--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (TagStart != -1 && Out[CharIdx] == ';')
|
else if (TagStart != -1 && Out[CharIdx] == ';')
|
||||||
{
|
{
|
||||||
int TagEnd = CharIdx + 1;
|
const int TagEnd = CharIdx + 1;
|
||||||
int TagLen = TagEnd - TagStart;
|
const int TagLen = TagEnd - TagStart;
|
||||||
Out.Remove(TagStart, TagLen);
|
Out.Remove(TagStart, TagLen);
|
||||||
CharIdx = TagStart - 1;
|
CharIdx = TagStart - 1;
|
||||||
TagStart = -1;
|
TagStart = -1;
|
||||||
|
|
|
@ -53,34 +53,34 @@ public:
|
||||||
explicit CStringTable(CResourceEntry *pEntry = nullptr) : CResource(pEntry) {}
|
explicit CStringTable(CResourceEntry *pEntry = nullptr) : CResource(pEntry) {}
|
||||||
|
|
||||||
/** Returns the number of languages in the table */
|
/** Returns the number of languages in the table */
|
||||||
uint NumLanguages() const { return mLanguages.size(); }
|
size_t NumLanguages() const { return mLanguages.size(); }
|
||||||
|
|
||||||
/** Returns the number of strings in the table */
|
/** Returns the number of strings in the table */
|
||||||
uint NumStrings() const { return mLanguages.empty() ? 0 : mLanguages[0].Strings.size(); }
|
size_t NumStrings() const { return mLanguages.empty() ? 0 : mLanguages[0].Strings.size(); }
|
||||||
|
|
||||||
/** Returns languages used by index */
|
/** Returns languages used by index */
|
||||||
ELanguage LanguageByIndex(uint Index) const { return mLanguages.size() > Index ? mLanguages[Index].Language : ELanguage::Invalid; }
|
ELanguage LanguageByIndex(size_t Index) const { return mLanguages.size() > Index ? mLanguages[Index].Language : ELanguage::Invalid; }
|
||||||
|
|
||||||
/** Returns the string name by string index. May be blank if the string at the requested index is unnamed */
|
/** Returns the string name by string index. May be blank if the string at the requested index is unnamed */
|
||||||
TString StringNameByIndex(uint Index) const { return mStringNames.size() > Index ? mStringNames[Index] : ""; }
|
TString StringNameByIndex(size_t Index) const { return mStringNames.size() > Index ? mStringNames[Index] : ""; }
|
||||||
|
|
||||||
/** Returns a string given a language/index pair */
|
/** Returns a string given a language/index pair */
|
||||||
TString GetString(ELanguage Language, uint StringIndex) const;
|
TString GetString(ELanguage Language, size_t StringIndex) const;
|
||||||
|
|
||||||
/** Updates a string for a given language */
|
/** Updates a string for a given language */
|
||||||
void SetString(ELanguage Language, uint StringIndex, const TString& kNewString);
|
void SetString(ELanguage Language, size_t StringIndex, TString kNewString);
|
||||||
|
|
||||||
/** Updates a string name */
|
/** Updates a string name */
|
||||||
void SetStringName(uint StringIndex, const TString& kNewName);
|
void SetStringName(size_t StringIndex, TString kNewName);
|
||||||
|
|
||||||
/** Move string to another position in the table */
|
/** Move string to another position in the table */
|
||||||
void MoveString(uint StringIndex, uint NewIndex);
|
void MoveString(size_t StringIndex, size_t NewIndex);
|
||||||
|
|
||||||
/** Add a new string to the table */
|
/** Add a new string to the table */
|
||||||
void AddString(uint AtIndex);
|
void AddString(size_t AtIndex);
|
||||||
|
|
||||||
/** Remove a string from the table */
|
/** Remove a string from the table */
|
||||||
void RemoveString(uint StringIndex);
|
void RemoveString(size_t StringIndex);
|
||||||
|
|
||||||
/** Initialize new resource data */
|
/** Initialize new resource data */
|
||||||
void InitializeNewResource() override;
|
void InitializeNewResource() override;
|
||||||
|
|
|
@ -115,9 +115,9 @@ void CStringEditor::InitUI()
|
||||||
// Set up language tabs
|
// Set up language tabs
|
||||||
mpUI->EditLanguageTabBar->setExpanding(false);
|
mpUI->EditLanguageTabBar->setExpanding(false);
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx);
|
const ELanguage Language = mpStringTable->LanguageByIndex(LanguageIdx);
|
||||||
const char* pkLanguageName = TEnumReflection<ELanguage>::ConvertValueToString(Language);
|
const char* pkLanguageName = TEnumReflection<ELanguage>::ConvertValueToString(Language);
|
||||||
mpUI->EditLanguageTabBar->addTab(pkLanguageName);
|
mpUI->EditLanguageTabBar->addTab(pkLanguageName);
|
||||||
}
|
}
|
||||||
|
@ -197,14 +197,14 @@ void CStringEditor::LoadSettings()
|
||||||
QSettings Settings;
|
QSettings Settings;
|
||||||
|
|
||||||
// Set language
|
// Set language
|
||||||
ELanguage Language = (ELanguage) Settings.value(gkpLanguageSetting, (int) ELanguage::English).toInt();
|
const auto Language = static_cast<ELanguage>(Settings.value(gkpLanguageSetting, static_cast<int>(ELanguage::English)).toInt());
|
||||||
|
|
||||||
for (uint LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
for (size_t LanguageIdx = 0; LanguageIdx < mpStringTable->NumLanguages(); LanguageIdx++)
|
||||||
{
|
{
|
||||||
if (mpStringTable->LanguageByIndex(LanguageIdx) == Language)
|
if (mpStringTable->LanguageByIndex(LanguageIdx) == Language)
|
||||||
{
|
{
|
||||||
SetActiveLanguage(Language);
|
SetActiveLanguage(Language);
|
||||||
mpUI->EditLanguageTabBar->setCurrentIndex(LanguageIdx);
|
mpUI->EditLanguageTabBar->setCurrentIndex(static_cast<int>(LanguageIdx));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -246,17 +246,17 @@ void CStringEditor::UpdateUI()
|
||||||
mpUI->RemoveStringButton->setEnabled( pSelectionModel->hasSelection() );
|
mpUI->RemoveStringButton->setEnabled( pSelectionModel->hasSelection() );
|
||||||
|
|
||||||
// Update language tabs
|
// Update language tabs
|
||||||
uint LanguageIndex = mpUI->EditLanguageTabBar->currentIndex();
|
const auto LanguageIndex = static_cast<size_t>(mpUI->EditLanguageTabBar->currentIndex());
|
||||||
ELanguage TabLanguage = mpStringTable->LanguageByIndex(LanguageIndex);
|
const ELanguage TabLanguage = mpStringTable->LanguageByIndex(LanguageIndex);
|
||||||
|
|
||||||
if (TabLanguage != mCurrentLanguage)
|
if (TabLanguage != mCurrentLanguage)
|
||||||
{
|
{
|
||||||
for (uint LangIdx = 0; LangIdx < mpStringTable->NumLanguages(); LangIdx++)
|
for (size_t LangIdx = 0; LangIdx < mpStringTable->NumLanguages(); LangIdx++)
|
||||||
{
|
{
|
||||||
if (mpStringTable->LanguageByIndex(LangIdx) == mCurrentLanguage)
|
if (mpStringTable->LanguageByIndex(LangIdx) == mCurrentLanguage)
|
||||||
{
|
{
|
||||||
mpUI->EditLanguageTabBar->blockSignals(true);
|
mpUI->EditLanguageTabBar->blockSignals(true);
|
||||||
mpUI->EditLanguageTabBar->setCurrentIndex(LangIdx);
|
mpUI->EditLanguageTabBar->setCurrentIndex(static_cast<int>(LangIdx));
|
||||||
mpUI->EditLanguageTabBar->blockSignals(false);
|
mpUI->EditLanguageTabBar->blockSignals(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -295,15 +295,15 @@ void CStringEditor::OnStringSelected(const QModelIndex& kIndex)
|
||||||
|
|
||||||
void CStringEditor::OnLanguageChanged(int LanguageIndex)
|
void CStringEditor::OnLanguageChanged(int LanguageIndex)
|
||||||
{
|
{
|
||||||
ASSERT( LanguageIndex >= 0 && LanguageIndex < (int) mpStringTable->NumLanguages() );
|
ASSERT(LanguageIndex >= 0 && LanguageIndex < static_cast<int>(mpStringTable->NumLanguages()));
|
||||||
ELanguage Language = mpStringTable->LanguageByIndex(LanguageIndex);
|
const ELanguage Language = mpStringTable->LanguageByIndex(LanguageIndex);
|
||||||
|
|
||||||
|
if (Language == mCurrentLanguage)
|
||||||
|
return;
|
||||||
|
|
||||||
if (Language != mCurrentLanguage)
|
|
||||||
{
|
|
||||||
IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, Language);
|
IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, Language);
|
||||||
UndoStack().push(pCommand);
|
UndoStack().push(pCommand);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CStringEditor::OnStringNameEdited()
|
void CStringEditor::OnStringNameEdited()
|
||||||
{
|
{
|
||||||
|
@ -312,7 +312,8 @@ void CStringEditor::OnStringNameEdited()
|
||||||
if (mpStringTable->StringNameByIndex(mCurrentStringIndex) != NewName)
|
if (mpStringTable->StringNameByIndex(mCurrentStringIndex) != NewName)
|
||||||
{
|
{
|
||||||
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>("Edit String Name", mpStringTable, false);
|
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>("Edit String Name", mpStringTable, false);
|
||||||
mpStringTable->SetStringName( mCurrentStringIndex, NewName );
|
|
||||||
|
mpStringTable->SetStringName(mCurrentStringIndex, std::move(NewName));
|
||||||
mIsEditingStringName = true;
|
mIsEditingStringName = true;
|
||||||
UndoStack().push(pCommand);
|
UndoStack().push(pCommand);
|
||||||
}
|
}
|
||||||
|
@ -325,7 +326,8 @@ void CStringEditor::OnStringTextEdited()
|
||||||
if (mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex) != NewText)
|
if (mpStringTable->GetString(mCurrentLanguage, mCurrentStringIndex) != NewText)
|
||||||
{
|
{
|
||||||
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>("Edit String", mpStringTable, false);
|
IUndoCommand* pCommand = new TSerializeUndoCommand<CStringTable>("Edit String", mpStringTable, false);
|
||||||
mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, NewText);
|
|
||||||
|
mpStringTable->SetString(mCurrentLanguage, mCurrentStringIndex, std::move(NewText));
|
||||||
mIsEditingStringData = true;
|
mIsEditingStringData = true;
|
||||||
UndoStack().push(pCommand);
|
UndoStack().push(pCommand);
|
||||||
}
|
}
|
||||||
|
@ -355,13 +357,13 @@ void CStringEditor::OnRemoveString()
|
||||||
if (mpUI->StringNameListView->selectionModel()->hasSelection())
|
if (mpUI->StringNameListView->selectionModel()->hasSelection())
|
||||||
{
|
{
|
||||||
UndoStack().beginMacro("Remove String");
|
UndoStack().beginMacro("Remove String");
|
||||||
uint Index = mCurrentStringIndex;
|
const size_t Index = mCurrentStringIndex;
|
||||||
|
|
||||||
// Change selection to a new string.
|
// Change selection to a new string.
|
||||||
// Do this before actually removing the string so that if the action is undone, the
|
// Do this before actually removing the string so that if the action is undone, the
|
||||||
// editor will not attempt to re-select the string before it gets readded to the table.
|
// editor will not attempt to re-select the string before it gets readded to the table.
|
||||||
uint NewStringCount = mpStringTable->NumStrings() - 1;
|
const size_t NewStringCount = mpStringTable->NumStrings() - 1;
|
||||||
uint NewIndex = (Index >= NewStringCount ? NewStringCount - 1 : Index);
|
const size_t NewIndex = (Index >= NewStringCount ? NewStringCount - 1 : Index);
|
||||||
IUndoCommand* pCommand = new CSetStringIndexCommand(this, Index, NewIndex);
|
IUndoCommand* pCommand = new CSetStringIndexCommand(this, Index, NewIndex);
|
||||||
UndoStack().push(pCommand);
|
UndoStack().push(pCommand);
|
||||||
|
|
||||||
|
@ -406,39 +408,39 @@ void CStringEditor::IncrementStringIndex()
|
||||||
|
|
||||||
void CStringEditor::DecrementStringIndex()
|
void CStringEditor::DecrementStringIndex()
|
||||||
{
|
{
|
||||||
uint NewIndex = mCurrentStringIndex - 1;
|
const uint32 NewIndex = mCurrentStringIndex - 1;
|
||||||
|
|
||||||
|
if (NewIndex == UINT32_MAX)
|
||||||
|
return;
|
||||||
|
|
||||||
if (NewIndex != -1)
|
|
||||||
{
|
|
||||||
IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex);
|
IUndoCommand* pCommand = new CSetStringIndexCommand(this, mCurrentStringIndex, NewIndex);
|
||||||
UndoStack().push(pCommand);
|
UndoStack().push(pCommand);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CStringEditor::IncrementLanguageIndex()
|
void CStringEditor::IncrementLanguageIndex()
|
||||||
{
|
{
|
||||||
for (uint i=0; i<mpStringTable->NumLanguages() - 1; i++)
|
for (size_t i = 0; i < mpStringTable->NumLanguages() - 1; i++)
|
||||||
{
|
{
|
||||||
if (mpStringTable->LanguageByIndex(i) == mCurrentLanguage)
|
if (mpStringTable->LanguageByIndex(i) != mCurrentLanguage)
|
||||||
{
|
continue;
|
||||||
ELanguage NewLanguage = mpStringTable->LanguageByIndex(i+1);
|
|
||||||
|
const ELanguage NewLanguage = mpStringTable->LanguageByIndex(i + 1);
|
||||||
IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage);
|
IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage);
|
||||||
UndoStack().push(pCommand);
|
UndoStack().push(pCommand);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void CStringEditor::DecrementLanguageIndex()
|
void CStringEditor::DecrementLanguageIndex()
|
||||||
{
|
{
|
||||||
for (uint i=mpStringTable->NumLanguages() - 1; i>0; i--)
|
for (size_t i = mpStringTable->NumLanguages() - 1; i > 0; i--)
|
||||||
{
|
{
|
||||||
if (mpStringTable->LanguageByIndex(i) == mCurrentLanguage)
|
if (mpStringTable->LanguageByIndex(i) != mCurrentLanguage)
|
||||||
{
|
continue;
|
||||||
ELanguage NewLanguage = mpStringTable->LanguageByIndex(i-1);
|
|
||||||
|
const ELanguage NewLanguage = mpStringTable->LanguageByIndex(i - 1);
|
||||||
IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage);
|
IUndoCommand* pCommand = new CSetLanguageCommand(this, mCurrentLanguage, NewLanguage);
|
||||||
UndoStack().push(pCommand);
|
UndoStack().push(pCommand);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
@ -16,26 +16,25 @@ CStringListModel::CStringListModel(CStringEditor* pInEditor)
|
||||||
/** Change the preview language display */
|
/** Change the preview language display */
|
||||||
void CStringListModel::SetPreviewLanguage(ELanguage InLanguage)
|
void CStringListModel::SetPreviewLanguage(ELanguage InLanguage)
|
||||||
{
|
{
|
||||||
if (mStringPreviewLanguage != InLanguage)
|
if (mStringPreviewLanguage == InLanguage)
|
||||||
{
|
return;
|
||||||
|
|
||||||
mStringPreviewLanguage = InLanguage;
|
mStringPreviewLanguage = InLanguage;
|
||||||
|
|
||||||
// Emit data changed for user role for the full range of strings
|
// Emit data changed for user role for the full range of strings
|
||||||
int NumStrings = mpStringTable ? mpStringTable->NumStrings() : 0;
|
const int NumStrings = mpStringTable ? static_cast<int>(mpStringTable->NumStrings()) : 0;
|
||||||
|
if (NumStrings == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
if (NumStrings)
|
|
||||||
{
|
|
||||||
QVector<int> Roles;
|
QVector<int> Roles;
|
||||||
Roles << Qt::UserRole;
|
Roles << Qt::UserRole;
|
||||||
emit dataChanged(index(0), index(NumStrings - 1), Roles);
|
emit dataChanged(index(0), index(NumStrings - 1), Roles);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/** QAbstractListModel interface */
|
/** QAbstractListModel interface */
|
||||||
int CStringListModel::rowCount(const QModelIndex& kParent) const
|
int CStringListModel::rowCount(const QModelIndex& kParent) const
|
||||||
{
|
{
|
||||||
return mpStringTable ? mpStringTable->NumStrings() : 0;
|
return mpStringTable ? static_cast<int>(mpStringTable->NumStrings()) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant CStringListModel::data(const QModelIndex& kIndex, int Role) const
|
QVariant CStringListModel::data(const QModelIndex& kIndex, int Role) const
|
||||||
|
@ -45,7 +44,7 @@ QVariant CStringListModel::data(const QModelIndex& kIndex, int Role) const
|
||||||
return QVariant::Invalid;
|
return QVariant::Invalid;
|
||||||
}
|
}
|
||||||
|
|
||||||
int StringIndex = kIndex.row();
|
const auto StringIndex = static_cast<size_t>(kIndex.row());
|
||||||
|
|
||||||
// display/tooltip role: return the string name
|
// display/tooltip role: return the string name
|
||||||
if (Role == Qt::DisplayRole || Role == Qt::ToolTipRole)
|
if (Role == Qt::DisplayRole || Role == Qt::ToolTipRole)
|
||||||
|
@ -131,13 +130,13 @@ bool CStringListModel::dropMimeData(const QMimeData* pkData, Qt::DropAction Acti
|
||||||
}
|
}
|
||||||
// If the user placed the string at the end of the list, then the index we receive
|
// If the user placed the string at the end of the list, then the index we receive
|
||||||
// will be out of range, so cap it to a valid index.
|
// will be out of range, so cap it to a valid index.
|
||||||
else if (Row >= (int) mpStringTable->NumStrings())
|
else if (Row >= static_cast<int>(mpStringTable->NumStrings()))
|
||||||
{
|
{
|
||||||
Row = mpStringTable->NumStrings() - 1;
|
Row = static_cast<int>(mpStringTable->NumStrings()) - 1;
|
||||||
}
|
}
|
||||||
// If the string is being moved further down the list, then account for the fact that
|
// If the string is being moved further down the list, then account for the fact that
|
||||||
// the rest of the strings below it will be bumped up.
|
// the rest of the strings below it will be bumped up.
|
||||||
else if (Row > (int) pkStringMimeData->StringIndex())
|
else if (Row > static_cast<int>(pkStringMimeData->StringIndex()))
|
||||||
{
|
{
|
||||||
Row--;
|
Row--;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue