diff --git a/Assets.Scripts.UI/MainUIController.cs b/Assets.Scripts.UI/MainUIController.cs index 55a6826b..8d498cf5 100644 --- a/Assets.Scripts.UI/MainUIController.cs +++ b/Assets.Scripts.UI/MainUIController.cs @@ -56,6 +56,8 @@ public class MainUIController : MonoBehaviour public MODMenu modMenu; private MODToaster toaster; + private float? FontWeight; + public void UpdateGuiPosition(int x, int y) { unscaledPosition = new Vector3((float)x, (float)y, 0f); @@ -825,6 +827,8 @@ private static void GUIUnclickableTextArea(Rect rect, string text) /// /// Sets the font outline width, and updates the current textwindow outline width /// Hopefully if you toggle language (which toggles the font on chapters 1-9), the outline width is retained. + /// You will likely need to increase the font weight if you increase the outline width, as the outline 'eats' + /// into the characters, rather than expanding outwards. /// /// The outline width as a float typically between (0, 1) public void SetFontOutlineWidth(float outlineWidth) @@ -832,5 +836,34 @@ public void SetFontOutlineWidth(float outlineWidth) gameSystem.OutlineWidth = outlineWidth; TextWindow.outlineWidth = GameSystem.Instance.OutlineWidth; } + + public float GetNormalFontWeight() + { + if (!FontWeight.HasValue) + { + FontWeight = TextWindow.fontSharedMaterial.GetFloat(TMPro.ShaderUtilities.ID_WeightNormal); + } + + return FontWeight.Value; + } + + /// + /// Some chapters TextWindow don't let you set the font weight. For those chapters, the "_WeightNormal" + /// parameter on the material is set directly. + /// + /// The font weight, between -1 and 1 (more or less). + /// Negative numbers reduce the weight, positive numbers increase it. + public void SetNormalFontWeight(float weight) + { + // Modifying fontSharedMaterial works, I guess doing so modifies all instances, + // while fontMaterial only modifies a single instance? + // See the docs: + // - http://digitalnativestudios.com/textmeshpro/docs/ScriptReference/TextMeshPro.html + // - http://digitalnativestudios.com/textmeshpro/docs/ScriptReference/TextMeshPro-fontSharedMaterial.html + TextWindow.fontSharedMaterial.SetFloat(TMPro.ShaderUtilities.ID_WeightNormal, weight); + + FontWeight = weight; + TextWindow.ForceMeshUpdate(); + } } } diff --git a/MOD.Scripts.UI/MODMenuCommon.cs b/MOD.Scripts.UI/MODMenuCommon.cs index f048b412..dce5409a 100644 --- a/MOD.Scripts.UI/MODMenuCommon.cs +++ b/MOD.Scripts.UI/MODMenuCommon.cs @@ -72,9 +72,9 @@ public static string TextField(string text, int maxLength, params GUILayoutOptio return GUILayout.TextField(text, maxLength, MODStyleManager.OnGUIInstance.Group.textField, options); } - public static string TextField(string text, int maxLength, out bool hasChanged, params GUILayoutOption[] options) + public static string TextField(string text, out bool hasChanged, params GUILayoutOption[] options) { - string newValue = GUILayout.TextField(text, maxLength, MODStyleManager.OnGUIInstance.Group.textField, options); + string newValue = GUILayout.TextField(text, MODStyleManager.OnGUIInstance.Group.textField, options); hasChanged = text != newValue; return newValue; diff --git a/MOD.Scripts.UI/MODMenuNormal.cs b/MOD.Scripts.UI/MODMenuNormal.cs index 73f3c6b8..b4bded53 100644 --- a/MOD.Scripts.UI/MODMenuNormal.cs +++ b/MOD.Scripts.UI/MODMenuNormal.cs @@ -47,6 +47,7 @@ class MODMenuNormal : MODMenuModuleInterface private static int gameClearClickCount = 3; string TextField_FontOutlineWidth; + string TextField_NormalFontWeight; public MODMenuNormal(MODMenu modMenu, MODMenuAudioOptions audioOptionsMenu) { @@ -168,6 +169,7 @@ public void OnBeforeMenuVisible() { TextField_ComputedLipSyncThreshold1 = threshold1.ToString(); TextField_ComputedLipSyncThreshold2 = threshold2.ToString(); TextField_FontOutlineWidth = GameSystem.Instance.OutlineWidth.ToString(); + TextField_NormalFontWeight = GameSystem.Instance.MainUIController.GetNormalFontWeight().ToString(); gameClearClickCount = 3; } @@ -475,18 +477,22 @@ private void OnGUIFontDebug() GUILayout.BeginHorizontal(); { Label(new GUIContent("Outline", "Font Outline Width")); - TextField_FontOutlineWidth = TextField(TextField_FontOutlineWidth, 5, out bool hasChanged); - if (hasChanged) + TextField_FontOutlineWidth = TextField(TextField_FontOutlineWidth, out bool outlineHasChanged); + + Label(new GUIContent("Normal Weight", "Normal Font Weight")); + TextField_NormalFontWeight = TextField(TextField_NormalFontWeight, out bool fontWeightHasChanged); + + if (outlineHasChanged || fontWeightHasChanged) { try { GameSystem.Instance.MainUIController.SetFontOutlineWidth(float.Parse(TextField_FontOutlineWidth)); + GameSystem.Instance.MainUIController.SetNormalFontWeight(float.Parse(TextField_NormalFontWeight)); } catch (Exception e) { MODToaster.Show("Failed to set font settings:" + e.ToString()); } - MODToaster.Show("Font Updated"); } } GUILayout.EndHorizontal();