mirror of
https://github.com/All-Of-Us-Mods/MiraAPI.git
synced 2026-11-19 13:17:10 +00:00
10 files changed
+156
-43
No files matched your search
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using MiraAPI.Patches.Stubs;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
@@ -101,6 +102,7 @@ public abstract class CustomMultiSelectMenu<TEntry> : CustomPhoneMenu<CustomMult
|
||||
protected void Begin(IEnumerable<TEntry> entries, Action<List<TEntry>?> onClick, int totalSelections, bool shouldConfirm, bool canRepeat = false)
|
||||
{
|
||||
MinigameStubs.Begin(Component, null);
|
||||
MeetingVoteAreaVisibility.HideNameplates(Component);
|
||||
|
||||
this.totalSelections = totalSelections;
|
||||
this.shouldConfirm = shouldConfirm;
|
||||
@@ -111,6 +113,7 @@ public abstract class CustomMultiSelectMenu<TEntry> : CustomPhoneMenu<CustomMult
|
||||
back.OnClick.AddListener((UnityAction)(() =>
|
||||
{
|
||||
selectedEntries.Clear();
|
||||
MeetingVoteAreaVisibility.Restore(Component);
|
||||
onClick(null);
|
||||
}));
|
||||
|
||||
@@ -172,6 +175,7 @@ public abstract class CustomMultiSelectMenu<TEntry> : CustomPhoneMenu<CustomMult
|
||||
}
|
||||
|
||||
selectedEntries.Add(menuEntry);
|
||||
MeetingVoteAreaVisibility.Restore(Component);
|
||||
|
||||
// Add choice to list of selections
|
||||
if (selectedEntries.Count <= totalSelections)
|
||||
|
||||
@@ -390,6 +390,7 @@ public abstract class CustomPaginableMenu : CustomPhoneMenu<CustomPaginableMenu.
|
||||
protected void Begin(Action registerEntryPanels)
|
||||
{
|
||||
MinigameStubs.Begin(Component, null);
|
||||
MeetingVoteAreaVisibility.HideNameplates(Component);
|
||||
|
||||
searchText = string.Empty;
|
||||
currentPage = 0;
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using AmongUs.GameOptions;
|
||||
using MiraAPI.Utilities;
|
||||
using MiraAPI.Utilities.Assets;
|
||||
using Reactor.Utilities.Attributes;
|
||||
using Reactor.Utilities.Extensions;
|
||||
@@ -22,6 +23,7 @@ public class CustomPhoneMenuComponent(IntPtr cppPtr) : Minigame(cppPtr)
|
||||
[SuppressMessage("Style", "IDE0051:Remove unused private members", Justification = "Unity convention.")]
|
||||
private void OnDisable()
|
||||
{
|
||||
MeetingVoteAreaVisibility.Restore(this);
|
||||
if (ControllerManager.Instance)
|
||||
{
|
||||
ControllerManager.Instance.CloseOverlayMenu(name);
|
||||
|
||||
@@ -75,6 +75,7 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
protected int TabIndex => LocalSettingsManager.Tabs.IndexOf(this) + 10;
|
||||
|
||||
private Scroller? scroller;
|
||||
private float MaxScroll { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Invoked when an option value is changed.
|
||||
@@ -107,6 +108,17 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
}
|
||||
}
|
||||
|
||||
internal void RefreshScrollBounds()
|
||||
{
|
||||
if (scroller == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
scroller.SetBounds(new FloatRange(0, MaxScroll), new FloatRange(0, 0));
|
||||
scroller.ScrollToTop();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates the tab <see cref="GameObject"/> and it's content.
|
||||
/// </summary>
|
||||
@@ -119,11 +131,13 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
tab.transform.DestroyChildren();
|
||||
tab.gameObject.SetActive(false);
|
||||
|
||||
if (scroller == null)
|
||||
if (scroller == null || scroller.transform.parent != tab.transform)
|
||||
{
|
||||
scroller = Helpers.CreateScroller(tab.transform, OptionsMenuPatches.MaskCollider);
|
||||
}
|
||||
|
||||
Labels.Clear();
|
||||
|
||||
if (TabButton != null)
|
||||
{
|
||||
TabButton.Content = tab.gameObject;
|
||||
@@ -217,7 +231,11 @@ public abstract class LocalSettingsTab(ConfigFile config)
|
||||
contentIndex++;
|
||||
}
|
||||
|
||||
scroller.SetBounds(new FloatRange(0, (Settings.Count + Buttons.Count) * 0.5f - 5f), new FloatRange(0, 0));
|
||||
const float visibleHeight = 5f;
|
||||
const float extraPadding = 0.25f;
|
||||
var itemRange = (Settings.Count + Buttons.Count) * 0.5f - visibleHeight;
|
||||
var offsetRange = contentOffset - visibleHeight + extraPadding;
|
||||
MaxScroll = Mathf.Max(0f, itemRange, offsetRange);
|
||||
return tab;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using BepInEx.Unity.IL2CPP.Utils.Collections;
|
||||
using HarmonyLib;
|
||||
using Il2CppInterop.Runtime.InteropTypes.Arrays;
|
||||
using MiraAPI.LocalSettings;
|
||||
@@ -180,7 +182,9 @@ public static class OptionsMenuPatches
|
||||
return true;
|
||||
}
|
||||
|
||||
CustomOpen(LocalSettingsManager.AvailableTabs[index - 10]);
|
||||
var tab = LocalSettingsManager.AvailableTabs[index - 10];
|
||||
CustomOpen(tab);
|
||||
__instance.StartCoroutine(RefreshScrollBoundsAfterOpen(__instance, tab).WrapToIl2Cpp());
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -226,6 +230,16 @@ public static class OptionsMenuPatches
|
||||
tab.Open();
|
||||
}
|
||||
|
||||
private static IEnumerator RefreshScrollBoundsAfterOpen(OptionsMenuBehaviour menu, LocalSettingsTab tab)
|
||||
{
|
||||
yield return new WaitForEndOfFrame();
|
||||
|
||||
if (menu && tab.TabButton && tab.TabButton!.Content && tab.TabButton.Content.activeInHierarchy)
|
||||
{
|
||||
tab.RefreshScrollBounds();
|
||||
}
|
||||
}
|
||||
|
||||
private static void CustomClose(LocalSettingsTab tab)
|
||||
{
|
||||
if (tab.TabButton)
|
||||
|
||||
@@ -373,6 +373,7 @@ public static class RoleSettingMenuPatches
|
||||
}
|
||||
|
||||
roleMenu.SetScrollBounds();
|
||||
roleMenu.scrollBar.ScrollToTop();
|
||||
_quotaTabCoroutine = null;
|
||||
}
|
||||
|
||||
|
||||
@@ -279,6 +279,8 @@ public static class RoleGuidePatches
|
||||
MapBehaviour.Instance.Close();
|
||||
}
|
||||
|
||||
MeetingVoteAreaVisibility.HideNameplates(__instance);
|
||||
|
||||
if (HudManager.InstanceExists)
|
||||
{
|
||||
ConsoleJoystick.SetMode_MenuAdditive();
|
||||
@@ -390,6 +392,13 @@ public static class RoleGuidePatches
|
||||
return false;
|
||||
}
|
||||
|
||||
[HarmonyPostfix]
|
||||
[HarmonyPatch(typeof(MatchInfoGuide), nameof(MatchInfoGuide.Close))]
|
||||
private static void ClosePostfix(MatchInfoGuide __instance)
|
||||
{
|
||||
MeetingVoteAreaVisibility.Restore(__instance);
|
||||
}
|
||||
|
||||
private static void SetUpTabGrids(MatchInfoTabPos position)
|
||||
{
|
||||
tabButtonContainer.startCorner = GridLayoutGroup.Corner.UpperLeft;
|
||||
|
||||
@@ -106,6 +106,7 @@ internal static class MeetingHudPatches
|
||||
[HarmonyPatch(nameof(MeetingHud.OnDestroy))]
|
||||
public static void OnDestroyPatch(MeetingHud __instance)
|
||||
{
|
||||
MeetingVoteAreaVisibility.RestoreAll();
|
||||
MiraEventManager.InvokeEvent(new EndMeetingEvent(__instance));
|
||||
}
|
||||
|
||||
@@ -113,6 +114,7 @@ internal static class MeetingHudPatches
|
||||
[HarmonyPatch(nameof(MeetingHud.VotingComplete))]
|
||||
public static void VotingCompletePatch(MeetingHud __instance)
|
||||
{
|
||||
MeetingVoteAreaVisibility.RestoreAll();
|
||||
foreach (var meetingAbility in MeetingButtonManager.UntargetedButtons.Where(x => x.Enabled(PlayerControl.LocalPlayer.Data.Role) &&
|
||||
(x.DisableUponVoting || x.HideUponWrapUp)))
|
||||
{
|
||||
|
||||
@@ -936,7 +936,7 @@ public static class Helpers
|
||||
{
|
||||
const float contentTop = 0.95f;
|
||||
const float horizontalOffset = -0.2f;
|
||||
const float headerContentGap = 0.2f;
|
||||
const float groupHeaderContentGap = 0.05f;
|
||||
const int contentSortingOrder = 151;
|
||||
|
||||
columns = Mathf.Clamp(columns, 1, 6);
|
||||
@@ -1024,7 +1024,7 @@ public static class Helpers
|
||||
groupColumns[group] = i % columns;
|
||||
bandHeights[band] = Mathf.Max(
|
||||
bandHeights[band],
|
||||
rowPitch * (groupedSettings[i].Count() + 1) + headerContentGap + 0.25f);
|
||||
rowPitch * (groupedSettings[i].Count() + 1) + groupHeaderContentGap + 0.25f);
|
||||
}
|
||||
|
||||
var bandOffset = 0f;
|
||||
@@ -1040,7 +1040,6 @@ public static class Helpers
|
||||
}
|
||||
}
|
||||
|
||||
var contentBottom = float.PositiveInfinity;
|
||||
var previousGroup = (AbstractOptionGroup?)null;
|
||||
var rowIndex = 0;
|
||||
var column = 0;
|
||||
@@ -1089,12 +1088,12 @@ public static class Helpers
|
||||
|
||||
if (headerSource)
|
||||
{
|
||||
const float headerScale = 0.46f;
|
||||
const float groupHeaderScale = 0.42f;
|
||||
var headerWidth = groupsAsColumns
|
||||
? columnWidth / headerScale
|
||||
: (columns * columnWidth + (columns - 1) * columnGap) / headerScale;
|
||||
? columnWidth / groupHeaderScale
|
||||
: (columns * columnWidth + (columns - 1) * columnGap) / groupHeaderScale;
|
||||
var header = Object.Instantiate(headerSource!, page.transform, false);
|
||||
header.transform.localScale = Vector3.one * headerScale;
|
||||
header.transform.localScale = Vector3.one * groupHeaderScale;
|
||||
if (groupsAsColumns)
|
||||
{
|
||||
var totalWidth = columns * columnWidth + (columns - 1) * columnGap;
|
||||
@@ -1155,12 +1154,6 @@ public static class Helpers
|
||||
renderer.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
renderer.material.SetInt(PlayerMaterial.MaskLayer, 50);
|
||||
renderer.sortingOrder = contentSortingOrder;
|
||||
if (renderer.enabled && renderer.sprite)
|
||||
{
|
||||
contentBottom = Mathf.Min(
|
||||
contentBottom,
|
||||
inner.InverseTransformPoint(renderer.bounds.min).y);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var text in header.GetComponentsInChildren<TextMeshPro>(true))
|
||||
@@ -1171,9 +1164,6 @@ public static class Helpers
|
||||
if (text.enabled)
|
||||
{
|
||||
text.ForceMeshUpdate();
|
||||
contentBottom = Mathf.Min(
|
||||
contentBottom,
|
||||
inner.InverseTransformPoint(text.bounds.min).y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1191,7 +1181,7 @@ public static class Helpers
|
||||
horizontalOffset;
|
||||
var centerY = groupsAsColumns && settings[i].Group is { } rowGroup
|
||||
? contentTop - groupTopOffsets[rowGroup] -
|
||||
(rowPitch * (groupRows[rowGroup] + 1)) - headerContentGap - (rowHeight / 2f)
|
||||
(rowPitch * (groupRows[rowGroup] + 1)) - groupHeaderContentGap - (rowHeight / 2f)
|
||||
: contentTop - (rowHeight / 2f) - (rowIndex * rowPitch) - groupSpacing;
|
||||
var row = Object.Instantiate(rowPrefab, page.transform);
|
||||
row.enabled = false;
|
||||
@@ -1238,27 +1228,6 @@ public static class Helpers
|
||||
renderer.maskInteraction = SpriteMaskInteraction.VisibleInsideMask;
|
||||
renderer.material.SetInt(PlayerMaterial.MaskLayer, 50);
|
||||
renderer.sortingOrder = contentSortingOrder;
|
||||
if (renderer.enabled &&
|
||||
renderer.sprite &&
|
||||
renderer.transform != row.PlusBtn.transform &&
|
||||
!renderer.transform.IsChildOf(row.PlusBtn.transform) &&
|
||||
renderer.transform != row.MinusBtn.transform &&
|
||||
!renderer.transform.IsChildOf(row.MinusBtn.transform))
|
||||
{
|
||||
contentBottom = Mathf.Min(
|
||||
contentBottom,
|
||||
inner.InverseTransformPoint(renderer.bounds.min).y);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var text in row.GetComponentsInChildren<TextMeshPro>(true))
|
||||
{
|
||||
if (text.enabled)
|
||||
{
|
||||
contentBottom = Mathf.Min(
|
||||
contentBottom,
|
||||
inner.InverseTransformPoint(text.bounds.min).y);
|
||||
}
|
||||
}
|
||||
|
||||
row.gameObject.SetActive(true);
|
||||
@@ -1277,6 +1246,26 @@ public static class Helpers
|
||||
}
|
||||
}
|
||||
|
||||
page.SetActive(true);
|
||||
var contentBottom = float.PositiveInfinity;
|
||||
foreach (var text in page.GetComponentsInChildren<TextMeshPro>(true))
|
||||
{
|
||||
if (text.enabled && text.gameObject.activeInHierarchy)
|
||||
{
|
||||
text.ForceMeshUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var renderer in page.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (renderer.enabled && renderer.gameObject.activeInHierarchy)
|
||||
{
|
||||
contentBottom = Mathf.Min(
|
||||
contentBottom,
|
||||
inner.InverseTransformPoint(renderer.bounds.min).y);
|
||||
}
|
||||
}
|
||||
|
||||
var maskArea = parent.transform.FindChild("MaskArea")?.GetComponent<SpriteRenderer>();
|
||||
var maskBottom = maskArea
|
||||
? inner.InverseTransformPoint(maskArea!.bounds.min).y
|
||||
@@ -1288,7 +1277,6 @@ public static class Helpers
|
||||
? contentOverflow + 0.05f
|
||||
: 0f;
|
||||
parent.SetYBoundsMax(Mathf.Clamp(scrollRange, 0f, 999f));
|
||||
page.SetActive(true);
|
||||
return page;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace MiraAPI.Utilities;
|
||||
|
||||
internal static class MeetingVoteAreaVisibility
|
||||
{
|
||||
private static readonly Dictionary<Renderer, bool> originalRendererStates = [];
|
||||
private static readonly HashSet<int> activeOwners = [];
|
||||
|
||||
internal static void HideNameplates(UnityEngine.Object owner)
|
||||
{
|
||||
var meetingHud = MeetingHud.Instance;
|
||||
if (!owner ||
|
||||
!meetingHud ||
|
||||
meetingHud.state is not (MeetingHud.MeetingStates.Discussion or
|
||||
MeetingHud.MeetingStates.NotVoted or
|
||||
MeetingHud.MeetingStates.Voted))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
activeOwners.Add(owner.GetInstanceID());
|
||||
foreach (var playerVoteArea in meetingHud.playerStates)
|
||||
{
|
||||
if (!playerVoteArea)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var buttons = playerVoteArea.Buttons;
|
||||
foreach (var renderer in playerVoteArea.GetComponentsInChildren<Renderer>(true))
|
||||
{
|
||||
if (!renderer ||
|
||||
(buttons &&
|
||||
(renderer.transform == buttons.transform || renderer.transform.IsChildOf(buttons.transform))))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!originalRendererStates.ContainsKey(renderer))
|
||||
{
|
||||
originalRendererStates.Add(renderer, renderer.enabled);
|
||||
}
|
||||
|
||||
renderer.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static void Restore(UnityEngine.Object owner)
|
||||
{
|
||||
if (!owner || !activeOwners.Remove(owner.GetInstanceID()) || activeOwners.Count > 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
RestoreAll();
|
||||
}
|
||||
|
||||
internal static void RestoreAll()
|
||||
{
|
||||
activeOwners.Clear();
|
||||
foreach (var rendererState in originalRendererStates)
|
||||
{
|
||||
if (rendererState.Key)
|
||||
{
|
||||
rendererState.Key.enabled = rendererState.Value;
|
||||
}
|
||||
}
|
||||
|
||||
originalRendererStates.Clear();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user