diff --git a/MiraAPI/MiraApiSettings.cs b/MiraAPI/MiraApiSettings.cs
index 60e5e6a..e7f5f72 100644
--- a/MiraAPI/MiraApiSettings.cs
+++ b/MiraAPI/MiraApiSettings.cs
@@ -1,6 +1,8 @@
using BepInEx.Configuration;
using MiraAPI.LocalSettings;
using MiraAPI.LocalSettings.Attributes;
+using MiraAPI.Patches;
+using MiraAPI.Utilities;
using MiraAPI.Utilities.Assets;
namespace MiraAPI;
@@ -21,6 +23,33 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
HideIconOnHover = false,
};
+ ///
+ /// Gets or sets the value stored for scaling buttons properly.
+ ///
+ public static float OldButtonScaleFactor { get; set; }
+
+ ///
+ public override void Open()
+ {
+ base.Open();
+ OldButtonScaleFactor = ButtonUIFactorSlider.Value;
+ }
+
+ ///
+ public override void OnOptionChanged(ConfigEntryBase configEntry)
+ {
+ base.OnOptionChanged(configEntry);
+ if (configEntry == ButtonUIFactorSlider)
+ {
+ if (HudManager.InstanceExists)
+ {
+ HudManagerPatches.ResizeUI(1f / OldButtonScaleFactor);
+ HudManagerPatches.ResizeUI(ButtonUIFactorSlider.Value);
+ }
+ OldButtonScaleFactor = ButtonUIFactorSlider.Value;
+ }
+ }
+
///
/// Gets whether the modifiers hud should be on the left side of the screen (under roles/task tab). Recommended for streamers.
///
@@ -31,8 +60,14 @@ public class MiraApiSettings(ConfigFile config) : LocalSettingsTab(config)
/// Gets whether to show keybinds on buttons.
///
[LocalToggleSetting]
- public ConfigEntry ShowKeybinds { get; private set; } = config.Bind("Keybinds", "Show Keybinds on Buttons", true);
- // This would be placed in the keybinds menu, but it crashes for Epic Games users. - Atony
+ public ConfigEntry ShowKeybinds { get; private set; } = config.Bind("Buttons", "Show Keybinds on Buttons", true);
+
+ ///
+ /// Gets the scale of the buttons.
+ ///
+ [LocalSliderSetting(min: 0.5f, max: 1.5f, suffixType: MiraNumberSuffixes.Multiplier, formatString: "0.00", displayValue: true)]
+ public ConfigEntry ButtonUIFactorSlider { get; private set; } =
+ config.Bind("Buttons", "Button Scale Factor", 0.75f);
///
/// Gets whether to apply cosmetic changes to the TaskAdder.
diff --git a/MiraAPI/Patches/HudManagerPatches.cs b/MiraAPI/Patches/HudManagerPatches.cs
index e95b72c..c5340b2 100644
--- a/MiraAPI/Patches/HudManagerPatches.cs
+++ b/MiraAPI/Patches/HudManagerPatches.cs
@@ -1,4 +1,5 @@
-using System.Collections.Generic;
+using System.Collections;
+using System.Collections.Generic;
using System.Linq;
using HarmonyLib;
using MiraAPI.Hud;
@@ -29,6 +30,84 @@ public static class HudManagerPatches
internal static List ModdedKeybindIcons = new();
+ public static IEnumerator CoResizeUI()
+ {
+ while (!HudManager.Instance)
+ {
+ yield return null;
+ }
+
+ yield return new WaitForSeconds(0.01f);
+ ResizeUI(LocalSettingsTabSingleton.Instance.ButtonUIFactorSlider.Value);
+ }
+
+ public static void ResizeUI(float scaleFactor)
+ {
+ var baseButtons = HudManager.Instance.transform.FindChild("Buttons");
+ if (baseButtons != null)
+ {
+ foreach (var aspect in baseButtons.GetComponentsInChildren(true))
+ {
+ if (aspect.gameObject == null)
+ {
+ continue;
+ }
+
+ if (aspect.gameObject.transform.parent.name == "TopRight")
+ {
+ continue;
+ }
+
+ if (aspect.gameObject.transform.parent.transform.parent.name == "TopRight")
+ {
+ continue;
+ }
+
+ aspect.gameObject.SetActive(!aspect.isActiveAndEnabled);
+ aspect.DistanceFromEdge *= new Vector2(scaleFactor, scaleFactor);
+ aspect.gameObject.SetActive(!aspect.isActiveAndEnabled);
+ }
+ }
+
+ foreach (var button in HudManager.Instance.GetComponentsInChildren(true))
+ {
+ if (button.gameObject == null)
+ {
+ continue;
+ }
+
+ button.gameObject.SetActive(!button.isActiveAndEnabled);
+ button.gameObject.transform.localScale *= scaleFactor;
+ button.gameObject.SetActive(!button.isActiveAndEnabled);
+ }
+
+ if (baseButtons != null)
+ {
+ foreach (var arrange in baseButtons.GetComponentsInChildren(true))
+ {
+ if (!arrange.gameObject || !arrange.transform)
+ {
+ continue;
+ }
+
+ arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
+ arrange.CellSize = new Vector2(scaleFactor, scaleFactor);
+ arrange.gameObject.SetActive(!arrange.isActiveAndEnabled);
+ if (arrange.isActiveAndEnabled && arrange.gameObject.transform.childCount != 0)
+ {
+ try
+ {
+ arrange.ArrangeChilds();
+ }
+ catch
+ {
+ // Error($"Error arranging child objects in GridArrange: {e}");
+ }
+ }
+ }
+ }
+ }
+
/*
///
/// Trigger hudstart on current custom gamemode
@@ -149,6 +228,7 @@ public static class HudManagerPatches
var comp = buttonObj.GetComponent();
KeybindManager.VanillaKeybinds[comp.GetType()].Button = comp;
}
+ Coroutines.Start(CoResizeUI());
}
///