mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using AmongUs.GameOptions;
|
|
using HarmonyLib;
|
|
using UnityEngine;
|
|
|
|
namespace BetterAmongUs;
|
|
|
|
// Code from: https://github.com/0xDrMoe/TownofHost-Enhanced
|
|
[HarmonyPatch(typeof(HudManager), nameof(HudManager.Update))]
|
|
public static class Zoom
|
|
{
|
|
private static bool resetButtons = false;
|
|
|
|
public static void Postfix()
|
|
{
|
|
if (GameStates.IsCanMove && !PlayerControl.LocalPlayer.Is(RoleTypes.GuardianAngel) && (!GameStates.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 && (GameStates.IsDead || GameStates.IsFreePlay || GameStates.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 (GameStates.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);
|
|
}
|
|
} |