Feature: Pair Categories (#35)

* Feature/pair categories re (#1)

Implemented pair categories:
- Paired users can now get tags
- Tags get rendered into the main UI as groups
- Tags are persistently stored on the local configuration

* Added multi-server capabilities and cleaned up code

- Tags and available tags are stored per API url
- Added a few tooltips

* Renamed both dictionary to reflect the fact that they are per-server dictionaries

* Swapped icons and no longer renders groups that are empty after filter
This commit is contained in:
Nia292
2023-01-22 10:21:36 +01:00
committed by GitHub
parent 05aa350c34
commit 115960262a
6 changed files with 529 additions and 19 deletions

View File

@@ -5,7 +5,6 @@ using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Reflection;
using System.Runtime.Serialization.Formatters;
using Dalamud.Interface;
using Dalamud.Interface.Colors;
using Dalamud.Interface.Components;
@@ -13,6 +12,8 @@ using Dalamud.Interface.Windowing;
using Dalamud.Utility;
using ImGuiNET;
using MareSynchronos.API;
using MareSynchronos.UI.Components;
using MareSynchronos.UI.Handlers;
using MareSynchronos.Utils;
using MareSynchronos.WebAPI;
@@ -22,6 +23,7 @@ public class CompactUi : Window, IDisposable
{
private readonly ApiController _apiController;
private readonly Configuration _configuration;
private readonly TagHandler _tagHandler;
public readonly Dictionary<string, bool> ShowUidForEntry = new(StringComparer.Ordinal);
private readonly UiShared _uiShared;
private readonly WindowSystem _windowSystem;
@@ -44,6 +46,9 @@ public class CompactUi : Window, IDisposable
private ClientPairDto? _lastAddedUser;
private string _lastAddedUserComment = string.Empty;
private readonly SelectGroupForPairUi _selectGroupForPairUi;
private readonly PairGroupsUi _pairGroupsUi;
public CompactUi(WindowSystem windowSystem,
UiShared uiShared, Configuration configuration, ApiController apiController) : base("###MareSynchronosMainUI")
{
@@ -72,8 +77,11 @@ public class CompactUi : Window, IDisposable
_uiShared = uiShared;
_configuration = configuration;
_apiController = apiController;
_tagHandler = new(_configuration);
groupPanel = new(this, uiShared, configuration, apiController);
_selectGroupForPairUi = new(_tagHandler, configuration);
_pairGroupsUi = new(_tagHandler, DrawPairedClient, apiController);
SizeConstraints = new WindowSizeConstraints()
{
@@ -149,6 +157,7 @@ public class CompactUi : Window, IDisposable
}
ImGui.Separator();
UiShared.DrawWithID("transfers", DrawTransfers);
UiShared.DrawWithID("grouping-popup", () => _selectGroupForPairUi.Draw(ShowUidForEntry));
TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight;
}
@@ -300,15 +309,18 @@ public class CompactUi : Window, IDisposable
private void DrawPairedClient(ClientPairDto entry)
{
var pauseIcon = entry.IsPaused ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause;
var buttonSize = UiShared.GetIconButtonSize(pauseIcon);
var pauseIconSize = UiShared.GetIconButtonSize(pauseIcon);
var trashButtonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Trash);
var barButtonSize = UiShared.GetIconButtonSize(FontAwesomeIcon.Bars);
var entryUID = string.IsNullOrEmpty(entry.VanityUID) ? entry.OtherUID : entry.VanityUID;
var textSize = ImGui.CalcTextSize(entryUID);
var originalY = ImGui.GetCursorPosY();
var buttonSizes = buttonSize.Y + trashButtonSize.Y;
var buttonSizes = pauseIconSize.Y + trashButtonSize.Y + barButtonSize.Y;
var spacingX = ImGui.GetStyle().ItemSpacing.X;
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth();
var textPos = originalY + buttonSize.Y / 2 - textSize.Y / 2;
var textPos = originalY + pauseIconSize.Y / 2 - textSize.Y / 2;
ImGui.SetCursorPosY(textPos);
if (!entry.IsSynced)
{
@@ -387,7 +399,7 @@ public class CompactUi : Window, IDisposable
{
ImGui.SetCursorPosY(originalY);
ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX() - buttonSizes - ImGui.GetStyle().ItemSpacing.X * 2);
ImGui.SetNextItemWidth(UiShared.GetWindowContentRegionWidth() - ImGui.GetCursorPosX() - buttonSizes - ImGui.GetStyle().ItemSpacing.X * 3);
if (ImGui.InputTextWithHint("", "Nick/Notes", ref EditUserComment, 255, ImGuiInputTextFlags.EnterReturnsTrue))
{
_configuration.SetCurrentServerUidComment(entry.OtherUID, EditUserComment);
@@ -402,20 +414,10 @@ public class CompactUi : Window, IDisposable
UiShared.AttachToolTip("Hit ENTER to save\nRight click to cancel");
}
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X);
ImGui.SetCursorPosY(originalY);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash))
{
if (UiShared.CtrlPressed())
{
_ = _apiController.UserRemovePair(entry.OtherUID);
}
}
UiShared.AttachToolTip("Hold CTRL and click to unpair permanently from " + entryUID);
// Pause Button
if (entry.IsSynced)
{
ImGui.SameLine(ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth() - buttonSize.X - ImGui.GetStyle().ItemSpacing.X - trashButtonSize.X);
ImGui.SameLine(windowEndX - barButtonSize.X - spacingX - pauseIconSize.X);
ImGui.SetCursorPosY(originalY);
if (ImGuiComponents.IconButton(pauseIcon))
{
@@ -425,6 +427,39 @@ public class CompactUi : Window, IDisposable
? "Pause pairing with " + entryUID
: "Resume pairing with " + entryUID);
}
// Flyout Menu
ImGui.SameLine(windowEndX - barButtonSize.X);
ImGui.SetCursorPosY(originalY);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
{
ImGui.OpenPopup("User Flyout Menu");
}
if (ImGui.BeginPopup("User Flyout Menu"))
{
UiShared.DrawWithID($"buttons-{entry.OtherUID}", () => DrawPairedClientMenu(entry));
ImGui.EndPopup();
}
}
private void DrawPairedClientMenu(ClientPairDto entry)
{
var entryUID = string.IsNullOrEmpty(entry.VanityUID) ? entry.OtherUID : entry.VanityUID;
if (UiShared.IconTextButton(FontAwesomeIcon.Folder, "Pair Groups"))
{
_selectGroupForPairUi.Open(entry);
}
UiShared.AttachToolTip("Chose pair groups for " + entryUID);
if (UiShared.IconTextButton(FontAwesomeIcon.Trash, "Unpair Permanently"))
{
if (UiShared.CtrlPressed())
{
_ = _apiController.UserRemovePair(entry.OtherUID);
}
}
UiShared.AttachToolTip("Hold CTRL and click to unpair permanently from " + entryUID);
}
private void DrawPairList()
@@ -446,7 +481,10 @@ public class CompactUi : Window, IDisposable
if (_configuration.ReverseUserSort) users = users.Reverse();
ImGui.BeginChild("list", new Vector2(_windowContentWidth, ySize), false);
foreach (var entry in users.ToList())
var allAvailablePairs = users.ToList();
var pairsWithoutTags = allAvailablePairs.Where(pair => !_tagHandler.HasAnyTag(pair));
_pairGroupsUi.Draw(allAvailablePairs);
foreach (var entry in pairsWithoutTags)
{
UiShared.DrawWithID(entry.OtherUID, () => DrawPairedClient(entry));
}