From 18452c0890d134d98243257f48f4dab0819443e0 Mon Sep 17 00:00:00 2001 From: Az <56699741+AlchlcDvl@users.noreply.github.com> Date: Fri, 18 Sep 2026 12:51:30 -0400 Subject: [PATCH] resolve new warnings --- .editorconfig | 3 ++ MiraAPI/Hud/CustomMultiSelectMenu.cs | 28 ++++++++++------- MiraAPI/Hud/CustomPaginableMenu.cs | 21 +++++++------ MiraAPI/Hud/CustomPhoneMenu.cs | 30 +++++++++++-------- .../Patches/GameModes/CreateOptionsPatch.cs | 5 ++-- MiraAPI/Patches/Options/MenuState.cs | 1 + 6 files changed, 54 insertions(+), 34 deletions(-) diff --git a/.editorconfig b/.editorconfig index b19810c..af9feb4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -83,3 +83,6 @@ dotnet_diagnostic.SA1407.severity = none # SA1133: Each attribute should be placed in its own set of square brackets dotnet_diagnostic.SA1133.severity = none + +# IDE0001: Simplify Names +dotnet_diagnostic.IDE0001.severity = warning diff --git a/MiraAPI/Hud/CustomMultiSelectMenu.cs b/MiraAPI/Hud/CustomMultiSelectMenu.cs index 0e87ade..d54afa3 100644 --- a/MiraAPI/Hud/CustomMultiSelectMenu.cs +++ b/MiraAPI/Hud/CustomMultiSelectMenu.cs @@ -1,9 +1,9 @@ -using MiraAPI.Patches.Stubs; -using MiraAPI.Utilities.Assets; -using System; +using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using MiraAPI.Patches.Stubs; +using MiraAPI.Utilities.Assets; using UnityEngine; using UnityEngine.Events; @@ -16,12 +16,13 @@ namespace MiraAPI.Hud; [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 +public abstract class CustomMultiSelectMenu : CustomPhoneMenu.MenuEntry> + where TEntry : class { + private readonly List selectedEntries = []; private int totalSelections; private bool shouldConfirm; private bool canRepeat; - private readonly List selectedEntries = []; private LoadableAsset? hoverSelectSprite; private LoadableAsset? hoverDeselectSprite; @@ -62,8 +63,8 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu? hoverDeselectSprite = null, Color? hoverDeselectColor = null, PanelButtonOnMouse? onMouseOut = null, - PanelButtonOnMouse? onMouseOver = null - ) where TMenu : CustomMultiSelectMenu, new() + PanelButtonOnMouse? onMouseOver = null) + where TMenu : CustomMultiSelectMenu, new() { TMenu customMenu = Create(onMouseOut, onMouseOver); @@ -118,7 +119,7 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu(); + var list2 = new CppCollections.List(); RegisterPanels( entries, (shapeshifterPanel, i, entry) => @@ -160,23 +161,28 @@ public abstract class CustomMultiSelectMenu : CustomPhoneMenu e.Entry == entry); - if (!canRepeat && selectedEntries.Remove(menuEntry)) // Unselect previous choice + // Unselect previous choice + if (!canRepeat && selectedEntries.Remove(menuEntry)) { // TODO: if confirm button is enabled, disable it SetNameplateAppearance(menuEntry, false); return; } - if (selectedEntries.Count >= totalSelections) // Do not go past total selections. + // Do not go past total selections + if (selectedEntries.Count >= totalSelections) { return; } selectedEntries.Add(menuEntry); - if (selectedEntries.Count <= totalSelections) // Add choice to list of selections + + // Add choice to list of selections + if (selectedEntries.Count <= totalSelections) { SetNameplateAppearance(menuEntry, true); } + if (selectedEntries.Count < totalSelections) { return; diff --git a/MiraAPI/Hud/CustomPaginableMenu.cs b/MiraAPI/Hud/CustomPaginableMenu.cs index 9c6b7b6..bfbc61f 100644 --- a/MiraAPI/Hud/CustomPaginableMenu.cs +++ b/MiraAPI/Hud/CustomPaginableMenu.cs @@ -1,17 +1,16 @@ -using MiraAPI.Patches.Stubs; -using MiraAPI.Utilities.Assets; -using Reactor.Utilities; -using Reactor.Utilities.Extensions; -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Linq; +using MiraAPI.Patches.Stubs; +using MiraAPI.Utilities.Assets; +using Reactor.Utilities; +using Reactor.Utilities.Extensions; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.UI; -using CppCollections = Il2CppSystem.Collections.Generic; using Object = UnityEngine.Object; namespace MiraAPI.Hud; @@ -24,6 +23,8 @@ namespace MiraAPI.Hud; [SuppressMessage("StyleCop.CSharp.NamingRules", "SA1307:Accessible fields should begin with upper-case letter", Justification = "Read above.")] public abstract class CustomPaginableMenu : CustomPhoneMenu { + private const int ItemsPerPage = 15; + /// /// Menu Entry used for when multiple pages are needed. /// @@ -52,8 +53,6 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu /// Creates a . /// @@ -61,7 +60,8 @@ public abstract class CustomPaginableMenu : 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, new() + protected static new TMenu Create(PanelButtonOnMouse? onMouseOut = null, PanelButtonOnMouse? onMouseOver = null) + where TMenu : CustomPaginableMenu, new() { TMenu customMenu = CustomPhoneMenu.Create(onMouseOut, onMouseOver); @@ -99,6 +99,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu GetFilteredEntries() { var query = NormalizeForSearch(searchText); @@ -252,6 +253,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu { @@ -321,6 +323,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu superclass that is being hidden by this one to work. /// /// The type of menu entry. -public interface ICustomMenu : ICustomMenu where TMenu : IMenuEntry +public interface ICustomMenu : ICustomMenu + where TMenu : IMenuEntry { /// /// Gets all registered s. @@ -133,9 +134,11 @@ public abstract class CustomPhoneMenu : ICustomMenu #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.) +#pragma warning disable SA1300 // Element should begin with upper-case letter (Justification: Read above.) public Transform transform => Component.transform; public GameObject gameObject => Component.gameObject; public string name => Component.name; +#pragma warning restore SA1300 // Element should begin with upper-case letter public float xStart = -0.8f; public float yStart = 2.15f; @@ -176,7 +179,8 @@ public abstract class CustomPhoneMenu : ICustomMenu /// 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, new() + protected static TMenu Create(PanelButtonOnMouse? onMouseOut = null, PanelButtonOnMouse? onMouseOver = null) + where TMenu : CustomPhoneMenu, new() { var shapeShifterRole = RoleManager.Instance.GetRole(RoleTypes.Shapeshifter); @@ -253,15 +257,14 @@ public abstract class CustomPhoneMenu : ICustomMenu { button.OnMouseOver.RemoveAllListeners(); button.OnMouseOver = new UnityEvent(); - button.OnMouseOver.AddListener((UnityAction) - (() => onMouseOverAction(highlight, icon, IsEntrySelected(menuEntry)))); + button.OnMouseOver.AddListener((UnityAction)(() => onMouseOverAction(highlight, icon, IsEntrySelected(menuEntry)))); } + if (onMouseOutAction != null) { button.OnMouseOut.RemoveAllListeners(); button.OnMouseOut = new UnityEvent(); - button.OnMouseOut.AddListener((UnityAction) - (() => onMouseOutAction(highlight, icon, IsEntrySelected(menuEntry)))); + button.OnMouseOut.AddListener((UnityAction)(() => onMouseOutAction(highlight, icon, IsEntrySelected(menuEntry)))); } } } @@ -310,11 +313,13 @@ public abstract class CustomPhoneMenu : ICustomMenu { icon.sprite = sprite.LoadAsset(); } + var button = nameplate.GetComponent(); if (overColor is { } oColor) { button.OverColor = oColor; } + if (unselectedColor is { } uColor) { button.UnselectedColor = uColor; @@ -324,7 +329,8 @@ public abstract class CustomPhoneMenu : ICustomMenu /// /// The type of menu entries. -public abstract class CustomPhoneMenu : CustomPhoneMenu, ICustomMenu where TMenu : IMenuEntry +public abstract class CustomPhoneMenu : CustomPhoneMenu, ICustomMenu + where TMenu : IMenuEntry { /// public new List MenuEntries diff --git a/MiraAPI/Patches/GameModes/CreateOptionsPatch.cs b/MiraAPI/Patches/GameModes/CreateOptionsPatch.cs index 166c2e4..b33c1fd 100644 --- a/MiraAPI/Patches/GameModes/CreateOptionsPatch.cs +++ b/MiraAPI/Patches/GameModes/CreateOptionsPatch.cs @@ -1,13 +1,14 @@ using HarmonyLib; +using GameModesEnum = AmongUs.GameOptions.GameModes; namespace MiraAPI.Patches.GameModes; [HarmonyPatch(typeof(CreateOptionsPicker), nameof(CreateOptionsPicker.SetGameMode))] internal static class CreateOptionsPatch { - public static bool Prefix(CreateOptionsPicker __instance, AmongUs.GameOptions.GameModes mode) + public static bool Prefix(CreateOptionsPicker __instance, GameModesEnum mode) { - if (mode <= AmongUs.GameOptions.GameModes.SeekFools) + if (mode <= GameModesEnum.SeekFools) { return true; } diff --git a/MiraAPI/Patches/Options/MenuState.cs b/MiraAPI/Patches/Options/MenuState.cs index d76ce13..6687699 100644 --- a/MiraAPI/Patches/Options/MenuState.cs +++ b/MiraAPI/Patches/Options/MenuState.cs @@ -383,6 +383,7 @@ public class MenuState(IntPtr cppPtr) : MonoBehaviour(cppPtr) private void UpdateUi() { var pageText = "MiraApi.Page".Translate(); + // Update mod text if (CurrentModIdx == 0) {