From 23a62cbe1254e0723ff1e7912ca4e239fa765c99 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Thu, 28 Feb 2019 23:52:47 +0100 Subject: [PATCH] - added a 'testfinale' CCMD, so that the layout of finale texts can be tested more easily --- src/gamedata/stringtable.cpp | 21 +++++++++++++++ src/gamedata/stringtable.h | 1 + src/intermission/intermission.cpp | 2 ++ src/intermission/intermission_parse.cpp | 36 +++++++++++++++++++++++++ 4 files changed, 60 insertions(+) diff --git a/src/gamedata/stringtable.cpp b/src/gamedata/stringtable.cpp index 98841c2d0..89695429b 100644 --- a/src/gamedata/stringtable.cpp +++ b/src/gamedata/stringtable.cpp @@ -366,6 +366,27 @@ const char *FStringTable::GetString(const char *name, uint32_t *langtable) const return nullptr; } +// Finds a string by name in a given language +const char *FStringTable::GetLanguageString(const char *name, uint32_t langtable) const +{ + if (name == nullptr || *name == 0) + { + return nullptr; + } + FName nm(name, true); + if (nm != NAME_None) + { + auto map = allStrings.CheckKey(langtable); + if (map == nullptr) return nullptr; + auto item = map->CheckKey(nm); + if (item) + { + return item->GetChars(); + } + } + return nullptr; +} + // Finds a string by name and returns its value. If the string does // not exist, returns the passed name instead. const char *FStringTable::operator() (const char *name) const diff --git a/src/gamedata/stringtable.h b/src/gamedata/stringtable.h index e88eb1a6f..d0d7b0347 100644 --- a/src/gamedata/stringtable.h +++ b/src/gamedata/stringtable.h @@ -76,6 +76,7 @@ public: UpdateLanguage(); } + const char *GetLanguageString(const char *name, uint32_t langtable) const; 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 diff --git a/src/intermission/intermission.cpp b/src/intermission/intermission.cpp index 33b09bf2b..9affb04ad 100644 --- a/src/intermission/intermission.cpp +++ b/src/intermission/intermission.cpp @@ -50,6 +50,7 @@ #include "d_net.h" #include "g_levellocals.h" #include "utf8.h" +#include "templates.h" FIntermissionDescriptorList IntermissionDescriptors; @@ -314,6 +315,7 @@ void DIntermissionScreenText::Drawer () int cx = (mTextX - 160)*CleanXfac + screen->GetWidth() / 2; int cy = (mTextY - 100)*CleanYfac + screen->GetHeight() / 2; + cx = MAX(0, cx); int startx = cx; // Does this text fall off the end of the screen? If so, try to eliminate some margins first. diff --git a/src/intermission/intermission_parse.cpp b/src/intermission/intermission_parse.cpp index 9fb601faf..67efbe491 100644 --- a/src/intermission/intermission_parse.cpp +++ b/src/intermission/intermission_parse.cpp @@ -37,7 +37,9 @@ #include "intermission/intermission.h" #include "g_level.h" #include "w_wad.h" +#include "c_dispatch.h" #include "gstrings.h" +#include "gi.h" static void ReplaceIntermission(FName intname,FIntermissionDescriptor *desc) @@ -904,3 +906,37 @@ void F_StartFinale (const char *music, int musicorder, int cdtrack, unsigned int } } } + + +CCMD(testfinale) +{ + if (argv.argc() < 2) + { + Printf("Usage: testfinale stringlabel [langId]\n"); + return; + } + const char *text; + + if (argv.argc() == 2) + { + text = GStrings.GetString(argv[1], nullptr); + } + else + { + auto len = strlen(argv[2]); + if (len < 2 || len > 3) + { + Printf("Language ID must be 2 or 3 characters\n"); + return; + } + auto id = MAKE_ID(tolower(argv[2][0]), tolower(argv[2][1]), tolower(argv[2][2]), 0); + text = GStrings.GetLanguageString(argv[1], id); + } + if (text == nullptr) + { + Printf("Text does not exist\n"); + return; + } + + F_StartFinale(gameinfo.finaleMusic, gameinfo.finaleOrder, -1, 0, gameinfo.FinaleFlat, text, false, false, true, true, false); +} \ No newline at end of file