- implemented OkForLocalization

This commit is contained in:
Christoph Oelckers 2019-02-21 00:56:03 +01:00
parent 48fcdacf06
commit 2907ba69a0
1 changed files with 41 additions and 4 deletions

View File

@ -39,6 +39,7 @@
#include "w_wad.h" #include "w_wad.h"
#include "templates.h" #include "templates.h"
#include "i_system.h" #include "i_system.h"
#include "gstrings.h"
#include "r_data/r_translate.h" #include "r_data/r_translate.h"
#include "r_data/sprites.h" #include "r_data/sprites.h"
@ -393,19 +394,56 @@ FTexture *FTextureManager::FindTexture(const char *texname, ETextureType usetype
return GetTexture(texnum.GetIndex()); return GetTexture(texnum.GetIndex());
} }
//==========================================================================
//
// Defines how graphics substitution is handled.
// 0: Never replace a text-containing graphic with a font-based text.
// 1: Always replace, regardless of any missing information. Useful for testing the substitution without providing full data.
// 2: Only replace for non-default texts, i.e. if some language redefines the string's content, use it instead of the graphic. Never replace a localized graphic.
// 3: Only replace if the string is not the default and the graphic comes from the IWAD. Never replace a localized graphic.
// 4: Like 1, but lets localized graphics pass.
//
//==========================================================================
CUSTOM_CVAR(Int, cl_localizationmode,0, CVAR_ARCHIVE)
{
if (self < 0 || self > 4) self = 0;
}
//========================================================================== //==========================================================================
// //
// FTextureManager :: OkForLocalization // FTextureManager :: OkForLocalization
// //
//========================================================================== //==========================================================================
CVAR(Int, cl_localizationmode,0, CVAR_ARCHIVE)
bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitute) bool FTextureManager::OkForLocalization(FTextureID texnum, const char *substitute)
{ {
if (!texnum.isValid()) return false; if (!texnum.isValid()) return false;
// Todo: Some decisions must be made here whether this texture is ok to use with the current locale settings. // First the unconditional settings, 0='never' and 1='always'.
return !cl_localizationmode; if (cl_localizationmode == 0) return true;
if (cl_localizationmode == 1) return false;
uint32_t langtable = 0;
if (*substitute == '$') substitute = GStrings.GetString(substitute+1, &langtable);
if (substitute == nullptr) return true; // The text does not exist.
// Modes 2, 3 and 4 must not replace localized textures.
int localizedTex = ResolveLocalizedTexture(texnum.GetIndex());
if (localizedTex != texnum.GetIndex()) return true; // Do not substitute a localized variant of the graphics patch.
// For mode 4 we are done now.
if (cl_localizationmode == 4) return false;
// Mode 2 and 3 must reject any text replacement from the default language tables.
if ((langtable & MAKE_ID(255,0,0,0)) == MAKE_ID('*', 0, 0, 0)) return true; // Do not substitute if the string comes from the default table.
if (cl_localizationmode == 2) return false;
// Mode 3 must also reject substitutions for non-IWAD content.
int file = Wads.GetLumpFile(Textures[texnum.GetIndex()].Texture->SourceLump);
if (file > Wads.GetIwadNum()) return true;
return false;
} }
static int OkForLocalization(int index, const FString &substitute) static int OkForLocalization(int index, const FString &substitute)
@ -421,7 +459,6 @@ DEFINE_ACTION_FUNCTION_NATIVE(_TexMan, OkForLocalization, OkForLocalization)
ACTION_RETURN_INT(OkForLocalization(name, subst)); ACTION_RETURN_INT(OkForLocalization(name, subst));
} }
//========================================================================== //==========================================================================
// //
// FTextureManager :: AddTexture // FTextureManager :: AddTexture