Add public control sawmill to UI Manager (#6231)

* Add public control sawmill

* Remove static IoCManager in MarkupTagManager

* very important comment

* release notes

* fix merge

* fix
This commit is contained in:
Leon Friedrich
2025-11-13 23:33:50 +13:00
committed by GitHub
parent b15d960c69
commit 80cad0cd8f
6 changed files with 22 additions and 8 deletions

View File

@@ -41,7 +41,7 @@ END TEMPLATE-->
### New features
*None yet*
* Added `IUserInterfaceManager.ControlSawmill` and `Control.Log` properties so that controls can easily use logging without using static methods.
### Bugfixes

View File

@@ -11,6 +11,7 @@ using Robust.Client.UserInterface.Themes;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Animations;
using Robust.Shared.IoC;
using Robust.Shared.Log;
using Robust.Shared.Maths;
using Robust.Shared.Timing;
using Robust.Shared.Utility;
@@ -74,6 +75,8 @@ namespace Robust.Client.UserInterface
// _nameScope = nameScope;
//}
public virtual ISawmill Log => UserInterfaceManager.ControlSawmill;
public UITheme Theme { get; internal set; }
private UITheme? _themeOverride;
@@ -381,8 +384,6 @@ namespace Robust.Client.UserInterface
/// </summary>
public event EventHandler? OnShowTooltip;
/// <summary>
/// If this control is currently showing a tooltip provided via TooltipSupplier,
/// returns that tooltip. Do not move this control within the tree, it should remain in PopupRoot.

View File

@@ -6,6 +6,7 @@ using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Shared;
using Robust.Shared.Audio.Sources;
using Robust.Shared.Log;
using Robust.Shared.Map;
using Robust.Shared.Maths;
@@ -157,6 +158,14 @@ namespace Robust.Client.UserInterface
/// Render a control and all of its children.
/// </summary>
void RenderControl(IRenderHandle handle, Control control, Vector2i position);
/// <summary>
/// Sawmill for use by controls.
/// </summary>
/// <remarks>
/// Exists so that control don't have to inject dependencies or otherwise obtain an <see cref="ILogManager"/> instance just to log errors.
/// </remarks>
ISawmill ControlSawmill { get; }
}
public readonly struct PostDrawUIRootEventArgs

View File

@@ -12,11 +12,13 @@ public sealed class MarkupTagManager
{
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
[Dependency] private readonly ISandboxHelper _sandboxHelper = default!;
[Dependency] private readonly IDependencyCollection _deps = default!;
/// <summary>
/// Tags defined in engine need to be instantiated here because of sandboxing
/// </summary>
private readonly Dictionary<string, IMarkupTagHandler> _markupTagTypes = new IMarkupTagHandler[] {
private readonly Dictionary<string, IMarkupTagHandler> _markupTagTypes = new IMarkupTagHandler[]
{
new BoldItalicTag(),
new BoldTag(),
new BulletTag(),
@@ -50,13 +52,13 @@ public sealed class MarkupTagManager
if (_engineTypes.Contains(type))
continue;
var instance = (IMarkupTagHandler)_sandboxHelper.CreateInstance(type);
var instance = (IMarkupTagHandler) _sandboxHelper.CreateInstance(type);
_markupTagTypes[instance.Name.ToLower()] = instance;
}
foreach (var (_, tag) in _markupTagTypes)
foreach (var tag in _markupTagTypes.Values)
{
IoCManager.InjectDependencies(tag);
_deps.InjectDependencies(tag);
}
}

View File

@@ -100,6 +100,7 @@ namespace Robust.Client.UserInterface
private Stylesheet? _stylesheet;
private ISawmill _sawmillUI = default!;
public ISawmill ControlSawmill { get; private set; } = default!;
public event Action<Control>? OnKeyBindDown;
@@ -147,6 +148,7 @@ namespace Robust.Client.UserInterface
private void _initializeCommon()
{
_sawmillUI = _logManager.GetSawmill("ui");
ControlSawmill = _logManager.GetSawmill("ctrl");
RootControl = CreateWindowRoot(_clyde.MainWindow);
RootControl.Name = "MainWindowRoot";

View File

@@ -19,7 +19,7 @@ namespace Robust.Shared.Log
/// The instance we're using.
/// As it's a direct proxy to IoC this will not work if IoC is not functional.
/// </summary>
// TODO: Maybe cache this to improve performance.
// TODO: Kill
private static ILogManager LogManagerSingleton => IoCManager.Resolve<ILogManager>();
/// <summary>