add GroupForPairUi

This commit is contained in:
rootdarkarchon
2023-01-22 11:32:41 +01:00
parent 115960262a
commit 4da73f2368
4 changed files with 241 additions and 125 deletions

View File

@@ -47,8 +47,9 @@ public class CompactUi : Window, IDisposable
private string _lastAddedUserComment = string.Empty; private string _lastAddedUserComment = string.Empty;
private readonly SelectGroupForPairUi _selectGroupForPairUi; private readonly SelectGroupForPairUi _selectGroupForPairUi;
private readonly SelectPairForGroupUi _selectPairsForGroupUi;
private readonly PairGroupsUi _pairGroupsUi; private readonly PairGroupsUi _pairGroupsUi;
public CompactUi(WindowSystem windowSystem, public CompactUi(WindowSystem windowSystem,
UiShared uiShared, Configuration configuration, ApiController apiController) : base("###MareSynchronosMainUI") UiShared uiShared, Configuration configuration, ApiController apiController) : base("###MareSynchronosMainUI")
{ {
@@ -81,7 +82,8 @@ public class CompactUi : Window, IDisposable
groupPanel = new(this, uiShared, configuration, apiController); groupPanel = new(this, uiShared, configuration, apiController);
_selectGroupForPairUi = new(_tagHandler, configuration); _selectGroupForPairUi = new(_tagHandler, configuration);
_pairGroupsUi = new(_tagHandler, DrawPairedClient, apiController); _selectPairsForGroupUi = new(_tagHandler, configuration);
_pairGroupsUi = new(_tagHandler, DrawPairedClient, apiController, _selectPairsForGroupUi);
SizeConstraints = new WindowSizeConstraints() SizeConstraints = new WindowSizeConstraints()
{ {
@@ -157,8 +159,9 @@ public class CompactUi : Window, IDisposable
} }
ImGui.Separator(); ImGui.Separator();
UiShared.DrawWithID("transfers", DrawTransfers); UiShared.DrawWithID("transfers", DrawTransfers);
UiShared.DrawWithID("grouping-popup", () => _selectGroupForPairUi.Draw(ShowUidForEntry));
TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight; TransferPartHeight = ImGui.GetCursorPosY() - TransferPartHeight;
UiShared.DrawWithID("group-user-popup", () => _selectPairsForGroupUi.Draw(_apiController.PairedClients, ShowUidForEntry));
UiShared.DrawWithID("grouping-popup", () => _selectGroupForPairUi.Draw(ShowUidForEntry));
} }
if (_configuration.OpenPopupOnAdd && _apiController.LastAddedUser != null) if (_configuration.OpenPopupOnAdd && _apiController.LastAddedUser != null)
@@ -318,7 +321,7 @@ public class CompactUi : Window, IDisposable
var buttonSizes = pauseIconSize.Y + trashButtonSize.Y + barButtonSize.Y; var buttonSizes = pauseIconSize.Y + trashButtonSize.Y + barButtonSize.Y;
var spacingX = ImGui.GetStyle().ItemSpacing.X; var spacingX = ImGui.GetStyle().ItemSpacing.X;
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth(); var windowEndX = ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth();
var textPos = originalY + pauseIconSize.Y / 2 - textSize.Y / 2; var textPos = originalY + pauseIconSize.Y / 2 - textSize.Y / 2;
ImGui.SetCursorPosY(textPos); ImGui.SetCursorPosY(textPos);
@@ -431,7 +434,7 @@ public class CompactUi : Window, IDisposable
// Flyout Menu // Flyout Menu
ImGui.SameLine(windowEndX - barButtonSize.X); ImGui.SameLine(windowEndX - barButtonSize.X);
ImGui.SetCursorPosY(originalY); ImGui.SetCursorPosY(originalY);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars)) if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
{ {
ImGui.OpenPopup("User Flyout Menu"); ImGui.OpenPopup("User Flyout Menu");
@@ -450,8 +453,8 @@ public class CompactUi : Window, IDisposable
{ {
_selectGroupForPairUi.Open(entry); _selectGroupForPairUi.Open(entry);
} }
UiShared.AttachToolTip("Chose pair groups for " + entryUID); UiShared.AttachToolTip("Choose pair groups for " + entryUID);
if (UiShared.IconTextButton(FontAwesomeIcon.Trash, "Unpair Permanently")) if (UiShared.IconTextButton(FontAwesomeIcon.Trash, "Unpair Permanently"))
{ {
if (UiShared.CtrlPressed()) if (UiShared.CtrlPressed())

View File

@@ -15,12 +15,14 @@ namespace MareSynchronos.UI.Components
private readonly Action<ClientPairDto> _clientRenderFn; private readonly Action<ClientPairDto> _clientRenderFn;
private readonly TagHandler _tagHandler; private readonly TagHandler _tagHandler;
private readonly ApiController _apiController; private readonly ApiController _apiController;
private readonly SelectPairForGroupUi _selectGroupForPairUi;
public PairGroupsUi(TagHandler tagHandler, Action<ClientPairDto> clientRenderFn, ApiController apiController) public PairGroupsUi(TagHandler tagHandler, Action<ClientPairDto> clientRenderFn, ApiController apiController, SelectPairForGroupUi selectGroupForPairUi)
{ {
_clientRenderFn = clientRenderFn; _clientRenderFn = clientRenderFn;
_tagHandler = tagHandler; _tagHandler = tagHandler;
_apiController = apiController; _apiController = apiController;
_selectGroupForPairUi = selectGroupForPairUi;
} }
public void Draw(List<ClientPairDto> availablePairs) public void Draw(List<ClientPairDto> availablePairs)
@@ -74,13 +76,13 @@ namespace MareSynchronos.UI.Components
{ {
var allArePaused = availablePairsInThisTag.All(pair => pair.IsPaused); var allArePaused = availablePairsInThisTag.All(pair => pair.IsPaused);
var pauseButton = allArePaused ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause; var pauseButton = allArePaused ? FontAwesomeIcon.Play : FontAwesomeIcon.Pause;
var trashButtonX = UiShared.GetIconButtonSize(FontAwesomeIcon.Trash).X; var flyoutMenuX = UiShared.GetIconButtonSize(FontAwesomeIcon.Bars).X;
var pauseButtonX = UiShared.GetIconButtonSize(pauseButton).X; var pauseButtonX = UiShared.GetIconButtonSize(pauseButton).X;
var windowX = ImGui.GetWindowContentRegionMin().X; var windowX = ImGui.GetWindowContentRegionMin().X;
var windowWidth = UiShared.GetWindowContentRegionWidth(); var windowWidth = UiShared.GetWindowContentRegionWidth();
var spacingX = ImGui.GetStyle().ItemSpacing.X; var spacingX = ImGui.GetStyle().ItemSpacing.X;
var buttonPauseOffset = windowX + windowWidth - trashButtonX - spacingX - pauseButtonX; var buttonPauseOffset = windowX + windowWidth - flyoutMenuX - spacingX - pauseButtonX;
ImGui.SameLine(buttonPauseOffset); ImGui.SameLine(buttonPauseOffset);
if (ImGuiComponents.IconButton(pauseButton)) if (ImGuiComponents.IconButton(pauseButton))
{ {
@@ -107,13 +109,37 @@ namespace MareSynchronos.UI.Components
UiShared.AttachToolTip($"Pause pairing with all pairs in {tag}"); UiShared.AttachToolTip($"Pause pairing with all pairs in {tag}");
} }
var buttonDeleteOffset = windowX + windowWidth - trashButtonX; var buttonDeleteOffset = windowX + windowWidth - flyoutMenuX;
ImGui.SameLine(buttonDeleteOffset); ImGui.SameLine(buttonDeleteOffset);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Trash)) if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
{ {
_tagHandler.RemoveTag(tag); ImGui.OpenPopup("Group Flyout Menu");
} }
UiShared.AttachToolTip($"Delete Group {tag} (Will not delete the pairs)");
if (ImGui.BeginPopup("Group Flyout Menu"))
{
UiShared.DrawWithID($"buttons-{tag}", () => DrawGroupMenu(tag));
ImGui.EndPopup();
}
}
private void DrawGroupMenu(string tag)
{
if (UiShared.IconTextButton(FontAwesomeIcon.Users, "Add people to " + tag))
{
_selectGroupForPairUi.Open(tag);
}
UiShared.AttachToolTip($"Add more users to Group {tag}");
if (UiShared.IconTextButton(FontAwesomeIcon.Trash, "Delete " + tag))
{
if (UiShared.CtrlPressed())
{
_tagHandler.RemoveTag(tag);
}
}
UiShared.AttachToolTip($"Delete Group {tag} (Will not delete the pairs)" + Environment.NewLine + "Hold CTRL to delete");
} }
private void DrawPairs(string tag, List<ClientPairDto> availablePairsInThisCategory) private void DrawPairs(string tag, List<ClientPairDto> availablePairsInThisCategory)

View File

@@ -6,150 +6,148 @@ using ImGuiNET;
using MareSynchronos.API; using MareSynchronos.API;
using MareSynchronos.UI.Handlers; using MareSynchronos.UI.Handlers;
namespace MareSynchronos.UI.Components namespace MareSynchronos.UI.Components;
public class SelectGroupForPairUi
{ {
public class SelectGroupForPairUi /// <summary>
/// Should the panel show, yes/no
/// </summary>
private bool _show;
/// <summary>
/// Has the panel already been opened?
/// This is used to prevent double opening
/// </summary>
private bool _opened;
/// <summary>
/// The group UI is always open for a specific pair. This defines which pair the UI is open for.
/// </summary>
/// <returns></returns>
private ClientPairDto? _pair;
/// <summary>
/// For the add category option, this stores the currently typed in tag name
/// </summary>
private string _tagNameToAdd = "";
private readonly TagHandler _tagHandler;
private readonly Configuration _configuration;
public SelectGroupForPairUi(TagHandler tagHandler, Configuration configuration)
{ {
/// <summary> _show = false;
/// Should the panel show, yes/no _pair = null;
/// </summary> _tagHandler = tagHandler;
private bool _show; _configuration = configuration;
}
/// <summary> public void Open(ClientPairDto pair)
/// Has the panel already been opened? {
/// This is used to prevent double opening _pair = pair;
/// </summary> // Using "_show" here to de-couple the opening of the popup
private bool _opened; // The popup name is derived from the name the user currently sees, which is
// based on the showUidForEntry dictionary.
// We'd have to derive the name here to open it popup modal here, when the Open() is called
_show = true;
}
/// <summary>
/// The group UI is always open for a specific pair. This defines which pair the UI is open for.
/// </summary>
/// <returns></returns>
private ClientPairDto? _pair;
/// <summary> public void Draw(Dictionary<string, bool> showUidForEntry)
/// For the add category option, this stores the currently typed in tag name {
/// </summary> if (_pair == null)
private string _tagNameToAdd = "";
private readonly TagHandler _tagHandler;
private readonly Configuration _configuration;
public SelectGroupForPairUi(TagHandler tagHandler, Configuration configuration)
{ {
_show = false; return;
_pair = null;
_tagHandler = tagHandler;
_configuration = configuration;
} }
public void Open(ClientPairDto pair) var name = PairName(showUidForEntry, _pair.OtherUID);
var popupName = $"Choose Groups for {name}";
// Is the popup supposed to show but did not open yet? Open it
if (_show && !_opened)
{ {
_pair = pair; ImGui.OpenPopup(popupName);
// Using "_show" here to de-couple the opening of the popup _opened = true;
// The popup name is derived from the name the user currently sees, which is
// based on the showUidForEntry dictionary.
// We'd have to derive the name here to open it popup modal here, when the Open() is called
_show = true;
} }
// Is the popup not supposed to show? Set _opened to false so we can re-open it.
public void Draw(Dictionary<string, bool> showUidForEntry) if (!_show)
{ {
if (_pair == null) _opened = false;
}
if (ImGui.BeginPopupModal(popupName, ref _show, UiShared.PopupWindowFlags))
{
UiShared.FontText($"Select the groups you want {name} to be in.", UiBuilder.DefaultFont);
foreach (var tag in _tagHandler.GetAllTagsSorted())
{ {
return; UiShared.DrawWithID($"groups-pair-{_pair.OtherUID}-{tag}", () => DrawGroupName(_pair, tag));
}
var name = PairName(showUidForEntry, _pair.OtherUID);
var popupName = $"Chose Groups for {name}";
// Is the popup supposed to show but did not open yet? Open it
if (_show && !_opened)
{
ImGui.OpenPopup(popupName);
_opened = true;
} }
// Is the popup not supposed to show? Set _opened to false so we can re-open it. UiShared.FontText($"Create a new group for {name}.", UiBuilder.DefaultFont);
if (!_show) if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
{ {
_opened = false; HandleAddTag();
} }
ImGui.SameLine();
if (ImGui.BeginPopupModal(popupName, ref _show, UiShared.PopupWindowFlags)) ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40);
{ {
UiShared.FontText($"Select the groups you want {name} to be in.", UiBuilder.DefaultFont); if (ImGui.IsKeyDown(ImGuiKey.Enter))
foreach (var tag in _tagHandler.GetAllTagsSorted())
{
UiShared.DrawWithID($"groups-pair-{_pair.OtherUID}-{tag}", () => DrawGroupName(_pair, tag));
}
UiShared.FontText($"Create a new group for {name}.", UiBuilder.DefaultFont);
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
{ {
HandleAddTag(); HandleAddTag();
} }
ImGui.SameLine(); }
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40); UiShared.SetScaledWindowSize(375);
{ ImGui.EndPopup();
if (ImGui.IsKeyDown(ImGuiKey.Enter)) }
{ else
HandleAddTag(); {
} _show = false;
} }
UiShared.SetScaledWindowSize(375); }
ImGui.EndPopup();
private void DrawGroupName(ClientPairDto pair, string name)
{
bool hasTagBefore = _tagHandler.HasTag(pair, name);
bool hasTag = hasTagBefore;
if (ImGui.Checkbox(name, ref hasTag))
{
if (hasTag)
{
_tagHandler.AddTagToPairedUid(pair, name);
} }
else else
{ {
_show = false; _tagHandler.RemoveTagFromPairedUid(pair, name);
}
}
private void DrawGroupName(ClientPairDto pair, string name)
{
bool hasTagBefore = _tagHandler.HasTag(pair, name);
bool hasTag = hasTagBefore;
if (ImGui.Checkbox(name, ref hasTag))
{
if (hasTag)
{
_tagHandler.AddTagToPairedUid(pair, name);
}
else
{
_tagHandler.RemoveTagFromPairedUid(pair, name);
}
} }
} }
}
private void HandleAddTag() private void HandleAddTag()
{
if (!_tagNameToAdd.IsNullOrWhitespace())
{ {
if (!_tagNameToAdd.IsNullOrWhitespace()) _tagHandler.AddTag(_tagNameToAdd);
if (_pair != null)
{ {
_tagHandler.AddTag(_tagNameToAdd); _tagHandler.AddTagToPairedUid(_pair, _tagNameToAdd);
if (_pair != null)
{
_tagHandler.AddTagToPairedUid(_pair, _tagNameToAdd);
}
_tagNameToAdd = string.Empty;
} }
_tagNameToAdd = string.Empty;
} }
}
private string PairName(Dictionary<string, bool> showUidForEntry, string otherUid) private string PairName(Dictionary<string, bool> showUidForEntry, string otherUid)
{
showUidForEntry.TryGetValue(otherUid, out var showUidInsteadOfName);
_configuration.GetCurrentServerUidComments().TryGetValue(otherUid, out var playerText);
if (showUidInsteadOfName)
{ {
showUidForEntry.TryGetValue(otherUid, out var showUidInsteadOfName); playerText = otherUid;
_configuration.GetCurrentServerUidComments().TryGetValue(otherUid, out var playerText);
if (showUidInsteadOfName)
{
playerText = otherUid;
}
else if (string.IsNullOrEmpty(playerText))
{
playerText = otherUid;
}
return playerText;
} }
else if (string.IsNullOrEmpty(playerText))
{
playerText = otherUid;
}
return playerText;
} }
} }

View File

@@ -0,0 +1,89 @@
using System.Collections.Generic;
using System.Linq;
using Dalamud.Interface;
using ImGuiNET;
using MareSynchronos.API;
using MareSynchronos.UI.Handlers;
namespace MareSynchronos.UI.Components;
public class SelectPairForGroupUi
{
private bool _show = false;
private bool _opened = false;
private HashSet<string> _peopleInGroup = new(System.StringComparer.Ordinal);
private string _tag = string.Empty;
private readonly TagHandler _tagHandler;
private readonly Configuration _configuration;
public SelectPairForGroupUi(TagHandler tagHandler, Configuration configuration)
{
_tagHandler = tagHandler;
_configuration = configuration;
}
public void Open(string tag)
{
_peopleInGroup = _tagHandler.GetOtherUidsForTag(tag);
_tag = tag;
_show = true;
}
public void Draw(List<ClientPairDto> pairs, Dictionary<string, bool> showUidForEntry)
{
var popupName = $"Choose Users for Group {_tag}";
if (!_show)
{
_opened = false;
}
if (_show && !_opened)
{
ImGui.SetWindowSize(new System.Numerics.Vector2(300, 400));
ImGui.OpenPopup(popupName);
_opened = true;
}
if (ImGui.BeginPopupModal(popupName, ref _show))
{
UiShared.FontText($"Select users for group {_tag}", UiBuilder.DefaultFont);
foreach (var item in pairs.OrderBy(p => string.IsNullOrEmpty(p.VanityUID) ? p.OtherUID : p.VanityUID, System.StringComparer.OrdinalIgnoreCase).ToList())
{
var isInGroup = _peopleInGroup.Contains(item.OtherUID);
if (ImGui.Checkbox(PairName(showUidForEntry, item.OtherUID), ref isInGroup))
{
if (isInGroup)
{
_tagHandler.AddTagToPairedUid(item, _tag);
_peopleInGroup.Add(item.OtherUID);
}
else
{
_tagHandler.RemoveTagFromPairedUid(item, _tag);
_peopleInGroup.Remove(item.OtherUID);
}
}
}
}
else
{
_show = false;
}
}
private string PairName(Dictionary<string, bool> showUidForEntry, string otherUid)
{
showUidForEntry.TryGetValue(otherUid, out var showUidInsteadOfName);
_configuration.GetCurrentServerUidComments().TryGetValue(otherUid, out var playerText);
if (showUidInsteadOfName)
{
playerText = otherUid;
}
else if (string.IsNullOrEmpty(playerText))
{
playerText = otherUid;
}
return playerText;
}
}