Files
BetterAmongUs/Modules/Zoom.cs
T
2024-11-03 14:39:08 -06:00

96 lines
3.1 KiB
C#

using AmongUs.GameOptions;
using BetterAmongUs.Helpers;
using HarmonyLib;
using UnityEngine;
namespace BetterAmongUs.Modules;
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))]
public static class Zoom
{
private static bool resetButtons = false;
public static void Postfix()
{
if (GameState.IsCanMove && !PlayerControl.LocalPlayer.Is(RoleTypes.GuardianAngel) && (!GameState.IsInGamePlay || !PlayerControl.LocalPlayer.IsAlive()))
{
if (Camera.main.orthographicSize > 3.0f)
resetButtons = true;
if (Input.mouseScrollDelta.y > 0 && Camera.main.orthographicSize > 3.0f)
{
SetZoomSize(times: false);
}
else if (Input.mouseScrollDelta.y < 0 && (GameState.IsDead || GameState.IsFreePlay || GameState.IsLobby) &&
Camera.main.orthographicSize < 18.0f)
{
SetZoomSize(times: true);
}
Flag.NewFlag("Zoom");
}
else
{
Flag.Run(() => SetZoomSize(reset: true), "Zoom");
}
}
private static void SetZoomSize(bool times = false, bool reset = false)
{
float size = times ? 1.5f : 1 / 1.5f;
if (reset)
{
Camera.main.orthographicSize = 3.0f;
HudManager.Instance.UICamera.orthographicSize = 3.0f;
HudManager.Instance.Chat.transform.localScale = Vector3.one;
if (GameState.IsMeeting)
MeetingHud.Instance.transform.localScale = Vector3.one;
}
else
{
Camera.main.orthographicSize *= size;
HudManager.Instance.UICamera.orthographicSize *= size;
}
DestroyableSingleton<HudManager>.Instance?.ShadowQuad?.gameObject?.SetActive((reset || Camera.main.orthographicSize == 3.0f) && PlayerControl.LocalPlayer.IsAlive());
if (resetButtons)
{
ResolutionManager.ResolutionChanged.Invoke((float)Screen.width / Screen.height, Screen.width, Screen.height, Screen.fullScreen);
resetButtons = false;
}
}
public static void OnFixedUpdate() =>
DestroyableSingleton<HudManager>.Instance?.ShadowQuad?.gameObject?.SetActive(Camera.main.orthographicSize == 3.0f && PlayerControl.LocalPlayer.IsAlive());
}
public static class Flag
{
private static readonly List<string> oneTimeList = new();
private static readonly List<string> firstRunList = new();
public static void Run(Action action, string type, bool firstrun = false)
{
if (oneTimeList.Contains(type) || firstrun && !firstRunList.Contains(type))
{
if (!firstRunList.Contains(type))
firstRunList.Add(type);
oneTimeList.Remove(type);
action();
}
}
public static void NewFlag(string type)
{
if (!oneTimeList.Contains(type))
oneTimeList.Add(type);
}
public static void DeleteFlag(string type)
{
oneTimeList.Remove(type);
}
}