Add DTR entry with number of visible pairs (#52)
* Add DTR entry with number of visible pairs * Simplify DTR visible pair counter - Merge the new PairHandlerInvisibleMessage and PairHandlerVisibleDisposedMessage ; - Leave alone a bunch of messages that were actually unneccessary. * Match encodings with the rest of the codebase * Make the DTR entry opt-in and add explanations * More reliable publishing of PairHandlerVisible/Invisible * Simplify things for DTR * Rework async
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -90,6 +90,8 @@ public sealed class PairManager : DisposableMediatorSubscriberBase
|
||||
|
||||
public List<UserData> 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))
|
||||
|
||||
@@ -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<ILogger<DalamudUtilService>>(),
|
||||
clientState, objectTable, framework, gameGui, condition, gameData,
|
||||
s.GetRequiredService<MareMediator>(), s.GetRequiredService<PerformanceCollectorService>()));
|
||||
collection.AddSingleton((s) => new DtrEntry(dtrBar, s.GetRequiredService<MareConfigService>(),
|
||||
s.GetRequiredService<PairManager>(), s.GetRequiredService<ApiController>()));
|
||||
collection.AddSingleton((s) => new IpcManager(s.GetRequiredService<ILogger<IpcManager>>(),
|
||||
pluginInterface, s.GetRequiredService<DalamudUtilService>(), s.GetRequiredService<MareMediator>()));
|
||||
|
||||
@@ -124,6 +127,7 @@ public sealed class Plugin : IDalamudPlugin
|
||||
collection.AddHostedService(p => p.GetRequiredService<ConfigurationMigrator>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<DalamudUtilService>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<PerformanceCollectorService>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<DtrEntry>());
|
||||
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
|
||||
})
|
||||
.Build()
|
||||
|
||||
99
MareSynchronos/UI/DtrEntry.cs
Normal file
99
MareSynchronos/UI/DtrEntry.cs
Normal file
@@ -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<MareConfig> _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<MareConfig> 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();
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user