DTR entry: Click to open main UI (#62)

This commit is contained in:
N. Lo
2023-10-05 23:51:22 +02:00
committed by GitHub
parent 9cf8a83223
commit fe30812aa7
2 changed files with 16 additions and 5 deletions

View File

@@ -3,6 +3,7 @@ using Dalamud.Plugin.Services;
using MareSynchronos.MareConfiguration;
using MareSynchronos.MareConfiguration.Configurations;
using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.Mediator;
using MareSynchronos.WebAPI;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
@@ -16,17 +17,19 @@ public sealed class DtrEntry : IDisposable, IHostedService
private readonly ILogger<DtrEntry> _logger;
private readonly IDtrBar _dtrBar;
private readonly ConfigurationServiceBase<MareConfig> _configService;
private readonly MareMediator _mareMediator;
private Lazy<DtrBarEntry> _entry;
private readonly PairManager _pairManager;
private Task? _runTask;
private string? _text;
public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, ConfigurationServiceBase<MareConfig> configService, PairManager pairManager, ApiController apiController)
public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, ConfigurationServiceBase<MareConfig> configService, MareMediator mareMediator, PairManager pairManager, ApiController apiController)
{
_logger = logger;
_dtrBar = dtrBar;
_entry = new(() => _dtrBar.Get("Mare Synchronos"));
_entry = new(CreateEntry);
_configService = configService;
_mareMediator = mareMediator;
_pairManager = pairManager;
_apiController = apiController;
}
@@ -63,6 +66,14 @@ public sealed class DtrEntry : IDisposable, IHostedService
}
}
private DtrBarEntry CreateEntry()
{
var entry = _dtrBar.Get("Mare Synchronos");
entry.OnClick = () => _mareMediator.Publish(new UiToggleMessage(typeof(CompactUi)));
return entry;
}
private void Clear()
{
if (!_entry.IsValueCreated) return;
@@ -72,7 +83,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
_entry.Value.Shown = false;
_entry.Value.Text = null;
_entry.Value.Dispose();
_entry = new(() => _dtrBar.Get("Mare Synchronos"));
_entry = new(CreateEntry);
}
private async Task RunAsync()
@@ -87,7 +98,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
private void Update()
{
if (!_configService.Current.EnableDtrEntry)
if (!_configService.Current.EnableDtrEntry || !_configService.Current.HasValidSetup())
{
if (_entry.IsValueCreated && _entry.Value.Shown)
{