From 16bf7a097f84ed282fe04d1bd644d75335de2795 Mon Sep 17 00:00:00 2001 From: Gurge44 Date: Thu, 9 Apr 2026 13:27:22 +0200 Subject: [PATCH] fix zoom --- Gamemodes/KingOfTheZones.cs | 2 +- Modules/ClientControlGUI.cs | 54 +++++++---------- Modules/Zoom.cs | 115 ++++++++++++++++++++---------------- 3 files changed, 86 insertions(+), 85 deletions(-) diff --git a/Gamemodes/KingOfTheZones.cs b/Gamemodes/KingOfTheZones.cs index e536d8b04..0868cfa21 100644 --- a/Gamemodes/KingOfTheZones.cs +++ b/Gamemodes/KingOfTheZones.cs @@ -142,7 +142,7 @@ public static class KingOfTheZones .SetGameMode(gameMode) .SetColor(color); - AllZonesMoveAtOnce = new BooleanOptionItem(id++, "KingOfTheZones.AllZonesMoveAtOnce", true, TabGroup.GameSettings) + AllZonesMoveAtOnce = new BooleanOptionItem(id++, "KingOfTheZones.AllZonesMoveAtOnce", false, TabGroup.GameSettings) .SetParent(ZonesMove) .SetGameMode(gameMode) .SetColor(color); diff --git a/Modules/ClientControlGUI.cs b/Modules/ClientControlGUI.cs index dbe5557f9..4ae75a549 100644 --- a/Modules/ClientControlGUI.cs +++ b/Modules/ClientControlGUI.cs @@ -16,12 +16,7 @@ public class ClientControlGUI : MonoBehaviour /// Whether the panel is currently visible or should be visible /// public bool IsOpen; - - /// - /// The value of in the last frame - /// - private bool _lastOpenState; - + /// /// Current scroll position inside the panel /// @@ -284,13 +279,6 @@ public class ClientControlGUI : MonoBehaviour { if (!HudManager.InstanceExists) return; - // Disable movement when GUI is open - if (_lastOpenState != IsOpen) - { - if (PlayerControl.LocalPlayer) KillAnimation.SetMovement(PlayerControl.LocalPlayer, !IsOpen); - _lastOpenState = IsOpen; - } - if (!_windowInitialized) InitWindowRect(); // Rebuild styles only when screen scale changes; HideAndDontSave keeps textures alive across scene transitions @@ -470,13 +458,12 @@ public class ClientControlGUI : MonoBehaviour InGameRoleInfoMenu.Show(); } }); + + Section(ref y, "Camera"); - if (inLobby || (inGame && !inMeeting && canMove && (!localAlive || GameStates.IsFreePlay || DebugModeManager.AmDebugger))) + if (Zoom.CanZoom) { - Section(ref y, "Camera"); - // Sync slider to actual camera value so external changes (scroll wheel, touch pinch) are reflected - // Camera.main is read inline each frame - caching it across scene loads causes the zoom to drift if (_cam) _zoomValue = _cam.orthographicSize; float newZoom = Slider(ref y, $"Zoom {_zoomValue:F1}x", _zoomValue, 3.0f, 18.0f, w); @@ -494,27 +481,26 @@ public class ClientControlGUI : MonoBehaviour _zoomValue = 3.0f; } y += ButtonHeight + Padding * 0.7f; + } - bool canNoclip = canMove && (!AmongUsClient.Instance.IsGameStarted || !GameStates.IsOnlineGame); - - if (canNoclip) + if (canMove && (!AmongUsClient.Instance.IsGameStarted || !GameStates.IsOnlineGame)) + { + // Reads live state every frame for correct label/colour; lambda also reads it on click to avoid stale values + bool noclipOn = ControllerManagerUpdatePatch.NoClipEnabled; + Btn(ref y, noclipOn ? "No-clip: ON" : "No-clip: OFF", noclipOn ? _sHost : _sAction, () => { - // Reads live state every frame for correct label/colour; lambda also reads it on click to avoid stale values - bool noclipOn = ControllerManagerUpdatePatch.NoClipEnabled; - Btn(ref y, noclipOn ? "No-clip: ON" : "No-clip: OFF", noclipOn ? _sHost : _sAction, () => - { - ControllerManagerUpdatePatch.NoClipEnabled = canNoclip && !ControllerManagerUpdatePatch.NoClipEnabled; - if (OperatingSystem.IsAndroid()) PlayerControl.LocalPlayer.Collider.offset = ControllerManagerUpdatePatch.NoClipEnabled ? new Vector2(0f, 127f) : new Vector2(0f, -0.3636f); - }); - } - - Btn(ref y, _hudHidden ? "Show HUD" : "Hide HUD", _hudHidden ? _sHost : _sAction, () => - { - _hudHidden = !_hudHidden; - if (HudManager.InstanceExists) - HudManager.Instance.gameObject.SetActive(!_hudHidden); + ControllerManagerUpdatePatch.NoClipEnabled = !ControllerManagerUpdatePatch.NoClipEnabled; + if (OperatingSystem.IsAndroid()) PlayerControl.LocalPlayer.Collider.offset = ControllerManagerUpdatePatch.NoClipEnabled ? new Vector2(0f, 127f) : new Vector2(0f, -0.3636f); }); } + else if (OperatingSystem.IsAndroid()) PlayerControl.LocalPlayer.Collider.offset = new Vector2(0f, -0.3636f); + + Btn(ref y, _hudHidden ? "Show HUD" : "Hide HUD", _hudHidden ? _sHost : _sAction, () => + { + _hudHidden = !_hudHidden; + if (HudManager.InstanceExists) + HudManager.Instance.gameObject.SetActive(!_hudHidden); + }); if (inLobby) { diff --git a/Modules/Zoom.cs b/Modules/Zoom.cs index fa6ddef36..8d267ef4a 100644 --- a/Modules/Zoom.cs +++ b/Modules/Zoom.cs @@ -12,6 +12,8 @@ public static class Zoom private static bool ResetButtons; private static Camera Main; + public static bool CanZoom => ((GameStates.IsShip && !GameStates.IsMeeting && GameStates.IsCanMove && !PlayerControl.LocalPlayer.IsAlive()) || (GameStates.IsLobby && GameStates.IsCanMove)) && !InGameRoleInfoMenu.Showing; + public static void Postfix() { try @@ -19,68 +21,71 @@ public static class Zoom if (!Main) Main = Camera.main; if (!Main) return; - if (((GameStates.IsShip && !GameStates.IsMeeting && GameStates.IsCanMove && !PlayerControl.LocalPlayer.IsAlive()) || (GameStates.IsLobby && GameStates.IsCanMove)) && !InGameRoleInfoMenu.Showing && !ClientControlGUI.Instance.IsOpen) + if (CanZoom) { - if (Main.orthographicSize > 3.0f) ResetButtons = true; - - if (Input.touchSupported && !MapBehaviour.Instance.IsOpen) + if (!ClientControlGUI.Instance.IsOpen) { - if (Input.touchCount == 2) + if (Main.orthographicSize > 3.0f) ResetButtons = true; + + if (Input.touchSupported && !MapBehaviour.Instance.IsOpen) { - Touch touch0 = Input.GetTouch(0); - Touch touch1 = Input.GetTouch(1); - - Vector2 touch0PrevPos = touch0.position - touch0.deltaPosition; - Vector2 touch1PrevPos = touch1.position - touch1.deltaPosition; - - float prevTouchDeltaMag = (touch0PrevPos - touch1PrevPos).magnitude; - float currentTouchDeltaMag = (touch0.position - touch1.position).magnitude; - float deltaMagnitudeDiff = currentTouchDeltaMag - prevTouchDeltaMag; - - switch (deltaMagnitudeDiff) + if (Input.touchCount == 2) { - case > 0: - { - if (Main.orthographicSize > 3.0f) - SetZoomSize(); + Touch touch0 = Input.GetTouch(0); + Touch touch1 = Input.GetTouch(1); - break; - } - case < 0: + Vector2 touch0PrevPos = touch0.position - touch0.deltaPosition; + Vector2 touch1PrevPos = touch1.position - touch1.deltaPosition; + + float prevTouchDeltaMag = (touch0PrevPos - touch1PrevPos).magnitude; + float currentTouchDeltaMag = (touch0.position - touch1.position).magnitude; + float deltaMagnitudeDiff = currentTouchDeltaMag - prevTouchDeltaMag; + + switch (deltaMagnitudeDiff) { - if (GameStates.IsDead || GameStates.IsFreePlay || DebugModeManager.AmDebugger || GameStates.IsLobby) + case > 0: { - if (Main.orthographicSize < 18.0f) - SetZoomSize(true); - } + if (Main.orthographicSize > 3.0f) + SetZoomSize(); - break; + break; + } + case < 0: + { + if (GameStates.IsDead || GameStates.IsFreePlay || DebugModeManager.AmDebugger || GameStates.IsLobby) + { + if (Main.orthographicSize < 18.0f) + SetZoomSize(true); + } + + break; + } } } } - } - switch (Input.mouseScrollDelta.y) - { - case > 0: + switch (Input.mouseScrollDelta.y) { - if (Main.orthographicSize > 3.0f) - SetZoomSize(); - - break; - } - case < 0: - { - if (GameStates.IsDead || GameStates.IsFreePlay || DebugModeManager.AmDebugger || GameStates.IsLobby) + case > 0: { - if (Main.orthographicSize < 18.0f) - SetZoomSize(true); - } + if (Main.orthographicSize > 3.0f) + SetZoomSize(); - break; + break; + } + case < 0: + { + if (GameStates.IsDead || GameStates.IsFreePlay || DebugModeManager.AmDebugger || GameStates.IsLobby) + { + if (Main.orthographicSize < 18.0f) + SetZoomSize(true); + } + + break; + } } + Flag.NewFlag("Zoom"); } - Flag.NewFlag("Zoom"); } else Flag.Run(() => SetZoomSize(reset: true), "Zoom"); @@ -97,24 +102,34 @@ public static class Zoom if (reset) { - 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; + Reset(); } else { Main.orthographicSize *= size; HudManager.Instance.UICamera.orthographicSize *= size; + + if (Main.orthographicSize < 3.0f || HudManager.Instance.UICamera.orthographicSize < 3.0f) + Reset(); } - HudManager.Instance?.ShadowQuad?.gameObject.SetActive((reset || Mathf.Approximately(Main.orthographicSize, 3.0f)) && PlayerControl.LocalPlayer.IsAlive()); + HudManager.Instance.ShadowQuad?.gameObject.SetActive((reset || Mathf.Approximately(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; } + + return; + + static void Reset() + { + 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; + } } public static void OnFixedUpdate()