mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
- to toggle ClientControlGUI
This commit is contained in:
1 parent
71c2906cff
commit
8bfc215a5a
3 files changed
+24
-26
No files matched your search
+13
-22
@@ -5,6 +5,7 @@ using EHR.Patches;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using static EHR.Translator;
|
||||
// ReSharper disable InconsistentNaming
|
||||
|
||||
namespace EHR;
|
||||
|
||||
@@ -12,9 +13,8 @@ public class ClientControlGUI : MonoBehaviour
|
||||
{
|
||||
public static ClientControlGUI Instance;
|
||||
|
||||
public bool IsOpen => _open;
|
||||
|
||||
private bool _open; // whether the panel is visible
|
||||
public bool IsOpen; // whether the panel is visible
|
||||
|
||||
private Vector2 _scroll; // current scroll position inside the panel
|
||||
private float _contentH; // total height of all drawn buttons, updated each frame
|
||||
|
||||
@@ -25,7 +25,7 @@ public class ClientControlGUI : MonoBehaviour
|
||||
|
||||
// Scale helpers - everything is relative to a 1080px-wide reference screen.
|
||||
// On PC the UI is scaled down to 60% but on Android we keep it at full size for better readability.
|
||||
private static float PS => OperatingSystem.IsAndroid() ? 1.0f : 0.6f; // PS: platform scale multiplier (Android full size, PC smaller)
|
||||
private static float PS => OperatingSystem.IsAndroid() ? 1.0f : 0.5f; // PS: platform scale multiplier (Android full size, PC smaller)
|
||||
private static float S => Screen.width / 1080f * PS; // S: global scale factor
|
||||
private static int FS => Mathf.Max(12, Mathf.RoundToInt(21f * S)); // FS: font size
|
||||
private static float BH => 66f * S; // BH: button height
|
||||
@@ -278,7 +278,7 @@ public class ClientControlGUI : MonoBehaviour
|
||||
|
||||
HandleDrag();
|
||||
DrawToggle();
|
||||
if (_open) DrawWindow();
|
||||
if (IsOpen) DrawWindow();
|
||||
}
|
||||
|
||||
// Draws the small square button that opens/closes the panel.
|
||||
@@ -288,7 +288,7 @@ public class ClientControlGUI : MonoBehaviour
|
||||
float size = 48f * S;
|
||||
float x, y;
|
||||
|
||||
if (_open)
|
||||
if (IsOpen)
|
||||
{
|
||||
// Sits just to the right of the window, vertically centred on it
|
||||
x = _windowRect.x + _windowRect.width + 8f * S;
|
||||
@@ -296,27 +296,18 @@ public class ClientControlGUI : MonoBehaviour
|
||||
}
|
||||
else
|
||||
{
|
||||
if (OperatingSystem.IsAndroid())
|
||||
{
|
||||
// Bottom-left center: horizontally centred on the left quarter of the screen,
|
||||
x = Screen.width * 0.25f - size * 0.5f;
|
||||
y = Screen.height - size - 10f * S;
|
||||
}
|
||||
else
|
||||
{
|
||||
// PC: left side, vertically centred but shifted down to avoid overlapping with game UI
|
||||
x = 20f * S;
|
||||
y = (Screen.height - size) * 0.5f + 60f * S;
|
||||
}
|
||||
// Bottom-left center: horizontally centred on the left quarter of the screen,
|
||||
x = Screen.width * 0.3f - size * 0.5f;
|
||||
y = Screen.height - size - 10f * S;
|
||||
}
|
||||
|
||||
// 90% transparent when in game and panel is closed, full opacity otherwise
|
||||
bool fadeOut = !_open && GameStates.IsInGame;
|
||||
bool fadeOut = !IsOpen && GameStates.IsInGame;
|
||||
Color prev = GUI.color;
|
||||
if (fadeOut) GUI.color = new Color(1f, 1f, 1f, 0.10f);
|
||||
|
||||
if (GUI.Button(new Rect(x, y, size, size), _open ? "X" : "=", _sToggle))
|
||||
_open = !_open;
|
||||
if (GUI.Button(new Rect(x, y, size, size), IsOpen ? "X" : "=", _sToggle))
|
||||
IsOpen = !IsOpen;
|
||||
|
||||
if (fadeOut) GUI.color = prev;
|
||||
}
|
||||
@@ -325,7 +316,7 @@ public class ClientControlGUI : MonoBehaviour
|
||||
// ImGUI doesn't have built-in window dragging, so we do it manually with mouse events.
|
||||
private void HandleDrag()
|
||||
{
|
||||
if (!_open) return;
|
||||
if (!IsOpen) return;
|
||||
|
||||
Event e = Event.current;
|
||||
float titleH = BH * 0.80f + P;
|
||||
|
||||
@@ -29,6 +29,9 @@ internal static class ControllerManagerUpdatePatch
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ClientControlGUI.Instance && (Input.GetKeyDown(KeyCode.Minus) || Input.GetKeyDown(KeyCode.KeypadMinus)))
|
||||
ClientControlGUI.Instance.IsOpen = !ClientControlGUI.Instance.IsOpen;
|
||||
|
||||
if (HudManager.InstanceExists)
|
||||
{
|
||||
if (PlayerControl.LocalPlayer)
|
||||
@@ -223,9 +226,9 @@ internal static class ControllerManagerUpdatePatch
|
||||
Utils.SendMessage(GetString("HostKillSelfByCommand"), title: $"<color=#ff0000>{GetString("DefaultSystemMessageTitle")}</color>");
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
if (!Options.NoGameEnd.GetBool()) return;
|
||||
|
||||
#if DEBUG
|
||||
if (KeysDown(KeyCode.F2, KeyCode.LeftControl))
|
||||
{
|
||||
Logger.IsAlsoInGame = !Logger.IsAlsoInGame;
|
||||
@@ -369,10 +372,12 @@ internal static class ControllerManagerUpdatePatch
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
private static bool OrGetKeysDown(params KeyCode[] keys)
|
||||
{
|
||||
return keys.Any(Input.GetKeyDown);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
[HarmonyPatch(typeof(ConsoleJoystick), nameof(ConsoleJoystick.HandleHUD))]
|
||||
|
||||
@@ -78,21 +78,23 @@ public static class HandshakePatch
|
||||
|
||||
public static void Postfix(ref Il2CppStructArray<byte> __result)
|
||||
{
|
||||
if (GameStates.CurrentServerType is not (GameStates.ServerType.Modded or GameStates.ServerType.Niko)) return;
|
||||
|
||||
var handshake = new MessageWriter(1000);
|
||||
|
||||
// Original data
|
||||
handshake.Write(__result);
|
||||
|
||||
// Reactor Header
|
||||
var version = (byte) ReactorProtocolVersion.Latest;
|
||||
var value = (MAGIC << 8) | version;
|
||||
const byte version = (byte)ReactorProtocolVersion.Latest;
|
||||
const ulong value = (MAGIC << 8) | version;
|
||||
handshake.Write(value);
|
||||
|
||||
// ModdedHandshakeC2S
|
||||
handshake.WritePacked(1);
|
||||
handshake.Write(Main.PluginGuid);
|
||||
handshake.Write(Main.PluginVersion);
|
||||
handshake.Write((ushort) (ModFlags.RequireOnHost | ModFlags.RequireOnAllClients));
|
||||
handshake.Write((ushort)(ModFlags.RequireOnHost | ModFlags.RequireOnAllClients));
|
||||
|
||||
__result = handshake.ToByteArray(true);
|
||||
handshake.Recycle();
|
||||
|
||||
Reference in new issue
Block a user