add GroupForPairUi
This commit is contained in:
@@ -47,8 +47,9 @@ public class CompactUi : Window, IDisposable
|
||||
private string _lastAddedUserComment = string.Empty;
|
||||
|
||||
private readonly SelectGroupForPairUi _selectGroupForPairUi;
|
||||
private readonly SelectPairForGroupUi _selectPairsForGroupUi;
|
||||
private readonly PairGroupsUi _pairGroupsUi;
|
||||
|
||||
|
||||
public CompactUi(WindowSystem windowSystem,
|
||||
UiShared uiShared, Configuration configuration, ApiController apiController) : base("###MareSynchronosMainUI")
|
||||
{
|
||||
@@ -81,7 +82,8 @@ public class CompactUi : Window, IDisposable
|
||||
|
||||
groupPanel = new(this, uiShared, configuration, apiController);
|
||||
_selectGroupForPairUi = new(_tagHandler, configuration);
|
||||
_pairGroupsUi = new(_tagHandler, DrawPairedClient, apiController);
|
||||
_selectPairsForGroupUi = new(_tagHandler, configuration);
|
||||
_pairGroupsUi = new(_tagHandler, DrawPairedClient, apiController, _selectPairsForGroupUi);
|
||||
|
||||
SizeConstraints = new WindowSizeConstraints()
|
||||
{
|
||||
@@ -157,8 +159,9 @@ public class CompactUi : Window, IDisposable
|
||||
}
|
||||
ImGui.Separator();
|
||||
UiShared.DrawWithID("transfers", DrawTransfers);
|
||||
UiShared.DrawWithID("grouping-popup", () => _selectGroupForPairUi.Draw(ShowUidForEntry));
|
||||
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)
|
||||
@@ -318,7 +321,7 @@ public class CompactUi : Window, IDisposable
|
||||
var buttonSizes = pauseIconSize.Y + trashButtonSize.Y + barButtonSize.Y;
|
||||
var spacingX = ImGui.GetStyle().ItemSpacing.X;
|
||||
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiShared.GetWindowContentRegionWidth();
|
||||
|
||||
|
||||
|
||||
var textPos = originalY + pauseIconSize.Y / 2 - textSize.Y / 2;
|
||||
ImGui.SetCursorPosY(textPos);
|
||||
@@ -431,7 +434,7 @@ public class CompactUi : Window, IDisposable
|
||||
// Flyout Menu
|
||||
ImGui.SameLine(windowEndX - barButtonSize.X);
|
||||
ImGui.SetCursorPosY(originalY);
|
||||
|
||||
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
|
||||
{
|
||||
ImGui.OpenPopup("User Flyout Menu");
|
||||
@@ -450,8 +453,8 @@ public class CompactUi : Window, IDisposable
|
||||
{
|
||||
_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.CtrlPressed())
|
||||
|
||||
@@ -15,12 +15,14 @@ namespace MareSynchronos.UI.Components
|
||||
private readonly Action<ClientPairDto> _clientRenderFn;
|
||||
private readonly TagHandler _tagHandler;
|
||||
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;
|
||||
_tagHandler = tagHandler;
|
||||
_apiController = apiController;
|
||||
_selectGroupForPairUi = selectGroupForPairUi;
|
||||
}
|
||||
|
||||
public void Draw(List<ClientPairDto> availablePairs)
|
||||
@@ -74,13 +76,13 @@ namespace MareSynchronos.UI.Components
|
||||
{
|
||||
var allArePaused = availablePairsInThisTag.All(pair => pair.IsPaused);
|
||||
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 windowX = ImGui.GetWindowContentRegionMin().X;
|
||||
var windowWidth = UiShared.GetWindowContentRegionWidth();
|
||||
var spacingX = ImGui.GetStyle().ItemSpacing.X;
|
||||
|
||||
var buttonPauseOffset = windowX + windowWidth - trashButtonX - spacingX - pauseButtonX;
|
||||
var buttonPauseOffset = windowX + windowWidth - flyoutMenuX - spacingX - pauseButtonX;
|
||||
ImGui.SameLine(buttonPauseOffset);
|
||||
if (ImGuiComponents.IconButton(pauseButton))
|
||||
{
|
||||
@@ -107,13 +109,37 @@ namespace MareSynchronos.UI.Components
|
||||
UiShared.AttachToolTip($"Pause pairing with all pairs in {tag}");
|
||||
}
|
||||
|
||||
var buttonDeleteOffset = windowX + windowWidth - trashButtonX;
|
||||
var buttonDeleteOffset = windowX + windowWidth - flyoutMenuX;
|
||||
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)
|
||||
|
||||
@@ -6,150 +6,148 @@ using ImGuiNET;
|
||||
using MareSynchronos.API;
|
||||
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>
|
||||
/// Should the panel show, yes/no
|
||||
/// </summary>
|
||||
private bool _show;
|
||||
_show = false;
|
||||
_pair = null;
|
||||
_tagHandler = tagHandler;
|
||||
_configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Has the panel already been opened?
|
||||
/// This is used to prevent double opening
|
||||
/// </summary>
|
||||
private bool _opened;
|
||||
public void Open(ClientPairDto pair)
|
||||
{
|
||||
_pair = pair;
|
||||
// Using "_show" here to de-couple the opening of the popup
|
||||
// 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>
|
||||
/// 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)
|
||||
public void Draw(Dictionary<string, bool> showUidForEntry)
|
||||
{
|
||||
if (_pair == null)
|
||||
{
|
||||
_show = false;
|
||||
_pair = null;
|
||||
_tagHandler = tagHandler;
|
||||
_configuration = configuration;
|
||||
return;
|
||||
}
|
||||
|
||||
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;
|
||||
// Using "_show" here to de-couple the opening of the popup
|
||||
// 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;
|
||||
ImGui.OpenPopup(popupName);
|
||||
_opened = true;
|
||||
}
|
||||
|
||||
|
||||
public void Draw(Dictionary<string, bool> showUidForEntry)
|
||||
// Is the popup not supposed to show? Set _opened to false so we can re-open it.
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
UiShared.DrawWithID($"groups-pair-{_pair.OtherUID}-{tag}", () => DrawGroupName(_pair, tag));
|
||||
}
|
||||
|
||||
// Is the popup not supposed to show? Set _opened to false so we can re-open it.
|
||||
if (!_show)
|
||||
UiShared.FontText($"Create a new group for {name}.", UiBuilder.DefaultFont);
|
||||
if (ImGuiComponents.IconButton(FontAwesomeIcon.Plus))
|
||||
{
|
||||
_opened = false;
|
||||
HandleAddTag();
|
||||
}
|
||||
|
||||
if (ImGui.BeginPopupModal(popupName, ref _show, UiShared.PopupWindowFlags))
|
||||
ImGui.SameLine();
|
||||
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40);
|
||||
{
|
||||
UiShared.FontText($"Select the groups you want {name} to be in.", UiBuilder.DefaultFont);
|
||||
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))
|
||||
if (ImGui.IsKeyDown(ImGuiKey.Enter))
|
||||
{
|
||||
HandleAddTag();
|
||||
}
|
||||
ImGui.SameLine();
|
||||
ImGui.InputTextWithHint("##category_name", "New Group", ref _tagNameToAdd, 40);
|
||||
{
|
||||
if (ImGui.IsKeyDown(ImGuiKey.Enter))
|
||||
{
|
||||
HandleAddTag();
|
||||
}
|
||||
}
|
||||
UiShared.SetScaledWindowSize(375);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
UiShared.SetScaledWindowSize(375);
|
||||
ImGui.EndPopup();
|
||||
}
|
||||
else
|
||||
{
|
||||
_show = false;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
{
|
||||
_show = false;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
_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);
|
||||
if (_pair != null)
|
||||
{
|
||||
_tagHandler.AddTagToPairedUid(_pair, _tagNameToAdd);
|
||||
}
|
||||
_tagNameToAdd = string.Empty;
|
||||
_tagHandler.AddTagToPairedUid(_pair, _tagNameToAdd);
|
||||
}
|
||||
_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);
|
||||
_configuration.GetCurrentServerUidComments().TryGetValue(otherUid, out var playerText);
|
||||
if (showUidInsteadOfName)
|
||||
{
|
||||
playerText = otherUid;
|
||||
}
|
||||
else if (string.IsNullOrEmpty(playerText))
|
||||
{
|
||||
playerText = otherUid;
|
||||
}
|
||||
return playerText;
|
||||
playerText = otherUid;
|
||||
}
|
||||
|
||||
else if (string.IsNullOrEmpty(playerText))
|
||||
{
|
||||
playerText = otherUid;
|
||||
}
|
||||
return playerText;
|
||||
}
|
||||
}
|
||||
89
MareSynchronos/UI/Components/SelectPairForGroupUi.cs
Normal file
89
MareSynchronos/UI/Components/SelectPairForGroupUi.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user