120 lines
3.6 KiB
C#
120 lines
3.6 KiB
C#
using Dalamud.Interface;
|
|
using Dalamud.Interface.Components;
|
|
using Dalamud.Interface.Utility;
|
|
using Dalamud.Interface.Utility.Raii;
|
|
using ImGuiNET;
|
|
using MareSynchronos.PlayerData.Pairs;
|
|
using MareSynchronos.UI.Handlers;
|
|
using System.Collections.Immutable;
|
|
|
|
namespace MareSynchronos.UI.Components;
|
|
|
|
public abstract class DrawFolderBase : IDrawFolder
|
|
{
|
|
public IImmutableList<DrawUserPair> DrawPairs { get; init; }
|
|
protected readonly string _id;
|
|
protected readonly IImmutableList<Pair> _allPairs;
|
|
protected readonly TagHandler _tagHandler;
|
|
private float _menuWidth = -1;
|
|
public int OnlinePairs => DrawPairs.Count(u => u.Pair.IsOnline);
|
|
public int TotalPairs => _allPairs.Count;
|
|
|
|
protected DrawFolderBase(string id, IImmutableList<DrawUserPair> drawPairs,
|
|
IImmutableList<Pair> allPairs, TagHandler tagHandler)
|
|
{
|
|
_id = id;
|
|
DrawPairs = drawPairs;
|
|
_allPairs = allPairs;
|
|
_tagHandler = tagHandler;
|
|
}
|
|
|
|
protected abstract bool RenderIfEmpty { get; }
|
|
protected abstract bool RenderMenu { get; }
|
|
|
|
public void Draw()
|
|
{
|
|
if (!RenderIfEmpty && !DrawPairs.Any()) return;
|
|
|
|
using var id = ImRaii.PushId("folder_" + _id);
|
|
|
|
// draw opener
|
|
var icon = _tagHandler.IsTagOpen(_id) ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight;
|
|
|
|
ImGui.AlignTextToFramePadding();
|
|
|
|
UiSharedService.NormalizedIcon(icon);
|
|
if (ImGui.IsItemClicked())
|
|
{
|
|
_tagHandler.SetTagOpen(_id, !_tagHandler.IsTagOpen(_id));
|
|
}
|
|
|
|
ImGui.SameLine();
|
|
var leftSideEnd = DrawIcon();
|
|
|
|
ImGui.SameLine();
|
|
var rightSideStart = DrawRightSideInternal();
|
|
|
|
// draw name
|
|
ImGui.SameLine(leftSideEnd);
|
|
DrawName(rightSideStart - leftSideEnd);
|
|
ImGui.Separator();
|
|
|
|
// if opened draw content
|
|
if (_tagHandler.IsTagOpen(_id))
|
|
{
|
|
using var indent = ImRaii.PushIndent(20f);
|
|
if (DrawPairs.Any())
|
|
{
|
|
foreach (var item in DrawPairs)
|
|
{
|
|
item.DrawPairedClient();
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ImGui.TextUnformatted("No users (online)");
|
|
}
|
|
|
|
ImGui.Separator();
|
|
}
|
|
}
|
|
|
|
protected abstract float DrawIcon();
|
|
|
|
protected abstract void DrawMenu(float menuWidth);
|
|
|
|
protected abstract void DrawName(float width);
|
|
|
|
protected abstract float DrawRightSide(float currentRightSideX);
|
|
|
|
private float DrawRightSideInternal()
|
|
{
|
|
var barButtonSize = UiSharedService.GetIconButtonSize(FontAwesomeIcon.Bars);
|
|
var spacingX = ImGui.GetStyle().ItemSpacing.X;
|
|
var windowEndX = ImGui.GetWindowContentRegionMin().X + UiSharedService.GetWindowContentRegionWidth();
|
|
|
|
// Flyout Menu
|
|
var rightSideStart = windowEndX - (RenderMenu ? (barButtonSize.X + spacingX) : spacingX);
|
|
|
|
if (RenderMenu)
|
|
{
|
|
ImGui.SameLine(windowEndX - barButtonSize.X);
|
|
if (ImGuiComponents.IconButton(FontAwesomeIcon.Bars))
|
|
{
|
|
ImGui.OpenPopup("User Flyout Menu");
|
|
}
|
|
if (ImGui.BeginPopup("User Flyout Menu"))
|
|
{
|
|
using (ImRaii.PushId($"buttons-{_id}")) DrawMenu(_menuWidth);
|
|
_menuWidth = ImGui.GetWindowContentRegionMax().X - ImGui.GetWindowContentRegionMin().X;
|
|
ImGui.EndPopup();
|
|
}
|
|
else
|
|
{
|
|
_menuWidth = 0;
|
|
}
|
|
}
|
|
|
|
return DrawRightSide(rightSideStart);
|
|
}
|
|
} |