67 lines
1.8 KiB
C#
67 lines
1.8 KiB
C#
using Dalamud.Interface.Windowing;
|
|
using LightlessSync.UI.Style;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace LightlessSync.Services.Mediator;
|
|
|
|
public abstract class WindowMediatorSubscriberBase : Window, IMediatorSubscriber, IDisposable
|
|
{
|
|
protected readonly ILogger _logger;
|
|
private readonly PerformanceCollectorService _performanceCollectorService;
|
|
|
|
protected WindowMediatorSubscriberBase(ILogger logger, LightlessMediator mediator, string name,
|
|
PerformanceCollectorService performanceCollectorService) : base(name)
|
|
{
|
|
_logger = logger;
|
|
Mediator = mediator;
|
|
_performanceCollectorService = performanceCollectorService;
|
|
_logger.LogTrace("Creating {type}", GetType());
|
|
|
|
Mediator.Subscribe<UiToggleMessage>(this, (msg) =>
|
|
{
|
|
if (msg.UiType == GetType())
|
|
{
|
|
Toggle();
|
|
}
|
|
});
|
|
}
|
|
|
|
public LightlessMediator Mediator { get; }
|
|
|
|
public void Dispose()
|
|
{
|
|
Dispose(disposing: true);
|
|
GC.SuppressFinalize(this);
|
|
}
|
|
|
|
public override void PreDraw()
|
|
{
|
|
base.PreDraw();
|
|
MainStyle.PushStyle(); // internally checks ShouldUseTheme
|
|
}
|
|
|
|
public override void PostDraw()
|
|
{
|
|
MainStyle.PopStyle(); // always attempts to pop if pushed
|
|
base.PostDraw();
|
|
}
|
|
|
|
public override void Draw()
|
|
{
|
|
_performanceCollectorService.LogPerformance(this, $"Draw", DrawInternal);
|
|
}
|
|
|
|
protected abstract void DrawInternal();
|
|
|
|
public virtual Task StopAsync(CancellationToken cancellationToken)
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
protected virtual void Dispose(bool disposing)
|
|
{
|
|
_logger.LogTrace("Disposing {type}", GetType());
|
|
|
|
Mediator.UnsubscribeAll(this);
|
|
}
|
|
} |