Move MainMenu code to a separate service that just injects our stuff into the mainmenu
This commit is contained in:
@@ -531,25 +531,6 @@ namespace Barotrauma
|
||||
}
|
||||
};
|
||||
#endif
|
||||
/*new GUIButton(new RectTransform(new Point(300, 30), Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(40, 50) },
|
||||
$"Open LuaCs Settings", style: "MainMenuGUIButton", color: GUIStyle.Red)
|
||||
{
|
||||
IgnoreLayoutGroups = true,
|
||||
OnClicked = (tb, userdata) =>
|
||||
{
|
||||
LuaCsSettingsMenu.Open(Frame.RectTransform);
|
||||
return true;
|
||||
}
|
||||
};*/
|
||||
|
||||
// TODO: Implement version reading.
|
||||
//string version = File.Exists(LuaCsSetup.VersionFile) ? File.ReadAllText(LuaCsSetup.VersionFile) : "Github";
|
||||
string version = "NOT_IMPLEMENTED";
|
||||
|
||||
new GUITextBlock(new RectTransform(new Point(300, 30), Frame.RectTransform, Anchor.TopLeft) { AbsoluteOffset = new Point(10, 10) }, $"Using LuaCsForBarotrauma revision {AssemblyInfo.GitRevision} version {version}", Color.Red)
|
||||
{
|
||||
IgnoreLayoutGroups = false
|
||||
};
|
||||
|
||||
var minButtonSize = new Point(120, 20);
|
||||
var maxButtonSize = new Point(480, 80);
|
||||
|
||||
@@ -195,7 +195,8 @@ namespace Barotrauma
|
||||
servicesProvider.RegisterServiceType<INetworkIdProvider, NetworkingIdProvider>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<HarmonyEventPatchesService, HarmonyEventPatchesService>(ServiceLifetime.Singleton);
|
||||
servicesProvider.RegisterServiceType<IConsoleCommandsService, ConsoleCommandsService>(ServiceLifetime.Transient);
|
||||
|
||||
servicesProvider.RegisterServiceType<MainMenuPatch, MainMenuPatch>(ServiceLifetime.Singleton);
|
||||
|
||||
// Extension/Sub Services
|
||||
servicesProvider.RegisterServiceType<IAssemblyLoaderService.IFactory, AssemblyLoader.Factory>(ServiceLifetime.Transient);
|
||||
servicesProvider.RegisterServiceType<ISettingsRegistrationProvider, SettingsEntryRegistrar>(ServiceLifetime.Transient);
|
||||
@@ -348,6 +349,7 @@ namespace Barotrauma
|
||||
LuaScriptManagementService.Reset();
|
||||
PackageManagementService.Reset();
|
||||
NetworkingService.Reset();
|
||||
_servicesProvider.GetService<MainMenuPatch>().Reset();
|
||||
|
||||
Logger.LogMessage("Services have been reset");
|
||||
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user