Skip to content

Commit 4d5ca54

Browse files
committed
fix(ui): restore NoEOL menu mouse interaction
1 parent e33440c commit 4d5ca54

2 files changed

Lines changed: 92 additions & 10 deletions

File tree

NoMoreEOL/Core.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public override void OnInitializeMelon()
5757
ModReleaseLog.ConfigEvent($"AutoRepairServers = {_prefAutoRepairServers.Value}");
5858
ModReleaseLog.ConfigEvent($"HideWarningTriangles = {_prefHideWarningTriangles.Value}");
5959

60-
LoggerInstance.Msg("gregMod.NoEOL v1.8.0 loaded. Press F5 for configuration.");
61-
ModReleaseLog.Info("gregMod.NoEOL v1.8.0 initialized successfully");
60+
LoggerInstance.Msg("gregMod.NoEOL v1.8.1 loaded. Press F5 for configuration.");
61+
ModReleaseLog.Info("gregMod.NoEOL v1.8.1 initialized successfully");
6262
ModReleaseLog.Info($"Release log: {ModReleaseLog.LogPath}");
6363
}
6464

NoMoreEOL/NoEolOverlay.cs

Lines changed: 90 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using MelonLoader;
22
using UnityEngine;
3+
using UnityEngine.InputSystem;
34

45
namespace GregModNoEOL;
56

@@ -61,7 +62,10 @@ internal static class NoEolOverlay
6162
private static readonly Color ColTealAccent = new(80f / 255f, 220f / 255f, 210f / 255f, 1f);
6263

6364
private const float WindowW = 420f;
64-
private const float WindowH = 450f;
65+
private const float WindowH = 560f;
66+
67+
private static int _hardwareClickFrame = -1;
68+
private static bool _hardwareClickHandled;
6569

6670
public static bool IsVisible
6771
{
@@ -119,6 +123,15 @@ public static void Draw()
119123
Cursor.lockState = CursorLockMode.None;
120124
Cursor.visible = true;
121125

126+
// Unity 6 / Input System can prevent IMGUI from receiving mouse events.
127+
// Process the hardware pointer before GUI.Window as a reliable fallback.
128+
if (_hardwareClickFrame != Time.frameCount)
129+
{
130+
_hardwareClickFrame = Time.frameCount;
131+
_hardwareClickHandled = false;
132+
}
133+
HandleHardwareMouseClick();
134+
122135
_windowRect = GUI.Window(9002, _windowRect, (GUI.WindowFunction)DrawWindow, "", _stBackdrop);
123136
}
124137

@@ -134,7 +147,7 @@ private static void DrawWindow(int id)
134147
GUI.Label(new Rect(16, 12, r.width - 80, 28), "NoEOL . Data Center", _stWindowTitle);
135148

136149
var closeBtnRect = new Rect(r.width - 40, 10, 28, 28);
137-
if (GUI.Button(closeBtnRect, "✕", _stMutedBtn))
150+
if (!_hardwareClickHandled && GUI.Button(closeBtnRect, "✕", _stMutedBtn))
138151
{
139152
_isVisible = false;
140153
GameInputSuppression.SetSuppressed(false);
@@ -182,7 +195,7 @@ private static void DrawWindow(int id)
182195

183196
var btnW = 120f;
184197
var btnX = r.width - pad - btnW;
185-
if (GUI.Button(new Rect(btnX, contentY, btnW, 32), "Close", _stMutedBtn))
198+
if (!_hardwareClickHandled && GUI.Button(new Rect(btnX, contentY, btnW, 32), "Close", _stMutedBtn))
186199
{
187200
_isVisible = false;
188201
GameInputSuppression.SetSuppressed(false);
@@ -205,12 +218,9 @@ private static float DrawToggleCard(float x, float y, float w, string title, str
205218
var toggleH = 26f;
206219
var toggleRect = new Rect(x + w - toggleW - 12, y + (cardH - toggleH) * 0.5f, toggleW, toggleH);
207220

208-
if (GUI.Button(toggleRect, toggleText, toggleStyle))
221+
if (!_hardwareClickHandled && GUI.Button(toggleRect, toggleText, toggleStyle))
209222
{
210-
pref.Value = !pref.Value;
211-
MelonPreferences.Save();
212-
ModReleaseLog.ConfigEvent($"{pref.DisplayName} = {pref.Value}");
213-
onChanged?.Invoke(pref.Value);
223+
TogglePreference(pref, onChanged);
214224
}
215225

216226
var textX = x + 14;
@@ -221,6 +231,78 @@ private static float DrawToggleCard(float x, float y, float w, string title, str
221231
return y + cardH + 8f;
222232
}
223233

234+
private static void HandleHardwareMouseClick()
235+
{
236+
var mouse = Mouse.current;
237+
if (mouse == null || !mouse.leftButton.wasPressedThisFrame)
238+
return;
239+
240+
if (_hardwareClickHandled)
241+
return;
242+
243+
var screen = mouse.position.ReadValue();
244+
screen.y = Screen.height - screen.y;
245+
var local = new Vector2(screen.x - _windowRect.x, screen.y - _windowRect.y);
246+
247+
var closeTop = new Rect(_windowRect.width - 40f, 10f, 28f, 28f);
248+
if (closeTop.Contains(local))
249+
{
250+
IsVisible = false;
251+
_hardwareClickHandled = true;
252+
return;
253+
}
254+
255+
const float titleBarH = 52f;
256+
const float pad = 20f;
257+
const float cardH = 62f;
258+
const float cardGap = 8f;
259+
const float toggleW = 52f;
260+
const float toggleH = 26f;
261+
var contentY = titleBarH + 8f + 30f + 28f;
262+
var contentW = _windowRect.width - pad * 2f;
263+
264+
var prefs = new[]
265+
{
266+
(_prefDisableSwitchEol, (System.Action<bool>)null),
267+
(_prefDisableServerEol, (System.Action<bool>)null),
268+
(_prefAutoRepairSwitches, (System.Action<bool>)null),
269+
(_prefAutoRepairServers, (System.Action<bool>)null),
270+
(_prefHideWarningTriangles, (System.Action<bool>)(visible => EolHider.ApplyVisibility(visible)))
271+
};
272+
273+
foreach (var (pref, onChanged) in prefs)
274+
{
275+
var toggleRect = new Rect(
276+
pad + contentW - toggleW - 12f,
277+
contentY + (cardH - toggleH) * 0.5f,
278+
toggleW, toggleH);
279+
if (toggleRect.Contains(local))
280+
{
281+
TogglePreference(pref, onChanged);
282+
_hardwareClickHandled = true;
283+
return;
284+
}
285+
contentY += cardH + cardGap;
286+
}
287+
288+
contentY += 8f;
289+
var closeBottom = new Rect(_windowRect.width - pad - 120f, contentY, 120f, 32f);
290+
if (closeBottom.Contains(local))
291+
{
292+
IsVisible = false;
293+
_hardwareClickHandled = true;
294+
}
295+
}
296+
297+
private static void TogglePreference(MelonPreferences_Entry<bool> pref, System.Action<bool> onChanged)
298+
{
299+
if (pref == null) return;
300+
pref.Value = !pref.Value;
301+
MelonPreferences.Save();
302+
ModReleaseLog.ConfigEvent($"{pref.DisplayName} = {pref.Value}");
303+
onChanged?.Invoke(pref.Value);
304+
}
305+
224306
private static void DrawBorder(Rect r, Texture2D tex)
225307
{
226308
GUI.DrawTexture(new Rect(r.x, r.y, r.width, 1), tex);

0 commit comments

Comments
 (0)