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(); } } }