diff --git a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs index 5ba7473..779c2ab 100644 --- a/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs +++ b/MareSynchronos/MareConfiguration/Configurations/MareConfig.cs @@ -10,6 +10,7 @@ public class MareConfig : IMareConfiguration public string CacheFolder { get; set; } = string.Empty; public bool DisableOptionalPluginWarnings { get; set; } = false; public bool EnableRightClickMenus { get; set; } = true; + public bool EnableDtrEntry { get; set; } = false; public NotificationLocation ErrorNotification { get; set; } = NotificationLocation.Both; public string ExportFolder { get; set; } = string.Empty; public bool FileScanPaused { get; set; } = false; diff --git a/MareSynchronos/PlayerData/Pairs/PairManager.cs b/MareSynchronos/PlayerData/Pairs/PairManager.cs index e2a7437..2e2179a 100644 --- a/MareSynchronos/PlayerData/Pairs/PairManager.cs +++ b/MareSynchronos/PlayerData/Pairs/PairManager.cs @@ -90,6 +90,8 @@ public sealed class PairManager : DisposableMediatorSubscriberBase public List GetVisibleUsers() => _allClientPairs.Where(p => p.Value.IsVisible).Select(p => p.Key).ToList(); + public int GetVisibleUserCount() => _allClientPairs.Count(p => p.Value.IsVisible); + public void MarkPairOffline(UserData user) { if (_allClientPairs.TryGetValue(user, out var pair)) diff --git a/MareSynchronos/Plugin.cs b/MareSynchronos/Plugin.cs index 26dc180..3f51f7c 100644 --- a/MareSynchronos/Plugin.cs +++ b/MareSynchronos/Plugin.cs @@ -6,6 +6,7 @@ using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Objects; using Dalamud.Game.Command; using Dalamud.Game.Gui; +using Dalamud.Game.Gui.Dtr; using Dalamud.Interface.ImGuiFileDialog; using Dalamud.Interface.Windowing; using Dalamud.Plugin; @@ -36,7 +37,7 @@ public sealed class Plugin : IDalamudPlugin public Plugin(DalamudPluginInterface pluginInterface, CommandManager commandManager, DataManager gameData, Framework framework, ObjectTable objectTable, ClientState clientState, Condition condition, ChatGui chatGui, - GameGui gameGui) + GameGui gameGui, DtrBar dtrBar) { new HostBuilder() .UseContentRoot(pluginInterface.ConfigDirectory.FullName) @@ -75,6 +76,8 @@ public sealed class Plugin : IDalamudPlugin collection.AddSingleton((s) => new DalamudUtilService(s.GetRequiredService>(), clientState, objectTable, framework, gameGui, condition, gameData, s.GetRequiredService(), s.GetRequiredService())); + collection.AddSingleton((s) => new DtrEntry(dtrBar, s.GetRequiredService(), + s.GetRequiredService(), s.GetRequiredService())); collection.AddSingleton((s) => new IpcManager(s.GetRequiredService>(), pluginInterface, s.GetRequiredService(), s.GetRequiredService())); @@ -124,6 +127,7 @@ public sealed class Plugin : IDalamudPlugin collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); + collection.AddHostedService(p => p.GetRequiredService()); collection.AddHostedService(p => p.GetRequiredService()); }) .Build() diff --git a/MareSynchronos/UI/DtrEntry.cs b/MareSynchronos/UI/DtrEntry.cs new file mode 100644 index 0000000..11223d0 --- /dev/null +++ b/MareSynchronos/UI/DtrEntry.cs @@ -0,0 +1,99 @@ +using Dalamud.Game.Gui.Dtr; +using MareSynchronos.MareConfiguration; +using MareSynchronos.MareConfiguration.Configurations; +using MareSynchronos.PlayerData.Pairs; +using MareSynchronos.Utils; +using MareSynchronos.WebAPI; +using Microsoft.Extensions.Hosting; + +namespace MareSynchronos.UI; + +public sealed class DtrEntry : IDisposable, IHostedService +{ + private readonly DtrBarEntry _entry; + private readonly ConfigurationServiceBase _configService; + private readonly PairManager _pairManager; + private readonly ApiController _apiController; + + private readonly CancellationTokenSource _cancellationTokenSource = new(); + private Task? _runTask; + private string? _text; + + public DtrEntry(DtrBar dtrBar, ConfigurationServiceBase configService, PairManager pairManager, ApiController apiController) + { + _entry = dtrBar.Get("Mare Synchronos"); + _configService = configService; + _pairManager = pairManager; + _apiController = apiController; + + Clear(); + } + + public void Dispose() + { + _entry.Dispose(); + } + + private void Update() + { + if (!_configService.Current.EnableDtrEntry) + { + if (_entry.Shown) + { + Clear(); + } + return; + } + + if (!_entry.Shown) + { + _entry.Shown = true; + } + + string text; + if (_apiController.IsConnected) + { + text = $"\uE044 {_pairManager.GetVisibleUserCount()}"; + } + else + { + text = "\uE044 \uE04C"; + } + if (!string.Equals(text, _text, StringComparison.Ordinal)) + { + _text = text; + _entry.Text = text; + } + } + + private void Clear() + { + _text = null; + + _entry.Shown = false; + _entry.Text = null; + } + + private async Task RunAsync() + { + while (!_cancellationTokenSource.IsCancellationRequested) + { + Update(); + await Task.Delay(1000, _cancellationTokenSource.Token).ConfigureAwait(false); + } + } + + public Task StartAsync(CancellationToken cancellationToken) + { + _runTask = Task.Run(RunAsync, _cancellationTokenSource.Token); + return Task.CompletedTask; + } + + public async Task StopAsync(CancellationToken cancellationToken) + { + _cancellationTokenSource.Cancel(); + await _runTask!.ConfigureAwait(false); + _cancellationTokenSource.Dispose(); + Clear(); + } +} \ No newline at end of file diff --git a/MareSynchronos/UI/SettingsUi.cs b/MareSynchronos/UI/SettingsUi.cs index 839f24a..efd2c24 100644 --- a/MareSynchronos/UI/SettingsUi.cs +++ b/MareSynchronos/UI/SettingsUi.cs @@ -515,6 +515,7 @@ public class SettingsUi : WindowMediatorSubscriberBase var profileDelay = _configService.Current.ProfileDelay; var profileOnRight = _configService.Current.ProfilePopoutRight; var enableRightClickMenu = _configService.Current.EnableRightClickMenus; + var enableDtrEntry = _configService.Current.EnableDtrEntry; var preferNotesInsteadOfName = _configService.Current.PreferNotesOverNamesForVisible; if (ImGui.Checkbox("Enable Game Right Click Menu Entries", ref enableRightClickMenu)) @@ -524,6 +525,13 @@ public class SettingsUi : WindowMediatorSubscriberBase } UiSharedService.DrawHelpText("This will add Mare related right click menu entries in the game UI on paired players."); + if (ImGui.Checkbox("Display status and visible pair count in Server Info Bar", ref enableDtrEntry)) + { + _configService.Current.EnableDtrEntry = enableDtrEntry; + _configService.Save(); + } + UiSharedService.DrawHelpText("This will add Mare connection status and visible pair count in the Server Info Bar.\nYou can further configure this through your Dalamud Settings."); + if (ImGui.Checkbox("Show separate Visible group", ref showVisibleSeparate)) { _configService.Current.ShowVisibleUsersSeparately = showVisibleSeparate;