Move MainMenu code to a separate service that just injects our stuff into the mainmenu

This commit is contained in:
Evil Factory
2026-03-15 17:52:40 -03:00
parent 80832459b9
commit b402e09b82
3 changed files with 70 additions and 20 deletions
@@ -0,0 +1,67 @@
using Barotrauma;
using Barotrauma.LuaCs;
using Barotrauma.LuaCs.Events;
using FluentResults;
using HarmonyLib;
using Microsoft.Xna.Framework;
[HarmonyPatch]
internal class MainMenuPatch : ISystem, IEventScreenSelected
{
public bool IsDisposed { get; private set; }
private readonly IEventService _eventService;
public MainMenuPatch(IEventService eventService)
{
_eventService = eventService;
RegisterEvents();
#if CLIENT
if (Screen.Selected is MainMenuScreen mainMenuScreen)
{
AddToMainMenu(mainMenuScreen);
}
#endif
}
public void OnScreenSelected(Screen screen)
{
#if CLIENT
if (screen is MainMenuScreen mainMenuScreen)
{
AddToMainMenu(mainMenuScreen);
}
#endif
}
#if CLIENT
private void AddToMainMenu(MainMenuScreen screen)
{
new GUITextBlock(new RectTransform(new Point(300, 30), screen.Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(10, 10) }, $"Using LuaCsForBarotrauma revision {AssemblyInfo.GitRevision}", Color.Red)
{
IgnoreLayoutGroups = false
};
}
#endif
private void RegisterEvents()
{
_eventService.Subscribe<IEventScreenSelected>(this);
}
public void Dispose()
{
_eventService.Unsubscribe<IEventScreenSelected>(this);
IsDisposed = true;
}
public FluentResults.Result Reset()
{
RegisterEvents();
return FluentResults.Result.Ok();
}
}