split individual ui to visible/group/online/offline

This commit is contained in:
Stanley Dimant
2023-01-30 10:35:49 +01:00
parent d218d06230
commit 246dbeb9b6
5 changed files with 47 additions and 79 deletions

Submodule MareAPI updated: 7c5bf39c31...f604e6d27e

View File

@@ -554,40 +554,6 @@ public class CompactUi : Window, IDisposable
_pairGroupsUi.Draw(visibleUsers, onlineUsers, offlineUsers);
visibleUsers = visibleUsers.Where(pair => !_tagHandler.HasAnyTag(pair.UserPair!)).ToList();
onlineUsers = onlineUsers.Where(pair => !_tagHandler.HasAnyTag(pair.UserPair!)).ToList();
offlineUsers = offlineUsers.Where(pair => !_tagHandler.HasAnyTag(pair.UserPair!)).ToList();
if (visibleUsers.Any())
{
ImGui.Text("Visible");
ImGui.Separator();
foreach (var entry in visibleUsers)
{
UiShared.DrawWithID(entry.UserData.UID, () => DrawPairedClient(entry));
}
}
if (onlineUsers.Any())
{
ImGui.Text("Online");
ImGui.Separator();
foreach (var entry in onlineUsers)
{
UiShared.DrawWithID(entry.UserData.UID, () => DrawPairedClient(entry));
}
}
if (offlineUsers.Any())
{
ImGui.Text("Offline/Unknown");
ImGui.Separator();
foreach (var entry in offlineUsers)
{
UiShared.DrawWithID(entry.UserData.UID, () => DrawPairedClient(entry));
}
}
ImGui.EndChild();
}

View File

@@ -28,59 +28,54 @@ namespace MareSynchronos.UI.Components
// Only render those tags that actually have pairs in them, otherwise
// we can end up with a bunch of useless pair groups
var tagsWithPairsInThem = _tagHandler.GetAllTagsSorted();
UiShared.DrawWithID("$group-VisibleCustomTag", () => DrawCategory(TagHandler.CustomVisibleTag, visibleUsers));
foreach (var tag in tagsWithPairsInThem)
{
UiShared.DrawWithID($"group-{tag}", () => DrawCategory(tag, visibleUsers, onlineUsers, offlineUsers));
UiShared.DrawWithID($"group-{tag}", () => DrawCategory(tag, onlineUsers));
}
UiShared.DrawWithID($"group-OnlineCustomTag", () => DrawCategory(TagHandler.CustomOnlineTag, onlineUsers.Where(u => !_tagHandler.HasAnyTag(u.UserPair!)).ToList()));
UiShared.DrawWithID($"group-OfflineCustomTag", () => DrawCategory(TagHandler.CustomOfflineTag, offlineUsers));
}
public void DrawCategory(string tag, List<Pair> visibleUsers, List<Pair> onlineUsers, List<Pair> offlineUsers)
private void DrawCategory(string tag, List<Pair> users)
{
var otherUidsTaggedWithTag = _tagHandler.GetOtherUidsForTag(tag);
var visiblePairsInThisTag = visibleUsers
.Where(pair => otherUidsTaggedWithTag.Contains(pair.UserData.UID))
.ToList();
var onlinePairsInThisTag = onlineUsers
.Where(pair => otherUidsTaggedWithTag.Contains(pair.UserData.UID))
.ToList();
var offlinePairsInThisTag = offlineUsers
.Where(pair => otherUidsTaggedWithTag.Contains(pair.UserData.UID))
.ToList();
if (visiblePairsInThisTag.Any() || onlinePairsInThisTag.Any() || offlinePairsInThisTag.Any())
List<Pair> usersInThisTag;
HashSet<string>? otherUidsTaggedWithTag = null;
if (tag is TagHandler.CustomOfflineTag or TagHandler.CustomOnlineTag or TagHandler.CustomVisibleTag)
{
DrawName(tag);
UiShared.DrawWithID($"group-{tag}-buttons", () => DrawButtons(tag, visiblePairsInThisTag.Concat(onlinePairsInThisTag).Concat(offlinePairsInThisTag).ToList()));
if (_tagHandler.IsTagOpen(tag))
{
ImGui.Indent(20);
if (visiblePairsInThisTag.Any())
{
ImGui.Text("Visible");
ImGui.Separator();
DrawPairs(tag, visiblePairsInThisTag);
}
if (onlinePairsInThisTag.Any())
{
ImGui.Text("Online");
ImGui.Separator();
DrawPairs(tag, onlinePairsInThisTag);
}
if (offlinePairsInThisTag.Any())
{
ImGui.Text("Offline/Unknown");
ImGui.Separator();
DrawPairs(tag, offlinePairsInThisTag);
}
ImGui.Unindent(20);
}
usersInThisTag = users;
}
else
{
otherUidsTaggedWithTag = _tagHandler.GetOtherUidsForTag(tag);
usersInThisTag = users
.Where(pair => otherUidsTaggedWithTag.Contains(pair.UserData.UID))
.ToList();
}
if (!usersInThisTag.Any()) return;
DrawName(tag, usersInThisTag.Count, otherUidsTaggedWithTag?.Count);
UiShared.DrawWithID($"group-{tag}-buttons", () => DrawButtons(tag, usersInThisTag));
if (!_tagHandler.IsTagOpen(tag)) return;
ImGui.Indent(20);
DrawPairs(tag, usersInThisTag);
ImGui.Unindent(20);
}
private void DrawName(string tag)
private void DrawName(string tag, int count, int? total)
{
var resultFolderName = $"{tag}";
string displayedName = tag switch
{
TagHandler.CustomOfflineTag => "Offline/Unknown",
TagHandler.CustomOnlineTag => "Online",
TagHandler.CustomVisibleTag => "Visible",
_ => tag
};
string resultFolderName = total != null ? $"{displayedName} ({count}/{total} Pairs)" : $"{displayedName} ({count} Pairs)";
// FontAwesomeIcon.CaretSquareDown : FontAwesomeIcon.CaretSquareRight
var icon = _tagHandler.IsTagOpen(tag) ? FontAwesomeIcon.CaretSquareDown : FontAwesomeIcon.CaretSquareRight;

View File

@@ -115,7 +115,7 @@ public class SelectGroupForPairUi
private void HandleAddTag()
{
if (!_tagNameToAdd.IsNullOrWhitespace())
if (!_tagNameToAdd.IsNullOrWhitespace() && _tagNameToAdd is not (TagHandler.CustomOfflineTag or TagHandler.CustomOnlineTag or TagHandler.CustomVisibleTag))
{
_tagHandler.AddTag(_tagNameToAdd);
if (_pair != null)
@@ -124,6 +124,10 @@ public class SelectGroupForPairUi
}
_tagNameToAdd = string.Empty;
}
else
{
_tagNameToAdd = string.Empty;
}
}
private string PairName(Dictionary<string, bool> showUidForEntry, Pair pair)

View File

@@ -6,6 +6,9 @@ namespace MareSynchronos.UI.Handlers
public class TagHandler
{
private readonly ServerConfigurationManager _serverConfigurationManager;
public const string CustomVisibleTag = "Mare_Visible";
public const string CustomOnlineTag = "Mare_Online";
public const string CustomOfflineTag = "Mare_Offline";
public TagHandler(ServerConfigurationManager serverConfigurationManager)
{