mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-10-19 15:51:48 +00:00
add tab open method and fixes
This commit is contained in:
1 parent
1f6962efe9
commit
ac113b6a7f
4 files changed
+42
-12
No files matched your search
@@ -36,9 +36,9 @@ public class ExampleLocalSettings(ConfigFile config) : LocalSettingsTab(config)
|
||||
[LocalEnumSetting]
|
||||
public ConfigEntry<ExampleEnumSetting> ExampleEnum { get; private set; } = config.Bind("General", "Example Enum", ExampleEnumSetting.Fries);
|
||||
|
||||
private static void OnExampleButtonClick(LocalSettingsTab instance)
|
||||
private static void OnExampleButtonClick()
|
||||
{
|
||||
Logger<ExamplePlugin>.Warning("Button clicked");
|
||||
LocalSettingsTabSingleton<MiraApiSettings>.Instance.Open();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace MiraAPI.LocalSettings;
|
||||
/// <summary>
|
||||
/// Represents a local settings button.
|
||||
/// </summary>
|
||||
public class LocalSettingsButton(string text, Action<LocalSettingsTab> onClick)
|
||||
public class LocalSettingsButton(string text, Action onClick)
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the button text.
|
||||
@@ -22,12 +22,12 @@ public class LocalSettingsButton(string text, Action<LocalSettingsTab> onClick)
|
||||
/// <summary>
|
||||
/// Gets or sets the button on-click action.
|
||||
/// </summary>
|
||||
public Action<LocalSettingsTab> OnClick { get; set; } = onClick;
|
||||
public Action OnClick { get; set; } = onClick;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the tab instance this button belongs to.
|
||||
/// </summary>
|
||||
public LocalSettingsTab Tab { get; internal set; }
|
||||
public LocalSettingsTab? Tab { get; internal set; }
|
||||
|
||||
internal GameObject CreateButton(ToggleButtonBehaviour toggle, Transform parent, ref float offset, ref int order, bool last)
|
||||
{
|
||||
@@ -59,11 +59,9 @@ public class LocalSettingsButton(string text, Action<LocalSettingsTab> onClick)
|
||||
rollover.OverColor = Tab!.TabAppearance.ButtonHoverColor;
|
||||
rollover.Target = background;
|
||||
background.color = Tab!.TabAppearance.ButtonColor;
|
||||
button.OnClick.AddListener((UnityAction)OnClick);
|
||||
|
||||
var tab = Tab;
|
||||
var click = OnClick;
|
||||
button.OnClick.AddListener((UnityAction)(() => click(tab)));
|
||||
|
||||
background.transform.localScale = new Vector3(1, 1.25f, 1);
|
||||
Helpers.DivideSize(button.gameObject, 1.1f);
|
||||
|
||||
order++;
|
||||
|
||||
@@ -57,6 +57,11 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
/// </summary>
|
||||
public List<LocalSettingsButton> Buttons { get; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets the index of this tab.
|
||||
/// </summary>
|
||||
protected int TabIndex => LocalSettingsManager.Tabs.IndexOf(this) + 10;
|
||||
|
||||
private Scroller? Scroller { get; set; }
|
||||
|
||||
/// <summary>
|
||||
@@ -67,6 +72,20 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to open the tab.
|
||||
/// Override for custom behavior.
|
||||
/// </summary>
|
||||
public virtual void Open()
|
||||
{
|
||||
OptionsMenuPatches.Instance?.OpenTabGroup(TabIndex);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the tab <see cref="GameObject"/> and it's content.
|
||||
/// </summary>
|
||||
/// <param name="instance">The <see cref="OptionsMenuBehaviour"/> instace.</param>
|
||||
/// <returns>The created tab <see cref="GameObject"/>.</returns>
|
||||
public virtual GameObject CreateTab(OptionsMenuBehaviour instance)
|
||||
{
|
||||
var tab = Object.Instantiate(instance.transform.FindChild("GeneralTab").gameObject, instance.transform);
|
||||
@@ -141,7 +160,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
contentOrder = 1;
|
||||
}
|
||||
|
||||
contentIndex = 0;
|
||||
contentIndex = 1;
|
||||
contentOrder = 1;
|
||||
foreach (var button in Buttons)
|
||||
{
|
||||
@@ -174,6 +193,13 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
return tab;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the tab button.
|
||||
/// </summary>
|
||||
/// <param name="instance">The <see cref="OptionsMenuBehaviour"/> instance.</param>
|
||||
/// <param name="tabIdx">The tab index.</param>
|
||||
/// <param name="offset">The current button offset.</param>
|
||||
/// <returns>The created button <see cref="GameObject"/>.</returns>
|
||||
public virtual GameObject CreateTabButton(OptionsMenuBehaviour instance, ref int tabIdx, ref float offset)
|
||||
{
|
||||
var tabButtonObject = Object.Instantiate(instance.Tabs[0], instance.transform);
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace MiraAPI.Patches.LocalSettings;
|
||||
[HarmonyPatch(typeof(OptionsMenuBehaviour))]
|
||||
public static class OptionsMenuPatches
|
||||
{
|
||||
internal static OptionsMenuBehaviour? Instance { get; private set; }
|
||||
internal static BoxCollider2D MaskCollider;
|
||||
private static SpriteRenderer? background;
|
||||
|
||||
@@ -27,6 +28,7 @@ public static class OptionsMenuPatches
|
||||
[HarmonyPatch(nameof(OptionsMenuBehaviour.Start))]
|
||||
public static void StartPostfix(OptionsMenuBehaviour __instance)
|
||||
{
|
||||
Instance = __instance;
|
||||
// Fix for tabs not being clickable in the main menu
|
||||
if (!AmongUsClient.Instance.IsInGame)
|
||||
{
|
||||
@@ -176,7 +178,7 @@ public static class OptionsMenuPatches
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Makes the custom tabs close when opening the options menu and reset pages.
|
||||
/// Makes the custom tabs close when opening the options menu and resets pages.
|
||||
/// </summary>
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(nameof(OptionsMenuBehaviour.Open))]
|
||||
@@ -191,7 +193,11 @@ public static class OptionsMenuPatches
|
||||
{
|
||||
foreach (var pages in tabButtons)
|
||||
{
|
||||
pages.Value.Do(x => x.SetActive(pages.Key == currentPage));
|
||||
pages.Value?
|
||||
.Where(x => x != null)
|
||||
.Do(
|
||||
x => x?.SetActive(
|
||||
pages.Key == currentPage));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user