optimized syncshell join UI with recently joined tracking and removing unknown broadcasters from the table

This commit is contained in:
choco
2025-10-05 15:29:21 +02:00
parent c82c633513
commit f31a139a3e

View File

@@ -29,6 +29,7 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
private readonly List<GroupJoinDto> _nearbySyncshells = [];
private List<GroupFullInfoDto> _currentSyncshells = [];
private int _selectedNearbyIndex = -1;
private readonly HashSet<string> _recentlyJoined = new(StringComparer.Ordinal);
private GroupJoinDto? _joinDto;
private GroupJoinInfoDto? _joinInfo;
@@ -120,6 +121,17 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
foreach (var shell in _nearbySyncshells)
{
// Check if there is an active broadcast for this syncshell, if not, skipping this syncshell
var broadcast = _broadcastScannerService.GetActiveSyncshellBroadcasts()
.FirstOrDefault(b => string.Equals(b.GID, shell.Group.GID, StringComparison.Ordinal));
if (broadcast == null)
continue; // no active broadcasts
var (Name, Address) = _dalamudUtilService.FindPlayerByNameHash(broadcast.HashedCID);
if (string.IsNullOrEmpty(Name))
continue; // broadcaster not found in area, skipping
ImGui.TableNextRow();
ImGui.TableNextColumn();
@@ -127,19 +139,8 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
ImGui.TextUnformatted(displayName);
ImGui.TableNextColumn();
var broadcasterName = "Unknown";
var broadcast = _broadcastScannerService.GetActiveSyncshellBroadcasts()
.FirstOrDefault(b => string.Equals(b.GID, shell.Group.GID, StringComparison.Ordinal));
if (broadcast != null)
{
var (Name, Address) = _dalamudUtilService.FindPlayerByNameHash(broadcast.HashedCID);
if (!string.IsNullOrEmpty(Name))
{
var worldName = _dalamudUtilService.GetWorldNameFromPlayerAddress(Address);
broadcasterName = !string.IsNullOrEmpty(worldName) ? $"{Name} ({worldName})" : Name;
}
}
var worldName = _dalamudUtilService.GetWorldNameFromPlayerAddress(Address);
var broadcasterName = !string.IsNullOrEmpty(worldName) ? $"{Name} ({worldName})" : Name;
ImGui.TextUnformatted(broadcasterName);
ImGui.TableNextColumn();
@@ -149,7 +150,10 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, UIColors.Get("LightlessGreen").WithAlpha(0.85f));
ImGui.PushStyleColor(ImGuiCol.ButtonActive, UIColors.Get("LightlessGreen").WithAlpha(0.75f));
if (!_currentSyncshells.Exists(g => string.Equals(g.GID, shell.GID, StringComparison.Ordinal)))
var isAlreadyMember = _currentSyncshells.Exists(g => string.Equals(g.GID, shell.GID, StringComparison.Ordinal));
var isRecentlyJoined = _recentlyJoined.Contains(shell.GID);
if (!isAlreadyMember && !isRecentlyJoined)
{
if (ImGui.Button(label))
{
@@ -224,9 +228,11 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
finalPermissions.SetDisableVFX(_ownPermissions.DisableGroupVFX);
_ = _apiController.GroupJoinFinalize(new GroupJoinDto(_joinDto.Group, _joinDto.Password, finalPermissions));
_recentlyJoined.Add(_joinDto.Group.GID);
_joinDto = null;
_joinInfo = null;
_ = RefreshSyncshellsAsync();
}
}
}
@@ -261,6 +267,8 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
{
var syncshellBroadcasts = _broadcastScannerService.GetActiveSyncshellBroadcasts();
_currentSyncshells = [.. _pairManager.GroupPairs.Select(g => g.Key)];
_recentlyJoined.RemoveWhere(gid => _currentSyncshells.Any(s => string.Equals(s.GID, gid, StringComparison.Ordinal)));
if (syncshellBroadcasts.Count == 0)
{
@@ -284,11 +292,6 @@ public class SyncshellFinderUI : WindowMediatorSubscriberBase
if (updatedList != null)
{
var newGids = updatedList.Select(s => s.Group.GID).ToHashSet(StringComparer.Ordinal);
if (currentGids.SetEquals(newGids))
return;
var previousGid = GetSelectedGid();
_nearbySyncshells.Clear();