diff --git a/MiraAPI/Hud/CustomPhoneMenu.cs b/MiraAPI/Hud/CustomPhoneMenu.cs index b82a703..d070c24 100644 --- a/MiraAPI/Hud/CustomPhoneMenu.cs +++ b/MiraAPI/Hud/CustomPhoneMenu.cs @@ -10,6 +10,7 @@ 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; @@ -40,6 +41,8 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr) public List menuEntries; + public List EntryPanels => menuEntries.Select(e => e.Panel).ToList(); + public float xStart = -0.8f; public float yStart = 2.15f; public float xOffset = 1.95f; @@ -49,9 +52,12 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr) public UiElement backButton; public UiElement defaultButtonSelected; - // These are the Highlight, Icon, and IsSelected variable respectively. - protected Action? onMouseOverAction; - protected Action? onMouseOutAction; + public Transform PhoneUI => transform.FindChild("PhoneUI"); + + public delegate void PanelButtonOnMouse(SpriteRenderer highlight, SpriteRenderer icon, bool isSelected); + + protected PanelButtonOnMouse? onMouseOverAction; + protected PanelButtonOnMouse? onMouseOutAction; protected virtual float MenuDepth => -50f; @@ -63,8 +69,8 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr) /// Function that can optionally be run when the mouse is moved over a menu panel. /// New object. protected static TMenu Create( - Action? onMouseOut = null, - Action? onMouseOver = null + PanelButtonOnMouse? onMouseOut = null, + PanelButtonOnMouse? onMouseOver = null ) where TMenu : CustomPhoneMenu { var shapeShifterRole = RoleManager.Instance.GetRole(RoleTypes.Shapeshifter); @@ -135,22 +141,23 @@ public abstract class CustomPhoneMenu(IntPtr il2CppPtr) : Minigame(il2CppPtr) var menuEntry = menuEntryMaker(shapeshifterPanel, entry); menuEntries.Add(menuEntry); + var button = shapeshifterPanel.Button; var nameplate = shapeshifterPanel.gameObject.transform.FindChild("Nameplate"); var highlight = nameplate.FindChild("Highlight").GetComponent(); var icon = highlight.transform.GetChild(0).GetComponent(); if (onMouseOverAction != null) { - shapeshifterPanel.Button.OnMouseOver.RemoveAllListeners(); - shapeshifterPanel.Button.OnMouseOver = new UnityEvent(); - shapeshifterPanel.Button.OnMouseOver.AddListener((UnityAction) + button.OnMouseOver.RemoveAllListeners(); + button.OnMouseOver = new UnityEvent(); + button.OnMouseOver.AddListener((UnityAction) (() => onMouseOverAction(highlight, icon, IsEntrySelected(menuEntry)))); } if (onMouseOutAction != null) { - shapeshifterPanel.Button.OnMouseOut.RemoveAllListeners(); - shapeshifterPanel.Button.OnMouseOut = new UnityEvent(); - shapeshifterPanel.Button.OnMouseOut.AddListener((UnityAction) + button.OnMouseOut.RemoveAllListeners(); + button.OnMouseOut = new UnityEvent(); + button.OnMouseOut.AddListener((UnityAction) (() => onMouseOutAction(highlight, icon, IsEntrySelected(menuEntry)))); } } diff --git a/MiraAPI/Hud/CustomPlayerMenu.cs b/MiraAPI/Hud/CustomPlayerMenu.cs index 22c8d74..0317dfc 100644 --- a/MiraAPI/Hud/CustomPlayerMenu.cs +++ b/MiraAPI/Hud/CustomPlayerMenu.cs @@ -63,7 +63,7 @@ public class CustomPlayerMenu(IntPtr il2CppPtr) : CustomPhoneMenu(il2CppPtr) shapeshifterPanel.NameText.color = flag ? player.Data.Role.NameColor : Color.white; list2.Add(shapeshifterPanel.Button); }); - potentialVictims = menuEntries.Cast().ToList(); + potentialVictims = EntryPanels; ControllerManager.Instance.OpenOverlayMenu(name, backButton, defaultButtonSelected, list2); } }