Skip to content

Commit

Permalink
Fix positioning of the version shower on different aspect ratios (#73)
Browse files Browse the repository at this point in the history
Co-authored-by: js6pak <me@6pak.dev>
  • Loading branch information
simonkellly and js6pak authored Jun 17, 2023
1 parent c84d36a commit f63569d
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions Reactor/Patches/ReactorVersionShower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public static class ReactorVersionShower
/// </summary>
public static event Action<TextMeshPro>? TextUpdated;

private static readonly Il2CppSystem.Action<float> _setMainMenuPositionFromAspect = (Action<float>) (aspect =>
{
if (Text == null) return;
var pos = new Vector3(-1.2287f * aspect + 10.9f, -0.57f, 4.5f);
Text.transform.position = pos;
});

internal static void Initialize()
{
SceneManager.add_sceneLoaded((Action<Scene, LoadSceneMode>) ((scene, _) =>
Expand All @@ -38,40 +45,41 @@ internal static void Initialize()

var gameObject = new GameObject("ReactorVersion");

var aspectPosition = gameObject.AddComponent<AspectPosition>();
Text = gameObject.AddComponent<TextMeshPro>();
Text.font = originalText.font;
Text.fontMaterial = originalText.fontMaterial;
Text.UpdateFontAsset();
Text.overflowMode = TextOverflowModes.Overflow;
Text.fontSize = 2;
Text.outlineWidth = 0.1f;
Text.enableWordWrapping = false;
Text.alignment = TextAlignmentOptions.TopLeft;

if (scene.name == "MainMenu")
{
aspectPosition.Alignment = AspectPosition.EdgeAlignments.Left;
aspectPosition.DistanceFromEdge = new Vector3(5f, 1.55f, 2f);
ResolutionManager.add_ResolutionChanged(_setMainMenuPositionFromAspect);
_setMainMenuPositionFromAspect.Invoke(Screen.width / (float) Screen.height);
}
else
{
var distanceFromEdge = new Vector3(1, 0.4f, -1);
ResolutionManager.remove_ResolutionChanged(_setMainMenuPositionFromAspect);
var aspectPosition = gameObject.AddComponent<AspectPosition>();
var distanceFromEdge = new Vector3(10.13f, 2.55f, -1);
if (originalAspectPosition.Alignment == AspectPosition.EdgeAlignments.LeftTop)
{
distanceFromEdge += new Vector3(0.05f, 0.15f, 0);
distanceFromEdge.y += 0.2f;
}
else if (AccountManager.Instance.isActiveAndEnabled)
{
distanceFromEdge += new Vector3(0.2f, 0.6f, 0);
distanceFromEdge.x += 0.2f;
distanceFromEdge.y += 0.575f;
}

aspectPosition.Alignment = AspectPosition.EdgeAlignments.LeftTop;
aspectPosition.DistanceFromEdge = distanceFromEdge;
aspectPosition.AdjustPosition();
}

aspectPosition.AdjustPosition();

Text = gameObject.AddComponent<TextMeshPro>();
Text.font = originalText.font;
Text.fontMaterial = originalText.fontMaterial;
Text.UpdateFontAsset();
Text.alignment = TextAlignmentOptions.TopLeft;
Text.autoSizeTextContainer = true;
Text.fontSize = 2;
Text.outlineWidth = 0.1f;

UpdateText();
}));
}
Expand Down

0 comments on commit f63569d

Please sign in to comment.