You've already forked rimworld-font-replacer
Initial commit
This commit is contained in:
121
Source/CustomGUIStyles.cs
Normal file
121
Source/CustomGUIStyles.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using Verse;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace raptureparty.RimWorldFontReplacer
|
||||
{
|
||||
[StaticConstructorOnStartup]
|
||||
static class CustomGUIStyles
|
||||
{
|
||||
public static GUIStyle[] fontStyles;
|
||||
|
||||
public static GUIStyle[] textFieldStyles;
|
||||
|
||||
public static GUIStyle[] textAreaStyles;
|
||||
|
||||
public static GUIStyle[] textAreaReadOnlyStyles;
|
||||
|
||||
public static void UpdateFonts()
|
||||
{
|
||||
if (fontStyles != null)
|
||||
{
|
||||
fontStyles[0].font = FontLoader.FontTiny;
|
||||
fontStyles[0].fontSize = FontLoader.FontTinySize;
|
||||
fontStyles[1].font = FontLoader.FontSmall;
|
||||
fontStyles[1].fontSize = FontLoader.FontSmallSize;
|
||||
fontStyles[2].font = FontLoader.FontMedium;
|
||||
fontStyles[2].fontSize = FontLoader.FontMediumSize;
|
||||
}
|
||||
if (textFieldStyles != null)
|
||||
{
|
||||
textFieldStyles[0].font = FontLoader.FontTiny;
|
||||
textFieldStyles[0].fontSize = FontLoader.FontTinySize;
|
||||
textFieldStyles[1].font = FontLoader.FontSmall;
|
||||
textFieldStyles[1].fontSize = FontLoader.FontSmallSize;
|
||||
textFieldStyles[2].font = FontLoader.FontMedium;
|
||||
textFieldStyles[2].fontSize = FontLoader.FontMediumSize;
|
||||
}
|
||||
if (textAreaStyles != null)
|
||||
{
|
||||
textAreaStyles[0].font = FontLoader.FontTiny;
|
||||
textAreaStyles[0].fontSize = FontLoader.FontTinySize;
|
||||
textAreaStyles[1].font = FontLoader.FontSmall;
|
||||
textAreaStyles[1].fontSize = FontLoader.FontSmallSize;
|
||||
textAreaStyles[2].font = FontLoader.FontMedium;
|
||||
textAreaStyles[2].fontSize = FontLoader.FontMediumSize;
|
||||
}
|
||||
if (textAreaReadOnlyStyles != null)
|
||||
{
|
||||
textAreaReadOnlyStyles[0].font = FontLoader.FontTiny;
|
||||
textAreaReadOnlyStyles[0].fontSize = FontLoader.FontTinySize;
|
||||
textAreaReadOnlyStyles[1].font = FontLoader.FontSmall;
|
||||
textAreaReadOnlyStyles[1].fontSize = FontLoader.FontSmallSize;
|
||||
textAreaReadOnlyStyles[2].font = FontLoader.FontMedium;
|
||||
textAreaReadOnlyStyles[2].fontSize = FontLoader.FontMediumSize;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Create()
|
||||
{
|
||||
try
|
||||
{
|
||||
fontStyles = new GUIStyle[3];
|
||||
textFieldStyles = new GUIStyle[3];
|
||||
textAreaStyles = new GUIStyle[3];
|
||||
textAreaReadOnlyStyles = new GUIStyle[3];
|
||||
fontStyles[0] = new GUIStyle(GUI.skin.label);
|
||||
fontStyles[0].font = FontLoader.FontTiny;
|
||||
fontStyles[0].fontSize = FontLoader.FontTinySize;
|
||||
fontStyles[1] = new GUIStyle(GUI.skin.label);
|
||||
fontStyles[1].font = FontLoader.FontSmall;
|
||||
fontStyles[1].fontSize = FontLoader.FontSmallSize;
|
||||
fontStyles[1].contentOffset = new Vector2(0f, -1f);
|
||||
fontStyles[2] = new GUIStyle(GUI.skin.label);
|
||||
fontStyles[2].font = FontLoader.FontMedium;
|
||||
fontStyles[2].fontSize = FontLoader.FontMediumSize;
|
||||
for (int i = 0; i < textFieldStyles.Length; i++)
|
||||
{
|
||||
textFieldStyles[i] = new GUIStyle(GUI.skin.textField);
|
||||
textFieldStyles[i].alignment = TextAnchor.MiddleLeft;
|
||||
}
|
||||
|
||||
textFieldStyles[0].font = FontLoader.FontTiny;
|
||||
textFieldStyles[0].fontSize = FontLoader.FontTinySize;
|
||||
textFieldStyles[1].font = FontLoader.FontSmall;
|
||||
textFieldStyles[1].fontSize = FontLoader.FontSmallSize;
|
||||
textFieldStyles[2].font = FontLoader.FontMedium;
|
||||
textFieldStyles[2].fontSize = FontLoader.FontMediumSize;
|
||||
for (int j = 0; j < textAreaStyles.Length; j++)
|
||||
{
|
||||
textAreaStyles[j] = new GUIStyle(textFieldStyles[j])
|
||||
{
|
||||
fontSize = textFieldStyles[j].fontSize,
|
||||
alignment = TextAnchor.UpperLeft,
|
||||
wordWrap = true
|
||||
};
|
||||
}
|
||||
|
||||
for (int k = 0; k < textAreaReadOnlyStyles.Length; k++)
|
||||
{
|
||||
textAreaReadOnlyStyles[k] = new GUIStyle(textAreaStyles[k]);
|
||||
textAreaReadOnlyStyles[k].fontSize = textAreaStyles[k].fontSize;
|
||||
GUIStyle obj = textAreaReadOnlyStyles[k];
|
||||
obj.normal.background = null;
|
||||
obj.active.background = null;
|
||||
obj.onHover.background = null;
|
||||
obj.hover.background = null;
|
||||
obj.onFocused.background = null;
|
||||
obj.focused.background = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Message("Could not create GUI styles, " + ex.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
110
Source/FontLoader.cs
Normal file
110
Source/FontLoader.cs
Normal file
@@ -0,0 +1,110 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
160
Source/FontPatches.cs
Normal file
160
Source/FontPatches.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using Verse;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RimWorld.Planet;
|
||||
using TMPro;
|
||||
|
||||
namespace raptureparty.RimWorldFontReplacer
|
||||
{
|
||||
[HarmonyPatch]
|
||||
static class Text_CurFontStyle_Patch
|
||||
{
|
||||
[HarmonyPatch(typeof(Text), nameof(Text.CurFontStyle), MethodType.Getter)]
|
||||
public static bool Prefix(ref GUIStyle __result)
|
||||
{
|
||||
if (CustomGUIStyles.fontStyles == null)
|
||||
{
|
||||
CustomGUIStyles.Create();
|
||||
}
|
||||
GUIStyle guistyle;
|
||||
switch (Text.Font)
|
||||
{
|
||||
case GameFont.Tiny:
|
||||
guistyle = CustomGUIStyles.fontStyles[0];
|
||||
break;
|
||||
case GameFont.Small:
|
||||
guistyle = CustomGUIStyles.fontStyles[1];
|
||||
break;
|
||||
default:
|
||||
case GameFont.Medium:
|
||||
guistyle = CustomGUIStyles.fontStyles[2];
|
||||
break;
|
||||
}
|
||||
guistyle.alignment = Text.Anchor;
|
||||
guistyle.wordWrap = Text.WordWrap;
|
||||
__result = guistyle;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
static class Text_CurTextFieldStyle_Patch
|
||||
{
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(Text), nameof(Text.CurTextFieldStyle), MethodType.Getter)]
|
||||
static bool Prefix(ref GUIStyle __result)
|
||||
{
|
||||
if (CustomGUIStyles.fontStyles == null)
|
||||
{
|
||||
CustomGUIStyles.Create();
|
||||
}
|
||||
GUIStyle guistyle;
|
||||
switch (Text.Font)
|
||||
{
|
||||
case GameFont.Tiny:
|
||||
guistyle = CustomGUIStyles.textFieldStyles[0];
|
||||
break;
|
||||
case GameFont.Small:
|
||||
guistyle = CustomGUIStyles.textFieldStyles[1];
|
||||
break;
|
||||
default:
|
||||
case GameFont.Medium:
|
||||
guistyle = CustomGUIStyles.textFieldStyles[2];
|
||||
break;
|
||||
}
|
||||
__result = guistyle;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
static class Text_CurTextAreaStyle_Patch
|
||||
{
|
||||
[HarmonyPatch(typeof(Text), nameof(Text.CurTextAreaStyle), MethodType.Getter)]
|
||||
static bool Prefix(ref GUIStyle __result)
|
||||
{
|
||||
if (CustomGUIStyles.fontStyles == null)
|
||||
{
|
||||
CustomGUIStyles.Create();
|
||||
}
|
||||
GUIStyle guistyle;
|
||||
switch (Text.Font)
|
||||
{
|
||||
case GameFont.Tiny:
|
||||
guistyle = CustomGUIStyles.textAreaStyles[0];
|
||||
break;
|
||||
case GameFont.Small:
|
||||
guistyle = CustomGUIStyles.textAreaStyles[1];
|
||||
break;
|
||||
default:
|
||||
case GameFont.Medium:
|
||||
guistyle = CustomGUIStyles.textAreaStyles[2];
|
||||
break;
|
||||
}
|
||||
__result = guistyle;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[HarmonyPatch]
|
||||
static class Text_CurTextAreaReadOnlyStyle_Patch
|
||||
{
|
||||
[HarmonyPatch(typeof(Text), nameof(Text.CurTextAreaReadOnlyStyle), MethodType.Getter)]
|
||||
static bool Prefix(ref GUIStyle __result)
|
||||
{
|
||||
if (CustomGUIStyles.fontStyles == null)
|
||||
{
|
||||
CustomGUIStyles.Create();
|
||||
}
|
||||
GUIStyle guistyle;
|
||||
switch (Text.Font)
|
||||
{
|
||||
case GameFont.Tiny:
|
||||
guistyle = CustomGUIStyles.textAreaReadOnlyStyles[0];
|
||||
break;
|
||||
case GameFont.Small:
|
||||
guistyle = CustomGUIStyles.textAreaReadOnlyStyles[1];
|
||||
break;
|
||||
default:
|
||||
case GameFont.Medium:
|
||||
guistyle = CustomGUIStyles.textAreaReadOnlyStyles[2];
|
||||
break;
|
||||
}
|
||||
__result = guistyle;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
static class WorldFeatureTextMesh_TextMeshLegacy_Patch
|
||||
{
|
||||
[HarmonyPatch(typeof(WorldFeatureTextMesh_Legacy), nameof(WorldFeatureTextMesh_Legacy.Init))]
|
||||
public static void Postfix(ref TextMesh ___textMesh)
|
||||
{
|
||||
Log.Message("Patching TextMesh init");
|
||||
___textMesh.font = FontLoader.FontMedium;
|
||||
}
|
||||
}
|
||||
|
||||
[HarmonyPatch]
|
||||
static class WorldFeatureTextMesh_TextMeshPro_Patch
|
||||
{
|
||||
[HarmonyPatch(typeof(WorldFeatureTextMesh_TextMeshPro), nameof(WorldFeatureTextMesh_TextMeshPro.Init))]
|
||||
public static void Postfix(ref TextMeshPro ___textMesh)
|
||||
{
|
||||
Log.Message("Patching TextMeshPro init");
|
||||
TMP_FontAsset asset = TMP_FontAsset.CreateFontAsset(FontLoader.FontPlanet);
|
||||
___textMesh.font = asset;
|
||||
___textMesh.UpdateFontAsset();
|
||||
}
|
||||
}
|
||||
}
|
||||
27
Source/Main.cs
Normal file
27
Source/Main.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using HarmonyLib;
|
||||
using System.Reflection;
|
||||
using Verse;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
namespace raptureparty.RimWorldFontReplacer
|
||||
{
|
||||
[StaticConstructorOnStartup]
|
||||
class RimWorldFontReplacer : Mod
|
||||
{
|
||||
public RimWorldFontReplacer(ModContentPack content) : base(content)
|
||||
{
|
||||
base.GetSettings<Settings>();
|
||||
var inst = new Harmony("rimworld.raptureparty.RimWorldFontReplacer");
|
||||
inst.PatchAll();
|
||||
}
|
||||
|
||||
public void Save() => LoadedModManager.GetMod<RimWorldFontReplacer>().GetSettings<Settings>().Write();
|
||||
|
||||
public override string SettingsCategory() => "RimWorld Font Replacer";
|
||||
|
||||
public override void DoSettingsWindowContents(Rect inRect) => Settings.Build(inRect);
|
||||
}
|
||||
}
|
||||
287
Source/RimWorldFontReplacer.csproj
Normal file
287
Source/RimWorldFontReplacer.csproj
Normal file
@@ -0,0 +1,287 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net472</TargetFramework>
|
||||
<EnableDefaultCompileItems>False</EnableDefaultCompileItems>
|
||||
<AppendTargetFrameworkToOutputPath>False</AppendTargetFrameworkToOutputPath>
|
||||
<OutputPath>../Assemblies/Current</OutputPath>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
<DebugType>None</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<!--
|
||||
RimWorld DLL references.
|
||||
To override:
|
||||
dotnet build -p:RimWorldManaged=/path/to/Managed -p:HarmonyAssemblies=/path/to/0Harmony
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<RimWorldManaged Condition="'$(RimWorldManaged)' == ''">/Applications/RimWorld.app/Contents/Resources/Data/Managed</RimWorldManaged>
|
||||
<HarmonyAssemblies Condition="'$(HarmonyAssemblies)' == ''">/Applications/RimWorld.app/Mods/HarmonyMod/Current/Assemblies</HarmonyAssemblies>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="0Harmony">
|
||||
<HintPath>$(HarmonyAssemblies)/0Harmony.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="Assembly-CSharp">
|
||||
<HintPath>$(RimWorldManaged)\Assembly-CSharp.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Unity.TextMeshPro">
|
||||
<HintPath>$(RimWorldManaged)\Unity.TextMeshPro.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AccessibilityModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.AccessibilityModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AIModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.AIModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AndroidJNIModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.AndroidJNIModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AnimationModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.AnimationModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ARModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ARModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AssetBundleModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.AssetBundleModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.AudioModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.AudioModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ClothModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ClothModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ClusterInputModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ClusterInputModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ClusterRendererModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ClusterRendererModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CoreModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.CoreModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.CrashReportingModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.CrashReportingModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.DirectorModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.DirectorModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.DSPGraphModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.DSPGraphModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.GameCenterModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.GameCenterModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.GridModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.GridModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.HotReloadModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.HotReloadModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ImageConversionModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ImageConversionModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.IMGUIModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.IMGUIModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.InputLegacyModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.InputLegacyModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.InputModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.InputModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.JSONSerializeModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.JSONSerializeModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.LocalizationModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.LocalizationModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ParticleSystemModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ParticleSystemModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PerformanceReportingModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.PerformanceReportingModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.Physics2DModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.Physics2DModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.PhysicsModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.PhysicsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ProfilerModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ProfilerModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.ScreenCaptureModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.ScreenCaptureModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.SharedInternalsModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.SharedInternalsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.SpriteMaskModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.SpriteMaskModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.SpriteShapeModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.SpriteShapeModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.StreamingModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.StreamingModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.SubstanceModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.SubstanceModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.TerrainModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.TerrainModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.TerrainPhysicsModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.TerrainPhysicsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.TextRenderingModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.TextRenderingModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.TilemapModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.TilemapModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.TLSModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.TLSModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UI">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UI.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UIElementsModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UIElementsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UIModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UIModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UmbraModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UmbraModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityAnalyticsModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityAnalyticsModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityConnectModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityConnectModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityTestProtocolModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityTestProtocolModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityWebRequestAssetBundleModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityWebRequestAssetBundleModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityWebRequestAudioModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityWebRequestAudioModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityWebRequestModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityWebRequestModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityWebRequestTextureModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityWebRequestTextureModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.UnityWebRequestWWWModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.UnityWebRequestWWWModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.VehiclesModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.VehiclesModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.VFXModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.VFXModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.VideoModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.VideoModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.VRModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.VRModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.WindModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.WindModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UnityEngine.XRModule">
|
||||
<HintPath>$(RimWorldManaged)\UnityEngine.XRModule.dll</HintPath>
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CustomGUIStyles.cs" />
|
||||
<Compile Include="FontLoader.cs" />
|
||||
<Compile Include="FontPatches.cs" />
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Settings.cs" />
|
||||
</ItemGroup>
|
||||
<Target Name="CopyToVersionDirs" AfterTargets="Build">
|
||||
<ItemGroup>
|
||||
<BuiltAssemblies Include="$(OutputPath)\*" />
|
||||
</ItemGroup>
|
||||
<MakeDir Directories="$(OutputPath)\..\1.4;$(OutputPath)\..\1.5" />
|
||||
<Copy SourceFiles="@(BuiltAssemblies)" DestinationFolder="$(OutputPath)\..\1.4" />
|
||||
<Copy SourceFiles="@(BuiltAssemblies)" DestinationFolder="$(OutputPath)\..\1.5" />
|
||||
</Target>
|
||||
</Project>
|
||||
257
Source/Settings.cs
Normal file
257
Source/Settings.cs
Normal file
@@ -0,0 +1,257 @@
|
||||
using UnityEngine;
|
||||
using Verse;
|
||||
using System;
|
||||
using HarmonyLib;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using UnityEngine.UI;
|
||||
using System.IO;
|
||||
|
||||
namespace raptureparty.RimWorldFontReplacer
|
||||
{
|
||||
|
||||
public class FontListDialog : Window
|
||||
{
|
||||
protected Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
protected string[] _fonts = new string[0];
|
||||
|
||||
protected float bottomAreaHeight;
|
||||
|
||||
protected string _filterText = "";
|
||||
|
||||
private string _prevFilterText = null;
|
||||
|
||||
public uint FontIndex = 0;
|
||||
|
||||
public FontListDialog()
|
||||
{
|
||||
doCloseButton = true;
|
||||
doCloseX = true;
|
||||
forcePause = true;
|
||||
absorbInputAroundWindow = true;
|
||||
closeOnAccept = false;
|
||||
}
|
||||
|
||||
public override void PreOpen()
|
||||
{
|
||||
base.PreOpen();
|
||||
_fonts = Font.GetOSInstalledFontNames();
|
||||
}
|
||||
|
||||
public override void PostClose()
|
||||
{
|
||||
base.PostClose();
|
||||
}
|
||||
|
||||
private string CurrentFontName
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (FontIndex)
|
||||
{
|
||||
case 0: return FontLoader.TargetTinyFontName;
|
||||
case 1: return FontLoader.TargetSmallFontName;
|
||||
case 2: return FontLoader.TargetMediumFontName;
|
||||
case 3: return FontLoader.TargetPlanetFontName;
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string FontTypeLabel
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (FontIndex)
|
||||
{
|
||||
case 0: return "RWFR.Tiny".Translate();
|
||||
case 1: return "RWFR.Small".Translate();
|
||||
case 2: return "RWFR.Medium".Translate();
|
||||
case 3: return "RWFR.Planet".Translate();
|
||||
default: return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void DoWindowContents(Rect inRect)
|
||||
{
|
||||
float y = inRect.y;
|
||||
|
||||
// Title
|
||||
Verse.Text.Font = GameFont.Medium;
|
||||
Widgets.Label(new Rect(inRect.x, y, inRect.width, 32f), "RWFR.ChooseFont_For".Translate(FontTypeLabel));
|
||||
Verse.Text.Font = GameFont.Small;
|
||||
y += 36f;
|
||||
|
||||
// Current selection
|
||||
string current = CurrentFontName;
|
||||
if (!string.IsNullOrEmpty(current))
|
||||
{
|
||||
GUI.color = new Color(0.7f, 0.7f, 0.7f);
|
||||
Widgets.Label(new Rect(inRect.x, y, inRect.width, 24f), "RWFR.Current".Translate() + ": " + current);
|
||||
GUI.color = Color.white;
|
||||
y += 26f;
|
||||
}
|
||||
|
||||
// Filter box
|
||||
Widgets.Label(new Rect(inRect.x, y + 2f, 60f, 28f), "RWFR.Filter".Translate());
|
||||
string newFilter = Widgets.TextField(new Rect(inRect.x + 64f, y, inRect.width - 64f, 28f), _filterText);
|
||||
if (newFilter != _prevFilterText)
|
||||
{
|
||||
scrollPosition = Vector2.zero;
|
||||
_prevFilterText = newFilter;
|
||||
}
|
||||
_filterText = newFilter;
|
||||
y += 34f;
|
||||
|
||||
// Build filtered list
|
||||
string[] filtered = string.IsNullOrEmpty(_filterText)
|
||||
? _fonts
|
||||
: System.Array.FindAll(_fonts, f => f.IndexOf(_filterText, StringComparison.OrdinalIgnoreCase) >= 0);
|
||||
|
||||
float listHeight = filtered.Length * 36f;
|
||||
Rect outRect = new Rect(inRect.x, y, inRect.width, inRect.height - (y - inRect.y) - bottomAreaHeight - 50f);
|
||||
Rect viewRect = new Rect(0f, 0f, outRect.width - 16f, listHeight);
|
||||
|
||||
Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect, true);
|
||||
|
||||
for (int i = 0; i < filtered.Length; i++)
|
||||
{
|
||||
bool isSelected = filtered[i] == current;
|
||||
if (isSelected)
|
||||
GUI.color = new Color(0.8f, 1f, 0.8f);
|
||||
|
||||
if (Widgets.ButtonText(new Rect(0f, i * 36f, viewRect.width, 26f), filtered[i]))
|
||||
{
|
||||
switch (FontIndex)
|
||||
{
|
||||
case 0: FontLoader.TargetTinyFontName = filtered[i]; break;
|
||||
case 1: FontLoader.TargetSmallFontName = filtered[i]; break;
|
||||
case 2: FontLoader.TargetMediumFontName = filtered[i]; break;
|
||||
case 3: FontLoader.TargetPlanetFontName = filtered[i]; break;
|
||||
}
|
||||
Close();
|
||||
}
|
||||
|
||||
if (isSelected)
|
||||
GUI.color = Color.white;
|
||||
}
|
||||
|
||||
Widgets.EndScrollView();
|
||||
}
|
||||
}
|
||||
|
||||
class Settings : ModSettings
|
||||
{
|
||||
public static Vector2 scrollPosition = Vector2.zero;
|
||||
|
||||
private static string s_fontTinySizeBuffer = FontLoader.FontTinySize.ToString();
|
||||
private static string s_fontSmallSizeBuffer = FontLoader.FontSmallSize.ToString();
|
||||
private static string s_fontMediumSizeBuffer = FontLoader.FontMediumSize.ToString();
|
||||
|
||||
public static void Build(Rect inRect)
|
||||
{
|
||||
|
||||
inRect.yMin += 15f;
|
||||
inRect.yMax -= 15f;
|
||||
|
||||
var defaultColumnWidth = inRect.width - 50;
|
||||
Listing_Standard list = new Listing_Standard() { ColumnWidth = defaultColumnWidth };
|
||||
|
||||
var outRect = new Rect(inRect.x, inRect.y, inRect.width, inRect.height);
|
||||
var scrollRect = new Rect(0f, 0f, inRect.width - 16f, inRect.height + 200);
|
||||
Widgets.BeginScrollView(outRect, ref scrollPosition, scrollRect, true);
|
||||
|
||||
list.Begin(scrollRect);
|
||||
|
||||
list.Label("RWFR.Fonts".Translate());
|
||||
list.GapLine();
|
||||
|
||||
list.Label("RWFR.Tiny".Translate());
|
||||
list.Indent();
|
||||
FontLoader.TargetTinyFontName = list.TextEntryLabeled("RWFR.Font_family".Translate(), FontLoader.TargetTinyFontName, 1);
|
||||
list.TextFieldNumericLabeled<int>("RWFR.Font_size".Translate(), ref FontLoader.FontTinySize, ref s_fontTinySizeBuffer, 1);
|
||||
if (list.ButtonTextLabeled("", "RWFR.ChooseFont".Translate()))
|
||||
{
|
||||
var selector = new FontListDialog { FontIndex = 0 };
|
||||
Find.WindowStack.Add(selector);
|
||||
}
|
||||
list.Label(FontLoader.FontTinyFound ? "" : (string)"RWFR.Not_found".Translate());
|
||||
list.Outdent();
|
||||
|
||||
list.Label("RWFR.Small".Translate());
|
||||
list.Indent();
|
||||
FontLoader.TargetSmallFontName = list.TextEntryLabeled("RWFR.Font_family".Translate(), FontLoader.TargetSmallFontName, 1);
|
||||
list.TextFieldNumericLabeled<int>("RWFR.Font_size".Translate(), ref FontLoader.FontSmallSize, ref s_fontSmallSizeBuffer, 1);
|
||||
if (list.ButtonTextLabeled("", "RWFR.ChooseFont".Translate()))
|
||||
{
|
||||
var selector = new FontListDialog { FontIndex = 1 };
|
||||
Find.WindowStack.Add(selector);
|
||||
}
|
||||
list.Label(FontLoader.FontSmallFound ? "" : (string)"RWFR.Not_found".Translate());
|
||||
list.Outdent();
|
||||
|
||||
list.Label("RWFR.Medium".Translate());
|
||||
list.Indent();
|
||||
FontLoader.TargetMediumFontName = list.TextEntryLabeled("RWFR.Font_family".Translate(), FontLoader.TargetMediumFontName, 1);
|
||||
list.TextFieldNumericLabeled<int>("RWFR.Font_size".Translate(), ref FontLoader.FontMediumSize, ref s_fontMediumSizeBuffer, 1);
|
||||
if (list.ButtonTextLabeled("", "RWFR.ChooseFont".Translate()))
|
||||
{
|
||||
var selector = new FontListDialog { FontIndex = 2 };
|
||||
Find.WindowStack.Add(selector);
|
||||
}
|
||||
list.Label(FontLoader.FontMediumFound ? "" : (string)"RWFR.Not_found".Translate());
|
||||
list.Outdent();
|
||||
|
||||
list.Gap(12f);
|
||||
list.Label("RWFR.Previews".Translate());
|
||||
list.GapLine();
|
||||
|
||||
string previewText = "RWFR.Preview_text".Translate();
|
||||
|
||||
list.Label("RWFR.Tiny".Translate(), 28f);
|
||||
list.Indent();
|
||||
if (CustomGUIStyles.fontStyles != null)
|
||||
{
|
||||
float h = Mathf.Max(FontLoader.FontTinySize, 12) + 10f;
|
||||
GUI.Label(list.GetRect(h), previewText, CustomGUIStyles.fontStyles[0]);
|
||||
}
|
||||
list.Outdent();
|
||||
|
||||
list.Label("RWFR.Small".Translate(), 28f);
|
||||
list.Indent();
|
||||
if (CustomGUIStyles.fontStyles != null)
|
||||
{
|
||||
float h = Mathf.Max(FontLoader.FontSmallSize, 12) + 10f;
|
||||
GUI.Label(list.GetRect(h), previewText, CustomGUIStyles.fontStyles[1]);
|
||||
}
|
||||
list.Outdent();
|
||||
|
||||
list.Label("RWFR.Medium".Translate(), 28f);
|
||||
list.Indent();
|
||||
if (CustomGUIStyles.fontStyles != null)
|
||||
{
|
||||
float h = Mathf.Max(FontLoader.FontMediumSize, 12) + 10f;
|
||||
GUI.Label(list.GetRect(h), previewText, CustomGUIStyles.fontStyles[2]);
|
||||
}
|
||||
list.Outdent();
|
||||
|
||||
list.End();
|
||||
Widgets.EndScrollView();
|
||||
CustomGUIStyles.UpdateFonts();
|
||||
}
|
||||
|
||||
public override void ExposeData()
|
||||
{
|
||||
base.ExposeData();
|
||||
Scribe_Values.Look(ref FontLoader.FontTinySize, "fontSizeTiny", 11);
|
||||
Scribe_Values.Look(ref FontLoader.FontSmallSize, "fontSizeSmall", 14);
|
||||
Scribe_Values.Look(ref FontLoader.FontMediumSize, "fontSizeMedium", 18);
|
||||
Scribe_Values.Look(ref FontLoader.TargetTinyFontName, "fontNameTiny", "Helvetica");
|
||||
Scribe_Values.Look(ref FontLoader.TargetSmallFontName, "fontNameSmall", "Helvetica");
|
||||
Scribe_Values.Look(ref FontLoader.TargetMediumFontName, "fontNameMedium", "Helvetica");
|
||||
Scribe_Values.Look(ref FontLoader.TargetPlanetFontName, "fontNamePlanet", "Helvetica");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user