Skip to content

Commit

Permalink
Allow changing font dilation (_FaceDilate)
Browse files Browse the repository at this point in the history
  • Loading branch information
drojf committed Feb 25, 2024
1 parent 9d37836 commit 72cbdc3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 14 deletions.
7 changes: 7 additions & 0 deletions Assets.Scripts.Core.Buriko/BurikoScriptFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,13 @@ public BurikoVariable OperationMODGenericCall()
}
break;

case "FaceDilate":
if (int.TryParse(callParameters, out int faceDilate))
{
GameSystem.Instance.MainUIController.SetBoldFontWeight(faceDilate / 100.0f);
}
break;

default:
Logger.Log($"WARNING: Unknown ModGenericCall ID '{callID}'");
break;
Expand Down
18 changes: 18 additions & 0 deletions Assets.Scripts.UI/MainUIController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public class MainUIController : MonoBehaviour

private float? FontWeight;
private float? BoldWeight;
private float? FaceDilate;

public void UpdateGuiPosition(int x, int y)
{
Expand Down Expand Up @@ -882,5 +883,22 @@ public void SetBoldFontWeight(float weight)

BoldWeight = weight;
}

public void SetFaceDilation(float faceDilate)
{
TextWindow.fontSharedMaterial.SetFloat(TMPro.ShaderUtilities.ID_FaceDilate, faceDilate);

FaceDilate = faceDilate;
}

public float GetFaceDilation()
{
if (!FaceDilate.HasValue)
{
FaceDilate = TextWindow.fontSharedMaterial.GetFloat(TMPro.ShaderUtilities.ID_FaceDilate);
}

return FaceDilate.Value;
}
}
}
38 changes: 24 additions & 14 deletions MOD.Scripts.UI/MODMenuFontConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class MODMenuFontConfig
string TextField_BoldFontWeight;
string TextField_FontSize;
string TextField_ConfigMenuFontSize;
string TextField_FaceDilation;

string TextArea_GeneratedScriptFragment = "";

Expand All @@ -22,6 +23,7 @@ public void OnBeforeMenuVisible() {
TextField_BoldFontWeight = asPercent(GameSystem.Instance.MainUIController.GetBoldFontWeight()).ToString();
TextField_FontSize = GameSystem.Instance.MainUIController.TextWindow.fontSize.ToString();
TextField_ConfigMenuFontSize = GameSystem.Instance.ConfigMenuFontSize.ToString();
TextField_FaceDilation = asPercent(GameSystem.Instance.MainUIController.GetFaceDilation()).ToString();

UpdateGeneratedScriptFragment();
}
Expand All @@ -30,33 +32,38 @@ public void OnGUIFontDebug()
{
Label("Font Debugging");

// --------- Font Weight Adjustment ---------
// --------- Font Outline and Size Adjustment ---------
GUILayout.BeginHorizontal();

Label(new GUIContent("Normal Weight (% change)", "Main Text Window Normal Font Weight"));
TextField_NormalFontWeight = TextField(TextField_NormalFontWeight, true, out bool fontWeightHasChanged);
Label(new GUIContent("Face Dilate (%)", "Face Dilation\n\nExpands or shrinks the text thickness.\n\nTry adjusting this rather than font weight."));
TextField_FaceDilation = TextField(TextField_FaceDilation, true, out bool faceDilationHasChanged);

Label(new GUIContent("Bold Weight (% change)", "Main Text Window Bold Font Weight"));
TextField_BoldFontWeight = TextField(TextField_BoldFontWeight, true, out bool fontBoldWeightHasChanged);
Label(new GUIContent("Outline (%)", "Main Text Window Font Outline Width"));
TextField_FontOutlineWidth = TextField(TextField_FontOutlineWidth, true, out bool outlineHasChanged);

GUILayout.EndHorizontal();

// --------- Font Outline and Size Adjustment ---------
// --------- Font Size Adjustment ---------
GUILayout.BeginHorizontal();

Label(new GUIContent("Outline (%)", "Main Text Window Font Outline Width"));
TextField_FontOutlineWidth = TextField(TextField_FontOutlineWidth, true, out bool outlineHasChanged);

Label(new GUIContent("Font Size", "Main Text Window Font Size"));
TextField_FontSize = TextField(TextField_FontSize, true, out bool fontSizeHasChanged);

Label(new GUIContent("Config Font Size", "Config Menu Font Size"));
TextField_ConfigMenuFontSize = TextField(TextField_ConfigMenuFontSize, true, out bool configFontSizeHasChanged);

GUILayout.EndHorizontal();

// --------- Config Menu Font Size Adjustment ---------
// --------- Font Weight Adjustment ---------
Label("!Note: Adjust face dilation instead of these values!");

GUILayout.BeginHorizontal();

Label(new GUIContent("Config Font Size", "Config Menu Font Size"));
TextField_ConfigMenuFontSize = TextField(TextField_ConfigMenuFontSize, true, out bool configFontSizeHasChanged);
Label(new GUIContent("!Normal Weight (% change)!", "Main Text Window Normal Font Weight"));
TextField_NormalFontWeight = TextField(TextField_NormalFontWeight, true, out bool fontWeightHasChanged);

Label(new GUIContent("!Bold Weight (% change)!", "Main Text Window Bold Font Weight"));
TextField_BoldFontWeight = TextField(TextField_BoldFontWeight, true, out bool fontBoldWeightHasChanged);

GUILayout.EndHorizontal();

Expand All @@ -67,7 +74,8 @@ public void OnGUIFontDebug()
fontWeightHasChanged ||
fontBoldWeightHasChanged ||
fontSizeHasChanged ||
configFontSizeHasChanged)
configFontSizeHasChanged ||
faceDilationHasChanged)
{
try
{
Expand All @@ -76,6 +84,7 @@ public void OnGUIFontDebug()
GameSystem.Instance.MainUIController.SetNormalFontWeight(fromPercent(TextField_NormalFontWeight));
GameSystem.Instance.MainUIController.SetBoldFontWeight(fromPercent(TextField_BoldFontWeight));
GameSystem.Instance.MainUIController.SetFontSize(int.Parse(TextField_FontSize)); // SetFontSize already takes an percentage as int
GameSystem.Instance.MainUIController.SetFaceDilation(fromPercent(TextField_FaceDilation));

// Update config menu font
GameSystem.Instance.ConfigMenuFontSize = int.Parse(TextField_ConfigMenuFontSize);
Expand All @@ -98,7 +107,8 @@ private void UpdateGeneratedScriptFragment()
$"ModSetConfigFontSize({TextField_ConfigMenuFontSize});\n" +
$"ModSetMainFontOutlineWidth({TextField_FontOutlineWidth});\n" +
$"ModGenericCall(\"NormalFontWeight\", \"{TextField_NormalFontWeight}\");\n" +
$"ModGenericCall(\"BoldFontWeight\", \"{TextField_BoldFontWeight}\");\n";
$"ModGenericCall(\"BoldFontWeight\", \"{TextField_BoldFontWeight}\");\n" +
$"ModGenericCall(\"FaceDilate\", \"{TextField_FaceDilation}\");\n";
}

public int asPercent(float fontOption) => Mathf.RoundToInt(fontOption * 100);
Expand Down

0 comments on commit 72cbdc3

Please sign in to comment.