Merge pull request #85 from MikeMatrix/main

Implement a hacky way of grouping Fixed Designs by character
This commit is contained in:
Ottermandias 2023-06-11 00:19:55 +02:00 committed by GitHub
commit 79d2c63ddb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,10 +19,14 @@ namespace Glamourer.Gui
private JobGroup? _newFixDesignGroup;
private Design? _newFixDesign;
private int _fixDragDropIdx = -1;
private readonly HashSet<string> _openNames = new();
private static unsafe bool IsDropping()
=> ImGui.AcceptDragDropPayload(FixDragDropLabel).NativePtr != null;
private static string NormalizeIdentifier(string value)
=> value.Replace(" ", "_").Replace("#", "_");
private void DrawFixedDesignsTab()
{
_newFixDesignGroup ??= _plugin.FixedDesigns.JobGroups[1];
@ -43,14 +47,60 @@ namespace Glamourer.Gui
var buttonWidth = 23.5f * ImGuiHelpers.GlobalScale;
ImGui.TableSetupColumn("##DeleteColumn", ImGuiTableColumnFlags.WidthFixed, 2 * buttonWidth);
ImGui.TableSetupColumn("Character", ImGuiTableColumnFlags.WidthFixed, 200 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("Jobs", ImGuiTableColumnFlags.WidthFixed, 175 * ImGuiHelpers.GlobalScale);
ImGui.TableSetupColumn("Design", ImGuiTableColumnFlags.WidthStretch);
ImGui.TableHeadersRow();
var xPos = 0f;
var grouping = new Dictionary<string, List<int>>();
for (var i = 0; i < _fullPathCache.Count; ++i)
{
var name = _plugin.FixedDesigns.Data[i].Name;
grouping.TryAdd(name, new List<int>());
grouping[name].Add(i);
}
var xPos = 0f;
foreach (var (groupedName, indices) in grouping.OrderBy(kvp => kvp.Key))
{
ImGui.TableNextRow();
ImGui.TableNextColumn();
raii.PushStyle(ImGuiStyleVar.ItemSpacing, ImGui.GetStyle().ItemSpacing / 2);
raii.PushFont(UiBuilder.IconFont);
var isOpen = _openNames.Contains(groupedName);
var groupIcon = isOpen ? FontAwesomeIcon.CaretDown : FontAwesomeIcon.CaretRight;
if (ImGui.Button($"{groupIcon.ToIconChar()}##group_{NormalizeIdentifier(groupedName)}"))
{
if (isOpen)
{
_openNames.Remove(groupedName);
} else
{
_openNames.Add(groupedName);
}
return;
}
raii.PopStyles();
raii.PopFonts();
ImGui.SameLine();
xPos = ImGui.GetCursorPosX();
ImGui.TableNextColumn();
ImGui.Text(groupedName);
if (!_openNames.Contains(groupedName))
{
ImGui.TableNextRow();
continue;
}
foreach (var i in indices)
{
var path = _fullPathCache[i];
var name = _plugin.FixedDesigns.Data[i];
@ -61,7 +111,7 @@ namespace Glamourer.Gui
raii.PushFont(UiBuilder.IconFont);
if (ImGui.Button($"{FontAwesomeIcon.Trash.ToIconChar()}##{i}"))
{
_fullPathCache.RemoveAt(i--);
_fullPathCache.RemoveAt(i);
_plugin.FixedDesigns.Remove(name);
continue;
}
@ -108,6 +158,9 @@ namespace Glamourer.Gui
ImGui.Text(path);
}
ImGui.TableNextRow();
}
ImGui.TableNextRow();
ImGui.TableNextColumn();
raii.PushFont(UiBuilder.IconFont);