Update 0.1.8.2 - Correctif UI, Correctif Nearby CompactUI, Add changelog

This commit is contained in:
2025-09-27 10:02:43 +02:00
parent bf770f19d9
commit 6572fdcc27
11 changed files with 481 additions and 69 deletions

View File

@@ -59,6 +59,7 @@ public class MareConfig : IMareConfiguration
public bool ShowUploading { get; set; } = true; public bool ShowUploading { get; set; } = true;
public bool ShowUploadingBigText { get; set; } = true; public bool ShowUploadingBigText { get; set; } = true;
public bool ShowVisibleUsersSeparately { get; set; } = true; public bool ShowVisibleUsersSeparately { get; set; } = true;
public string LastChangelogVersionSeen { get; set; } = string.Empty;
public bool EnableAutoDetectDiscovery { get; set; } = false; public bool EnableAutoDetectDiscovery { get; set; } = false;
public bool AllowAutoDetectPairRequests { get; set; } = false; public bool AllowAutoDetectPairRequests { get; set; } = false;
public int AutoDetectMaxDistanceMeters { get; set; } = 40; public int AutoDetectMaxDistanceMeters { get; set; } = 40;

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<AssemblyName>UmbraSync</AssemblyName> <AssemblyName>UmbraSync</AssemblyName>
<RootNamespace>UmbraSync</RootNamespace> <RootNamespace>UmbraSync</RootNamespace>
<Version>0.1.8.1</Version> <Version>0.1.8.2</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@@ -182,6 +182,7 @@ public sealed class Plugin : IDalamudPlugin
collection.AddScoped<WindowMediatorSubscriberBase, IntroUi>(); collection.AddScoped<WindowMediatorSubscriberBase, IntroUi>();
collection.AddScoped<WindowMediatorSubscriberBase, DownloadUi>(); collection.AddScoped<WindowMediatorSubscriberBase, DownloadUi>();
collection.AddScoped<WindowMediatorSubscriberBase, AutoDetectUi>(); collection.AddScoped<WindowMediatorSubscriberBase, AutoDetectUi>();
collection.AddScoped<WindowMediatorSubscriberBase, ChangelogUi>();
collection.AddScoped<WindowMediatorSubscriberBase, PopoutProfileUi>(); collection.AddScoped<WindowMediatorSubscriberBase, PopoutProfileUi>();
collection.AddScoped<WindowMediatorSubscriberBase, DataAnalysisUi>(); collection.AddScoped<WindowMediatorSubscriberBase, DataAnalysisUi>();
collection.AddScoped<WindowMediatorSubscriberBase, EventViewerUI>(); collection.AddScoped<WindowMediatorSubscriberBase, EventViewerUI>();

View File

@@ -1,3 +1,5 @@
using System;
using System.Collections.Generic;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using MareSynchronos.WebAPI.AutoDetect; using MareSynchronos.WebAPI.AutoDetect;
using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration;
@@ -15,6 +17,11 @@ public class AutoDetectRequestService
private readonly MareConfigService _configService; private readonly MareConfigService _configService;
private readonly DalamudUtilService _dalamud; private readonly DalamudUtilService _dalamud;
private readonly MareMediator _mediator; private readonly MareMediator _mediator;
private readonly object _syncRoot = new();
private readonly Dictionary<string, DateTime> _activeCooldowns = new(StringComparer.Ordinal);
private readonly Dictionary<string, RefusalTracker> _refusalTrackers = new(StringComparer.Ordinal);
private static readonly TimeSpan RequestCooldown = TimeSpan.FromMinutes(5);
private static readonly TimeSpan RefusalLockDuration = TimeSpan.FromMinutes(15);
public AutoDetectRequestService(ILogger<AutoDetectRequestService> logger, DiscoveryConfigProvider configProvider, DiscoveryApiClient client, MareConfigService configService, MareMediator mediator, DalamudUtilService dalamudUtilService) public AutoDetectRequestService(ILogger<AutoDetectRequestService> logger, DiscoveryConfigProvider configProvider, DiscoveryApiClient client, MareConfigService configService, MareMediator mediator, DalamudUtilService dalamudUtilService)
{ {
@@ -26,7 +33,7 @@ public class AutoDetectRequestService
_dalamud = dalamudUtilService; _dalamud = dalamudUtilService;
} }
public async Task<bool> SendRequestAsync(string token, CancellationToken ct = default) public async Task<bool> SendRequestAsync(string token, string? uid = null, string? targetDisplayName = null, CancellationToken ct = default)
{ {
if (!_configService.Current.AllowAutoDetectPairRequests) if (!_configService.Current.AllowAutoDetectPairRequests)
{ {
@@ -34,6 +41,47 @@ public class AutoDetectRequestService
_mediator.Publish(new NotificationMessage("Nearby request blocked", "Enable 'Allow pair requests' in Settings to send requests.", NotificationType.Info)); _mediator.Publish(new NotificationMessage("Nearby request blocked", "Enable 'Allow pair requests' in Settings to send requests.", NotificationType.Info));
return false; return false;
} }
var targetKey = BuildTargetKey(uid, token, targetDisplayName);
if (!string.IsNullOrEmpty(targetKey))
{
var now = DateTime.UtcNow;
lock (_syncRoot)
{
if (_refusalTrackers.TryGetValue(targetKey, out var tracker))
{
if (tracker.LockUntil.HasValue && tracker.LockUntil.Value > now)
{
PublishLockNotification(tracker.LockUntil.Value - now);
return false;
}
if (tracker.LockUntil.HasValue && tracker.LockUntil.Value <= now)
{
tracker.LockUntil = null;
tracker.Count = 0;
if (tracker.Count == 0 && tracker.LockUntil == null)
{
_refusalTrackers.Remove(targetKey);
}
}
}
if (_activeCooldowns.TryGetValue(targetKey, out var lastSent))
{
var elapsed = now - lastSent;
if (elapsed < RequestCooldown)
{
PublishCooldownNotification(RequestCooldown - elapsed);
return false;
}
if (elapsed >= RequestCooldown)
{
_activeCooldowns.Remove(targetKey);
}
}
}
}
var endpoint = _configProvider.RequestEndpoint; var endpoint = _configProvider.RequestEndpoint;
if (string.IsNullOrEmpty(endpoint)) if (string.IsNullOrEmpty(endpoint))
{ {
@@ -53,10 +101,51 @@ public class AutoDetectRequestService
var ok = await _client.SendRequestAsync(endpoint!, token, displayName, ct).ConfigureAwait(false); var ok = await _client.SendRequestAsync(endpoint!, token, displayName, ct).ConfigureAwait(false);
if (ok) if (ok)
{ {
if (!string.IsNullOrEmpty(targetKey))
{
lock (_syncRoot)
{
_activeCooldowns[targetKey] = DateTime.UtcNow;
if (_refusalTrackers.TryGetValue(targetKey, out var tracker))
{
tracker.Count = 0;
tracker.LockUntil = null;
if (tracker.Count == 0 && tracker.LockUntil == null)
{
_refusalTrackers.Remove(targetKey);
}
}
}
}
_mediator.Publish(new NotificationMessage("Nearby request sent", "The other user will receive a request notification.", NotificationType.Info)); _mediator.Publish(new NotificationMessage("Nearby request sent", "The other user will receive a request notification.", NotificationType.Info));
} }
else else
{ {
if (!string.IsNullOrEmpty(targetKey))
{
var now = DateTime.UtcNow;
lock (_syncRoot)
{
_activeCooldowns.Remove(targetKey);
if (!_refusalTrackers.TryGetValue(targetKey, out var tracker))
{
tracker = new RefusalTracker();
_refusalTrackers[targetKey] = tracker;
}
if (tracker.LockUntil.HasValue && tracker.LockUntil.Value <= now)
{
tracker.LockUntil = null;
tracker.Count = 0;
}
tracker.Count++;
if (tracker.Count >= 3)
{
tracker.LockUntil = now.Add(RefusalLockDuration);
}
}
}
_mediator.Publish(new NotificationMessage("Nearby request failed", "The server rejected the request. Try again soon.", NotificationType.Warning)); _mediator.Publish(new NotificationMessage("Nearby request failed", "The server rejected the request. Try again soon.", NotificationType.Warning));
} }
return ok; return ok;
@@ -80,4 +169,42 @@ public class AutoDetectRequestService
_logger.LogInformation("Nearby: sending accept notify via {endpoint}", endpoint); _logger.LogInformation("Nearby: sending accept notify via {endpoint}", endpoint);
return await _client.SendAcceptAsync(endpoint!, targetUid, displayName, ct).ConfigureAwait(false); return await _client.SendAcceptAsync(endpoint!, targetUid, displayName, ct).ConfigureAwait(false);
} }
private static string? BuildTargetKey(string? uid, string? token, string? displayName)
{
if (!string.IsNullOrEmpty(uid)) return "uid:" + uid;
if (!string.IsNullOrEmpty(token)) return "token:" + token;
if (!string.IsNullOrEmpty(displayName)) return "name:" + displayName;
return null;
}
private void PublishCooldownNotification(TimeSpan remaining)
{
var durationText = FormatDuration(remaining);
_mediator.Publish(new NotificationMessage("Nearby request en attente", $"Nearby request déjà envoyée. Merci d'attendre environ {durationText} avant de réessayer.", NotificationType.Info, TimeSpan.FromSeconds(5)));
}
private void PublishLockNotification(TimeSpan remaining)
{
var durationText = FormatDuration(remaining);
_mediator.Publish(new NotificationMessage("Nearby request bloquée", $"Nearby request bloquée après plusieurs refus. Réessayez dans {durationText}.", NotificationType.Warning, TimeSpan.FromSeconds(5)));
}
private static string FormatDuration(TimeSpan remaining)
{
if (remaining.TotalMinutes >= 1)
{
var minutes = Math.Max(1, (int)Math.Ceiling(remaining.TotalMinutes));
return minutes == 1 ? "1 minute" : minutes + " minutes";
}
var seconds = Math.Max(1, (int)Math.Ceiling(remaining.TotalSeconds));
return seconds == 1 ? "1 seconde" : seconds + " secondes";
}
private sealed class RefusalTracker
{
public int Count;
public DateTime? LockUntil;
}
} }

View File

@@ -201,7 +201,7 @@ public sealed class CharaDataNearbyManager : DisposableMediatorSubscriberBase
foreach (var data in _metaInfoCache.Where(d => (string.IsNullOrWhiteSpace(UserNoteFilter) foreach (var data in _metaInfoCache.Where(d => (string.IsNullOrWhiteSpace(UserNoteFilter)
|| ((d.Key.Alias ?? string.Empty).Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase) || ((d.Key.Alias ?? string.Empty).Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase)
|| d.Key.UID.Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase) || d.Key.UID.Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase)
|| (_serverConfigurationManager.GetNoteForUid(UserNoteFilter) ?? string.Empty).Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase)))) || (_serverConfigurationManager.GetNoteForUid(d.Key.UID) ?? string.Empty).Contains(UserNoteFilter, StringComparison.OrdinalIgnoreCase))))
.ToDictionary(k => k.Key, k => k.Value)) .ToDictionary(k => k.Key, k => k.Value))
{ {
// filter all poses based on territory, that always must be correct // filter all poses based on territory, that always must be correct

View File

@@ -1,4 +1,5 @@
using Dalamud.Game.Text.SeStringHandling; using System;
using Dalamud.Game.Text.SeStringHandling;
using Dalamud.Interface.ImGuiNotification; using Dalamud.Interface.ImGuiNotification;
using Dalamud.Plugin.Services; using Dalamud.Plugin.Services;
using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration;
@@ -81,41 +82,94 @@ public class NotificationService : DisposableMediatorSubscriberBase, IHostedServ
if (!_dalamudUtilService.IsLoggedIn) return; if (!_dalamudUtilService.IsLoggedIn) return;
switch (msg.Type) bool appendInstruction;
bool forceChat = ShouldForceChat(msg, out appendInstruction);
var effectiveMessage = forceChat && appendInstruction ? AppendUsyncInstruction(msg.Message) : msg.Message;
var adjustedMsg = forceChat && appendInstruction ? msg with { Message = effectiveMessage } : msg;
switch (adjustedMsg.Type)
{ {
case NotificationType.Info: case NotificationType.Info:
ShowNotificationLocationBased(msg, _configurationService.Current.InfoNotification); ShowNotificationLocationBased(adjustedMsg, _configurationService.Current.InfoNotification, forceChat);
break; break;
case NotificationType.Warning: case NotificationType.Warning:
ShowNotificationLocationBased(msg, _configurationService.Current.WarningNotification); ShowNotificationLocationBased(adjustedMsg, _configurationService.Current.WarningNotification, forceChat);
break; break;
case NotificationType.Error: case NotificationType.Error:
ShowNotificationLocationBased(msg, _configurationService.Current.ErrorNotification); ShowNotificationLocationBased(adjustedMsg, _configurationService.Current.ErrorNotification, forceChat);
break; break;
} }
} }
private void ShowNotificationLocationBased(NotificationMessage msg, NotificationLocation location) private static bool ShouldForceChat(NotificationMessage msg, out bool appendInstruction)
{ {
switch (location) appendInstruction = false;
bool IsNearbyRequestText(string? text)
{
if (string.IsNullOrEmpty(text)) return false;
return text.Contains("Nearby request", StringComparison.OrdinalIgnoreCase)
|| text.Contains("Nearby Request", StringComparison.Ordinal);
}
bool IsNearbyAcceptText(string? text)
{
if (string.IsNullOrEmpty(text)) return false;
return text.Contains("Nearby Accept", StringComparison.OrdinalIgnoreCase);
}
bool isAccept = IsNearbyAcceptText(msg.Title) || IsNearbyAcceptText(msg.Message);
if (isAccept)
return false;
bool isRequest = IsNearbyRequestText(msg.Title) || IsNearbyRequestText(msg.Message);
if (isRequest)
{
appendInstruction = !IsRequestSentConfirmation(msg);
return true;
}
return false;
}
private static bool IsRequestSentConfirmation(NotificationMessage msg)
{
if (string.Equals(msg.Title, "Nearby request sent", StringComparison.OrdinalIgnoreCase))
return true;
if (!string.IsNullOrEmpty(msg.Message) && msg.Message.Contains("The other user will receive a request notification.", StringComparison.OrdinalIgnoreCase))
return true;
return false;
}
private static string AppendUsyncInstruction(string? message)
{
const string suffix = " | Ouvrez /usync pour voir l'invitation.";
if (string.IsNullOrWhiteSpace(message))
return suffix.TrimStart(' ', '|');
if (message.Contains("/usync", StringComparison.OrdinalIgnoreCase))
return message;
return message.TrimEnd() + suffix;
}
private void ShowNotificationLocationBased(NotificationMessage msg, NotificationLocation location, bool forceChat)
{
bool showToast = location is NotificationLocation.Toast or NotificationLocation.Both;
bool showChat = forceChat || location is NotificationLocation.Chat or NotificationLocation.Both;
if (showToast)
{ {
case NotificationLocation.Toast:
ShowToast(msg); ShowToast(msg);
break; }
case NotificationLocation.Chat: if (showChat)
{
ShowChat(msg); ShowChat(msg);
break;
case NotificationLocation.Both:
ShowToast(msg);
ShowChat(msg);
break;
case NotificationLocation.Nowhere:
break;
} }
} }

View File

@@ -108,7 +108,7 @@ public class AutoDetectUi : WindowMediatorSubscriberBase
} }
else if (ImGui.Button($"Send request##{e.Name}")) else if (ImGui.Button($"Send request##{e.Name}"))
{ {
_ = _requestService.SendRequestAsync(e.Token!); _ = _requestService.SendRequestAsync(e.Token!, e.Uid, e.DisplayName);
} }
} }
} }

View File

@@ -0,0 +1,204 @@
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Reflection;
using Dalamud.Bindings.ImGui;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Utility.Raii;
using MareSynchronos.MareConfiguration;
using MareSynchronos.Services;
using MareSynchronos.Services.Mediator;
using Microsoft.Extensions.Logging;
namespace MareSynchronos.UI;
public sealed class ChangelogUi : WindowMediatorSubscriberBase
{
private const int AlwaysExpandedEntryCount = 2;
private readonly MareConfigService _configService;
private readonly UiSharedService _uiShared;
private readonly Version _currentVersion;
private readonly string _currentVersionLabel;
private readonly IReadOnlyList<ChangelogEntry> _entries;
private bool _showAllEntries;
private bool _hasAcknowledgedVersion;
public ChangelogUi(ILogger<ChangelogUi> logger, UiSharedService uiShared, MareConfigService configService,
MareMediator mediator, PerformanceCollectorService performanceCollectorService)
: base(logger, mediator, "Umbra Sync - Notes de version", performanceCollectorService)
{
_uiShared = uiShared;
_configService = configService;
_currentVersion = Assembly.GetExecutingAssembly().GetName().Version ?? new Version(0, 0, 0, 0);
_currentVersionLabel = _currentVersion.ToString();
_entries = BuildEntries();
_hasAcknowledgedVersion = string.Equals(_configService.Current.LastChangelogVersionSeen, _currentVersionLabel, StringComparison.Ordinal);
RespectCloseHotkey = true;
SizeConstraints = new()
{
MinimumSize = new(520, 360),
MaximumSize = new(900, 1200)
};
Flags |= ImGuiWindowFlags.NoResize;
ShowCloseButton = true;
if (!string.Equals(_configService.Current.LastChangelogVersionSeen, _currentVersionLabel, StringComparison.Ordinal))
{
IsOpen = true;
}
}
public override void OnClose()
{
MarkCurrentVersionAsReadIfNeeded();
base.OnClose();
}
protected override void DrawInternal()
{
_ = _uiShared.DrawOtherPluginState();
DrawHeader();
DrawEntries();
DrawFooter();
}
private void DrawHeader()
{
using (_uiShared.UidFont.Push())
{
ImGui.TextUnformatted("Notes de version");
}
ImGui.TextColored(ImGuiColors.DalamudGrey, $"Version chargée : {_currentVersionLabel}");
ImGui.Separator();
}
private void DrawEntries()
{
bool expandedOldVersions = false;
for (int index = 0; index < _entries.Count; index++)
{
var entry = _entries[index];
if (!_showAllEntries && index >= AlwaysExpandedEntryCount)
{
if (!expandedOldVersions)
{
expandedOldVersions = ImGui.CollapsingHeader("Historique complet");
}
if (!expandedOldVersions)
{
continue;
}
}
DrawEntry(entry);
}
}
private void DrawEntry(ChangelogEntry entry)
{
using (ImRaii.PushId(entry.VersionLabel))
{
ImGui.Spacing();
UiSharedService.ColorText(entry.VersionLabel, entry.Version == _currentVersion
? ImGuiColors.HealerGreen
: ImGuiColors.DalamudWhite);
ImGui.Spacing();
foreach (var line in entry.Lines)
{
DrawLine(line);
}
ImGui.Spacing();
ImGui.Separator();
}
}
private static void DrawLine(ChangelogLine line)
{
using var indent = line.IndentLevel > 0 ? ImRaii.PushIndent(line.IndentLevel) : null;
if (line.Color != null)
{
ImGui.TextColored(line.Color.Value, $"- {line.Text}");
}
else
{
ImGui.TextUnformatted($"- {line.Text}");
}
}
private void DrawFooter()
{
ImGui.Spacing();
if (!_showAllEntries && _entries.Count > AlwaysExpandedEntryCount)
{
if (ImGui.Button("Tout afficher"))
{
_showAllEntries = true;
}
ImGui.SameLine();
}
if (ImGui.Button("Marquer comme lu"))
{
MarkCurrentVersionAsReadIfNeeded();
IsOpen = false;
}
}
private void MarkCurrentVersionAsReadIfNeeded()
{
if (_hasAcknowledgedVersion)
return;
_configService.Current.LastChangelogVersionSeen = _currentVersionLabel;
_configService.Save();
_hasAcknowledgedVersion = true;
}
private static IReadOnlyList<ChangelogEntry> BuildEntries()
{
return new List<ChangelogEntry>
{
new(new Version(0, 1, 8, 2), "0.1.8.2", new List<ChangelogLine>
{
new("Détection Nearby : la liste rapide ne montre plus que les joueurs réellement invitables."),
new("Sont filtrés automatiquement les personnes refusées ou déjà appairées."),
new("Invitations Nearby : anti-spam de 5 minutes par personne, blocage 15 minutes après trois refus."),
new("Affichage : Correction de l'affichage des notes par défaut plutôt que de l'ID si disponible."),
new("Les notifications de blocage sont envoyées directement dans le tchat."),
new("Overlay DTR : affiche le nombre d'invitations Nearby disponibles dans le titre et l'infobulle."),
new("Poses Nearby : le filtre re-fonctionne avec vos notes locales pour retrouver les entrées correspondantes."),
}),
new(new Version(0, 1, 8, 1), "0.1.8.1", new List<ChangelogLine>
{
new("Correctif 'Vu sous' : l'infobulle affiche désormais le dernier personnage observé."),
new("Invitations AutoDetect : triées en tête de liste pour mieux les repérer."),
new("Invitations AutoDetect : conservées entre les redémarrages du plugin ou du jeu."),
new("Barre de statut serveur : couleur violette adoptée par défaut."),
}),
new(new Version(0, 1, 8, 0), "0.1.8.0", new List<ChangelogLine>
{
new("AutoDetect : détection automatique des joueurs Umbra autour de vous et propositions d'appairage."),
new("AutoDetect : désactivé par défaut pour préserver la confidentialité.", 1, ImGuiColors.DalamudGrey),
new("AutoDetect : activez-le dans 'Transfers' avec les options Nearby detection et Allow pair requests.", 1, ImGuiColors.DalamudGrey),
new("Syncshell temporaire : durée configurable de 1 h à 7 jours, expiration automatique."),
new("Syncshell permanente : possibilité de nommer et d'organiser vos groupes sur la durée."),
new("Interface : palette UmbraSync harmonisée et menus allégés pour l'usage RP."),
}),
};
}
private readonly record struct ChangelogEntry(Version Version, string VersionLabel, IReadOnlyList<ChangelogLine> Lines);
private readonly record struct ChangelogLine(string Text, int IndentLevel = 0, System.Numerics.Vector4? Color = null);
}

View File

@@ -471,9 +471,11 @@ public class CompactUi : WindowMediatorSubscriberBase
_uiSharedService.IconText(icon); _uiSharedService.IconText(icon);
if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) _nearbyOpen = !_nearbyOpen; if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) _nearbyOpen = !_nearbyOpen;
ImGui.SameLine(); ImGui.SameLine();
var onUmbra = _nearbyEntries?.Count(e => e.IsMatch) ?? 0; var onUmbra = _nearbyEntries?.Count(e => e.IsMatch && e.AcceptPairRequests && !string.IsNullOrEmpty(e.Token) && !IsAlreadyPairedQuickMenu(e)) ?? 0;
ImGui.TextUnformatted($"Nearby ({onUmbra})"); ImGui.TextUnformatted($"Nearby ({onUmbra})");
if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) _nearbyOpen = !_nearbyOpen; if (ImGui.IsItemClicked(ImGuiMouseButton.Left)) _nearbyOpen = !_nearbyOpen;
if (_nearbyOpen)
{
var btnWidth = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.UserPlus, "Nearby"); var btnWidth = _uiSharedService.GetIconTextButtonSize(FontAwesomeIcon.UserPlus, "Nearby");
var headerRight = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth(); var headerRight = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth();
ImGui.SameLine(); ImGui.SameLine();
@@ -483,57 +485,44 @@ public class CompactUi : WindowMediatorSubscriberBase
Mediator.Publish(new UiToggleMessage(typeof(AutoDetectUi))); Mediator.Publish(new UiToggleMessage(typeof(AutoDetectUi)));
} }
if (_nearbyOpen)
{
ImGui.Indent(); ImGui.Indent();
var nearby = _nearbyEntries == null var nearby = _nearbyEntries == null
? new List<Services.Mediator.NearbyEntry>() ? new List<Services.Mediator.NearbyEntry>()
: _nearbyEntries.Where(e => e.IsMatch) : _nearbyEntries.Where(e => e.IsMatch && e.AcceptPairRequests && !string.IsNullOrEmpty(e.Token) && !IsAlreadyPairedQuickMenu(e))
.OrderBy(e => e.Distance) .OrderBy(e => e.Distance)
.ToList(); .ToList();
if (nearby.Count == 0) if (nearby.Count == 0)
{ {
UiSharedService.ColorTextWrapped("Aucun joueur detecté.", ImGuiColors.DalamudGrey3); UiSharedService.ColorTextWrapped("Aucun nouveau joueur detecté.", ImGuiColors.DalamudGrey3);
} }
else else
{ {
foreach (var e in nearby) foreach (var e in nearby)
{ {
if (!e.AcceptPairRequests || string.IsNullOrEmpty(e.Token))
continue;
var name = e.DisplayName ?? e.Name; var name = e.DisplayName ?? e.Name;
ImGui.AlignTextToFramePadding(); ImGui.AlignTextToFramePadding();
ImGui.TextUnformatted(name); ImGui.TextUnformatted(name);
var right = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth(); var right = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth();
ImGui.SameLine(); ImGui.SameLine();
bool isPaired = false;
try
{
isPaired = _pairManager.DirectPairs.Any(p => string.Equals(p.UserData.UID, e.Uid, StringComparison.Ordinal));
}
catch
{
var key = (e.DisplayName ?? e.Name) ?? string.Empty;
isPaired = _pairManager.DirectPairs.Any(p => string.Equals(p.UserData.AliasOrUID, key, StringComparison.OrdinalIgnoreCase));
}
var statusButtonSize = _uiSharedService.GetIconButtonSize(FontAwesomeIcon.UserPlus); var statusButtonSize = _uiSharedService.GetIconButtonSize(FontAwesomeIcon.UserPlus);
ImGui.SetCursorPosX(right - statusButtonSize.X); ImGui.SetCursorPosX(right - statusButtonSize.X);
if (!e.AcceptPairRequests)
if (isPaired)
{
_uiSharedService.IconText(FontAwesomeIcon.Check, ImGuiColors.ParsedGreen);
UiSharedService.AttachToolTip("Déjà appairé");
}
else if (!e.AcceptPairRequests)
{ {
_uiSharedService.IconText(FontAwesomeIcon.Ban, ImGuiColors.DalamudGrey3); _uiSharedService.IconText(FontAwesomeIcon.Ban, ImGuiColors.DalamudGrey3);
UiSharedService.AttachToolTip("Les demandes sont désactivées pour ce joueur"); UiSharedService.AttachToolTip("Les demandes sont désactivées pour ce joueur");
} }
else if (!string.IsNullOrEmpty(e.Token)) else if (!string.IsNullOrEmpty(e.Token))
{
using (ImRaii.PushId(e.Token ?? e.Uid ?? e.Name ?? string.Empty))
{ {
if (_uiSharedService.IconButton(FontAwesomeIcon.UserPlus)) if (_uiSharedService.IconButton(FontAwesomeIcon.UserPlus))
{ {
_ = _autoDetectRequestService.SendRequestAsync(e.Token!); _ = _autoDetectRequestService.SendRequestAsync(e.Token!, e.Uid, e.DisplayName);
}
} }
UiSharedService.AttachToolTip("Envoyer une invitation d'apparaige"); UiSharedService.AttachToolTip("Envoyer une invitation d'apparaige");
} }
@@ -553,6 +542,27 @@ public class CompactUi : WindowMediatorSubscriberBase
ImGui.EndChild(); ImGui.EndChild();
} }
private bool IsAlreadyPairedQuickMenu(Services.Mediator.NearbyEntry entry)
{
try
{
if (!string.IsNullOrEmpty(entry.Uid))
{
if (_pairManager.DirectPairs.Any(p => string.Equals(p.UserData.UID, entry.Uid, StringComparison.Ordinal)))
return true;
}
var key = (entry.DisplayName ?? entry.Name) ?? string.Empty;
if (string.IsNullOrEmpty(key)) return false;
return _pairManager.DirectPairs.Any(p => string.Equals(p.UserData.AliasOrUID, key, StringComparison.OrdinalIgnoreCase));
}
catch
{
return false;
}
}
private void DrawServerStatus() private void DrawServerStatus()
{ {
var buttonSize = _uiSharedService.GetIconButtonSize(FontAwesomeIcon.Link); var buttonSize = _uiSharedService.GetIconButtonSize(FontAwesomeIcon.Link);

View File

@@ -6,6 +6,7 @@ using Dalamud.Interface;
using MareSynchronos.MareConfiguration; using MareSynchronos.MareConfiguration;
using MareSynchronos.MareConfiguration.Configurations; using MareSynchronos.MareConfiguration.Configurations;
using MareSynchronos.PlayerData.Pairs; using MareSynchronos.PlayerData.Pairs;
using MareSynchronos.Services.AutoDetect;
using MareSynchronos.Services.Mediator; using MareSynchronos.Services.Mediator;
using MareSynchronos.WebAPI; using MareSynchronos.WebAPI;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
@@ -41,12 +42,13 @@ public sealed class DtrEntry : IDisposable, IHostedService
private readonly ILogger<DtrEntry> _logger; private readonly ILogger<DtrEntry> _logger;
private readonly MareMediator _mareMediator; private readonly MareMediator _mareMediator;
private readonly PairManager _pairManager; private readonly PairManager _pairManager;
private readonly NearbyPendingService _nearbyPendingService;
private Task? _runTask; private Task? _runTask;
private string? _text; private string? _text;
private string? _tooltip; private string? _tooltip;
private Colors _colors; private Colors _colors;
public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, MareConfigService configService, MareMediator mareMediator, PairManager pairManager, ApiController apiController) public DtrEntry(ILogger<DtrEntry> logger, IDtrBar dtrBar, MareConfigService configService, MareMediator mareMediator, PairManager pairManager, ApiController apiController, NearbyPendingService nearbyPendingService)
{ {
_logger = logger; _logger = logger;
_dtrBar = dtrBar; _dtrBar = dtrBar;
@@ -55,6 +57,7 @@ public sealed class DtrEntry : IDisposable, IHostedService
_mareMediator = mareMediator; _mareMediator = mareMediator;
_pairManager = pairManager; _pairManager = pairManager;
_apiController = apiController; _apiController = apiController;
_nearbyPendingService = nearbyPendingService;
} }
public void Dispose() public void Dispose()
@@ -147,8 +150,9 @@ public sealed class DtrEntry : IDisposable, IHostedService
if (_apiController.IsConnected) if (_apiController.IsConnected)
{ {
var pairCount = _pairManager.GetVisibleUserCount(); var pairCount = _pairManager.GetVisibleUserCount();
var baseText = RenderDtrStyle(_configService.Current.DtrStyle, pairCount.ToString());
text = RenderDtrStyle(_configService.Current.DtrStyle, pairCount.ToString()); var pendingNearby = _nearbyPendingService.Pending.Count;
text = pendingNearby > 0 ? $"{baseText} ({pendingNearby})" : baseText;
if (pairCount > 0) if (pairCount > 0)
{ {
IEnumerable<string> visiblePairs; IEnumerable<string> visiblePairs;
@@ -165,12 +169,21 @@ public sealed class DtrEntry : IDisposable, IHostedService
.Select(x => string.Format("{0}", _configService.Current.PreferNoteInDtrTooltip ? x.GetNoteOrName() : x.PlayerName)); .Select(x => string.Format("{0}", _configService.Current.PreferNoteInDtrTooltip ? x.GetNoteOrName() : x.PlayerName));
} }
tooltip = $"Umbra: Connected{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}"; tooltip = $"Umbra: Connected";
if (pendingNearby > 0)
{
tooltip += $"{Environment.NewLine}Invitation en attente : {pendingNearby}";
}
tooltip += $"{Environment.NewLine}----------{Environment.NewLine}{string.Join(Environment.NewLine, visiblePairs)}";
colors = _configService.Current.DtrColorsPairsInRange; colors = _configService.Current.DtrColorsPairsInRange;
} }
else else
{ {
tooltip = "Umbra: Connected"; tooltip = "Umbra: Connected";
if (pendingNearby > 0)
{
tooltip += $"{Environment.NewLine}Invitation en attente : {pendingNearby}";
}
colors = _configService.Current.DtrColorsDefault; colors = _configService.Current.DtrColorsDefault;
} }
} }

View File

@@ -154,16 +154,15 @@ public class UidDisplayHandler
public (bool isUid, string text) GetPlayerText(Pair pair) public (bool isUid, string text) GetPlayerText(Pair pair)
{ {
// When the user is offline or not visible, always show the raw UID (no alias/note/character name) bool showUidInsteadOfName = ShowUidInsteadOfName(pair);
if (!pair.IsOnline || !pair.IsVisible) if (showUidInsteadOfName)
{ {
return (true, pair.UserData.UID); return (true, pair.UserData.UID);
} }
var textIsUid = true; var textIsUid = true;
bool showUidInsteadOfName = ShowUidInsteadOfName(pair);
string? playerText = _serverManager.GetNoteForUid(pair.UserData.UID); string? playerText = _serverManager.GetNoteForUid(pair.UserData.UID);
if (!showUidInsteadOfName && playerText != null) if (playerText != null)
{ {
if (string.IsNullOrEmpty(playerText)) if (string.IsNullOrEmpty(playerText))
{ {
@@ -179,7 +178,7 @@ public class UidDisplayHandler
playerText = pair.UserData.AliasOrUID; playerText = pair.UserData.AliasOrUID;
} }
if (_mareConfigService.Current.ShowCharacterNames && textIsUid && !showUidInsteadOfName) if (_mareConfigService.Current.ShowCharacterNames && textIsUid && pair.IsOnline && pair.IsVisible)
{ {
var name = pair.PlayerName; var name = pair.PlayerName;
if (name != null) if (name != null)
@@ -215,8 +214,11 @@ public class UidDisplayHandler
private bool ShowUidInsteadOfName(Pair pair) private bool ShowUidInsteadOfName(Pair pair)
{ {
_showUidForEntry.TryGetValue(pair.UserData.UID, out var showUidInsteadOfName); if (_showUidForEntry.TryGetValue(pair.UserData.UID, out var showUidInsteadOfName))
{
return showUidInsteadOfName; return showUidInsteadOfName;
} }
return false;
}
} }