Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions Core/GameEngine/Include/GameClient/GlobalLanguage.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,28 @@ class GlobalLanguage : public SubsystemInterface
ResolutionFontSizeMethod_Default = ResolutionFontSizeMethod_ClassicNoCeiling,
};

typedef std::list<AsciiString> StringList; // Used for our font file names that we want to load

public:

GlobalLanguage();
virtual ~GlobalLanguage();

void init();
void reset();
void update() { }
void update() {}

Real getResolutionFontSizeAdjustment() const;
Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba.

void parseCustomDefinition();

// Get current resolution font size scale for the given method and scaler, based on the base game resolution of 800 x 600.
// Defaults to a scaler of 1 for a uniform resolution scale.
static Real getResolutionFontSizeScale(ResolutionFontSizeMethod method, Real scaler = 1.0f);

static void parseFontFileName(INI *ini, void *instance, void *store, const void *userData);
static void parseFontDesc(INI *ini, void *instance, void *store, const void *userData);

AsciiString m_unicodeFontName;
AsciiString m_unicodeFontFileName;
Expand All @@ -111,19 +125,9 @@ class GlobalLanguage : public SubsystemInterface
Real m_resolutionFontSizeAdjustment;
Real m_userResolutionFontSizeAdjustment;
ResolutionFontSizeMethod m_resolutionFontSizeMethod;

float getResolutionFontSizeAdjustment() const;
Int adjustFontSize(Int theFontSize); // Adjusts font size for resolution. jba.

void parseCustomDefinition();

typedef std::list<AsciiString> StringList; // Used for our font file names that we want to load
typedef StringList::iterator StringListIt;

StringList m_localFonts; // List of the font filenames that are in our local directory
static void parseFontFileName( INI *ini, void *instance, void *store, const void* userData );
static void parseFontDesc(INI *ini, void *instance, void *store, const void* userData);
StringList m_localFonts; // List of the font filenames that are in our local directory
};

//-----------------------------------------------------------------------------
// INLINING ///////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
Expand Down
58 changes: 34 additions & 24 deletions Core/GameEngine/Source/GameClient/GlobalLanguage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
//-----------------------------------------------------------------------------
// DEFINES ////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
GlobalLanguage *TheGlobalLanguageData = nullptr; ///< The global language singleton
GlobalLanguage *TheGlobalLanguageData = nullptr;

static const LookupListRec ResolutionFontSizeMethodNames[] =
{
Expand Down Expand Up @@ -116,7 +116,7 @@ void INI::parseLanguageDefinition( INI *ini )
DEBUG_ASSERTCRASH(TheGlobalLanguageData, ("INI::parseLanguageDefinition - TheGlobalLanguage Data is not around, please create it before trying to parse the ini file."));
return;
}
// parse the ini weapon definition

ini->initFromINI( TheGlobalLanguageData, TheGlobalLanguageDataFieldParseTable );
}

Expand All @@ -136,7 +136,7 @@ GlobalLanguage::GlobalLanguage()

GlobalLanguage::~GlobalLanguage()
{
StringListIt it = m_localFonts.begin();
StringList::iterator it = m_localFonts.begin();
while( it != m_localFonts.end())
{
AsciiString font = *it;
Expand All @@ -146,7 +146,7 @@ GlobalLanguage::~GlobalLanguage()
}
}

void GlobalLanguage::init( void )
void GlobalLanguage::init()
{
{
AsciiString fname;
Expand All @@ -156,7 +156,7 @@ void GlobalLanguage::init( void )
ini.loadFileDirectory( fname, INI_LOAD_OVERWRITE, nullptr );
}

StringListIt it = m_localFonts.begin();
StringList::iterator it = m_localFonts.begin();
while( it != m_localFonts.end())
{
AsciiString font = *it;
Expand All @@ -174,49 +174,48 @@ void GlobalLanguage::init( void )
// override values with user preferences
OptionPreferences optionPref;
m_userResolutionFontSizeAdjustment = optionPref.getResolutionFontAdjustment();

}
void GlobalLanguage::reset( void ) {}

void GlobalLanguage::reset()
{
}

void GlobalLanguage::parseFontDesc(INI *ini, void *instance, void *store, const void* userData)
void GlobalLanguage::parseFontDesc(INI *ini, void *instance, void *store, const void *userData)
{
FontDesc *fontDesc = (FontDesc *)store;
fontDesc->name = ini->getNextQuotedAsciiString();
fontDesc->size = ini->scanInt(ini->getNextToken());
fontDesc->bold = ini->scanBool(ini->getNextToken());
}

void GlobalLanguage::parseFontFileName( INI *ini, void * instance, void *store, const void* userData )
void GlobalLanguage::parseFontFileName(INI *ini, void *instance, void *store, const void *userData)
{
GlobalLanguage *monkey = (GlobalLanguage *)instance;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RIP monkey

GlobalLanguage *globalLanguage = static_cast<GlobalLanguage *>(instance);
AsciiString asciiString = ini->getNextAsciiString();
monkey->m_localFonts.push_front(asciiString);
globalLanguage->m_localFonts.push_front(asciiString);
}

float GlobalLanguage::getResolutionFontSizeAdjustment( void ) const
Real GlobalLanguage::getResolutionFontSizeAdjustment() const
{
if (m_userResolutionFontSizeAdjustment >= 0.0f)
return m_userResolutionFontSizeAdjustment;
else
return m_resolutionFontSizeAdjustment;
}

Int GlobalLanguage::adjustFontSize(Int theFontSize)
Real GlobalLanguage::getResolutionFontSizeScale(ResolutionFontSizeMethod method, Real scaler)
{
// TheSuperHackers @todo This function is called very often.
// Therefore cache the adjustFactor on resolution change to not recompute it on every call.
Real adjustFactor;

switch (m_resolutionFontSizeMethod)
switch (method)
{
default:
case ResolutionFontSizeMethod_Classic:
{
// TheSuperHackers @info The original font scaling for this game.
// Useful for not breaking legacy Addons and Mods. Scales poorly with large resolutions.
adjustFactor = TheDisplay->getWidth() / (Real)DEFAULT_DISPLAY_WIDTH;
adjustFactor = 1.0f + (adjustFactor - 1.0f) * getResolutionFontSizeAdjustment();
adjustFactor = 1.0f + (adjustFactor - 1.0f) * scaler;
if (adjustFactor > 2.0f)
adjustFactor = 2.0f;
break;
Expand All @@ -226,7 +225,7 @@ Int GlobalLanguage::adjustFontSize(Int theFontSize)
// TheSuperHackers @feature The original font scaling, but without ceiling.
// Useful for not changing the original look of the game. Scales alright with large resolutions.
adjustFactor = TheDisplay->getWidth() / (Real)DEFAULT_DISPLAY_WIDTH;
adjustFactor = 1.0f + (adjustFactor - 1.0f) * getResolutionFontSizeAdjustment();
adjustFactor = 1.0f + (adjustFactor - 1.0f) * scaler;
break;
}
case ResolutionFontSizeMethod_Strict:
Expand All @@ -236,7 +235,7 @@ Int GlobalLanguage::adjustFontSize(Int theFontSize)
const Real wScale = TheDisplay->getWidth() / (Real)DEFAULT_DISPLAY_WIDTH;
const Real hScale = TheDisplay->getHeight() / (Real)DEFAULT_DISPLAY_HEIGHT;
adjustFactor = min(wScale, hScale);
adjustFactor = 1.0f + (adjustFactor - 1.0f) * getResolutionFontSizeAdjustment();
adjustFactor = 1.0f + (adjustFactor - 1.0f) * scaler;
break;
}
case ResolutionFontSizeMethod_Balanced:
Expand Down Expand Up @@ -265,14 +264,25 @@ Int GlobalLanguage::adjustFontSize(Int theFontSize)
hScale = h / (Real)DEFAULT_DISPLAY_HEIGHT;
}
adjustFactor = (wScale + hScale) * 0.5f;
adjustFactor = 1.0f + (adjustFactor - 1.0f) * getResolutionFontSizeAdjustment();
adjustFactor = 1.0f + (adjustFactor - 1.0f) * scaler;
break;
}
}

if (adjustFactor < 1.0f)
adjustFactor = 1.0f;
Int pointSize = REAL_TO_INT_FLOOR(theFontSize*adjustFactor);

return adjustFactor;
}

Int GlobalLanguage::adjustFontSize(Int theFontSize)
{
// TheSuperHackers @todo This function is called very often.
// Therefore cache the adjustFactor on resolution change to not recompute it on every call.
const Real resolutionScaler = getResolutionFontSizeAdjustment();
const Real adjustFactor = getResolutionFontSizeScale(m_resolutionFontSizeMethod, resolutionScaler);
const Int pointSize = REAL_TO_INT_FLOOR(theFontSize * adjustFactor);

return pointSize;
}

Expand All @@ -288,9 +298,9 @@ void GlobalLanguage::parseCustomDefinition()

FontDesc::FontDesc(void)
{
name = "Arial Unicode MS"; ///<name of font
size = 12; ///<point size
bold = FALSE; ///<is bold?
name = "Arial Unicode MS";
size = 12;
bold = FALSE;
}
//-----------------------------------------------------------------------------
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
Expand Down
Loading