You've already forked rimworld-font-replacer
111 lines
3.6 KiB
C#
111 lines
3.6 KiB
C#
using System;
|
|
using System.Linq;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using Verse;
|
|
|
|
namespace raptureparty.RimWorldFontReplacer
|
|
{
|
|
[StaticConstructorOnStartup]
|
|
class FontLoader
|
|
{
|
|
public static string TargetTinyFontName;
|
|
|
|
public static string TargetSmallFontName;
|
|
|
|
public static string TargetMediumFontName;
|
|
|
|
public static string TargetPlanetFontName;
|
|
|
|
public static int FontTinySize = 11;
|
|
|
|
public static int FontSmallSize = 14;
|
|
|
|
public static int FontMediumSize = 18;
|
|
|
|
static private Font s_fontTiny;
|
|
static private string s_fontTinySearchedName;
|
|
static public bool FontTinyFound
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
static private Font s_fontSmall;
|
|
static private string s_fontSmallSearchedName;
|
|
static public bool FontSmallFound
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
static private Font s_fontMedium;
|
|
static private string s_fontMediumSearchedName;
|
|
static public bool FontMediumFound
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
static private Font s_fontPlanet;
|
|
static private string s_fontPlanetSearchedName;
|
|
static public bool FontPlanetFound
|
|
{
|
|
get; private set;
|
|
}
|
|
|
|
static public Font FontTiny
|
|
{
|
|
get
|
|
{
|
|
if (s_fontTinySearchedName != TargetTinyFontName)
|
|
{
|
|
s_fontTiny = Font.CreateDynamicFontFromOSFont(TargetTinyFontName, FontTinySize);
|
|
s_fontTinySearchedName = TargetTinyFontName;
|
|
FontTinyFound = Font.GetOSInstalledFontNames().Contains(TargetTinyFontName);
|
|
}
|
|
return FontTinyFound ? s_fontTiny : Text.fontStyles[0].font;
|
|
}
|
|
}
|
|
|
|
static public Font FontSmall
|
|
{
|
|
get
|
|
{
|
|
if (s_fontSmallSearchedName != TargetSmallFontName)
|
|
{
|
|
s_fontSmall = Font.CreateDynamicFontFromOSFont(TargetSmallFontName, FontSmallSize);
|
|
s_fontSmallSearchedName = TargetSmallFontName;
|
|
FontSmallFound = Font.GetOSInstalledFontNames().Contains(TargetSmallFontName);
|
|
}
|
|
return FontSmallFound ? s_fontSmall : Text.fontStyles[1].font;
|
|
}
|
|
}
|
|
|
|
static public Font FontMedium
|
|
{
|
|
get
|
|
{
|
|
if (s_fontMediumSearchedName != TargetMediumFontName)
|
|
{
|
|
s_fontMedium = Font.CreateDynamicFontFromOSFont(TargetMediumFontName, FontMediumSize);
|
|
s_fontMediumSearchedName = TargetMediumFontName;
|
|
FontMediumFound = Font.GetOSInstalledFontNames().Contains(TargetMediumFontName); ;
|
|
}
|
|
return FontMediumFound ? s_fontMedium : Text.fontStyles[2].font;
|
|
}
|
|
}
|
|
|
|
static public Font FontPlanet
|
|
{
|
|
get
|
|
{
|
|
if (s_fontPlanetSearchedName != TargetPlanetFontName)
|
|
{
|
|
s_fontPlanet = Font.CreateDynamicFontFromOSFont(TargetPlanetFontName, Text.fontStyles[2].font.fontSize); // TODO: find correct size
|
|
s_fontPlanetSearchedName = TargetPlanetFontName;
|
|
FontPlanetFound = Font.GetOSInstalledFontNames().Contains(TargetPlanetFontName); ;
|
|
}
|
|
return FontPlanetFound ? s_fontPlanet : Text.fontStyles[2].font; // TODO: find correct size
|
|
}
|
|
}
|
|
}
|
|
}
|