mirror of
https://github.com/ZDoom/gzdoom.git
synced 2025-03-24 11:42:19 +00:00
adapted string table so that it can be initialized without full game data being available.
This is for the IWAD picker which runs before many things are known.
This commit is contained in:
parent
48c18e1730
commit
f7a4f00177
6 changed files with 24 additions and 15 deletions
|
@ -47,27 +47,29 @@
|
|||
//
|
||||
//==========================================================================
|
||||
|
||||
void FStringTable::LoadStrings (const char *language)
|
||||
void FStringTable::LoadStrings (FileSys::FileSystem& fileSystem_, const char *language)
|
||||
{
|
||||
int lastlump, lump;
|
||||
|
||||
fileSystem = &fileSystem_;
|
||||
allStrings.Clear();
|
||||
lastlump = 0;
|
||||
while ((lump = fileSystem.FindLump("LMACROS", &lastlump)) != -1)
|
||||
while ((lump = fileSystem->FindLump("LMACROS", &lastlump)) != -1)
|
||||
{
|
||||
readMacros(lump);
|
||||
}
|
||||
|
||||
lastlump = 0;
|
||||
while ((lump = fileSystem.FindLump ("LANGUAGE", &lastlump)) != -1)
|
||||
while ((lump = fileSystem->FindLump ("LANGUAGE", &lastlump)) != -1)
|
||||
{
|
||||
auto lumpdata = fileSystem.ReadFile(lump);
|
||||
auto lumpdata = fileSystem->ReadFile(lump);
|
||||
|
||||
if (!ParseLanguageCSV(lump, lumpdata.string(), lumpdata.size()))
|
||||
LoadLanguage (lump, lumpdata.string(), lumpdata.size());
|
||||
}
|
||||
UpdateLanguage(language);
|
||||
allMacros.Clear();
|
||||
fileSystem = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -159,9 +161,10 @@ TArray<TArray<FString>> FStringTable::parseCSV(const char* buffer, size_t size)
|
|||
|
||||
bool FStringTable::readMacros(int lumpnum)
|
||||
{
|
||||
auto lumpdata = fileSystem.ReadFile(lumpnum);
|
||||
auto lumpdata = fileSystem->ReadFile(lumpnum);
|
||||
auto data = parseCSV(lumpdata.string(), lumpdata.size());
|
||||
|
||||
allMacros.Clear();
|
||||
for (unsigned i = 1; i < data.Size(); i++)
|
||||
{
|
||||
auto macroname = data[i][0];
|
||||
|
@ -410,7 +413,7 @@ void FStringTable::DeleteForLabel(int lumpnum, FName label)
|
|||
{
|
||||
decltype(allStrings)::Iterator it(allStrings);
|
||||
decltype(allStrings)::Pair *pair;
|
||||
auto filenum = fileSystem.GetFileContainer(lumpnum);
|
||||
auto filenum = fileSystem->GetFileContainer(lumpnum);
|
||||
|
||||
while (it.NextPair(pair))
|
||||
{
|
||||
|
@ -432,7 +435,7 @@ void FStringTable::DeleteForLabel(int lumpnum, FName label)
|
|||
void FStringTable::InsertString(int lumpnum, int langid, FName label, const FString &string)
|
||||
{
|
||||
const char *strlangid = (const char *)&langid;
|
||||
TableElement te = { fileSystem.GetFileContainer(lumpnum), { string, string, string, string } };
|
||||
TableElement te = { fileSystem->GetFileContainer(lumpnum), { string, string, string, string } };
|
||||
ptrdiff_t index;
|
||||
while ((index = te.strings[0].IndexOf("@[")) >= 0)
|
||||
{
|
||||
|
|
|
@ -84,7 +84,7 @@ public:
|
|||
using LangMap = TMap<uint32_t, StringMap>;
|
||||
using StringMacroMap = TMap<FName, StringMacro>;
|
||||
|
||||
void LoadStrings(const char *language);
|
||||
void LoadStrings(FileSys::FileSystem& fileSystem, const char *language);
|
||||
void UpdateLanguage(const char* language);
|
||||
StringMap GetDefaultStrings() { return allStrings[default_table]; } // Dehacked needs these for comparison
|
||||
void SetOverrideStrings(StringMap & map)
|
||||
|
@ -108,6 +108,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
FileSys::FileSystem* fileSystem;
|
||||
FString activeLanguage;
|
||||
StringMacroMap allMacros;
|
||||
LangMap allStrings;
|
||||
|
|
|
@ -69,7 +69,6 @@
|
|||
|
||||
#ifndef NO_GTK
|
||||
bool I_GtkAvailable ();
|
||||
int I_PickIWad_Gtk (WadStuff *wads, int numwads, bool showwin, int defaultiwad, int& autoloadflags);
|
||||
void I_ShowFatalError_Gtk(const char* errortext);
|
||||
#elif defined(__APPLE__)
|
||||
int I_PickIWad_Cocoa (WadStuff *wads, int numwads, bool showwin, int defaultiwad);
|
||||
|
|
|
@ -49,6 +49,7 @@
|
|||
#include "fs_findfile.h"
|
||||
#include "findfile.h"
|
||||
#include "i_interface.h"
|
||||
#include "gstrings.h"
|
||||
|
||||
EXTERN_CVAR(Bool, queryiwad);
|
||||
EXTERN_CVAR(String, defaultiwad);
|
||||
|
@ -56,6 +57,7 @@ EXTERN_CVAR(Bool, disableautoload)
|
|||
EXTERN_CVAR(Bool, autoloadlights)
|
||||
EXTERN_CVAR(Bool, autoloadbrightmaps)
|
||||
EXTERN_CVAR(Bool, autoloadwidescreen)
|
||||
EXTERN_CVAR(String, language)
|
||||
|
||||
//==========================================================================
|
||||
//
|
||||
|
@ -313,12 +315,15 @@ FIWadManager::FIWadManager(const char *firstfn, const char *optfn)
|
|||
|
||||
if (check.InitMultipleFiles(fns, &lfi, nullptr))
|
||||
{
|
||||
// this is for the IWAD picker. As we have a filesystem open here that contains the base files, it is the easiest place to load the strings early.
|
||||
GStrings.LoadStrings(check, language);
|
||||
int num = check.CheckNumForName("IWADINFO");
|
||||
if (num >= 0)
|
||||
{
|
||||
auto data = check.ReadFile(num);
|
||||
ParseIWadInfo("IWADINFO", data.string(), (int)data.size());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2641,7 +2641,7 @@ int StrTable_GetGender()
|
|||
bool StrTable_ValidFilter(const char* str)
|
||||
{
|
||||
if (gameinfo.gametype == GAME_Strife && (gameinfo.flags & GI_SHAREWARE) && !stricmp(str, "strifeteaser")) return true;
|
||||
return stricmp(str, GameNames[gameinfo.gametype]) == 0;
|
||||
return gameinfo.gametype == 0 || stricmp(str, GameNames[gameinfo.gametype]) == 0;
|
||||
}
|
||||
|
||||
bool System_WantGuiCapture()
|
||||
|
@ -3238,8 +3238,8 @@ static int D_InitGame(const FIWADInfo* iwad_info, std::vector<std::string>& allw
|
|||
exec = NULL;
|
||||
}
|
||||
|
||||
// [RH] Initialize localizable strings.
|
||||
GStrings.LoadStrings (language);
|
||||
// [RH] Initialize localizable strings.
|
||||
GStrings.LoadStrings(fileSystem, language);
|
||||
|
||||
V_InitFontColors ();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "v_video.h"
|
||||
#include "version.h"
|
||||
#include "i_interface.h"
|
||||
#include "gstrings.h"
|
||||
#include <zwidget/core/image.h>
|
||||
#include <zwidget/window/window.h>
|
||||
#include <zwidget/widgets/textedit/textedit.h>
|
||||
|
@ -83,9 +84,9 @@ LauncherWindow::LauncherWindow(WadStuff* wads, int numwads, int defaultiwad, int
|
|||
OpenGLCheckbox = new CheckboxLabel(this);
|
||||
GLESCheckbox = new CheckboxLabel(this);
|
||||
BackendLabel->SetText("Render Backend");
|
||||
VulkanCheckbox->SetText("Vulkan");
|
||||
OpenGLCheckbox->SetText("OpenGL");
|
||||
GLESCheckbox->SetText("OpenGL ES");
|
||||
VulkanCheckbox->SetText(GStrings("OPTVAL_VULKAN"));
|
||||
OpenGLCheckbox->SetText(GStrings("OPTVAL_OPENGL"));
|
||||
GLESCheckbox->SetText(GStrings("OPTVAL_OPENGLES"));
|
||||
#endif
|
||||
|
||||
FString welcomeText, versionText;
|
||||
|
|
Loading…
Reference in a new issue