From 34a4fcf69ff39e58b30c4fa4413985d507d1088f Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Sat, 12 Sep 2026 01:23:01 -0400 Subject: [PATCH] change custom menu behaviour to wrap a script instead --- MiraAPI/Hud/CustomMultiSelectMenu.cs | 38 +++--- MiraAPI/Hud/CustomPaginableMenu.cs | 168 ++++++++++++++------------- MiraAPI/Hud/CustomPhoneMenu.cs | 164 +++++++++++++++++--------- MiraAPI/Hud/CustomPlayerMenu.cs | 19 ++- 4 files changed, 220 insertions(+), 169 deletions(-) diff --git a/MiraAPI/Hud/CustomMultiSelectMenu.cs b/MiraAPI/Hud/CustomMultiSelectMenu.cs index b58a44b..0e87ade 100644 --- a/MiraAPI/Hud/CustomMultiSelectMenu.cs +++ b/MiraAPI/Hud/CustomMultiSelectMenu.cs @@ -1,30 +1,22 @@ -using Il2CppInterop.Runtime.Attributes; -using MiraAPI.Patches.Stubs; +using MiraAPI.Patches.Stubs; using MiraAPI.Utilities.Assets; -using Reactor.Utilities.Attributes; using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; using UnityEngine; using UnityEngine.Events; -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. -#pragma warning disable S2365 // Properties should not make collection or array copies namespace MiraAPI.Hud; /// /// Multi-select using the as a base. /// -/// Used by Il2Cpp. Do not use constructor, this is a . /// The type of object each entry represents. -[RegisterInIl2Cpp] -[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Unity Convention")] -public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) - : CustomPhoneMenu.MenuEntry>(il2CppPtr) where TEntry : class +[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity convention.")] +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] +[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Read above.")] +public abstract class CustomMultiSelectMenu : CustomPhoneMenu.MenuEntry> where TEntry : class { private int totalSelections; private bool shouldConfirm; @@ -37,10 +29,18 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) private Color? hoverSelectColor; private Color? hoverDeselectColor; +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Unity convention.")] public UiElement confirmButton; +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member private Action>? onSelection; + /// + /// Menu Entry used when multiple entries are at play. + /// + /// The panel of the entry. + /// The entry itself. public record MenuEntry(ShapeshifterPanel Panel, TEntry Entry) : IMenuEntry; /// @@ -63,7 +63,7 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) Color? hoverDeselectColor = null, PanelButtonOnMouse? onMouseOut = null, PanelButtonOnMouse? onMouseOver = null - ) where TMenu : CustomMultiSelectMenu + ) where TMenu : CustomMultiSelectMenu, new() { TMenu customMenu = Create(onMouseOut, onMouseOver); @@ -101,10 +101,9 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) /// The number of selections required. /// Whether the entire selection should be confirmed manually. /// If the same entry can be selected multiple times, else unselect entry on click. - [HideFromIl2Cpp] protected void Begin(IEnumerable entries, Action?> onClick, int totalSelections, bool shouldConfirm, bool canRepeat = false) { - MinigameStubs.Begin(this, null); + MinigameStubs.Begin(Component, null); this.totalSelections = totalSelections; this.shouldConfirm = shouldConfirm; @@ -118,7 +117,7 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) onClick(null); })); - DebugAnalytics.Instance.Analytics.MinigameOpened(PlayerControl.LocalPlayer.Data, TaskType); + DebugAnalytics.Instance.Analytics.MinigameOpened(PlayerControl.LocalPlayer.Data, Component.TaskType); var list2 = new Il2CppSystem.Collections.Generic.List(); RegisterPanels( entries, @@ -140,7 +139,6 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) /// All entries to give the custom menu. /// Function called when the selection is made. /// Whether the set of both selections should be confirmed manually. - [HideFromIl2Cpp] protected void Begin(IEnumerable entries, Action onClick, bool shouldConfirm) { Begin(entries, list => onClick(list?[0]), 1, shouldConfirm); @@ -153,7 +151,6 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) /// Function called when both selections are made. /// Whether the set of both selections should be confirmed manually. /// If the same entry can be selected both times, else unselect entry on click. - [HideFromIl2Cpp] protected void Begin(IEnumerable entries, Action onClick, bool shouldConfirm, bool canRepeat = false) { Begin(entries, list => onClick(list?[0], list?[1]), 2, shouldConfirm, canRepeat); @@ -198,7 +195,7 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) private void OnCompleteSelection() { - onSelection!(selectedEntries.Select(se => se.Entry).ToList()); + onSelection!([.. selectedEntries.Select(se => se.Entry)]); } /// @@ -210,7 +207,6 @@ public abstract class CustomMultiSelectMenu(IntPtr il2CppPtr) /// /// /// Whether the menu entry is actively selected. - [HideFromIl2Cpp] protected void SetNameplateAppearance(IMenuEntry menuEntry, bool isSelected) { SetNameplateAppearance( diff --git a/MiraAPI/Hud/CustomPaginableMenu.cs b/MiraAPI/Hud/CustomPaginableMenu.cs index b3ef876..9c6b7b6 100644 --- a/MiraAPI/Hud/CustomPaginableMenu.cs +++ b/MiraAPI/Hud/CustomPaginableMenu.cs @@ -1,8 +1,6 @@ -using Il2CppInterop.Runtime.Attributes; -using MiraAPI.Patches.Stubs; +using MiraAPI.Patches.Stubs; using MiraAPI.Utilities.Assets; using Reactor.Utilities; -using Reactor.Utilities.Attributes; using Reactor.Utilities.Extensions; using System; using System.Collections; @@ -13,38 +11,49 @@ using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. -#pragma warning disable S2365 // Properties should not make collection or array copies +using CppCollections = Il2CppSystem.Collections.Generic; +using Object = UnityEngine.Object; namespace MiraAPI.Hud; /// /// Paginable using the as a base. /// -/// Used by Il2Cpp. Do not use constructor, this is a . -[RegisterInIl2Cpp] -[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Unity Convention")] -public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu(il2CppPtr) +[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity convention.")] +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] +[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Read above.")] +public abstract class CustomPaginableMenu : CustomPhoneMenu { + /// + /// Menu Entry used for when multiple pages are needed. + /// + /// The panel. + /// The key by which the panels are sorted. + public record MenuEntry(ShapeshifterPanel Panel, string SortKey) : IMenuEntry; + + /// + /// Gets the name of the menu. + /// protected abstract string Name { get; } - protected int currentPage; - + /// + /// Gets the prefab used to generate the search field. + /// protected abstract TextBoxTMP? PrefabTextbox { get; } + /// + protected override float MenuDepth => -60f; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member + protected int currentPage; +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + private TextBoxTMP? searchTextbox; private string searchText = string.Empty; private TextMeshPro? noResultsText; private const int ItemsPerPage = 15; - protected override float MenuDepth => -60f; - - public record MenuEntry(ShapeshifterPanel Panel, string SortKey) : IMenuEntry; - /// /// Creates a . /// @@ -52,14 +61,11 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenuFunction that can optionally be run when the mouse is moved outside a menu panel. /// Function that can optionally be run when the mouse is moved over a menu panel. /// New object. - protected static new TMenu Create( - PanelButtonOnMouse? onMouseOut = null, - PanelButtonOnMouse? onMouseOver = null - ) where TMenu : CustomPaginableMenu + protected static new TMenu Create(PanelButtonOnMouse? onMouseOut = null, PanelButtonOnMouse? onMouseOver = null) where TMenu : CustomPaginableMenu, new() { TMenu customMenu = CustomPhoneMenu.Create(onMouseOut, onMouseOver); - var nextButton = Instantiate(customMenu.backButton, customMenu.transform).gameObject; + var nextButton = Object.Instantiate(customMenu.backButton, customMenu.transform).gameObject; nextButton.transform.localPosition = new Vector3(1.85f, -2.185f, customMenu.MenuDepth); nextButton.transform.localScale = new Vector3(0.65f, 0.65f, 1); nextButton.name = "RightArrowButton"; @@ -70,7 +76,7 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu().Destroy(); @@ -93,22 +99,19 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu GetFilteredEntries() { var query = NormalizeForSearch(searchText); - if (string.IsNullOrEmpty(query)) - { - return MenuEntries; - } - return MenuEntries + if (string.IsNullOrEmpty(query)) + return MenuEntries; + + return [.. MenuEntries .Where(e => e.SortKey.Contains(query, StringComparison.OrdinalIgnoreCase)) .OrderByDescending(e => e.SortKey.Equals(query, StringComparison.OrdinalIgnoreCase)) .ThenByDescending(e => e.SortKey.StartsWith(query, StringComparison.OrdinalIgnoreCase)) .ThenByDescending(e => e.SortKey.Contains(query, StringComparison.OrdinalIgnoreCase)) - .ThenBy(e => e.SortKey, StringComparer.OrdinalIgnoreCase) - .ToList(); + .ThenBy(e => e.SortKey, StringComparer.OrdinalIgnoreCase)]; } private static int GetTotalPages(int itemCount) @@ -116,7 +119,7 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu list) + private void RefreshControllerOverlay(CppCollections.List list) { if (ControllerManager.Instance && backButton != null) { @@ -124,7 +127,6 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu ShowPage() + /// + /// Shows the current page. + /// + /// The Il2CPP list of ui elements displayed on the page. + public CppCollections.List ShowPage() { foreach (var entry in MenuEntries) { @@ -162,7 +168,7 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu(); + var list2 = new CppCollections.List(); for (var i = 0; i < list.Count; i++) { @@ -178,7 +184,9 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu + /// Ensures that the search UI exists. + /// protected void EnsureSearchUi() { if (searchTextbox != null) @@ -195,7 +203,7 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu(true)) @@ -265,7 +273,7 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu()?.DestroyImmediate(); + clearObj.GetComponent()?.DestroyImmediate(); + + var clearSearchButton = clearObj.GetComponent(); + if (clearSearchButton == null) { - var clearButtonX = searchBounds.max.x + 0.2f; - var clearButtonY = searchBounds.center.y; - - var clearObj = Instantiate(backButton.gameObject, transform); - clearObj.name = "ClearSearchButton"; - clearObj.transform.localScale = new Vector3(0.35f, 0.35f, 1f); - clearObj.transform.localPosition = new Vector3(clearButtonX, clearButtonY, -1f); - - clearObj.GetComponent()?.DestroyImmediate(); - clearObj.GetComponent()?.DestroyImmediate(); - - var clearSearchButton = clearObj.GetComponent(); - if (clearSearchButton != null) - { - if (wikiClickSound != null) - { - clearSearchButton.ClickSound = wikiClickSound; - } - - clearSearchButton.OnClick.RemoveAllListeners(); - clearSearchButton.OnClick = new Button.ButtonClickedEvent(); - clearSearchButton.OnClick.AddListener((UnityAction)(() => - { - if (searchTextbox == null) - { - return; - } - - searchTextbox.SetText(string.Empty); - searchText = string.Empty; - currentPage = 0; - var list = ShowPage(); - RefreshControllerOverlay(list); - })); - } + return; } + if (wikiClickSound != null) + { + clearSearchButton.ClickSound = wikiClickSound; + } + + clearSearchButton.OnClick.RemoveAllListeners(); + clearSearchButton.OnClick = new Button.ButtonClickedEvent(); + clearSearchButton.OnClick.AddListener((UnityAction)(() => + { + if (searchTextbox == null) + { + return; + } + + searchTextbox.SetText(string.Empty); + searchText = string.Empty; + currentPage = 0; + var list = ShowPage(); + RefreshControllerOverlay(list); + })); } - [HideFromIl2Cpp] private static Bounds CalcSpriteBoundsInParentSpace(Transform parent, GameObject root) { var first = true; @@ -342,7 +350,8 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu(true)) { - if (r == null || r.sprite == null) continue; + if (r == null || r.sprite == null) + continue; var b = r.bounds; var c = b.center; @@ -372,10 +381,9 @@ public abstract class CustomPaginableMenu(IntPtr il2CppPtr) : CustomPhoneMenu /// Function where all panels should be registered. - [HideFromIl2Cpp] protected void Begin(Action registerEntryPanels) { - MinigameStubs.Begin(this, null); + MinigameStubs.Begin(Component, null); searchText = string.Empty; currentPage = 0; diff --git a/MiraAPI/Hud/CustomPhoneMenu.cs b/MiraAPI/Hud/CustomPhoneMenu.cs index 8bda766..51f508f 100644 --- a/MiraAPI/Hud/CustomPhoneMenu.cs +++ b/MiraAPI/Hud/CustomPhoneMenu.cs @@ -1,5 +1,4 @@ using AmongUs.GameOptions; -using Il2CppInterop.Runtime.Attributes; using MiraAPI.Utilities.Assets; using Reactor.Utilities.Attributes; using Reactor.Utilities.Extensions; @@ -9,12 +8,26 @@ using System.Diagnostics.CodeAnalysis; using System.Linq; using UnityEngine; using UnityEngine.Events; -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. -#pragma warning disable S2365 // Properties should not make collection or array copies +using Object = UnityEngine.Object; namespace MiraAPI.Hud; +/// +/// Component registered in Il2Cpp domain to handle Unity events for custom menus. +/// +[RegisterInIl2Cpp] +public class CustomPhoneMenuComponent(IntPtr cppPtr) : Minigame(cppPtr) +{ + [SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity convention.")] + private void OnDisable() + { + if (ControllerManager.Instance) + { + ControllerManager.Instance.CloseOverlayMenu(name); + } + } +} + /// /// Defines an entry in a with a Panel. /// @@ -53,14 +66,13 @@ public interface ICustomMenu : ICustomMenu where TMenu : IMenuEntry } /// -/// Custom Phone Menu using the as a base. +/// Custom Phone Menu logic using the as a base. /// -/// Used by Il2Cpp. Do not use constructor, this is a . -[RegisterInIl2Cpp] -[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Unity Convention")] -public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), ICustomMenu +[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention.")] +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] +[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Read above.")] +[SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Proxy for Unity properties.")] +public abstract class CustomPhoneMenu : ICustomMenu { /// /// Menu Entry used when specifically only the Panel itself is required. @@ -68,14 +80,51 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I /// The instance. protected sealed record class BasicEntry(ShapeshifterPanel Panel) : IMenuEntry { - public static implicit operator ShapeshifterPanel(BasicEntry entry) => entry.Panel; + /// + /// Implicitly converts to . + /// + /// The entry that contains the reference to the panel. + public static implicit operator ShapeshifterPanel(BasicEntry entry) + { + return entry.Panel; + } - public static implicit operator BasicEntry(ShapeshifterPanel panel) => new(panel); + /// + /// Implicitly converts to an instance of . + /// + /// The panel instance to make an entry off of. + public static implicit operator BasicEntry(ShapeshifterPanel panel) + { + return new(panel); + } } + /// + /// A delegate that is invoked when the mouse interacts with a panel. + /// + /// The panel's highlight that the delegate modifies. + /// The panel's icon that the delegate modifies. + /// A flag that indicates if the current panel is selected. + public delegate void PanelButtonOnMouse(SpriteRenderer highlight, SpriteRenderer icon, bool isSelected); + + /// + /// Gets the wrapped component that the menu modifies. + /// + public CustomPhoneMenuComponent Component { get; internal set; } = null!; + + /// public List MenuEntries { get; protected set; } = []; - public List EntryPanels => MenuEntries.Select(e => e.Panel).ToList(); + /// + /// Gets all of the panels of the menu. + /// + public List EntryPanels => [.. MenuEntries.Select(e => e.Panel)]; + +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member (Justification: Unity convention.) +#pragma warning disable S1104 // Fields should not have public accessibility (Justification: Read above.) + public Transform transform => Component.transform; + public GameObject gameObject => Component.gameObject; + public string name => Component.name; public float xStart = -0.8f; public float yStart = 2.15f; @@ -86,15 +135,29 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I public UiElement backButton; public UiElement defaultButtonSelected; - public Transform PhoneUI => transform.FindChild("PhoneUI"); - - public delegate void PanelButtonOnMouse(SpriteRenderer highlight, SpriteRenderer icon, bool isSelected); - protected PanelButtonOnMouse? onMouseOverAction; protected PanelButtonOnMouse? onMouseOutAction; +#pragma warning restore S1104 // Fields should not have public accessibility +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member + /// + /// Gets the transform of the menu's Phone UI. + /// + public Transform PhoneUI => transform.FindChild("PhoneUI"); + + /// + /// Gets the z-axis depth that the menu is instantiated at. + /// protected virtual float MenuDepth => -50f; + /// + /// Closes the menu. + /// + public void Close() + { + Component.Close(); + } + /// /// Creates a . /// @@ -102,32 +165,32 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I /// Function that can optionally be run when the mouse is moved outside a menu panel. /// Function that can optionally be run when the mouse is moved over a menu panel. /// New object. - protected static TMenu Create( - PanelButtonOnMouse? onMouseOut = null, - PanelButtonOnMouse? onMouseOver = null - ) where TMenu : CustomPhoneMenu + protected static TMenu Create(PanelButtonOnMouse? onMouseOut = null, PanelButtonOnMouse? onMouseOver = null) where TMenu : CustomPhoneMenu, new() { var shapeShifterRole = RoleManager.Instance.GetRole(RoleTypes.Shapeshifter); var ogMenu = shapeShifterRole.TryCast()!.ShapeshifterMenu; - var newMenu = Instantiate(ogMenu); - var customMenu = newMenu.gameObject.AddComponent(); - - customMenu.panelPrefab = newMenu.PanelPrefab; - customMenu.xStart = newMenu.XStart; - customMenu.yStart = newMenu.YStart; - customMenu.xOffset = newMenu.XOffset; - customMenu.yOffset = newMenu.YOffset; - customMenu.defaultButtonSelected = newMenu.DefaultButtonSelected; - customMenu.backButton = newMenu.BackButton; + var newMenu = Object.Instantiate(ogMenu); + var component = newMenu.gameObject.AddComponent(); + var customMenu = new TMenu + { + Component = component, + panelPrefab = newMenu.PanelPrefab, + xStart = newMenu.XStart, + yStart = newMenu.YStart, + xOffset = newMenu.XOffset, + yOffset = newMenu.YOffset, + defaultButtonSelected = newMenu.DefaultButtonSelected, + backButton = newMenu.BackButton, + }; var back = customMenu.backButton.GetComponent(); back.OnClick.RemoveAllListeners(); back.OnClick.AddListener((UnityAction)customMenu.Close); - customMenu.CloseSound = newMenu.CloseSound; - customMenu.logger = newMenu.logger; - customMenu.OpenSound = newMenu.OpenSound; + component.CloseSound = newMenu.CloseSound; + component.logger = newMenu.logger; + component.OpenSound = newMenu.OpenSound; newMenu.DestroyImmediate(); @@ -140,20 +203,6 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I return customMenu; } - private void OnDisable() - { - ControllerManager.Instance.CloseOverlayMenu(name); - } - -#pragma warning disable CS0809 // Obsolete member overrides non-obsolete member - [Obsolete("Will always fail. Call or define another Begin method that calls MinigameStubs.Begin", true)] - [SuppressMessage("Info Code Smell", "S1133:Deprecated code should be removed", Justification = "Overrides an unusable method.")] - public override sealed void Begin(PlayerTask task) - { - throw new NotImplementedException("Use the other Begin method."); - } -#pragma warning restore CS0809 // Obsolete member overrides non-obsolete member - /// /// Register new menu panels given a set of entries. /// @@ -176,7 +225,7 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I var index = currentEntries + i; var entry = list[i]; - var shapeshifterPanel = Instantiate(panelPrefab, transform); + var shapeshifterPanel = Object.Instantiate(panelPrefab, transform); shapeshifterPanel.transform.localPosition = new Vector3(0f, 0f, -1f); entryPanelConfig(shapeshifterPanel, index, entry); @@ -226,7 +275,10 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I /// /// The to check. /// if the is selected, else . - protected virtual bool IsEntrySelected(IMenuEntry entry) => false; + protected virtual bool IsEntrySelected(IMenuEntry entry) + { + return false; + } /// /// Set the icon, over color, and unselected color for a given entry. @@ -235,7 +287,6 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I /// The to use as the icon, if any. /// The to use when hovering over an entry. /// The to use when not hovering over an entry. - [HideFromIl2Cpp] protected static void SetNameplateAppearance( IMenuEntry menuEntry, LoadableAsset? sprite, Color? overColor, Color? unselectedColor) { @@ -260,13 +311,14 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr), I } } -/// +/// /// The type of menu entries. -public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : CustomPhoneMenu(il2CppPtr), ICustomMenu where TMenu : IMenuEntry +public abstract class CustomPhoneMenu : CustomPhoneMenu, ICustomMenu where TMenu : IMenuEntry { + /// public new List MenuEntries { - get => base.MenuEntries.Cast().ToList(); - protected set => base.MenuEntries = value.Cast().ToList(); + get => [.. base.MenuEntries.Cast()]; + protected set => base.MenuEntries = [.. value.Cast()]; } } diff --git a/MiraAPI/Hud/CustomPlayerMenu.cs b/MiraAPI/Hud/CustomPlayerMenu.cs index 461a3e0..a0b57a2 100644 --- a/MiraAPI/Hud/CustomPlayerMenu.cs +++ b/MiraAPI/Hud/CustomPlayerMenu.cs @@ -2,25 +2,22 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; -using Il2CppInterop.Runtime.Attributes; -using Reactor.Utilities.Attributes; using UnityEngine; -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member -#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring as nullable. namespace MiraAPI.Hud; /// /// Custom Player Menu using the as a base. /// -/// Used by Il2Cpp. Do not use constructor, this is a . -[RegisterInIl2Cpp] -[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Unity Convention")] -[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Unity Convention")] -public class CustomPlayerMenu(IntPtr il2CppPtr) : CustomMultiSelectMenu(il2CppPtr) +[SuppressMessage("Design", "CA1051:Do not declare visible instance fields", Justification = "Unity Convention.")] +[SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Read above.")] +[SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Read above.")] +public class CustomPlayerMenu : CustomMultiSelectMenu { + [SuppressMessage("Minor Code Smell", "S1104:Fields should not have public accessibility", Justification = "Read above.")] +#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public List potentialVictims; +#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member /// /// Creates a . @@ -37,7 +34,6 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : CustomMultiSelectMenuFunction to determine if player should show in the custom menu. /// action for player. /// Whether the set of both selections should be confirmed manually. - [HideFromIl2Cpp] public void Begin(Func playerMatch, Action onClick, bool shouldConfirm = false) { Begin(PlayerControl.AllPlayerControls.ToArray().Where(playerMatch), onClick, shouldConfirm); @@ -51,7 +47,6 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : CustomMultiSelectMenu action for the two-player selection. /// Whether the set of both selections should be confirmed manually. /// If the same entry can be selected both times, else unselect entry on click. - [HideFromIl2Cpp] public void Begin(Func playerMatch, Action onClick, bool shouldConfirm = false, bool canRepeat = false) { Begin(PlayerControl.AllPlayerControls.ToArray().Where(playerMatch), onClick, shouldConfirm, canRepeat);