You've already forked rimworld-font-replacer
122 lines
5.1 KiB
C#
122 lines
5.1 KiB
C#
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());
|
|
}
|
|
}
|
|
}
|
|
}
|