mirror of
https://github.com/ZDoom/gzdoom-gles.git
synced 2024-11-16 09:31:14 +00:00
- Changes to the language table.
(patch by Graf)
This commit is contained in:
parent
02ee44772c
commit
ef1047db20
4 changed files with 33 additions and 18 deletions
|
@ -160,7 +160,7 @@ public:
|
|||
int GetIWadFlags(unsigned int num) const
|
||||
{
|
||||
if (num < mIWadInfos.Size()) return mIWadInfos[num].flags;
|
||||
else return false;
|
||||
else return 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
|
|
@ -87,11 +87,11 @@ void FStringTable::LoadLanguage (int lumpnum)
|
|||
}
|
||||
if (len == 1 && sc.String[0] == '*')
|
||||
{
|
||||
activeMaps.Push(MAKE_ID('*', 0, 0, 0));
|
||||
activeMaps.Push(global_table);
|
||||
}
|
||||
else if (len == 7 && stricmp (sc.String, "default") == 0)
|
||||
{
|
||||
activeMaps.Push(MAKE_ID('*', '*', 0, 0));
|
||||
activeMaps.Push(default_table);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -177,15 +177,15 @@ void FStringTable::UpdateLanguage()
|
|||
auto checkone = [&](uint32_t lang_id)
|
||||
{
|
||||
auto list = allStrings.CheckKey(lang_id);
|
||||
if (list && currentLanguageSet.Find(list) == currentLanguageSet.Size())
|
||||
currentLanguageSet.Push(list);
|
||||
if (list && currentLanguageSet.FindEx([&](const auto &element) { return element.first == lang_id; }) == currentLanguageSet.Size())
|
||||
currentLanguageSet.Push(std::make_pair(lang_id, list));
|
||||
};
|
||||
|
||||
checkone(MAKE_ID('*', '*', '*', 0));
|
||||
checkone(MAKE_ID('*', 0, 0, 0));
|
||||
checkone(dehacked_table);
|
||||
checkone(global_table);
|
||||
checkone(LanguageID);
|
||||
checkone(LanguageID & MAKE_ID(0xff, 0xff, 0, 0));
|
||||
checkone(MAKE_ID('*', '*', 0, 0));
|
||||
checkone(default_table);
|
||||
}
|
||||
|
||||
// Replace \ escape sequences in a string with the escaped characters.
|
||||
|
@ -226,7 +226,7 @@ bool FStringTable::exists(const char *name)
|
|||
FName nm(name, true);
|
||||
if (nm != NAME_None)
|
||||
{
|
||||
uint32_t defaultStrings[] = { MAKE_ID('*', '*', '*', 0), MAKE_ID('*', 0, 0, 0), MAKE_ID('*', '*', 0, 0) };
|
||||
uint32_t defaultStrings[] = { default_table, global_table, dehacked_table };
|
||||
|
||||
for (auto mapid : defaultStrings)
|
||||
{
|
||||
|
@ -242,7 +242,7 @@ bool FStringTable::exists(const char *name)
|
|||
}
|
||||
|
||||
// Finds a string by name and returns its value
|
||||
const char *FStringTable::operator[] (const char *name) const
|
||||
const char *FStringTable::GetString(const char *name, uint32_t *langtable) const
|
||||
{
|
||||
if (name == nullptr || *name == 0)
|
||||
{
|
||||
|
@ -253,8 +253,12 @@ const char *FStringTable::operator[] (const char *name) const
|
|||
{
|
||||
for (auto map : currentLanguageSet)
|
||||
{
|
||||
auto item = map->CheckKey(nm);
|
||||
if (item) return item->GetChars();
|
||||
auto item = map.second->CheckKey(nm);
|
||||
if (item)
|
||||
{
|
||||
if (langtable) *langtable = map.first;
|
||||
return item->GetChars();
|
||||
}
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -58,25 +58,36 @@ public:
|
|||
class FStringTable
|
||||
{
|
||||
public:
|
||||
enum : uint32_t
|
||||
{
|
||||
default_table = MAKE_ID('*', '*', 0, 0),
|
||||
global_table = MAKE_ID('*', 0, 0, 0),
|
||||
dehacked_table = MAKE_ID('*', '*', '*', 0)
|
||||
};
|
||||
|
||||
using LangMap = TMap<uint32_t, StringMap>;
|
||||
|
||||
void LoadStrings ();
|
||||
void UpdateLanguage();
|
||||
StringMap GetDefaultStrings() { return allStrings[MAKE_ID('*', '*', 0, 0)]; } // Dehacked needs these for comparison
|
||||
StringMap GetDefaultStrings() { return allStrings[default_table]; } // Dehacked needs these for comparison
|
||||
void SetDehackedStrings(StringMap && map)
|
||||
{
|
||||
allStrings.Insert(MAKE_ID('*', '*', '*', 0), map);
|
||||
allStrings.Insert(dehacked_table, map);
|
||||
UpdateLanguage();
|
||||
}
|
||||
|
||||
|
||||
const char *GetString(const char *name, uint32_t *langtable) const;
|
||||
const char *operator() (const char *name) const; // Never returns NULL
|
||||
const char *operator[] (const char *name) const; // Can return NULL
|
||||
const char *operator[] (const char *name) const
|
||||
{
|
||||
return GetString(name, nullptr);
|
||||
}
|
||||
bool exists(const char *name);
|
||||
|
||||
private:
|
||||
|
||||
LangMap allStrings;
|
||||
TArray<StringMap*> currentLanguageSet;
|
||||
TArray<std::pair<uint32_t, StringMap*>> currentLanguageSet;
|
||||
|
||||
void LoadLanguage (int lumpnum);
|
||||
static size_t ProcessEscapes (char *str);
|
||||
|
|
|
@ -486,7 +486,7 @@ void FString::DeleteLastCharacter()
|
|||
{
|
||||
if (Len() == 0) return;
|
||||
auto pos = Len() - 1;
|
||||
while (pos > 0 && Chars[pos] >= 0x80 && Chars[pos] < 0xc0) pos--;
|
||||
while (pos > 0 && uint8_t(Chars[pos]) >= 0x80 && uint8_t(Chars[pos]) < 0xc0) pos--;
|
||||
if (pos <= 0)
|
||||
{
|
||||
Data()->Release();
|
||||
|
|
Loading…
Reference in a new issue